Class: Kitchen::Driver::Oci::Config

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

Overview

Config class that defines the oci config that will be used for the API calls.

Author:

  • Justin Steele <justin.steele@oracle.com>

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver_config) ⇒ Config

Returns a new instance of Config.



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

def initialize(driver_config)
  setup_driver_config(driver_config)
  @config = oci_config
end

Instance Attribute Details

#configOCI::Config (readonly)

The config used to authenticate to OCI.

Returns:

  • (OCI::Config)


37
38
39
# File 'lib/kitchen/driver/oci/config.rb', line 37

def config
  @config
end

Instance Method Details

#compartmentString

The ocid of the compartment where the Kitchen instance will be created.

  • If compartment_id is specified in the kitchen.yml, that will be returned.

  • If compartment_name is specified in the kitchen.yml, lookup with the Identity API to find the ocid by the compartment name.

Returns:

  • (String)

    the ocid of the compartment where instances will be created.

Raises:

  • (StandardError)

    if neither compartment_id nor compartment_name are specified OR if lookup by name fails to find a match.



60
61
62
63
64
65
66
67
68
# File 'lib/kitchen/driver/oci/config.rb', line 60

def compartment
  @compartment ||= @compartment_id
  return @compartment if @compartment

  raise "must specify either compartment_id or compartment_name" unless [@compartment_id, @compartment_name].any?

  @compartment ||= compartment_id_by_name(@compartment_name)
  raise "compartment not found" unless @compartment
end

#oci_configOCI::Config

Creates a new instance of OCI::Config to be used to authenticate to OCI.

Returns:

  • (OCI::Config)


42
43
44
45
46
47
48
49
50
51
52
# File 'lib/kitchen/driver/oci/config.rb', line 42

def oci_config
  # OCI::Config is missing this attribute. It is always added so that a security_token_file
  # present in the selected profile is loaded, which enables auto-detection of session
  # (RPST) token authentication even when use_token_auth is not explicitly set.
  OCI::Config.class_eval { attr_accessor :security_token_file } unless OCI::Config.instance_methods.include?(:security_token_file)
  conf = config_loader(config_file_location: @driver_config[:oci_config_file], profile_name: @driver_config[:oci_profile_name])
  @driver_config[:oci_config].each do |key, value|
    conf.send("#{key}=", value) unless value.nil? || value.empty?
  end
  conf
end