class OCI::Config

This class contains accessors for configuration attributes needed when using the SDK

Constants

OCI_REGION_ENV
PATTERNS

Patterns to use validate value for different attribute

Attributes

additional_user_agent[RW]

If set, then this string will be added to the user agent sent with each request.

@return [String]

authentication_type[RW]

The authentication type user want to apply Example: instance_principal

@return [String]

connection_timeout[RW]

The time limit for the connection phase in seconds. Defaults to 10 seconds.

@return [Integer]

delegation_token_file[RW]

The file location of delegation token Example: ~/.oci/delegation

@return [String]

fingerprint[RW]

SSL Fingerprint to use for authentication. Example: 20:3b:97:13:55:1c:1c:0d:d3:37:d8:50:4e:c5:3a:12

@return [String]

key_content[RW]

Client private key content. key_content takes precedence if both key_file and key_content are provided. For the security reason, don't provide the key content in the configuration file itself and it will be ignored by SDK. The value should be same as the content which is normally found in a .pem file. Example: “—–BEGIN RSA PRIVATE KEY—–nProc-Type: 4,ENCRYPTEDnDEK-Info: AES-128-CBC,D3D04C29BD3061489F4FF579A2133620nnjZO+B3DMBTz6Pszk0EUS8O2gU0T…jZpon—–END RSA PRIVATE KEY—–n”

@return [String]

key_file[RW]

Client private key file. Example: ~/.ssh/oci_key

@return [String]

log_requests[RW]

Whether to log detailed request and response data. This will always write to STDOUT. Defaults to false.

@return [true, false]

logger[W]

Defines the logger used for debugging. For example, log to STDOUT by setting this to Logger.new(STDOUT). This property cannot be set from a config file.

pass_phrase[RW]

Pass phrase used for key file, if it is encrypted.

@return [String]

region[W]

A region to use for APIs created with this Config.

@return [OCI::Regions::REGION_ENUM]

tenancy[RW]

OCID of the tenancy to use for authentication. Example: ocid1.tenancy.oc1..aaaaaaaaba3pv6wkcr4jqae5f15p2b2m2yt2j6rx32uzr4h25vqstifsfdsq

@return [String]

timeout[RW]

The time limit for HTTP request in seconds. Defaults to 0 (times out in 365 days).

@return [Integer]

user[RW]

OCID of the user to use for authentication. Example: ocidv1:user:oc1:phx:1460406592659:aaaaaaaawcbqrkycbolrirg2n3xjl5fabc

@return [String]

Public Class Methods

new() click to toggle source
# File lib/oci/config.rb, line 107
def initialize
  @timeout = 0
  @connection_timeout = 10
  @log_requests = false
  @key_content = nil
end
validate_and_build_config_with_signer(config, signer) click to toggle source

rubocop:enable Metrics/PerceivedComplexity

# File lib/oci/config.rb, line 155
def self.validate_and_build_config_with_signer(config, signer)
  config ||= OCI.config unless signer.is_a?(OCI::Auth::Signers::InstancePrincipalsSecurityTokenSigner) || \
                               signer.is_a?(OCI::Auth::Signers::SecurityTokenSigner)
  config ||= OCI::Config.new if signer.is_a?(OCI::Auth::Signers::InstancePrincipalsSecurityTokenSigner) || \
                                signer.is_a?(OCI::Auth::Signers::SecurityTokenSigner)
  config.validate unless signer.is_a?(OCI::Auth::Signers::InstancePrincipalsSecurityTokenSigner) || \
                         signer.is_a?(OCI::Auth::Signers::SecurityTokenSigner)
  config
end

Public Instance Methods

logger() click to toggle source

Gets the logger used for debugging. If nil, then {OCI#logger} will be returned instead.

@return [Logger]

# File lib/oci/config.rb, line 117
def logger
  return OCI.logger if @logger.nil?

  @logger
end
region() click to toggle source

Gets the region var. If the region doesn't exist, check OCI_REGION_ENV env var to search for it

@return [OCI::Regions::REGION_ENUM]

# File lib/oci/config.rb, line 126
def region
  @region ||= ENV[OCI::Config::OCI_REGION_ENV]

  @region
end
validate() click to toggle source

rubocop:disable Metrics/PerceivedComplexity

# File lib/oci/config.rb, line 133
def validate
  # currently, config file auth type only supports delegation token auth which is `instance_principal` based auth
  return unless @authentication_type.nil? && @delegation_token_file.nil?

  %w[user fingerprint tenancy].each do |name|
    if !instance_variable_defined?("@#{name}") || instance_variable_get("@#{name}").nil?
      raise OCI::InvalidConfigError, "The #{name} is missing in configuration."
    end
  end

  raise OCI::InvalidConfigError, 'The region is missing in configuration or environment variable.' if @region.nil?

  if (!instance_variable_defined?('@key_file') || instance_variable_get('@key_file').nil?) && @key_content.nil?
    raise OCI::InvalidConfigError, 'The key_file and key_content cannot both be missing in configuration.'
  end

  PATTERNS.each do |name, pattern|
    raise OCI::InvalidConfigError, "The format of #{name} is invalid." if (pattern =~ instance_variable_get("@#{name}")).nil?
  end
end