Openstex v0.4.1 Openstex.Swift.V1 View Source
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()
Link to this section 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
Link to this section Functions
account_info(String.t()) :: HTTPipe.Conn.t()
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()
container_info(String.t(), String.t()) :: HTTPipe.Conn.t()
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.comread 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-Writereferrers are not supported.Examples:
- For giving write access to a user account:
[write_acl: "user_account"]
- For giving write access to a 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_pathnameif none given.multipart_manifest: Defaults to:false. If:true, addsmultipart-manifest=putto the query string. This option should be set to:truewhen 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-Manifestheader. The format used should be[x_object_manifest: "container/myobject/"].chunked_transfer: Defaults to:false, if:true, set theTransfer-Encodingtochunked. -content_type: Defaults to:false, otherwise changes theContent-Typeheader, 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-Typeheader, theX-Detect-Content-Typeheader 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 theETagheader of the file. Enhances upload integrity. If set to:false, theETagheader will be excluded. -content_disposition: Defaults to:false. Otherwise theContent-Dispositionheader can be changed from the default browser behaviourinlineto another value. Eg[content_disposition: “attachment; my_file.pdf”]-delete_after: Defaults to:false. Otherwise theX-Delete-Afterheader 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 theETagheader 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_container(String.t(), String.t()) :: HTTPipe.Conn.t()
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 return304if the local file md5 was the same as the object etag on the server.
get_objects(String.t(), String.t()) :: HTTPipe.Conn.t()
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/2andOpenstex.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.comread 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"]
- For giving write access to a 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()