class ThreeScaleToolbox::Commands::ProxyConfigCommand::Promote::PromoteSubcommand

Public Class Methods

command() click to toggle source
# File lib/3scale_toolbox/commands/proxy_config_command/promote_command.rb, line 8
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

Public Instance Methods

run() click to toggle source
# File lib/3scale_toolbox/commands/proxy_config_command/promote_command.rb, line 21
def run
  if promotable?
    latest_proxy_config_from.promote(to: to_env)
    puts "Proxy Configuration version #{latest_proxy_config_from.version} promoted to '#{to_env}'"
  else
    warn "warning: Nothing to promote. Proxy Configuration version #{latest_proxy_config_from.version} already promoted to production"
  end
end

Private Instance Methods

find_proxy_config_latest_from() click to toggle source
# File lib/3scale_toolbox/commands/proxy_config_command/promote_command.rb, line 48
def find_proxy_config_latest_from
  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
find_proxy_config_latest_to() click to toggle source
# File lib/3scale_toolbox/commands/proxy_config_command/promote_command.rb, line 54
def find_proxy_config_latest_to
  Entities::ProxyConfig.find_latest(service: service, environment: to_env)
end
find_service() click to toggle source
# File lib/3scale_toolbox/commands/proxy_config_command/promote_command.rb, line 62
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
from_env() click to toggle source
# File lib/3scale_toolbox/commands/proxy_config_command/promote_command.rb, line 77
def from_env
  "sandbox"
end
latest_proxy_config_from() click to toggle source
# File lib/3scale_toolbox/commands/proxy_config_command/promote_command.rb, line 36
def latest_proxy_config_from
  @proxy_config_from ||= find_proxy_config_latest_from
end
latest_proxy_config_to() click to toggle source
# File lib/3scale_toolbox/commands/proxy_config_command/promote_command.rb, line 40
def latest_proxy_config_to
  @proxy_config_to ||= find_proxy_config_latest_to
end
promotable?() click to toggle source
# File lib/3scale_toolbox/commands/proxy_config_command/promote_command.rb, line 44
def promotable?
  return latest_proxy_config_to.nil? || latest_proxy_config_from.version != latest_proxy_config_to.version
end
remote() click to toggle source
# File lib/3scale_toolbox/commands/proxy_config_command/promote_command.rb, line 32
def remote
  @remote ||= threescale_client(arguments[:remote])
end
service() click to toggle source
# File lib/3scale_toolbox/commands/proxy_config_command/promote_command.rb, line 69
def service
  @service ||= find_service
end
service_ref() click to toggle source
# File lib/3scale_toolbox/commands/proxy_config_command/promote_command.rb, line 58
def service_ref
  arguments[:service_ref]
end
to_env() click to toggle source
# File lib/3scale_toolbox/commands/proxy_config_command/promote_command.rb, line 73
def to_env
  "production"
end