Class: ThreeScaleToolbox::Entities::ProxyConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/3scale_toolbox/entities/proxy_config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment:, service:, version:, attrs: nil) ⇒ ProxyConfig

Returns a new instance of ProxyConfig.



24
25
26
27
28
29
30
# File 'lib/3scale_toolbox/entities/proxy_config.rb', line 24

def initialize(environment:, service:, version:, attrs: nil)
  @remote = service.remote
  @service = service
  @environment = environment
  @version = version
  @attrs = attrs
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



22
23
24
# File 'lib/3scale_toolbox/entities/proxy_config.rb', line 22

def environment
  @environment
end

#remoteObject (readonly)

Returns the value of attribute remote.



22
23
24
# File 'lib/3scale_toolbox/entities/proxy_config.rb', line 22

def remote
  @remote
end

#serviceObject (readonly)

Returns the value of attribute service.



22
23
24
# File 'lib/3scale_toolbox/entities/proxy_config.rb', line 22

def service
  @service
end

#versionObject (readonly)

Returns the value of attribute version.



22
23
24
# File 'lib/3scale_toolbox/entities/proxy_config.rb', line 22

def version
  @version
end

Class Method Details

.find(service:, environment:, version:) ⇒ Object



5
6
7
8
9
# File 'lib/3scale_toolbox/entities/proxy_config.rb', line 5

def find(service:, environment:, version:)
  new(service: service, environment: environment, version: version).tap(&:attrs)
rescue ThreeScale::API::HttpClient::NotFoundError
  nil
end

.find_latest(service:, environment:) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/3scale_toolbox/entities/proxy_config.rb', line 11

def find_latest(service:, environment:)
  proxy_cfg = service.remote.proxy_config_latest(service.id, environment)
  if (errors = proxy_cfg['errors'])
    raise ThreeScaleToolbox::ThreeScaleApiError.new('ProxyConfig find_latest not read', errors)
  end
  new(service: service, environment: environment, version: proxy_cfg["version"], attrs: proxy_cfg)
rescue ThreeScale::API::HttpClient::NotFoundError
  nil
end

Instance Method Details

#attrsObject



32
33
34
# File 'lib/3scale_toolbox/entities/proxy_config.rb', line 32

def attrs
  @attrs ||= proxy_config_attrs
end

#promote(to:) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/3scale_toolbox/entities/proxy_config.rb', line 36

def promote(to:)
  res = remote.promote_proxy_config(service.id, environment, version, to)

  if (errors = res['errors'])
    raise ThreeScaleToolbox::ThreeScaleApiError.new('ProxyConfig not promoted', errors)
  end
  res
end