Class: Kontena::Callbacks::BeforeDeployConfigurationWizard
- Inherits:
-
Kontena::Callback
- Object
- Kontena::Callback
- Kontena::Callbacks::BeforeDeployConfigurationWizard
- Includes:
- Kontena::Cli::Common
- Defined in:
- lib/kontena/callbacks/master/deploy/05_before_deploy_configuration_wizard.rb
Instance Attribute Summary
Attributes inherited from Kontena::Callback
Instance Method Summary collapse
- #after_load ⇒ Object
- #before ⇒ Object
- #login_to_kontena ⇒ Object
-
#next_default_name ⇒ Object
Scans config server names and returns default-2 if default exists, default-3 if default-2 exists, etc.
- #unless_param(param, &block) ⇒ Object
Methods included from Kontena::Cli::Common
#access_token=, #add_master, #any_key_to_continue, #any_key_to_continue_with_timeout, #api_url, #api_url=, #api_url_version, #ask, #clear_current_grid, #client, #cloud_auth?, #cloud_client, #config, #confirm, #confirm_command, #current_account, #current_grid, #current_grid=, #current_master, #current_master=, #current_master_index, #display_account_login_info, #display_login_info, #display_logo, #display_master_login_info, #error, #exit_with_error, #kontena_account, #logger, #pastel, #print, #prompt, #puts, #require_api_url, #require_current_account, #require_current_grid, #require_current_master, #require_token, #reset_client, #reset_cloud_client, #running_silent?, #running_verbose?, #settings, #settings_filename, #spinner, #sprint, #sputs, #use_refresh_token, #vfakespinner, #vputs, #vspinner, #warning, #yes?
Methods inherited from Kontena::Callback
callbacks, #initialize, matches_commands, run_callbacks
Constructor Details
This class inherits a constructor from Kontena::Callback
Instance Method Details
#after_load ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/kontena/callbacks/master/deploy/05_before_deploy_configuration_wizard.rb', line 9 def after_load command.class_eval do option ['--no-prompt'], :flag, "Don't ask questions" option ['--skip-auth-provider'], :flag, "Skip auth provider configuration (single user mode)" option ['--use-kontena-cloud'], :flag, "Use Kontena Cloud as authentication provider" option ['--cloud-master-id'], '[ID]', "Use Kontena Cloud Master ID for auth provider configuration" end end |
#before ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/kontena/callbacks/master/deploy/05_before_deploy_configuration_wizard.rb', line 52 def before unless_param(:name) do if command.cloud_master_id response = spinner "Receiving Master information from Kontena Cloud" do cloud_client.get("user/masters/#{command.cloud_master_id}") end if response.kind_of?(Hash) && response.has_key?('data') command.name = response['data']['attributes']['name'] else exit_with_error "Unable to receive Master information using id" end elsif command.no_prompt? command.name = next_default_name else command.name = prompt.ask("Enter a name for this Kontena Master: ", default: next_default_name, required: true) do |q| q.validate /^[a-z0-9\_\-\.]+$/, 'Name should only include lower case letters, numbers and -._, example: "master-4"' end end end unless_param(:skip_auth_provider) do unless command.no_prompt? || command.use_kontena_cloud? || command.cloud_master_id answer = prompt.select("Select OAuth2 authentication provider: ") do || .choice 'Kontena Cloud (recommended)', :kontena_new .choice 'Custom', :custom .choice 'None (single user mode)', :none end case answer when :kontena_new login_to_kontena || abort('You must login to Kontena Cloud') command.skip_auth_provider = false when :custom puts puts 'Learn how to configure custom user authentication provider after installation at: www.kontena.io/docs/using-kontena/authentication' puts command.cloud_master_id = nil command.skip_auth_provider = true when :none puts puts "You have selected to use Kontena Master in single user mode. You can configure an authentication provider later. For more information, see here: www.kontena.io/docs/using-kontena/authentication" puts command.cloud_master_id = nil command.skip_auth_provider = true else abort 'Should never be here' end end end true end |
#login_to_kontena ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/kontena/callbacks/master/deploy/05_before_deploy_configuration_wizard.rb', line 35 def login_to_kontena if cloud_auth? return true if cloud_client.authentication_ok?(kontena_account.userinfo_endpoint) end puts puts "You don't seem to be logged in to Kontena Cloud" puts Kontena.run("cloud login --verbose") config.reset_instance reset_cloud_client result = false Retriable.retriable do result = cloud_client.authentication_ok?(kontena_account.userinfo_endpoint) end result end |
#next_default_name ⇒ Object
Scans config server names and returns default-2 if default exists, default-3 if default-2 exists, etc.
26 27 28 29 30 31 32 33 |
# File 'lib/kontena/callbacks/master/deploy/05_before_deploy_configuration_wizard.rb', line 26 def next_default_name last_default = config.servers.map(&:name).select{ |n| n =~ /kontena\-master(?:\-\d+)?$/ }.sort.last return "kontena-master" unless last_default unless last_default =~ /\d$/ last_default << "-1" end last_default.succ end |
#unless_param(param, &block) ⇒ Object
18 19 20 21 22 |
# File 'lib/kontena/callbacks/master/deploy/05_before_deploy_configuration_wizard.rb', line 18 def unless_param(param, &block) return if command.respond_to?(param) && !command.send(param).nil? return if command.respond_to?("#{param}?".to_sym) && command.send("#{param}?".to_sym) yield end |