View Source CozyAliyunOpenAPI.Specs.OSS (cozy_aliyun_open_api v0.3.0)

Describes an OSS style API.

Read more at:

About spec_config

spec_config is a plain map for describing a RESTful API request.

Adding signature

This implementation has built-in V4 signature support, and it's controlled by the :sign_type option:

  • :header - add signature to the headers of request.
  • :url - add signature to the url of request.

V1 signature is not supported.

Required headers

All necessary headers of requests will be generated automatically. You don't have to specifically set them, unless you want to customize it.

Examples

Send a request for ListBucktets operation

alias CozyAliyunOpenAPI.Config
alias CozyAliyunOpenAPI.Specs.OSS
alias CozyAliyunOpenAPI.HTTPRequest
alias CozyAliyunOpenAPI.HTTPClient

config =
  Config.new!(%{
    access_key_id: "...",
    access_key_secret: "..."
  })

OSS.new!(config, %{
  sign_type: :header,
  region: "oss-us-west-1",
  endpoint: "https://oss-us-west-1.aliyuncs.com/",
  method: :get,
  path: "/"
})
|> HTTPRequest.from_spec!()
|> HTTPClient.request()

Create a pre-signed url for GetObject operation

alias CozyAliyunOpenAPI.Config
alias CozyAliyunOpenAPI.Specs.OSS
alias CozyAliyunOpenAPI.HTTPRequest

config =
  Config.new!(%{
    access_key_id: "...",
    access_key_secret: "..."
  })

OSS.new!(config, %{
  sign_type: :url,
  region: "oss-us-west-1",
  bucket: "example-bucket",
  endpoint: "https://example-bucket.oss-us-west-1.aliyuncs.com/",
  method: :get,
  path: "/example-object",
  headers: %{
    "x-oss-expires" => 900
  }
})
|> HTTPRequest.from_spec!()
|> HTTPRequest.url()

Summary

Types

@type body() :: iodata() | nil
@type bucket() :: String.t() | nil
@type endpoint() :: String.t()

The base url that the request is sent to.

Following formats are supported:

  • region URL, such as https://oss-us-west-1.aliyuncs.com.
  • virtual-hosted style URL, such as https://example-bucket.oss-us-west-1.aliyuncs.com.
  • custom domain name, such as https://www.example.com.
  • ...
@type headers() :: %{
  optional(name :: String.t()) =>
    value :: nil | boolean() | number() | String.t()
}
@type method() :: String.t()
@type path() :: String.t()
@type query() :: %{
  optional(name :: String.t()) =>
    value :: nil | boolean() | number() | String.t()
}
@type region() :: String.t()
@type sign_type() :: :header | :url
@type spec_config() :: %{
  region: region(),
  bucket: bucket(),
  sign_type: sign_type(),
  endpoint: endpoint(),
  method: method(),
  path: path(),
  query: query(),
  headers: headers(),
  body: body()
}
@type t() :: %CozyAliyunOpenAPI.Specs.OSS{
  body: body(),
  bucket: bucket(),
  config: CozyAliyunOpenAPI.Config.t(),
  endpoint: endpoint(),
  headers: headers(),
  method: method(),
  path: path(),
  query: query(),
  region: region(),
  sign_type: sign_type()
}

Functions

Link to this function

new!(config, spec_config)

View Source
@spec new!(CozyAliyunOpenAPI.Config.t(), spec_config()) :: t()