Class: OCI::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/oci/config.rb

Overview

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



93
94
95
96
97
98
# File 'lib/oci/config.rb', line 93

def initialize
  @timeout = 0
  @connection_timeout = 10
  @log_requests = false
  @key_content = nil
end

Instance Attribute Details

#additional_user_agentString

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

Returns:

  • (String)


91
92
93
# File 'lib/oci/config.rb', line 91

def additional_user_agent
  @additional_user_agent
end

#connection_timeoutInteger

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

Returns:

  • (Integer)


85
86
87
# File 'lib/oci/config.rb', line 85

def connection_timeout
  @connection_timeout
end

#fingerprintString

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

Returns:

  • (String)


30
31
32
# File 'lib/oci/config.rb', line 30

def fingerprint
  @fingerprint
end

#key_contentString

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”

Returns:

  • (String)


51
52
53
# File 'lib/oci/config.rb', line 51

def key_content
  @key_content
end

#key_fileString

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

Returns:

  • (String)


42
43
44
# File 'lib/oci/config.rb', line 42

def key_file
  @key_file
end

#log_requeststrue, false

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

Returns:

  • (true, false)


73
74
75
# File 'lib/oci/config.rb', line 73

def log_requests
  @log_requests
end

#loggerLogger

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

Returns:

  • (Logger)


103
104
105
106
107
# File 'lib/oci/config.rb', line 103

def logger
  return OCI.logger if @logger.nil?

  @logger
end

#pass_phraseString

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

Returns:

  • (String)


56
57
58
# File 'lib/oci/config.rb', line 56

def pass_phrase
  @pass_phrase
end

#regionOCI::Regions::REGION_ENUM

A region to use for APIs created with this Config.



61
62
63
# File 'lib/oci/config.rb', line 61

def region
  @region
end

#tenancyString

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

Returns:

  • (String)


36
37
38
# File 'lib/oci/config.rb', line 36

def tenancy
  @tenancy
end

#timeoutInteger

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

Returns:

  • (Integer)


79
80
81
# File 'lib/oci/config.rb', line 79

def timeout
  @timeout
end

#userString

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

Returns:

  • (String)


24
25
26
# File 'lib/oci/config.rb', line 24

def user
  @user
end

Class Method Details

.validate_and_build_config_with_signer(config, signer) ⇒ Object



127
128
129
130
131
132
133
134
135
# File 'lib/oci/config.rb', line 127

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

Instance Method Details

#validateObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/oci/config.rb', line 109

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

  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|
    if (pattern =~ instance_variable_get("@#{name}")).nil?
      raise OCI::InvalidConfigError, "The format of #{name} is invalid."
    end
  end
end