SwiftClient
Small but powerful client to interact with OpenStack Swift.
Installation
Add this line to your application's Gemfile:
gem 'swift_client'
And then execute:
$ bundle
Or install it yourself as:
$ gem install swift_client
Usage
First, connect to a Swift cluster:
swift_client = SwiftClient.new(
:auth_url => "https://example.com/auth/v1.0",
:username => "account:username",
:api_key => "api key",
:temp_url_key => "temp url key",
:storage_url => "https://example.com/v1/AUTH_account"
)
To connect via v2 you have to add version and method specific details:
swift_client = SwiftClient.new(
:auth_url => "https://auth.example.com/v2.0",
:storage_url => "https://storage.example.com/v1/AUTH_account",
:tenant_name => "tenant",
:username => "username",
:password => "password"
)
# OR
swift_client = SwiftClient.new(
:auth_url => "https://auth.example.com/v2.0",
:storage_url => "https://storage.example.com/v1/AUTH_account",
:tenant_name => "tenant",
:access_key => "access key",
:secret_key => "secret key"
)
To connect via v3:
swift_client = SwiftClient.new(
:auth_url => "https://auth.example.com/v3",
:storage_url => "https://storage.example.com/v1/AUTH_account",
:username => "username",
:password => "password",
:user_domain => "example.com" # :user_domain_id => "..." is valid as well
)
# OR
# project scoped authentication
swift_client = SwiftClient.new(
:auth_url => "https://auth.example.com/v3",
:username => "username",
:password => "password",
:user_domain => "example.com", # :user_domain_id => "..." is valid as well
:project_id => "p-123456", # :project_name => "..." is valid as well
:project_domain_id => "d-123456" # :project_domain_name => "..." is valid as well
)
# OR
# domain scoped authentication
swift_client = SwiftClient.new(
:auth_url => "https://auth.example.com/v3",
:username => "username",
:password => "password",
:user_domain => "example.com", # :user_domain_id => "..." is valid as well
:domain_id => "d-123456" # :domain_name => "..." is valid as well
)
# OR
swift_client = SwiftClient.new(
:auth_url => "https://auth.example.com/v3",
:storage_url => "https://storage.example.com/v1/AUTH_account",
:user_id => "user id",
:password => "password"
)
# OR
swift_client = SwiftClient.new(
:auth_url => "https://auth.example.com/v3",
:storage_url => "https://storage.example.com/v1/AUTH_account",
:token => "token"
)
where temp_url_key
and storage_url
are optional.
SwiftClient will automatically reconnect in case the endpoint responds with 401
Unauthorized to one of your requests using the provided credentials. In case
the endpoint does not respond with 2xx to any of SwiftClient's requests,
SwiftClient will raise a SwiftClient::ResponseError
. Otherwise, SwiftClient
responds with an HTTParty::Response
object, such that you can call #headers
to access the response headers or #body
as well as #parsed_response
to
access the response body and JSON response. Checkout the
HTTParty gem to learn more.
SwiftClient offers the following requests:
- head_account -> HTTParty::Response
- post_account(headers = {}) -> HTTParty::Response
- head_containers -> HTTParty::Response
- get_containers(query = {}) -> HTTParty::Response
- paginate_containers(query = {}) -> Enumerator
- get_container(container_name, query = {}) -> HTTParty::Response
- paginate_container(container_name, query = {}) -> Enumerator
- head_container(container_name) -> HTTParty::Response
- put_container(container_name, headers = {}) -> HTTParty::Response
- post_container(container_name, headers = {}) -> HTTParty::Response
- delete_container(container_name) -> HTTParty::Response
- put_object(object_name, data_or_io, container_name, headers = {}) -> HTTParty::Response
- post_object(object_name, container_name, headers = {}) -> HTTParty::Response
- get_object(object_name, container_name) -> HTTParty::Response
- head_object(object_name, container_name) -> HTTParty::Response
- delete_object(object_name, container_name) -> HTTParty::Response
- get_objects(container_name, query = {}) -> HTTParty::Response
- paginate_objects(container_name, query = {}) -> Enumerator
- public_url(object_name, container_name) -> HTTParty::Response
- temp_url(object_name, container_name, options = {}) -> HTTParty::Response
- bulk_delete(entries) -> entries
bulk_delete
Takes an array containing container_name/object_name entries. Automatically slices and sends 1_000 items per request.
Contributing
- Fork it ( https://github.com/mrkamel/swift_client/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request