Openstex v0.3.4 Openstex.Swift.V1
Helper functions to assist in building requests for openstack compatible swift apis.
Builds a request in a format that subsequently is easily modified. The request may ultimately be sent to
an openstack/swift compliant api with a library such as :hackney
. See
ex_hubic for an example implementation.
Example
client = Client.Swift
account = client.swift().get_account()
Openstex.Swift.V1.account_info(account) |> ExOvh.request()
Summary
Functions
Get account details and containers for given account
Get information about the container
Create a new container
Create or replace an object (file)
Delete a container
Delete an Object (Delete a file)
Get/Download a specific object (file)
List objects in a container
List all objects and psuedofolders in a psuedofolder for a given container
Modify a container. See docs for possible changes to container metadata which are achieved by sending changes in the request headers
Functions
Get account details and containers for given account.
Api
GET /v1/{account}
Example
as implemented a client from the ExOvh
library
client = Client.Swift
account = client.swift().get_account()
Openstex.Swift.V1.account_info(account) |> client.request()
Get information about the container
Api
DELETE /v1/{account}/{container}
Example
as implemented a client from the ExOvh
library
client = Client.Swift
account = client.swift().get_account()
query = Openstex.Swift.V1.container_info("new_container", account) |> client.request()
create_container(String.t, String.t, Keyword.t) :: HTTPipe.Conn.t
Create a new container.
Api
PUT /v1/{account}/{container}
Arguments
container
: name of the container to be createdaccount
: account of user accessing swift serviceopts
:read_acl
: headers for the container read access control list.Examples:
- For giving public read access:
[read_acl: ".r:*" ]
, note:.r:
can be any of.ref:
,.referer:
, or.referrer:
. - For giving a
*.some_website.com
read access:[read_acl: ".r:.some_website.com"]
- For giving a user accountread access, [read_acl:
user_account
] - See Swift Docs for more examples
- For giving write access and list access:
[read_acl: ".r:*,.rlistings"]
- For giving public read access:
write_acl
: headers for the container write access control list. Note: ForX-Container-Write
referrers are not supported.Examples:
For giving write access to a user account:
[write_acl: "user_account"]
headers
: other metadata headers to be applied to the container.Examples:
Appying changes to the CORS restrictions for a container. eg:
[headers: [{"X-Container-Meta-Access-Control-Allow-Origin", "http://localhost:4000"}]]
# allowed origins to make cross-origin requests.[headers: [{"X-Container-Meta-Access-Control-Max-Age", "1000"}]]
# validity of preflight requests in seconds. Other CORS headers includeX-Container-Meta-Access-Control-Allow-Headers
,X-Container-Meta-Access-Control-Expose-Headers
Example
as implemented a client from the ExOvh
library
client = Client.Swift
account = client.swift().get_account()
Openstex.Swift.V1.create_container("new_container", account) |> client.request()
create_object(String.t, String.t, String.t, list) :: HTTPipe.Conn.t | File.posix
Create or replace an object (file).
Api
PUT /v1/{account}/{container}/{object}
Example
as implemented a client from the ExOvh
library
client = Client.Swift
account = client.swift().get_account()
container = "new_container"
object_name = "client_file.txt"
client_object_pathname = Kernel.to_string(:code.priv_dir(:openstex)) <> "/" <> object_name
Openstex.Swift.V1.create_object(container, account, client_object_pathname, [server_object: "server_file.txt"])
|> client.request(query)
Arguments
container
: container to upload the file toaccount
: account uploading the file.client_object_pathname
: path of the file being uploaded.opts
:server_object
: filename under which the file will be stored on the openstack object storage server. defaults to theclient_object_pathname
if none given.multipart_manifest
: Defaults to:false
. If:true
, addsmultipart-manifest=put
to the query string. This option should be set to:true
when uploading the manifest for a large static object.x_object_manifest
: Relevant to dynamic upload of large objects. Defaults to:false
. If set, modifies theX-Object-Manifest
header. The format used should be[x_object_manifest: "container/myobject/"]
.chunked_transfer
: Defaults to:false
, if:true, set the
Transfer-Encodingto
chunked`.content_type
: Defaults to:false
, otherwise changes theContent-Type
header, which changes the MIME type for the object. Eg,[content_type: "image/jpeg"]
x_detect_content_type
: Defaults to:false
, otherwise changes theX-Detect-Content-Type
header, theX-Detect-Content-Type
header will be ignored and the actual file MIME type will be autodetected. Eg,[x_detect_content_type: :true]
e_tag
: Defaults to:true
, if:true
, sets theETag
header of the file. Enhances upload integrity. If set to:false
, theETag
header will be excluded.content_disposition
: Defaults to:false
. Otherwise theContent-Disposition
header can be changed from the default browser behaviourinline
to another value. Eg[content_disposition: "attachment; my_file.pdf"]
delete_after
: Defaults to:false
. Otherwise theX-Delete-After
header can be added so that the object is deleted after n seconds. Eg[delete_after: (24 * 60 * 60)]
will delete the object in 1 day.e_tag
: Defaults to:true
, if:true
, sets theETag
header of the file. Enhances upload integrity. If set to:false
, theETag
header will be excluded.
Notes
See the openstack docs for more information relating to object uploads and large object uploads. For uploading large objects, the operation typically involves multiple queries so a Helper function is planned for large uploads. Large objects are categorized as those over 5GB in size. There are two ways of uploading large files - dynamic uploads and static uploads. See here for more information.
Delete a container
Api
DELETE /v1/{account}/{container}
Example
as implemented a client from the ExOvh
library
client = Client.Swift
account = client.swift().get_account()
Openstex.Swift.V1.delete_container("new_container", account) |> client.request(query)
delete_object(String.t, String.t, String.t) :: HTTPipe.Conn.t
Delete an Object (Delete a file)
Api
DELETE /v1/{account}/{container}/{object}
Example
as implemented a client from the ExOvh
library
client = Client.Swift
account = client.swift().get_account()
container = "new_container"
server_object = "server_file.txt"
Openstex.Swift.V1.delete_object(server_object, container, account, server_object) |> client.request(query)
get_object(String.t, String.t, String.t, Keyword.t) :: HTTPipe.Conn.t
Get/Download a specific object (file)
Api
GET /v1/{account}/{container}/{object}
Example
as implemented a client from the ExOvh
library
client = Client.Swift
account = client.swift().get_account()
server_object = "server_file.txt"
container = "new_container"
Openstex.Swift.V1.get_object(server_object, container, account) |> client.request(query)
Arguments
server_object
: The path name of the object in the servercontainer
: The container of the object in the serveraccount
: The account accessing the objectopts
:headers
: Additional headers metadata in the request. Eg[headers: [{"If-None-Match", "<local_file_md5>"}]
, this example would return304
if the local file md5 was the same as the object etag on the server.
List objects in a container
Api
GET /v1/{account}/{container}
Example
as implemented a client from the ExOvh
library
client = Client.Swift
account = client.swift().get_account()
Openstex.Swift.V1.get_objects("new_container", account) |> client.request()
get_objects_in_folder(String.t, String.t, String.t) :: HTTPipe.Conn.t
List all objects and psuedofolders in a psuedofolder for a given container.
Api
GET /v1/{account}/{container}?prefix=pseudofolder&delimiter=/
Notes
- Query for only the top level objects and pseudofolders
- Query execution will not return nested objects and pseudofolders
- In order to view nested objects and pseudofolders, the function should be called recursively. See
Openstex.Helpers.list_pseudofolders_recursively/2
andOpenstex.Helpers.list_all_objects/3
.
Example
as implemented a client from the ExOvh
library
client = Client.Swift
account = client.swift().get_account()
Openstex.Swift.V1.get_objects_in_folder("test_folder/", "default", account) |> client.request(query)
modify_container(String.t, String.t, Keyword.t) :: HTTPipe.Conn.t
Modify a container. See docs for possible changes to container metadata which are achieved by sending changes in the request headers.
Api
POST /v1/{account}/{container}
Arguments
container
: name of the container to be createdaccount
: account of user accessing swift serviceopts
:read_acl
: headers for the container read access control list.Examples:
- For giving public read access:
[read_acl: ".r:*" ]
- For giving a
*.some_website.com
read access:[read_acl: ".r:.some_website.com"]
- For giving a user accountread access, [read_acl:
user_account
] - See Swift Docs for more examples
- For giving write access and list access:
[read_acl: ".r:*,.rlistings"]
- For giving public read access:
write_acl
: headers for the container write access control list.Example:
For giving write access to a user account:
[write_acl: "user_account"]
headers
: other metadata headers to be applied to the container.Examples:
Appying changes to the CORS restrictions for a container. eg:
[headers: [{"X-Container-Meta-Access-Control-Allow-Origin", "http://localhost:4000"}]]
# allowed origins to make cross-origin requests.[headers: [{"X-Container-Meta-Access-Control-Max-Age", "1000"}]]
# validity of preflight requests in seconds. Other CORS headers includeX-Container-Meta-Access-Control-Allow-Headers
,X-Container-Meta-Access-Control-Expose-Headers
Example
as implemented a client from the ExOvh
library
client = Client.Swift
account = client.swift().get_account()
headers = []
Openstex.Swift.V1.modify_container("new_container", account, headers) |> client.request()