Class: DigitalOceanInventory::Config

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

Defined Under Namespace

Classes: MissingAccessTokenError

Constant Summary collapse

CONFIG_FILE_PATHS =
%w[
  ./digitalocean.yml
  ~/.ansible/digitalocean.yml
  /etc/ansible/digitalocean.yml
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/digital_ocean_inventory/config.rb', line 25

def initialize
  conf = load_from_file.merge load_from_env

  @token = conf[:access_token]
  raise MissingAccessTokenError unless @token

  @client = DropletKit::Client.new access_token: @token

  @project         = conf.fetch :project, "default"
  @select_tags     = conf.fetch :select_tags, []
  @ignore_tags     = conf.fetch :ignore_tags, []
  @ignore_hosts    = conf.fetch :ignore_hosts, []
  @group_by_region = conf.fetch :group_by_region, true
  @group_by_tag    = conf.fetch :group_by_tag, true
  @cache_path      = conf.fetch :cache_path, "."
  @cache_max_age   = conf.fetch :cache_max_age, 900
end

Instance Attribute Details

#cache_max_ageObject (readonly)

Returns the value of attribute cache_max_age.



14
15
16
# File 'lib/digital_ocean_inventory/config.rb', line 14

def cache_max_age
  @cache_max_age
end

#cache_pathObject (readonly)

Returns the value of attribute cache_path.



14
15
16
# File 'lib/digital_ocean_inventory/config.rb', line 14

def cache_path
  @cache_path
end

#clientObject (readonly)

Returns the value of attribute client.



14
15
16
# File 'lib/digital_ocean_inventory/config.rb', line 14

def client
  @client
end

#group_by_regionObject (readonly)

Returns the value of attribute group_by_region.



14
15
16
# File 'lib/digital_ocean_inventory/config.rb', line 14

def group_by_region
  @group_by_region
end

#group_by_tagObject (readonly)

Returns the value of attribute group_by_tag.



14
15
16
# File 'lib/digital_ocean_inventory/config.rb', line 14

def group_by_tag
  @group_by_tag
end

#ignore_hostsObject (readonly)

Returns the value of attribute ignore_hosts.



14
15
16
# File 'lib/digital_ocean_inventory/config.rb', line 14

def ignore_hosts
  @ignore_hosts
end

#ignore_tagsObject (readonly)

Returns the value of attribute ignore_tags.



14
15
16
# File 'lib/digital_ocean_inventory/config.rb', line 14

def ignore_tags
  @ignore_tags
end

#projectObject (readonly)

Returns the value of attribute project.



14
15
16
# File 'lib/digital_ocean_inventory/config.rb', line 14

def project
  @project
end

#select_tagsObject (readonly)

Returns the value of attribute select_tags.



14
15
16
# File 'lib/digital_ocean_inventory/config.rb', line 14

def select_tags
  @select_tags
end

#tokenObject (readonly)

Returns the value of attribute token.



14
15
16
# File 'lib/digital_ocean_inventory/config.rb', line 14

def token
  @token
end

Instance Method Details

#cache_fileObject



43
44
45
# File 'lib/digital_ocean_inventory/config.rb', line 43

def cache_file
  "#{cache_path}/.ansible_digital_ocean_inventory_cache.json"
end