aliyun_oss v0.1.0 Aliyun.Oss.Bucket

Bucket 相关操作

Link to this section Summary

Functions

GetBucket(ListObject) 接口可用来列出 Bucket中所有Object的信息。

GetBucketAcl 接口用来获取某个Bucket的访问权限。

GetBucketInfo 接口用于查看bucket的相关信息。 可查看内容包含如下:

GetBucketLifecycle 用于查看Bucket的Lifecycle配置。

GetBucketLocation GetBucketLocation用于查看Bucket所属的数据中心位置信息。

GetBucketLogging 用于查看Bucket的访问日志配置情况。

GetBucketReferer 操作用于查看bucket的Referer相关配置。

GetBucketWebsite 接口用于查看bucket的静态网站托管状态以及跳转规则。

GetService (ListBuckets) 对于服务地址作Get请求可以返回请求者拥有的所有Bucket。

Link to this section Types

Link to this type error_details()
error_details() ::
  {:http_error, String.t()}
  | {:xml_parse_error, String.t()}
  | {:oss_error, integer(), map()}

Link to this section Functions

Link to this function get_bucket(bucket, query_params \\ %{}, sub_resources \\ %{})
get_bucket(String.t(), map(), map()) ::
  {:error, error_details()} | {:ok, map()}

GetBucket(ListObject) 接口可用来列出 Bucket中所有Object的信息。

Examples

iex> Aliyun.Oss.Bucket.get_bucket("some-bucket", %{"prefix" => "foo/"})
{:ok, %{ "ListAllMyBucketsResult" => %{
  "Contents" => [
    %{
      "ETag" => ""D410293F000B000D00D"",
      "key" => "foo/bar",
      "LastModified" => "2018-09-12T02:59:41.000Z",
      "Owner" => %{"DislayName" => "11111111", "ID" => "11111111"},
      "Size" => "12345",
      "StorageClass" => "IA",
      "Type" => "Normal"
    },
    ...
  ],
  "Delimiter" => nil,
  "IsTruncated" => true,
  "Marker" => nil,
  "MaxKeys" => 100,
  "Name" => "some-bucket",
  "NextMarker" => "XXXXX",
  "Prefix" => "foo/"
}}}

iex> Aliyun.Oss.Bucket.get_bucket("unknown-bucket")
{:error,
  {:oss_error, 404,
    %{ "ListBucketResult" => %{
      "BucketName" => "unknown-bucket",
      "Code" => "NoSuchBucket",
      "HostId" => "unknown-bucket.oss-cn-shenzhen.aliyuncs.com",
      "Message" => "The specified bucket does not exist.",
      "RequestId" => "5BFF89955E29FF66F10B9763"
    }}}}

注:所有 GetBucketXXX 相关操作亦可由此接口实现, 即 Bucket.get_bucket_acl(“some-bucket”) 等同于 Bucket.get_bucket(“some-bucket”, %{}, %{“acl” => nil})

Link to this function get_bucket_acl(bucket)
get_bucket_acl(String.t()) :: {:error, error_details()} | {:ok, map()}

GetBucketAcl 接口用来获取某个Bucket的访问权限。

Examples

iex> Aliyun.Oss.Bucket.get_bucket_acl("some-bucket")
{:ok, %{ "AccessControlPolicy" => %{
  "AccessControlList" => %{"Grant" => "private"},
  "Owner" => %{"DislayName" => "11111111", "ID" => "11111111"}
}}}
Link to this function get_bucket_info(bucket)
get_bucket_info(String.t()) :: {:error, error_details()} | {:ok, map()}

GetBucketInfo 接口用于查看bucket的相关信息。 可查看内容包含如下:

  • 创建时间
  • 外网访问Endpoint
  • 内网访问Endpoint
  • bucket的拥有者信息
  • bucket的ACL(AccessControlList)

Examples

iex> Aliyun.Oss.Bucket.get_bucket_info("some-bucket")
{:ok,
%{ "BucketInfo" => %{
  "Bucket" => %{
    "AccessControlList" => %{"Grant" => "private"},
    "Comment" => nil,
    "CreationDate" => "2018-08-29T01:52:03.000Z",
    "DataRedundancyType" => "LRS",
    "ExtranetEndpoint" => "oss-cn-shenzhen.aliyuncs.com",
    "IntranetEndpoint" => "oss-cn-shenzhen-internal.aliyuncs.com",
    "Location" => "oss-cn-shenzhen",
    "Name" => "some-bucket",
    "Owner" => %{
      "DisplayName" => "11111111",
      "ID" => "11111111"
    },
    "StorageClass" => "IA"
  }
}}}
Link to this function get_bucket_lifecycle(bucket)
get_bucket_lifecycle(String.t()) :: {:error, error_details()} | {:ok, map()}

