GcsSignedUrl (gcs_signed_url v0.4.2) View Source
Create Signed URLs for Google Cloud Storage in Elixir
Link to this section Summary
Functions
If the first argument is a GcsSignedUrl.Client{}
: Generate V2 signed url using its private key.
If the first argument is a GcsSignedUrl.Client{}
: Generate V4 signed url using its private key.
Calculate future timestamp from given hour offset.
Link to this section Types
Specs
Specs
sign_v4_opts() :: [ verb: String.t(), headers: Keyword.t(), query_params: Keyword.t(), valid_from: DateTime.t(), expires: integer() ]
Link to this section Functions
Specs
generate(GcsSignedUrl.Client.t(), String.t(), String.t(), sign_v2_opts()) :: String.t()
generate( GcsSignedUrl.SignBlob.OAuthConfig.t(), String.t(), String.t(), sign_v2_opts() ) :: {:ok, String.t()} | {:error, String.t()}
If the first argument is a GcsSignedUrl.Client{}
: Generate V2 signed url using its private key.
If the first argument is a %GcsSignedUrl.SignBlob.OAuthConfig{}
: Generate V2 signed url using the
Google IAM REST API with a OAuth2 token of a service account.
Examples
iex> client = GcsSignedUrl.Client.load(%{private_key: "...", client_email: "..."})
iex> GcsSignedUrl.generate(client, "my-bucket", "my-object.mp4", expires: 1503599316)
"https://storage.googleapis.com/my-bucket/my-object.mp4?Expires=15..."
iex> oauth_config = %GcsSignedUrl.SignBlob.OAuthConfig{service_account: "...", access_token: "..."}
iex> GcsSignedUrl.generate(oauth_config, "my-bucket", "my-object.mp4", expires: 1503599316)
{:ok, "https://storage.googleapis.com/my-bucket/my-object.mp4?X-Goog-Expires=1800..."}
Specs
generate_v4(GcsSignedUrl.Client.t(), String.t(), String.t(), sign_v4_opts()) :: String.t()
generate_v4( GcsSignedUrl.SignBlob.OAuthConfig.t(), String.t(), String.t(), sign_v4_opts() ) :: {:ok, String.t()} | {:error, String.t()}
If the first argument is a GcsSignedUrl.Client{}
: Generate V4 signed url using its private key.
If the first argument is a %GcsSignedUrl.SignBlob.OAuthConfig{}
: Generate V4 signed url using the
Google IAM REST API with a OAuth2 token of a service account.
Examples
iex> client = GcsSignedUrl.Client.load(%{private_key: "...", client_email: "..."})
iex> GcsSignedUrl.generate_v4(client, "my-bucket", "my-object.mp4", verb: "PUT", expires: 1800, headers: ["Content-Type": "application/json"])
"https://storage.googleapis.com/my-bucket/my-object.mp4?X-Goog-Expires=1800..."
iex> oauth_config = %GcsSignedUrl.SignBlob.OAuthConfig{service_account: "...", access_token: "..."}
iex> GcsSignedUrl.generate_v4(oauth_config, "my-bucket", "my-object.mp4", verb: "PUT", expires: 1800, headers: ["Content-Type": "application/json"])
{:ok, "https://storage.googleapis.com/my-bucket/my-object.mp4?X-Goog-Expires=1800..."}
Calculate future timestamp from given hour offset.
Examples
iex> 10 |> GcsUrlSigner.hours_after
1503599316