Sha256: a1cb695a30949ed671c90eb822335370e79517eb7176ada7b38cbbe156a54ff3

Contents?: true

Size: 1.7 KB

Versions: 10

Compression:

Stored size: 1.7 KB

Contents

module ThreeScaleToolbox
  module Entities
    class ProxyConfig
      class << self
        def find(service:, environment:, version:)
          new(service: service, environment: environment, version: version).tap(&:attrs)
        rescue ThreeScale::API::HttpClient::NotFoundError
          nil
        end

        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
      end

      attr_reader :remote, :service, :environment, :version

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

      def attrs
        @attrs ||= proxy_config_attrs
      end

      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

      private

      def proxy_config_attrs
        proxy_cfg = remote.show_proxy_config(service.id, environment, version)

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
3scale_toolbox-1.0.1 lib/3scale_toolbox/entities/proxy_config.rb
3scale_toolbox-1.0.0 lib/3scale_toolbox/entities/proxy_config.rb
3scale_toolbox-0.20.0 lib/3scale_toolbox/entities/proxy_config.rb
3scale_toolbox-0.19.3 lib/3scale_toolbox/entities/proxy_config.rb
3scale_toolbox-0.19.2 lib/3scale_toolbox/entities/proxy_config.rb
3scale_toolbox-0.19.1 lib/3scale_toolbox/entities/proxy_config.rb
3scale_toolbox-0.19.0 lib/3scale_toolbox/entities/proxy_config.rb
3scale_toolbox-0.18.3 lib/3scale_toolbox/entities/proxy_config.rb
3scale_toolbox-0.18.2 lib/3scale_toolbox/entities/proxy_config.rb
3scale_toolbox-0.18.0 lib/3scale_toolbox/entities/proxy_config.rb