Sha256: d0f901f12ba2a37a554ad51f472e6ee4301f1f64e65c319e65e046eb2dff4859

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

module ThreeScaleToolbox
  module Commands
    module ProxyConfigCommand
      module Promote
        class PromoteSubcommand < Cri::CommandRunner
          include ThreeScaleToolbox::Command

          def self.command
            Cri::Command.define do
              name        'promote'
              usage       'promote <remote> <service>'
              summary     'Promote latest staging Proxy Configuration to the production environment'
              description 'Promote latest staging Proxy Configuration to the production environment'
              runner PromoteSubcommand

              param   :remote
              param   :service_ref
            end
          end

          def run
            latest_proxy_config.promote(to: to_env)
            puts "Proxy Configuration promoted to '#{to_env}'"
          end

          private

          def remote
            @remote ||= threescale_client(arguments[:remote])
          end

          def latest_proxy_config
            @proxy_config ||= find_proxy_config_latest
          end

          def find_proxy_config_latest
            Entities::ProxyConfig.find_latest(service: service, environment: from_env).tap do |pc|
              raise ThreeScaleToolbox::Error, "ProxyConfig #{from_env} in service #{service.id} does not exist" if pc.nil?
            end
          end

          def service_ref
            arguments[:service_ref]
          end

          def find_service
            Entities::Service.find(remote: remote,
                                   ref: service_ref).tap do |svc|
              raise ThreeScaleToolbox::Error, "Service #{service_ref} does not exist" if svc.nil?
            end
          end

          def service
            @service ||= find_service
          end

          def to_env
            "production"
          end

          def from_env
            "sandbox"
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
3scale_toolbox-0.11.0 lib/3scale_toolbox/commands/proxy_config_command/promote_command.rb