GetBucketLifecycle 用于查看Bucket的Lifecycle配置。

Examples

iex> Aliyun.Oss.Bucket.get_bucket_lifecycle("some-bucket")
{:ok,
%{
  "LifecycleConfiguration" => %{
    "Rule" => %{
      "ID" => "delete after one day",
      "Prefix" => "logs/",
      "Status" => "Enabled",
      "Expiration" => %{
        "Days" => "1"
      }
    }
  }
}}
Link to this function get_bucket_location(bucket)
get_bucket_location(String.t()) :: {:error, error_details()} | {:ok, map()}

GetBucketLocation GetBucketLocation用于查看Bucket所属的数据中心位置信息。

Examples

iex> Aliyun.Oss.Bucket.get_bucket_location("some-bucket")
{:ok, %{"LocationConstraint" => "oss-cn-shenzhen"}}
Link to this function get_bucket_logging(bucket)
get_bucket_logging(String.t()) :: {:error, error_details()} | {:ok, map()}

GetBucketLogging 用于查看Bucket的访问日志配置情况。

Examples

iex> Aliyun.Oss.Bucket.get_bucket_logging("some-bucket")
{:ok,
%{
  "BucketLoggingStatus" => %{
    "LoggingEnabled" => %{
      "TargetBucket" => "some-bucket",
      "TargetPrefix" => "oss-accesslog/"
    }
  }
}}
Link to this function get_bucket_referer(bucket)
get_bucket_referer(String.t()) :: {:error, error_details()} | {:ok, map()}

GetBucketReferer 操作用于查看bucket的Referer相关配置。

Examples

iex> Aliyun.Oss.Bucket.get_bucket_referer("some-bucket")
{:ok,
%{
  "RefererConfiguration" => %{
    "AllowEmptyReferer" => "true",
    "RefererList" => nil
  }
}}
Link to this function get_bucket_website(bucket)
get_bucket_website(String.t()) :: {:error, error_details()} | {:ok, map()}

GetBucketWebsite 接口用于查看bucket的静态网站托管状态以及跳转规则。

Examples

iex> Aliyun.Oss.Bucket.get_bucket_website("some-bucket")
{:ok, %{"WebsiteConfiguration" => %{"IndexDocument" => %{"Suffix" => "index.html"}}}}

iex> Aliyun.Oss.Bucket.get_bucket_website("unkown-bucket")
{:error,
  {:oss_error, 404,
    %{
      "BucketName" => "unkown-bucket",
      "Code" => "NoSuchBucket",
      "HostId" => "unkown-bucket.oss-cn-shenzhen.aliyuncs.com",
      "Message" => "The specified bucket does not exist.",
      "RequestId" => "5C0000000000000000000000"
    }}}
Link to this function list_buckets(query_params \\ %{})
list_buckets(map()) :: {:error, error_details()} | {:ok, map()}

GetService (ListBuckets) 对于服务地址作Get请求可以返回请求者拥有的所有Bucket。

Examples

iex> Aliyun.Oss.Bucket.list_buckets(%{"max-keys" => 5})
{:ok, %{
  "Buckets" => %{
    "Bucket" => [
      %{
        "CreationDate" => "2018-10-12T07:57:51.000Z",
        "ExtranetEndpoint" => "oss-cn-shenzhen.aliyuncs.com",
        "IntranetEndpoint" => "oss-cn-shenzhen-internal.aliyuncs.com",
        "Location" => "oss-cn-shenzhen",
        "Name" => "XXXXX",
        "StorageClass" => "Standard"
      },
      ...
    ]
  },
  "IsTruncated" => true,
  "Marker" => nil,
  "MaxKeys" => 5,
  "NextMarker" => "XXXXX",
  "Owner" => %{"DislayName" => "11111111", "ID" => "11111111"},
  "Prefix" => nil
}}

iex> Aliyun.Oss.Bucket.list_buckets(%{"max-keys" => 100000})
{:error,
  {:oss_error, 400,
    %{
      "ArgumentName" => "max-keys",
      "ArgumentValue" => "100000",
      "Code" => "InvalidArgument",
      "HostId" => "oss-cn-shenzhen.aliyuncs.com",
      "Message" => "Argument max-keys must be an integer between 1 and 1000.",
      "RequestId" => "5BFF8912332CCD8D560F65D9"
    }}}