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
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
@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 requestfingerprint
- Fingerprint of the public key uploaded to OCItenancy
- The OCID of your tenancyregion
- The region of the OCI services being accessedkey_content
- The private key content as a string (mutually exclusive withkey_content_file
)key_content_file
- Path to the private key file (mutually exclusive withkey_content
)
@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 requestfingerprint
- Fingerprint of the public key uploaded to OCItenancy
- The OCID of your tenancyregion
- The region of the OCI services being accessedkey_content
- The private key content used for signing requests
Functions
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
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 requestfingerprint
- Fingerprint of the public key uploaded to OCItenancy
- The OCID of your tenancyregion
- The region of the OCI services being accessed- Either
key_content
(private key as string) ORkey_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 missingRuntimeError
- If bothkey_content
andkey_file
are providedRuntimeError
- If neitherkey_content
norkey_file
is provided- All raises from
new!/1
(including key validation errors)
@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. Seeconfig_options/0
for details.
Returns
t/0
- The configuration struct
Raises
ArgumentError
- If the key content is invalid or not in PEM formatFile.Error
- If the key file cannot be read (when usingkey_content_file
)