View Source GcsSignedUrl (gcs_signed_url v0.4.6)

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

@type sign_v2_opts() :: [
  verb: String.t(),
  md5_digest: String.t(),
  content_type: String.t(),
  expires: integer()
]
@type sign_v4_opts() :: [
  verb: String.t(),
  headers: Keyword.t(),
  query_params: Keyword.t(),
  valid_from: DateTime.t(),
  expires: integer(),
  host: String.t()
]

Link to this section Functions

Link to this function

generate(client, bucket, filename, opts \\ [])

View Source
This function is deprecated. Use GcsSignedUrl.generate_v4/4 instead. [V2 signing process is considered legacy](https://cloud.google.com/storage/docs/access-control/signed-urls-v2).
@spec generate(GcsSignedUrl.Client.t(), String.t(), String.t(), sign_v2_opts()) ::
  String.t()
@spec 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

Examples

iex> client = %GcsSignedUrl.Client{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..."}
Link to this function

generate_v4(client, bucket, filename, opts \\ [])

View Source
@spec generate_v4(GcsSignedUrl.Client.t(), String.t(), String.t(), sign_v4_opts()) ::
  String.t()
@spec 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

Examples

iex> client = %GcsSignedUrl.Client%{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

Examples

iex> 10 |> GcsUrlSigner.hours_after
1503599316