Skip to main content

Swift

OpenStack Swift and compatible services support.

For more information about swift-compatible services, refer to Compatible Services.

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.
  • container: Swift container.
  • token: Swift personal access token.

Refer to [SwiftBuilder]'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/v1/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/v1/AUTH_test".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(())
}

Compatible Services

OpenStack Swift

OpenStack Swift is the default implementations of swift services.

To connect to OpenStack Swift, we need to set:

  • endpoint: The endpoint of OpenStack Swift, for example: http://127.0.0.1:8080/v1/AUTH_test.
  • container: The name of OpenStack Swift container.
  • token: OpenStack Swift container personal access token.
builder.endpoint("http://127.0.0.1:8080/v1/AUTH_test");
builder.container("container");
builder.token("token");

endpoint is the full URL that serves as the access point to all containers under an OpenStack Swift account. It represents the entry point for accessing the resources of the account. Alongside endpoint, token is used as a credential to verify the user's identity and authorize access to the relevant resources. Both endpoint and token can be obtained through OpenStack Swift authentication service.

endpoint consists of server address and port, API version, authenticated account ID. For instance, it might appear as follows:

  • http://127.0.0.1:8080/v1/AUTH_test.
  • http://192.168.66.88:8080/swift/v1.
  • https://openstack-controller.example.com:8080/v1/account.

Please note that the exact format of endpoint may vary depending on the deployment configuration and version of swift services. Users can refer to the specific services documentation for the correct endpoint format and authentication method.

For more information, refer:

Ceph Rados Gateway

Ceph Rados Gateway supports a RESTful API that is compatible with the basic data access model of OpenStack Swift API.

To connect to Ceph Rados Gateway, we need to set:

  • endpoint: The endpoint of swift services, for example: http://127.0.0.1:8080/swift/v1.
  • container: The name of swift container.
  • token: swift container personal access token.
builder.endpoint("http://127.0.0.1:8080/swift/v1");
builder.container("container");
builder.token("token");

For more information, refer: