Class: Eco::API::Session::Config::Apis
- Inherits:
-
BaseConfig
- Object
- Hash
- BaseConfig
- Eco::API::Session::Config::Apis
- Defined in:
- lib/eco/api/session/config/apis.rb
Instance Attribute Summary
Attributes inherited from BaseConfig
Attributes included from Language::AuxiliarLogger
Instance Method Summary collapse
- #active_api ⇒ Object
- #active_name ⇒ Object
- #active_name=(name) ⇒ Object
-
#active_root_name ⇒ Object
the active environment.
- #add(name, key:, host:, version: :internal, mode: :local, user_key: nil, external_key: nil, email: nil, pass: nil, org_id: nil) ⇒ Object
- #any_defined?(*names) ⇒ Boolean
- #api(logger = ::Logger.new(IO::NULL), version: nil) ⇒ Object
- #apis ⇒ Object
- #apis? ⇒ Boolean
- #default_email ⇒ Object
- #default_email=(email) ⇒ Object
- #default_pass ⇒ Object
- #default_pass=(pass) ⇒ Object
- #default_user_key ⇒ Object
- #default_user_key=(key) ⇒ Object
- #defined?(name) ⇒ Boolean
- #enviros ⇒ Object
-
#one_off ⇒ Object
Method to support CLI one-off API requests.
- #service_up? ⇒ Boolean
Methods inherited from BaseConfig
attr_key, #clone, #file_manager, #initialize
Methods included from Language::AuxiliarLogger
Methods inherited from Hash
Constructor Details
This class inherits a constructor from Eco::API::Session::Config::BaseConfig
Instance Method Details
#active_api ⇒ Object
47 48 49 |
# File 'lib/eco/api/session/config/apis.rb', line 47 def active_api self["active-api"] end |
#active_name ⇒ Object
58 59 60 |
# File 'lib/eco/api/session/config/apis.rb', line 58 def active_name self["active-name"] end |
#active_name=(name) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/eco/api/session/config/apis.rb', line 51 def active_name=(name) raise "'#{name}' Api environment not defined" if !apis[name] self["active-name"] = name self["active-api"] = apis[name] self end |
#active_root_name ⇒ Object
the active environment
63 64 65 |
# File 'lib/eco/api/session/config/apis.rb', line 63 def active_root_name active_name end |
#add(name, key:, host:, version: :internal, mode: :local, user_key: nil, external_key: nil, email: nil, pass: nil, org_id: nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/eco/api/session/config/apis.rb', line 28 def add(name, key:, host:, version: :internal, mode: :local, user_key: nil, external_key: nil, email: nil, pass: nil, org_id: nil) apis[name] = Session::Config::Api.new( name, 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 |
#any_defined?(*names) ⇒ Boolean
22 23 24 25 26 |
# File 'lib/eco/api/session/config/apis.rb', line 22 def any_defined?(*names) [names].flatten.any? do |name| self.defined?(name) end end |
#api(logger = ::Logger.new(IO::NULL), version: nil) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/eco/api/session/config/apis.rb', line 74 def api(logger = ::Logger.new(IO::NULL), version: nil) unless active_api raise "There's no 'active_api'. Use apis.active_name='api_enviro_name' to set the active api" end active_api.api(version: version, logger: logger) end |
#apis ⇒ Object
6 7 8 |
# File 'lib/eco/api/session/config/apis.rb', line 6 def apis self["apis"] ||= {} end |
#apis? ⇒ Boolean
10 11 12 |
# File 'lib/eco/api/session/config/apis.rb', line 10 def apis? apis.keys.length > 0 end |
#default_email ⇒ Object
93 94 95 |
# File 'lib/eco/api/session/config/apis.rb', line 93 def default_email self["default_email"] || ENV['USER_EMAIL'] end |
#default_email=(email) ⇒ Object
89 90 91 |
# File 'lib/eco/api/session/config/apis.rb', line 89 def default_email=(email) self["default_email"] = email end |
#default_pass ⇒ Object
101 102 103 |
# File 'lib/eco/api/session/config/apis.rb', line 101 def default_pass self["default_pass"] || ENV['USER_PASS'] end |
#default_pass=(pass) ⇒ Object
97 98 99 |
# File 'lib/eco/api/session/config/apis.rb', line 97 def default_pass=(pass) self["default_pass"] = pass end |
#default_user_key ⇒ Object
85 86 87 |
# File 'lib/eco/api/session/config/apis.rb', line 85 def default_user_key self["user_key"] end |
#default_user_key=(key) ⇒ Object
81 82 83 |
# File 'lib/eco/api/session/config/apis.rb', line 81 def default_user_key=(key) self["user_key"] = key end |
#defined?(name) ⇒ Boolean
18 19 20 |
# File 'lib/eco/api/session/config/apis.rb', line 18 def defined?(name) apis.key?(name) end |
#enviros ⇒ Object
14 15 16 |
# File 'lib/eco/api/session/config/apis.rb', line 14 def enviros apis.keys end |
#one_off ⇒ Object
Method to support CLI one-off API requests
106 107 108 109 110 111 |
# File 'lib/eco/api/session/config/apis.rb', line 106 def one_off if one_off? add(one_off_org, key: one_off_key, host: "#{one_off_enviro}.ecoportal.com") return one_off_org end end |
#service_up? ⇒ Boolean
67 68 69 70 71 72 |
# File 'lib/eco/api/session/config/apis.rb', line 67 def service_up? @api_test ||= Session::Config::Api.api_class(active_api.version).new("foobar", host: active_api.host, logger: ::Logger.new(IO::NULL)) status = @api_test.client.get("/policy_groups").status # 401 Unauthorized "Permission denied. API key may be invalid." status == 401 end |