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
Link to this section Functions
@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..."}
@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