kontena-cli 0.15.5 → 0.16.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +0 -3
- data/Gemfile +3 -0
- data/LOGO +8 -0
- data/VERSION +1 -1
- data/kontena-cli.gemspec +2 -3
- data/lib/kontena/callback.rb +57 -0
- data/lib/kontena/callbacks/.gitkeep +0 -0
- data/lib/kontena/callbacks/auth/01_list_and_select_grid_after_master_auth.rb +27 -0
- data/lib/kontena/callbacks/master/01_clear_current_master_after_terminate.rb +20 -0
- data/lib/kontena/callbacks/master/deploy/01_show_logo_before_deploy.rb +15 -0
- data/lib/kontena/callbacks/master/deploy/05_before_deploy_configuration_wizard.rb +124 -0
- data/lib/kontena/callbacks/master/deploy/50_authenticate_after_deploy.rb +53 -0
- data/lib/kontena/callbacks/master/deploy/55_create_initial_grid_after_deploy.rb +32 -0
- data/lib/kontena/callbacks/master/deploy/60_configure_auth_provider_after_deploy.rb +49 -0
- data/lib/kontena/callbacks/master/deploy/90_suggest_inviting_yourself_after_deploy.rb +24 -0
- data/lib/kontena/cli/app_command.rb +2 -1
- data/lib/kontena/cli/apps/build_command.rb +1 -1
- data/lib/kontena/cli/apps/common.rb +6 -1
- data/lib/kontena/cli/apps/config_command.rb +1 -1
- data/lib/kontena/cli/apps/deploy_command.rb +1 -1
- data/lib/kontena/cli/apps/init_command.rb +3 -5
- data/lib/kontena/cli/apps/list_command.rb +1 -1
- data/lib/kontena/cli/apps/logs_command.rb +1 -1
- data/lib/kontena/cli/apps/monitor_command.rb +1 -1
- data/lib/kontena/cli/apps/remove_command.rb +2 -3
- data/lib/kontena/cli/apps/restart_command.rb +1 -1
- data/lib/kontena/cli/apps/scale_command.rb +1 -1
- data/lib/kontena/cli/apps/show_command.rb +1 -1
- data/lib/kontena/cli/apps/start_command.rb +1 -1
- data/lib/kontena/cli/apps/stop_command.rb +1 -1
- data/lib/kontena/cli/apps/yaml/reader.rb +3 -13
- data/lib/kontena/cli/apps/yaml/validator.rb +0 -4
- data/lib/kontena/cli/apps/yaml/validator_v2.rb +1 -5
- data/lib/kontena/cli/certificate/authorize_command.rb +1 -1
- data/lib/kontena/cli/certificate/get_command.rb +1 -1
- data/lib/kontena/cli/certificate/register_command.rb +1 -1
- data/lib/kontena/cli/certificate_command.rb +1 -1
- data/lib/kontena/cli/cloud/login_command.rb +128 -0
- data/lib/kontena/cli/cloud/master/add_command.rb +54 -0
- data/lib/kontena/cli/cloud/master/delete_command.rb +20 -0
- data/lib/kontena/cli/cloud/master/list_command.rb +29 -0
- data/lib/kontena/cli/cloud/master/show_command.rb +23 -0
- data/lib/kontena/cli/cloud/master/update_command.rb +58 -0
- data/lib/kontena/cli/cloud/master_command.rb +21 -0
- data/lib/kontena/cli/cloud_command.rb +10 -0
- data/lib/kontena/cli/common.rb +230 -88
- data/lib/kontena/cli/config.rb +537 -0
- data/lib/kontena/cli/container_command.rb +1 -1
- data/lib/kontena/cli/containers/exec_command.rb +1 -1
- data/lib/kontena/cli/containers/inspect_command.rb +1 -1
- data/lib/kontena/cli/etcd/get_command.rb +1 -1
- data/lib/kontena/cli/etcd/list_command.rb +1 -1
- data/lib/kontena/cli/etcd/mkdir_command.rb +1 -1
- data/lib/kontena/cli/etcd/remove_command.rb +1 -1
- data/lib/kontena/cli/etcd/set_command.rb +1 -1
- data/lib/kontena/cli/etcd_command.rb +1 -1
- data/lib/kontena/cli/external_registries/add_command.rb +1 -1
- data/lib/kontena/cli/external_registries/delete_command.rb +1 -1
- data/lib/kontena/cli/external_registries/list_command.rb +1 -1
- data/lib/kontena/cli/external_registries/remove_command.rb +1 -1
- data/lib/kontena/cli/external_registry_command.rb +1 -1
- data/lib/kontena/cli/grid_command.rb +1 -1
- data/lib/kontena/cli/grids/audit_log_command.rb +6 -5
- data/lib/kontena/cli/grids/cloud_config_command.rb +1 -1
- data/lib/kontena/cli/grids/common.rb +1 -1
- data/lib/kontena/cli/grids/create_command.rb +8 -4
- data/lib/kontena/cli/grids/current_command.rb +1 -1
- data/lib/kontena/cli/grids/env_command.rb +1 -1
- data/lib/kontena/cli/grids/list_command.rb +35 -10
- data/lib/kontena/cli/grids/logs_command.rb +1 -1
- data/lib/kontena/cli/grids/remove_command.rb +2 -2
- data/lib/kontena/cli/grids/show_command.rb +1 -1
- data/lib/kontena/cli/grids/trusted_subnet_command.rb +1 -1
- data/lib/kontena/cli/grids/trusted_subnets/add_command.rb +1 -1
- data/lib/kontena/cli/grids/trusted_subnets/list_command.rb +1 -1
- data/lib/kontena/cli/grids/trusted_subnets/remove_command.rb +1 -1
- data/lib/kontena/cli/grids/update_command.rb +1 -1
- data/lib/kontena/cli/grids/use_command.rb +11 -6
- data/lib/kontena/cli/grids/user_command.rb +1 -1
- data/lib/kontena/cli/grids/users/add_command.rb +1 -1
- data/lib/kontena/cli/grids/users/list_command.rb +1 -1
- data/lib/kontena/cli/grids/users/remove_command.rb +1 -1
- data/lib/kontena/cli/localhost_web_server.rb +93 -0
- data/lib/kontena/cli/login_command.rb +5 -118
- data/lib/kontena/cli/logout_command.rb +33 -2
- data/lib/kontena/cli/master/audit_log_command.rb +19 -0
- data/lib/kontena/cli/master/config/export_command.rb +47 -0
- data/lib/kontena/cli/master/config/get_command.rb +24 -0
- data/lib/kontena/cli/master/config/import_command.rb +69 -0
- data/lib/kontena/cli/master/config/set_command.rb +19 -0
- data/lib/kontena/cli/master/config/unset_command.rb +20 -0
- data/lib/kontena/cli/master/config_command.rb +24 -0
- data/lib/kontena/cli/master/create_command.rb +76 -0
- data/lib/kontena/cli/master/current_command.rb +10 -2
- data/lib/kontena/cli/master/join_command.rb +20 -0
- data/lib/kontena/cli/master/list_command.rb +4 -4
- data/lib/kontena/cli/master/login_command.rb +274 -0
- data/lib/kontena/cli/master/use_command.rb +8 -19
- data/lib/kontena/cli/master/users/invite_command.rb +33 -6
- data/lib/kontena/cli/master/users/list_command.rb +2 -2
- data/lib/kontena/cli/master/users/remove_command.rb +1 -1
- data/lib/kontena/cli/master/users/role_command.rb +1 -1
- data/lib/kontena/cli/master/users/roles/add_command.rb +18 -16
- data/lib/kontena/cli/master/users/roles/remove_command.rb +1 -1
- data/lib/kontena/cli/master/users_command.rb +1 -1
- data/lib/kontena/cli/master_command.rb +21 -1
- data/lib/kontena/cli/node_command.rb +1 -1
- data/lib/kontena/cli/nodes/label_command.rb +1 -1
- data/lib/kontena/cli/nodes/labels/add_command.rb +1 -1
- data/lib/kontena/cli/nodes/labels/remove_command.rb +1 -1
- data/lib/kontena/cli/nodes/list_command.rb +1 -1
- data/lib/kontena/cli/nodes/remove_command.rb +1 -1
- data/lib/kontena/cli/nodes/show_command.rb +1 -1
- data/lib/kontena/cli/nodes/ssh_command.rb +1 -1
- data/lib/kontena/cli/nodes/update_command.rb +1 -1
- data/lib/kontena/cli/plugin_command.rb +1 -1
- data/lib/kontena/cli/plugins/install_command.rb +2 -2
- data/lib/kontena/cli/plugins/list_command.rb +2 -2
- data/lib/kontena/cli/plugins/search_command.rb +1 -1
- data/lib/kontena/cli/plugins/uninstall_command.rb +2 -2
- data/lib/kontena/cli/registry/create_command.rb +2 -4
- data/lib/kontena/cli/registry/delete_command.rb +1 -1
- data/lib/kontena/cli/registry/remove_command.rb +1 -1
- data/lib/kontena/cli/registry_command.rb +1 -1
- data/lib/kontena/cli/service_command.rb +1 -1
- data/lib/kontena/cli/services/container_command.rb +1 -1
- data/lib/kontena/cli/services/containers_command.rb +1 -1
- data/lib/kontena/cli/services/create_command.rb +1 -1
- data/lib/kontena/cli/services/delete_command.rb +1 -1
- data/lib/kontena/cli/services/deploy_command.rb +1 -1
- data/lib/kontena/cli/services/env_command.rb +1 -1
- data/lib/kontena/cli/services/envs/add_command.rb +1 -1
- data/lib/kontena/cli/services/envs/list_command.rb +1 -1
- data/lib/kontena/cli/services/envs/remove_command.rb +1 -1
- data/lib/kontena/cli/services/link_command.rb +1 -1
- data/lib/kontena/cli/services/list_command.rb +1 -1
- data/lib/kontena/cli/services/logs_command.rb +1 -1
- data/lib/kontena/cli/services/monitor_command.rb +1 -1
- data/lib/kontena/cli/services/remove_command.rb +1 -1
- data/lib/kontena/cli/services/restart_command.rb +1 -1
- data/lib/kontena/cli/services/scale_command.rb +1 -1
- data/lib/kontena/cli/services/secret_command.rb +1 -1
- data/lib/kontena/cli/services/secrets/link_command.rb +1 -1
- data/lib/kontena/cli/services/secrets/unlink_command.rb +1 -1
- data/lib/kontena/cli/services/services_helper.rb +6 -3
- data/lib/kontena/cli/services/show_command.rb +1 -1
- data/lib/kontena/cli/services/start_command.rb +1 -1
- data/lib/kontena/cli/services/stats_command.rb +1 -1
- data/lib/kontena/cli/services/stop_command.rb +1 -1
- data/lib/kontena/cli/services/unlink_command.rb +1 -1
- data/lib/kontena/cli/services/update_command.rb +1 -1
- data/lib/kontena/cli/spinner.rb +122 -0
- data/lib/kontena/cli/stack_command.rb +1 -1
- data/lib/kontena/cli/stacks/create_command.rb +1 -1
- data/lib/kontena/cli/stacks/deploy_command.rb +1 -1
- data/lib/kontena/cli/stacks/list_command.rb +1 -1
- data/lib/kontena/cli/stacks/remove_command.rb +1 -1
- data/lib/kontena/cli/stacks/show_command.rb +1 -1
- data/lib/kontena/cli/stacks/update_command.rb +1 -1
- data/lib/kontena/cli/vault/list_command.rb +1 -1
- data/lib/kontena/cli/vault/read_command.rb +1 -1
- data/lib/kontena/cli/vault/remove_command.rb +1 -1
- data/lib/kontena/cli/vault/update_command.rb +1 -1
- data/lib/kontena/cli/vault/write_command.rb +1 -1
- data/lib/kontena/cli/vault_command.rb +1 -1
- data/lib/kontena/cli/version.rb +1 -1
- data/lib/kontena/cli/version_command.rb +1 -1
- data/lib/kontena/cli/vpn/config_command.rb +1 -1
- data/lib/kontena/cli/vpn/create_command.rb +2 -4
- data/lib/kontena/cli/vpn/delete_command.rb +1 -1
- data/lib/kontena/cli/vpn/remove_command.rb +1 -1
- data/lib/kontena/cli/vpn_command.rb +1 -1
- data/lib/kontena/cli/whoami_command.rb +16 -13
- data/lib/kontena/client.rb +410 -90
- data/lib/kontena/command.rb +172 -0
- data/lib/kontena/main_command.rb +7 -8
- data/lib/kontena/presets/github_auth_provider.yml +11 -0
- data/lib/kontena/presets/kontena_auth_provider.yml +11 -0
- data/lib/kontena_cli.rb +51 -1
- data/spec/kontena/cli/app/deploy_command_spec.rb +14 -44
- data/spec/kontena/cli/app/scale_spec.rb +1 -1
- data/spec/kontena/cli/app/yaml/reader_spec.rb +0 -48
- data/spec/kontena/cli/common_spec.rb +63 -59
- data/spec/kontena/cli/grids/use_command_spec.rb +43 -0
- data/spec/kontena/cli/master/current_command_spec.rb +3 -24
- data/spec/kontena/cli/master/use_command_spec.rb +2 -27
- data/spec/kontena/cli/master/users/invite_command_spec.rb +4 -18
- data/spec/kontena/cli/master/users/roles/add_command_spec.rb +2 -16
- data/spec/kontena/cli/master/users/roles/remove_command_spec.rb +2 -13
- data/spec/kontena/cli/services/restart_command_spec.rb +1 -1
- data/spec/kontena/cli/services/update_command_spec.rb +5 -5
- data/spec/kontena/client_spec.rb +104 -35
- data/spec/kontena/config_spec.rb +65 -0
- data/spec/spec_helper.rb +25 -3
- data/spec/support/client_helpers.rb +10 -3
- data/spec/support/requirements_helper.rb +32 -0
- metadata +61 -48
- data/lib/kontena/cli/register_command.rb +0 -23
- data/lib/kontena/cli/user/forgot_password_command.rb +0 -16
- data/lib/kontena/cli/user/reset_password_command.rb +0 -23
- data/lib/kontena/cli/user/verify_command.rb +0 -20
- data/lib/kontena/cli/user_command.rb +0 -13
- data/spec/fixtures/kontena-malformed-yaml.yml +0 -6
- data/spec/fixtures/kontena-not-hash-service-config.yml +0 -3
- data/spec/kontena/cli/login_command_spec.rb +0 -32
- data/spec/kontena/cli/register_command_spec.rb +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6dd79efbf65d99f1a53951c4064ae5361a6f45e7
|
4
|
+
data.tar.gz: 826215936d53f0c1e45896d648c21c3fbd2862b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 226857ae59df5a8d5e4d9ae3eb22900360ee35eb3dc84754ad242d06c48e04dcc5130f47888abc555c850d438c9757eb716323474125cbb38c84e3e829d2046a
|
7
|
+
data.tar.gz: da4bc3d5892b56af1bb0adc7ab1d1fd2ab581fdcf0284675fa703d5d8ad8c27b1ca81db89ae73e7b78483f023448f1a3876cf82c22c037375ed4104a1eaccce6
|
data/Dockerfile
CHANGED
@@ -9,12 +9,9 @@ RUN apk update && \
|
|
9
9
|
ca-certificates libssl1.0 openssl libstdc++ && \
|
10
10
|
gem install kontena-cli --no-rdoc --no-ri -v ${CLI_VERSION} && \
|
11
11
|
adduser kontena -D -h /home/kontena -s /bin/sh && \
|
12
|
-
echo "gem: --user-install" > /home/kontena/.gemrc && \
|
13
12
|
chown -R kontena.kontena /home/kontena && \
|
14
13
|
chmod +sx /usr/local/bin/docker
|
15
14
|
|
16
|
-
ENV PATH=$PATH:/home/kontena/.gem/ruby/2.3.0/bin
|
17
|
-
|
18
15
|
VOLUME ["/home/kontena"]
|
19
16
|
WORKDIR /home/kontena
|
20
17
|
USER kontena
|
data/Gemfile
CHANGED
@@ -4,5 +4,8 @@ source 'https://rubygems.org'
|
|
4
4
|
gemspec
|
5
5
|
group :development, :test do
|
6
6
|
gem "rspec"
|
7
|
+
gem 'simplecov', :require => false, :group => :test
|
7
8
|
gem "kontena-plugin-hello", path: "./examples/kontena-plugin-hello"
|
9
|
+
gem 'pry', require: false
|
10
|
+
gem 'pry-byebug', require: false
|
8
11
|
end
|
data/LOGO
ADDED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.16.0.pre1
|
data/kontena-cli.gemspec
CHANGED
@@ -23,14 +23,13 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.7"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
25
|
spec.add_runtime_dependency "excon", "~> 0.49.0"
|
26
|
-
spec.add_runtime_dependency "
|
26
|
+
spec.add_runtime_dependency "tty-prompt", "~> 0.7.1"
|
27
27
|
spec.add_runtime_dependency "clamp", "~> 1.0.0"
|
28
|
-
spec.add_runtime_dependency "highline", "~> 1.7.8"
|
29
|
-
spec.add_runtime_dependency "shell-spinner", "~> 1.0.4"
|
30
28
|
spec.add_runtime_dependency "ruby_dig", "~> 0.0.2"
|
31
29
|
spec.add_runtime_dependency "dry-validation", "0.8.0"
|
32
30
|
spec.add_runtime_dependency "dry-types", "0.8.0"
|
33
31
|
spec.add_runtime_dependency "dry-configurable", "0.1.6"
|
34
32
|
spec.add_runtime_dependency "dry-monads", "0.1.1"
|
35
33
|
spec.add_runtime_dependency "dry-logic", "0.3.0"
|
34
|
+
spec.add_runtime_dependency "launchy", "~> 2.4.3"
|
36
35
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class Kontena::Callback
|
2
|
+
|
3
|
+
attr_reader :command
|
4
|
+
|
5
|
+
def initialize(command)
|
6
|
+
@command = command
|
7
|
+
end
|
8
|
+
|
9
|
+
# Register callback for command types it is supposed to run with.
|
10
|
+
def self.matches_commands(*commands)
|
11
|
+
cmd_types = {}
|
12
|
+
|
13
|
+
commands.each do |cmd|
|
14
|
+
cmd_class, cmd_type = cmd.split(' ', 2)
|
15
|
+
|
16
|
+
if cmd_class == '*'
|
17
|
+
cmd_class = :all
|
18
|
+
end
|
19
|
+
|
20
|
+
if cmd_type.nil? || cmd_type == '*'
|
21
|
+
cmd_type = :all
|
22
|
+
else
|
23
|
+
cmd_type = cmd_type.to_sym
|
24
|
+
end
|
25
|
+
cmd_types[cmd_class.to_sym] = cmd_type
|
26
|
+
end
|
27
|
+
|
28
|
+
# Finally it should be normalized into a hash that looks like :cmd_class => :cmd_type, :app => :init, :grid => :all
|
29
|
+
cmd_types.each do |cmd_class, cmd_type|
|
30
|
+
Kontena::Callback.callbacks[cmd_class] ||= {}
|
31
|
+
Kontena::Callback.callbacks[cmd_class][cmd_type] ||= []
|
32
|
+
Kontena::Callback.callbacks[cmd_class][cmd_type] << self
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.callbacks
|
37
|
+
@@callbacks ||= {}
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.run_callbacks(cmd_type, state, obj)
|
41
|
+
[cmd_type.last, :all].compact.uniq.each do |cmdtype|
|
42
|
+
[cmd_type.first, :all].compact.uniq.each do |cmdclass|
|
43
|
+
callbacks.fetch(cmdclass, {}).fetch(cmdtype, []).each do |klass|
|
44
|
+
if klass.instance_methods.include?(state)
|
45
|
+
cb = klass.new(obj)
|
46
|
+
if cb.send(state).kind_of?(FalseClass)
|
47
|
+
ENV["DEBUG"] && puts("Execution aborted by #{klass}")
|
48
|
+
exit 1
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
Dir[File.expand_path('../callbacks/**/*.rb', __FILE__)].sort_by{ |file| File.basename(file) }.each { |file| require file }
|
File without changes
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Kontena
|
2
|
+
module Callbacks
|
3
|
+
class ListAndSelectGrid < Kontena::Callback
|
4
|
+
|
5
|
+
include Kontena::Cli::Common
|
6
|
+
|
7
|
+
matches_commands 'master auth'
|
8
|
+
|
9
|
+
def after_load
|
10
|
+
command.class_eval do
|
11
|
+
option ['--skip-grid-auto-select'], :flag, 'Do not auto select grid'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Runs kontena grids list --use which will auto join the first available
|
16
|
+
# grid
|
17
|
+
def after
|
18
|
+
return if command.skip_grid_auto_select?
|
19
|
+
return unless current_master
|
20
|
+
return unless command.exit_code == 0
|
21
|
+
return unless current_master.grid.nil?
|
22
|
+
|
23
|
+
Kontena.run('grid list --use --verbose')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Kontena
|
2
|
+
module Callbacks
|
3
|
+
class ClearCurrentMasterAfterTerminate < Kontena::Callback
|
4
|
+
|
5
|
+
include Kontena::Cli::Common
|
6
|
+
|
7
|
+
matches_commands 'master terminate'
|
8
|
+
|
9
|
+
def after
|
10
|
+
return unless command.exit_code == 0
|
11
|
+
return unless config.current_master
|
12
|
+
|
13
|
+
ENV["DEBUG"] && puts("Removing current master from config")
|
14
|
+
config.servers.delete_at(config.find_server_index(config.current_master.name))
|
15
|
+
config.current_server = nil
|
16
|
+
config.write
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module Kontena
|
2
|
+
module Callbacks
|
3
|
+
class BeforeDeployConfigurationWizard < Kontena::Callback
|
4
|
+
|
5
|
+
include Kontena::Cli::Common
|
6
|
+
|
7
|
+
matches_commands 'master create'
|
8
|
+
|
9
|
+
def after_load
|
10
|
+
command.class_eval do
|
11
|
+
option ['--no-prompt'], :flag, "Don't ask questions"
|
12
|
+
option ['--skip-auth-provider'], :flag, "Skip auth provider configuration (single user mode)"
|
13
|
+
option ['--cloud-master-id'], '[ID]', "Use Kontena Cloud Master ID for auth provider configuration"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def unless_param(param, &block)
|
18
|
+
return if command.respond_to?(param) && !command.send(param).nil?
|
19
|
+
return if command.respond_to?("#{param}?".to_sym) && command.send("#{param}?".to_sym)
|
20
|
+
yield
|
21
|
+
end
|
22
|
+
|
23
|
+
# Scans config server names and returns default-2 if default exists,
|
24
|
+
# default-3 if default-2 exists, etc.
|
25
|
+
def next_default_name
|
26
|
+
last_default = config.servers.map(&:name).select{ |n| n =~ /default(?:\-\d+)?$/ }.sort.last
|
27
|
+
return "default" unless last_default
|
28
|
+
unless last_default =~ /\d$/
|
29
|
+
last_default << "-1"
|
30
|
+
end
|
31
|
+
last_default.succ
|
32
|
+
end
|
33
|
+
|
34
|
+
def login_to_kontena
|
35
|
+
if kontena_auth?
|
36
|
+
return true if cloud_client.authentication_ok?(kontena_account.userinfo_endpoint)
|
37
|
+
end
|
38
|
+
puts
|
39
|
+
puts "You don't seem to be logged in to Kontena Cloud"
|
40
|
+
puts
|
41
|
+
Kontena.run("cloud login --verbose")
|
42
|
+
cloud_client.authentication_ok?(kontena_account.userinfo_endpoint)
|
43
|
+
end
|
44
|
+
|
45
|
+
def select_cloud_master
|
46
|
+
masters = []
|
47
|
+
spinner "Retrieving a list of registered masters on your Kontena Cloud account" do
|
48
|
+
masters = cloud_client.get("user/masters")["data"]
|
49
|
+
end
|
50
|
+
if masters.empty?
|
51
|
+
puts
|
52
|
+
puts "You have no registered masters. Adding a new master."
|
53
|
+
puts
|
54
|
+
return create_cloud_master
|
55
|
+
else
|
56
|
+
puts
|
57
|
+
return prompt.select("Select master") do |menu|
|
58
|
+
masters.each do |master|
|
59
|
+
name = master['attributes']['name']
|
60
|
+
url = master['attributes']['url']
|
61
|
+
master_id = master['id']
|
62
|
+
menu.choice "#{master['attributes']['name']} (#{url.nil? ? "setup not done" : url})", master_id
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def create_cloud_master
|
69
|
+
master_id = nil
|
70
|
+
spinner "Registering a new cloud master '#{command.name}'" do
|
71
|
+
master_id = Kontena.run("cloud master add --return #{command.name}", returning: :result)
|
72
|
+
end
|
73
|
+
if master_id.to_s =~ /^[0-9a-f]{16,32}$/
|
74
|
+
master_id
|
75
|
+
else
|
76
|
+
abort 'Cloud Master registration failed'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def before
|
81
|
+
unless_param(:name) do
|
82
|
+
if command.no_prompt?
|
83
|
+
command.name = next_default_name
|
84
|
+
else
|
85
|
+
command.name = prompt.ask("Enter a name for this Kontena Master: ", default: next_default_name, required: true) do |q|
|
86
|
+
q.validate /^[a-z0-9\_\-\.]+$/, 'Name should only include lower case letters, numbers and -._, example: "master-4"'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
unless_param(:skip_auth_provider) do
|
92
|
+
if command.no_prompt?
|
93
|
+
command.cloud_master_id ||= create_cloud_master
|
94
|
+
elsif command.cloud_master_id.nil?
|
95
|
+
answer = prompt.select("Select user authentication provider") do |menu|
|
96
|
+
menu.choice 'Kontena Cloud (add a new master)', :kontena_new
|
97
|
+
menu.choice 'Kontena Cloud (use an existing master)', :kontena_existing
|
98
|
+
menu.choice 'Custom', :custom
|
99
|
+
menu.choice 'None (single user mode)', :none
|
100
|
+
end
|
101
|
+
case answer
|
102
|
+
when :kontena_new, :kontena_existing
|
103
|
+
login_to_kontena || abort('You must login to Kontena Cloud')
|
104
|
+
if answer == :kontena_new
|
105
|
+
command.cloud_master_id = create_cloud_master
|
106
|
+
else
|
107
|
+
command.cloud_master_id = select_cloud_master
|
108
|
+
end
|
109
|
+
when :custom
|
110
|
+
puts 'Learn how to configure custom user authentication provider after installation at: www.kontena.io/docs/configuring-custom-auth-provider'
|
111
|
+
when :none
|
112
|
+
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/configuring-custom-auth-provider"
|
113
|
+
else
|
114
|
+
abort 'Should never be here'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
command.skip_auth_provider = !command.cloud_master_id.nil?
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
module Kontena
|
3
|
+
module Callbacks
|
4
|
+
class AuthenticateAfterDeploy < Kontena::Callback
|
5
|
+
|
6
|
+
include Kontena::Cli::Common
|
7
|
+
|
8
|
+
matches_commands 'master create'
|
9
|
+
|
10
|
+
def after
|
11
|
+
ENV["DEBUG"] && puts("Command result: #{command.result.inspect}")
|
12
|
+
ENV["DEBUG"] && puts("Command exit code: #{command.exit_code.inspect}")
|
13
|
+
return unless command.exit_code == 0
|
14
|
+
return unless command.result.kind_of?(Hash)
|
15
|
+
return unless command.result.has_key?(:public_ip)
|
16
|
+
return unless command.result.has_key?(:code)
|
17
|
+
return unless command.result.has_key?(:name)
|
18
|
+
|
19
|
+
# In case there already is a server with the same name add random characters to name
|
20
|
+
if config.find_server(command.result[:name])
|
21
|
+
command.result[:name] = "#{command.result[:name]}-#{SecureRandom.hex(2)}"
|
22
|
+
end
|
23
|
+
|
24
|
+
new_master = Kontena::Cli::Config::Server.new(
|
25
|
+
url: "https://#{command.result[:public_ip]}",
|
26
|
+
name: command.result[:name]
|
27
|
+
)
|
28
|
+
|
29
|
+
retried = false
|
30
|
+
|
31
|
+
# Figure out if HTTPS works, if not, try HTTP
|
32
|
+
begin
|
33
|
+
ENV["DEBUG"] && puts("Trying to request / from #{new_master.url}")
|
34
|
+
client = Kontena::Client.new(new_master.url, nil, ignore_ssl_errors: true)
|
35
|
+
client.get('/')
|
36
|
+
rescue
|
37
|
+
ENV["DEBUG"] && puts("HTTPS test failed: #{$!} #{$!.message}")
|
38
|
+
unless retried
|
39
|
+
new_master.url = "http://#{command.result[:public_ip]}"
|
40
|
+
retried = true
|
41
|
+
retry
|
42
|
+
end
|
43
|
+
return
|
44
|
+
end
|
45
|
+
|
46
|
+
require 'shellwords'
|
47
|
+
cmd = "master login --verbose --name #{command.result[:name].shellescape} --code #{command.result[:code].shellescape} #{new_master.url.shellescape}"
|
48
|
+
ENV["DEBUG"] && puts("Running: #{cmd}")
|
49
|
+
Kontena.run(cmd)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Kontena
|
2
|
+
module Callbacks
|
3
|
+
# Runs kontena master auth-provider config after deployment if
|
4
|
+
# auth provider configuration options have been supplied.
|
5
|
+
#
|
6
|
+
# Runs the config command with --preset kontena if the user has
|
7
|
+
# authenticated to Kontena unless --no-auth-config is used.
|
8
|
+
class CreateInitialGridAfterDeploy < Kontena::Callback
|
9
|
+
|
10
|
+
include Kontena::Cli::Common
|
11
|
+
|
12
|
+
matches_commands 'master create'
|
13
|
+
|
14
|
+
def after
|
15
|
+
return unless command.exit_code == 0
|
16
|
+
return unless config.current_master
|
17
|
+
return unless config.current_master.name == command.result[:name]
|
18
|
+
|
19
|
+
cmd = "grid create --silent test"
|
20
|
+
ENV["DEBUG"] && puts("Running: #{cmd}")
|
21
|
+
|
22
|
+
spinner "Creating initial grid 'test'" do
|
23
|
+
Kontena.run(cmd)
|
24
|
+
end
|
25
|
+
|
26
|
+
spinner "Selecting 'test' as current grid" do
|
27
|
+
Kontena.run("grid use test")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Kontena
|
2
|
+
module Callbacks
|
3
|
+
class ConfigureAuthProviderAfterDeploy < Kontena::Callback
|
4
|
+
|
5
|
+
include Kontena::Cli::Common
|
6
|
+
|
7
|
+
matches_commands 'master create'
|
8
|
+
|
9
|
+
def get_oauth_app_config(master_id)
|
10
|
+
attrs = nil
|
11
|
+
spinner "Retrieving master OAuth2 application settings from Kontena Cloud" do
|
12
|
+
attrs = cloud_client.get("user/masters/#{master_id}")["data"]["attributes"]
|
13
|
+
end
|
14
|
+
attrs
|
15
|
+
rescue
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def configure_auth_provider(oauth_config)
|
20
|
+
require 'shellwords'
|
21
|
+
spinner "Setting Kontena Cloud authentication provider base settings to Master config" do
|
22
|
+
Kontena.run("master config import --force --preset kontena_auth_provider")
|
23
|
+
end
|
24
|
+
spinner "Setting Kontena Cloud authentication provider consumer credentials to Master config" do
|
25
|
+
Kontena.run("master config set oauth2.client_id=#{oauth_config['client-id'].shellescape} oauth2.client_secret=#{oauth_config['client-secret'].shellescape} server.root_url=#{config.current_master.url.shellescape}")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def after
|
30
|
+
return unless command.exit_code == 0
|
31
|
+
return unless command.result.kind_of?(Hash)
|
32
|
+
return unless command.result.has_key?(:name)
|
33
|
+
return unless config.current_master
|
34
|
+
return unless config.current_master.name == command.result[:name]
|
35
|
+
if command.respond_to?(:skip_auth_provider) && command.skip_auth_provider?
|
36
|
+
return
|
37
|
+
end
|
38
|
+
|
39
|
+
if command.respond_to?(:cloud_master_id) && command.cloud_master_id
|
40
|
+
oauth_config = get_oauth_app_config(command.cloud_master_id)
|
41
|
+
if oauth_config
|
42
|
+
configure_auth_provider(oauth_config)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|