View Source ExOciSdk.Config (ex_oci_sdk v0.2.2)

Provides configuration structure and validation for Oracle Cloud Infrastructure (OCI) credentials.

This module manages the configuration required for authenticating with OCI services, including user, tenancy information, and private key authentication.

Summary

Types

Options for creating a new configuration.

t()

Configuration structure for OCI authentication.

Functions

Creates a new configuration from an OCI config file.

Creates a new configuration from the application runtime environment.

Creates a new configuration struct with the provided options.

Types

config_options()

@type config_options() :: %{
  user: String.t(),
  fingerprint: String.t(),
  tenancy: String.t(),
  region: String.t(),
  key_content: String.t() | nil,
  key_file: String.t() | nil
}

Options for creating a new configuration.

Fields

  • user - The OCID of the user making the request
  • fingerprint - Fingerprint of the public key uploaded to OCI
  • tenancy - The OCID of your tenancy
  • region - The region of the OCI services being accessed
  • key_content - The private key content as a string (mutually exclusive with key_content_file)
  • key_content_file - Path to the private key file (mutually exclusive with key_content)

t()

@type t() :: %ExOciSdk.Config{
  fingerprint: String.t(),
  key_content: String.t(),
  region: String.t(),
  tenancy: String.t(),
  user: String.t()
}

Configuration structure for OCI authentication.

Fields

  • user - The OCID of the user making the request
  • fingerprint - Fingerprint of the public key uploaded to OCI
  • tenancy - The OCID of your tenancy
  • region - The region of the OCI services being accessed
  • key_content - The private key content used for signing requests

Functions

from_file!(config_file_path \\ "~/.oci/config", profile \\ "DEFAULT")

@spec from_file!(config_file_path :: String.t(), profile :: String.t()) ::
  t() | no_return()

Creates a new configuration from an OCI config file.

The function reads and parses an INI-formatted OCI configuration file and creates a new configuration struct based on the specified profile.

Parameters

  • config_file_path - Path to the OCI config file. Defaults to "~/.oci/config"
  • profile - The profile name to use from the config file. Defaults to "DEFAULT"

Returns

  • t/0 - The configuration struct

Raises

  • ArgumentError - If the config file cannot be parsed or if the specified profile is not found
  • All raises from new!/1

from_runtime!()

(since 0.2.2)
@spec from_runtime!() :: t() | no_return()

Creates a new configuration from the application runtime environment.

This function reads OCI configuration values from the application's runtime configuration and creates a new configuration struct. It looks for configuration under the :ex_oci_sdk application key.

The function expects the following configuration keys to be present:

  • user - The OCID of the user making the request
  • fingerprint - Fingerprint of the public key uploaded to OCI
  • tenancy - The OCID of your tenancy
  • region - The region of the OCI services being accessed
  • Either key_content (private key as string) OR key_file (path to private key file)

Example Configuration

# In config/runtime.exs
config :ex_oci_sdk,
  user: System.get_env("OCI_USER_OCID"),
  fingerprint: System.get_env("OCI_KEY_FINGERPRINT"),
  tenancy: System.get_env("OCI_TENANCY_OCID"),
  region: System.get_env("OCI_REGION") || "sa-saopaulo-1",
  key_file: System.get_env("OCI_PRIVATE_KEY_PATH") || "~/.oci/oci_api_key.pem"

# OR with key_content
config :ex_oci_sdk,
  user: System.get_env("OCI_USER_OCID"),
  fingerprint: System.get_env("OCI_KEY_FINGERPRINT"),
  tenancy: System.get_env("OCI_TENANCY_OCID"),
  region: System.get_env("OCI_REGION") || "sa-saopaulo-1",
  key_content: System.get_env("OCI_PRIVATE_KEY_CONTENT")

Returns

  • t/0 - The configuration struct

Raises

  • RuntimeError - If no configuration is found for :ex_oci_sdk
  • RuntimeError - If any required configuration key is missing
  • RuntimeError - If both key_content and key_file are provided
  • RuntimeError - If neither key_content nor key_file is provided
  • All raises from new!/1 (including key validation errors)

new!(map)

@spec new!(config_options()) :: t() | no_return()
@spec new!(config_options()) :: t() | no_return()

Creates a new configuration struct with the provided options.

This function accepts either direct key content or a path to a key file, but not both. The private key content will be validated to ensure it's in the correct PEM format.

Parameters

  • options - Map containing configuration values. See config_options/0 for details.

Returns

  • t/0 - The configuration struct

Raises

  • ArgumentError - If the key content is invalid or not in PEM format
  • File.Error - If the key file cannot be read (when using key_content_file)