Skip to main content

Swift

OpenStack Swift service support.

This service will visit the Swift API supported by OpenStack Object Storage.

Capabilities

This service can be used to:

  • stat
  • read
  • write
  • create_dir
  • delete
  • copy
  • rename
  • list
  • scan
  • presign
  • blocking

Configurations

  • endpoint: Set the endpoint for backend.
  • account_name: Name of Swift account.
  • container: Swift container.
  • token: Swift personal access token.

Refer to [Builder]'s public API docs for more information.

Examples

Via Builder

use std::sync::Arc;

use anyhow::Result;
use opendal::services::Swift;
use opendal::Operator;

#[tokio::main]
async fn main() -> Result<()> {
// Create Swift backend builder
let mut builder = Swift::default();

// Set the root for swift, all operations will happen under this root
builder.root("/path/to/dir");
// set the endpoint of Swift backend
builder.endpoint("https://openstack-controller.example.com:8080");
// set the account name of Swift workspace
builder.account_name("account");
// set the container name of Swift workspace
builder.container("container");
// set the auth token for builder
builder.token("token");

let op: Operator = Operator::new(builder)?.finish();

Ok(())
}

Via Config

use anyhow::Result;
use opendal::Operator;
use opendal::Scheme;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<()> {
let mut map = HashMap::new();
map.insert("endpoint".to_string(), "http://127.0.0.1:8080".to_string());
map.insert("account".to_string(), "test_account".to_string());
map.insert("container".to_string(), "test_container".to_string());
map.insert("token".to_string(), "test_token".to_string());
map.insert("root".to_string(), "/".to_string());

let op: Operator = Operator::via_map(Scheme::Swift, map)?;
Ok(())
}