Class: Eco::API::Session::Config::Apis

Inherits:
BaseConfig show all
Includes:
EnviroSpaces, OneOff, ServiceUp
Defined in:
lib/eco/api/session/config/apis.rb,
lib/eco/api/session/config/apis/one_off.rb,
lib/eco/api/session/config/apis/service_up.rb,
lib/eco/api/session/config/apis/enviro_spaces.rb,
lib/eco/api/session/config/apis/space_helpers.rb

Defined Under Namespace

Modules: EnviroSpaces, OneOff, ServiceUp, SpaceHelpers Classes: UndefinedApi

Instance Attribute Summary

Attributes inherited from BaseConfig

#config

Attributes included from Language::AuxiliarLogger

#logger

Instance Method Summary collapse

Methods included from ServiceUp

#service_up?

Methods included from EnviroSpaces

#active_space, #any_defined?, #api?, #apis, #apis?, #defined?, #enviro_spaces, #enviro_spaces?, #enviro_spaces_str, #enviros, #missing_api_message

Methods included from SpaceHelpers

#set_options_space!, #space_option, #space_option?

Methods inherited from BaseConfig

#apis, attr_key, #clone, #file_manager, #initialize

Methods included from Language::AuxiliarLogger

#log

Methods inherited from Hash

#deep_merge, #deep_merge!

Constructor Details

This class inherits a constructor from Eco::API::Session::Config::BaseConfig

Instance Method Details

#active_apiObject



63
64
65
# File 'lib/eco/api/session/config/apis.rb', line 63

def active_api
  self['active-api']
end

#active_nameObject



59
60
61
# File 'lib/eco/api/session/config/apis.rb', line 59

def active_name
  self['active-name']
end

#active_name=(name) ⇒ Object



67
68
69
# File 'lib/eco/api/session/config/apis.rb', line 67

def active_name=(name)
  set_active_name(name)
end

#active_root_nameObject

the active environment



55
56
57
# File 'lib/eco/api/session/config/apis.rb', line 55

def active_root_name
  active_name
end

#add(name, key:, host:, space: nil, version: :internal, mode: :local, user_key: nil, external_key: nil, email: nil, pass: nil, org_id: nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/eco/api/session/config/apis.rb', line 17

def add(
  name,
  key:,
  host:,
  space:        nil,
  version:      :internal,
  mode:         :local,
  user_key:     nil,
  external_key: nil,
  email:        nil,
  pass:         nil,
  org_id:       nil
)
  # ensure that space_option isn't used
  space = to_space(space)

  msg = "WARNING: Overriding #{full_name(name, space: space)} API credentials"
  puts msg if self.defined?(name, space: space)

  apis(space)[name] = Session::Config::Api.new(
    name,
    space:        space,
    key:          key,
    host:         host,
    version:      version,
    mode:         mode,
    root:         self,
    user_key:     user_key,
    external_key: external_key,
    email:        email,
    pass:         pass,
    org_id:       org_id
  )

  self
end

#api(logger = ::Logger.new(IO::NULL), version: nil) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/eco/api/session/config/apis.rb', line 84

def api(logger = ::Logger.new(IO::NULL), version: nil)
  msg  = "There's no 'active_api'. "
  msg << "To set the target environment, please use either of:\n"
  msg << "  * apis.set_active_name('api_enviro_name', space: 'the-space')\n"
  msg << "  * apis.active_name='api_enviro_name'\n"
  raise msg unless active_api

  active_api.api(version: version, logger: logger)
end

#default_emailObject



106
107
108
# File 'lib/eco/api/session/config/apis.rb', line 106

def default_email
  self['default_email'] || ENV['USER_EMAIL']
end

#default_email=(email) ⇒ Object



102
103
104
# File 'lib/eco/api/session/config/apis.rb', line 102

def default_email=(email)
  self['default_email'] = email
end

#default_passObject



114
115
116
# File 'lib/eco/api/session/config/apis.rb', line 114

def default_pass
  self['default_pass'] || ENV['USER_PASS']
end

#default_pass=(pass) ⇒ Object



110
111
112
# File 'lib/eco/api/session/config/apis.rb', line 110

def default_pass=(pass)
  self['default_pass'] = pass
end

#default_user_keyObject



98
99
100
# File 'lib/eco/api/session/config/apis.rb', line 98

def default_user_key
  self['user_key']
end

#default_user_key=(key) ⇒ Object



94
95
96
# File 'lib/eco/api/session/config/apis.rb', line 94

def default_user_key=(key)
  self['user_key'] = key
end

#one_offObject

Method to support CLI one-off API requests



119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/eco/api/session/config/apis.rb', line 119

def one_off
  return unless one_off?

  name = one_off_org

  add(
    name,
    key:  one_off_key,
    host: "#{one_off_enviro}.ecoportal.com"
  )

  name
end

#set_active_name(name, space: space_option) ⇒ Object

Raises:



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/eco/api/session/config/apis.rb', line 71

def set_active_name(name, space: space_option)
  space ||= space_option

  msg = missing_api_message(name, space: space)
  raise UndefinedApi, msg unless self.api?(name, space: space)

  self['active-name'] = name
  self['active-api']  = apis(space)[name]
  set_options_space!(active_space)

  self
end