Class: ThreeScaleToolbox::Commands::ApplicationCommand::Apply::ApplySubcommand

Inherits:
Cri::CommandRunner
  • Object
show all
Includes:
ThreeScaleToolbox::Command
Defined in:
lib/3scale_toolbox/commands/application_command/apply_command.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ThreeScaleToolbox::Command

#config, #config_file, #exit_with_message, #fetch_required_option, included, #remotes, #threescale_client, #verbose, #verify_ssl

Class Method Details

.commandObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/3scale_toolbox/commands/application_command/apply_command.rb', line 26

def self.command
  Cri::Command.define do
    name        'apply'
    usage       'apply [opts] <remote> <application>'
    summary     'update (or create) application'
    description <<-HEREDOC
    Update (create if it does not exist) application'
    \n Application param allows:
    \n * User_key (API key)
    \n * App_id (from app_id/app_key pair) or Client ID (for OAuth and OpenID Connect authentication modes)
    \n * Application internal id
    HEREDOC

    option      nil, 'user-key', 'User Key (API Key) of the application to be created.', argument: :required
    option      nil, 'application-key', 'App Key(s) or Client Secret (for OAuth and OpenID Connect authentication modes) of the application to be created. Only used when application does not exist.' , argument: :required
    option      nil, :description, 'Application description', argument: :required
    option      nil, :name, 'Application name', argument: :required
    option      nil, :account, 'Application\'s account. Required when creating', argument: :required
    option      nil, :service, 'Application\'s service. Required when creating', argument: :required
    option      nil, :plan, 'Application\'s plan. Required when creating', argument: :required
    option      nil, :'redirect-url', 'OpenID Connect redirect url', argument: :required
    flag        nil, :resume, 'Resume a suspended application'
    flag        nil, :suspend, 'Suspends an application (changes the state to suspended)'
    ThreeScaleToolbox::CLI.output_flag(self)

    param       :remote
    param       :application

    runner ApplySubcommand
  end
end

Instance Method Details

#runObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/3scale_toolbox/commands/application_command/apply_command.rb', line 58

def run
  validate_option_params

  application = Entities::Application.find(remote: remote, service_id: service_id,
                                           ref: application_ref)
  if application.nil?
    validate_creation_option_params
    application = Entities::Application.create(remote: remote,
                                               account_id: .id,
                                               plan_id: plan.id,
                                               app_attrs: create_app_attrs)
  else
    application.update(app_attrs) unless app_attrs.empty?
  end

  application.resume if option_resume
  application.suspend if option_suspend

  printer.print_record application.attrs
end