Skip to content

EdmondFrank/elixir_bce_sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ElixirBceSdk

Baidu Could Storage SDK for Elixir

Support

  • BOS

    • Bucket API
    • Object API
    • Coming soon
  • BCM

    • get_metric_data
    • put_metric_data
  • Coming soon

Installation

If available in Hex, the package can be installed by adding elixir_bce_sdk to your list of dependencies in mix.exs:

def deps do
  [
    {:elixir_bce_sdk, "~> 0.2"}
  ]
end

Then run $ mix deps.get

  • Config the BOS Credentials
# config/config.exs

config :elixir_bce_sdk,
    access_key_id: "<your access_key_id>",
    secret_access_key: "<your secret_access_key>",
    bos_endpoint: "<bos endpoint (eg: su.bcebos.com)>",
    bcm_user_id: "<bcm user id>",
    bcm_endpoint: "<bcm endpoint (eg: bcm.su.baidubce.com)>"

config :elixir_bce_sdk, ElixirBceSdk.Client,
  timeout: 30_000

Or if you want to config them via run-time system environment variables:

# config/config.exs

config :elixir_bce_sdk,
    access_key_id: {:system, "BOS_ACCESS_KEY_ID"},
    secret_access_key: {:system, "BOS_SECRET_ACCESS_KEY"},
    bos_endpoint: {:system, "BOS_ENDPOINT"},
    bcm_user_id:  {:system, "BCM_USER_ID"},
    bcm_endpoint: {:system, "BCM_ENDPOINT"}

config :elixir_bce_sdk, ElixirBceSdk.Client,
  timeout: {:system, "TIMEOUT"}

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/elixir_bce_sdk.

Usage

Bucket Api

List Buckets

ElixirBceSdk.Bos.Bucket.list_buckets()

Create Bucket

ElixirBceSdk.Bos.Bucket.create_bucket("bucket-name")

Delete Bucket

ElixirBceSdk.Bos.Bucket.delete_bucket("bucket-name")

Check Bucket is exist?

ElixirBceSdk.Bos.Bucket.bucket_exist?("bucket-name")

Get Bucket location

ElixirBceSdk.Bos.Bucket.get_bucket_location("bucket-name")
# => {:ok, 200, %{"locationConstraint" => "su"}}

Get Access Control Level of Bucket

ElixirBceSdk.Bos.Bucket.get_bucket_acl("bucket-name")

Set Access Control Level of Bucket by body

acl = [
  %{
    "grantee" => [
    %{ "id" => "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" },
    %{ "id" => "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }
  ],
    "permission" => ["FULL_CONTROL"]
  }
]
ElixirBceSdk.Bos.Bucket.set_bucket_acl("bucket_name", acl)

Set Access Control Level of Bucket by headers

ElixirBceSdk.Bos.Bucket.set_bucket_canned_acl("bucket-name", "public-read")

Get Bucket Lifecycle

ElixirBceSdk.Bos.Bucket.get_bucket_lifecycle("bucket-name")

Put Bucket Lifecycle

rule = [
  %{
    "id" => "rule-id",
    "status" => "enabled",
    "resource" => ["bucket/prefix/*"],
    "condition" => %{
      "time" => %{
      "dateGreaterThan" => "2016-09-07T00:00:00Z"
      }
    },
    "action" => %{
      "name" => "DeleteObject"
    }
  }
]
ElixirBceSdk.Bos.Bucket.put_bucket_lifecycle("bucket-name", rule)

Delete Bucket Lifecycle

ElixirBceSdk.Bos.Bucket.delete_bucket_lifecycle("bucket-name")

Get Bucket Storageclass

ElixirBceSdk.Bos.Bucket.get_bucket_storageclass("bucket-name")

Put Bucket Storageclass

ElixirBceSdk.Bos.Bucket.put_bucket_storageclass("bucket-name", "COLD")

Objects Api

Get Object Information of Bucket

ElixirBceSdk.Bos.Bucket.list_objects("bucket-name")

Get object of Bucket

ElixirBceSdk.Bos.Object.get_object("bucket-name", "object-key")

Get object to file

ElixirBceSdk.Bos.Object.get_object_to_file("bucket-name", "object-key", "path/to/save")

Get mete of object

ElixirBceSdk.Bos.Object.get_object_meta_data("bucket-name", "object-key")

Create object and put content of string to the object

ElixirBceSdk.Bos.Object.put_object_from_string("bucket-name", "object-key", "string data")

Put object and put content of file to the object

ElixirBceSdk.Bos.Object.put_object_from_file("bucket-name", "object-key", "path/to/file")

Delete Object

ElixirBceSdk.Bos.Object.delete_object("bucket-name", "object-key")

Get object acl

ElixirBceSdk.Bos.Object.get_object_acl("bucket-name", "object-key")

Set object acl by headers

ElixirBceSdk.Bos.Object.set_object_canned_acl("bucket-name", "object-key", "public-read")

Delete object acl

ElixirBceSdk.Bos.Object.delete_object_acl("bucket-name", "object-key")

See the bos directory for other features

BCM Api

Get metric data

# default get last 15 minues range metric data and `period_in_second` is 60
# please use `h ElixirBceSdk.Bcm.Client.get_metric_data` to know more
ElixirBceSdk.Bcm.Client.get_metric_data("BCE_BOS", "BucketObjectCount", "BucketId:maven-mirror")

About

Baidu Could Storage SDK for Elixir

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages