Openstex v0.4.0 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

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

Link to this function account_info(account) View Source
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()
Link to this function container_info(container, account) View Source
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()
Link to this function create_container(container, account, opts \\ []) View Source
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 created
  • account: account of user accessing swift service
  • opts:

    • read_acl: headers for the container read access control list.

    • Examples:

      1. For giving public read access: [read_acl: ".r:*" ], note: .r: can be any of .ref:, .referer:, or .referrer:.
      2. For giving a *.some_website.com read access: [read_acl: ".r:.some_website.com"]
      3. For giving a user accountread access, [read_acl: user_account]
      4. See Swift Docs for more examples
      5. For giving write access and list access: [read_acl: ".r:*,.rlistings"]
    • write_acl: headers for the container write access control list. Note: For X-Container-Write referrers are not supported.

    • Examples:

      1. For giving write access to a user account: [write_acl: "user_account"]
    • headers: other metadata headers to be applied to the container.

    • Examples:

    1. 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 include X-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()
Link to this function create_object(container, account, client_object_pathname, opts \\ []) View Source
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 to
  • account: 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 the client_object_pathname if none given.
    • multipart_manifest: Defaults to :false. If :true, adds multipart-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 the X-Object-Manifest header. 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.
Link to this function delete_container(container, account) View Source
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)
Link to this function delete_object(server_object, container, account) View Source
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)
Link to this function get_object(server_object, container, account, opts \\ []) View Source
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 server
  • container: The container of the object in the server
  • account: The account accessing the object
  • opts:

    • headers: Additional headers metadata in the request. Eg [headers: [{"If-None-Match", "<local_file_md5>"}], this example would return 304 if the local file md5 was the same as the object etag on the server.
Link to this function get_objects(container, account) View Source
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()
Link to this function get_objects_in_folder(pseudofolder \\ "", container, account) View Source
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 and Openstex.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)
Link to this function modify_container(container, account, opts \\ []) View Source
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 created
  • account: account of user accessing swift service
  • opts:

    • read_acl: headers for the container read access control list.

    • Examples:

      1. For giving public read access: [read_acl: ".r:*" ]
      2. For giving a *.some_website.com read access: [read_acl: ".r:.some_website.com"]
      3. For giving a user accountread access, [read_acl: user_account]
      4. See Swift Docs for more examples
      5. For giving write access and list access: [read_acl: ".r:*,.rlistings"]
    • write_acl: headers for the container write access control list.

    • Example:

      1. For giving write access to a user account: [write_acl: "user_account"]
    • headers: other metadata headers to be applied to the container.

    • Examples:

    1. 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 include X-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()