ExAzureCore.Credentials.AzureNamedKeyCredential (ex_azure_core v0.2.0)

Copy Markdown

Credential type for named key authentication.

Stores both an account name and account key, used with services like Azure Storage and Cosmos DB that require both values for authentication.

Example

{:ok, credential} = AzureNamedKeyCredential.new("myaccount", "base64key==")
credential.name
#=> "myaccount"
credential.key
#=> "base64key=="

# Update returns a new credential (immutable)
{:ok, updated} = AzureNamedKeyCredential.update(credential, "newaccount", "newkey==")

Summary

Functions

Returns the named key as a tuple {name, key}.

Creates a new named key credential.

Creates a new named key credential, raising on invalid input.

Updates both name and key values, returning a new credential.

Types

t()

@type t() :: %ExAzureCore.Credentials.AzureNamedKeyCredential{
  key: String.t(),
  name: String.t()
}

Functions

named_key(azure_named_key_credential)

@spec named_key(t()) :: {String.t(), String.t()}

Returns the named key as a tuple {name, key}.

Useful for pattern matching or passing to functions that expect a tuple.

new(name, key)

@spec new(String.t(), String.t()) ::
  {:ok, t()} | {:error, ExAzureCore.Credentials.Errors.CredentialError.t()}

Creates a new named key credential.

Returns {:ok, credential} if both name and key are non-empty strings, or {:error, CredentialError} otherwise.

new!(name, key)

@spec new!(String.t(), String.t()) :: t()

Creates a new named key credential, raising on invalid input.

update(azure_named_key_credential, new_name, new_key)

@spec update(t(), String.t(), String.t()) ::
  {:ok, t()} | {:error, ExAzureCore.Credentials.Errors.CredentialError.t()}

Updates both name and key values, returning a new credential.

This is immutable - returns a new struct rather than modifying in-place. Both values must be provided together (atomic update).