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
data/lib/kontena/command.rb
CHANGED
@@ -1,4 +1,176 @@
|
|
1
1
|
require 'clamp'
|
2
2
|
|
3
3
|
class Kontena::Command < Clamp::Command
|
4
|
+
|
5
|
+
attr_accessor :arguments
|
6
|
+
attr_reader :result
|
7
|
+
attr_reader :exit_code
|
8
|
+
|
9
|
+
|
10
|
+
def self.inherited(where)
|
11
|
+
return if where.has_subcommands?
|
12
|
+
return if where.callback_matcher
|
13
|
+
|
14
|
+
name_parts = where.name.split('::')[-2, 2]
|
15
|
+
|
16
|
+
unless name_parts.compact.empty?
|
17
|
+
# 1: Remove trailing 'Command' from for example AuthCommand
|
18
|
+
# 2: Convert the string from CamelCase to under_score
|
19
|
+
# 3: Convert the string into a symbol
|
20
|
+
#
|
21
|
+
# In comes: ['ExternalRegistry', 'UseCommand']
|
22
|
+
# Out goes: [:external_registry, :use]
|
23
|
+
name_parts = name_parts.map { |np|
|
24
|
+
np.gsub(/Command$/, '').
|
25
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
26
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
27
|
+
tr("-", "_").
|
28
|
+
downcase.
|
29
|
+
to_sym
|
30
|
+
}
|
31
|
+
where.callback_matcher(*name_parts)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Run all #after_load callbacks for this command.
|
35
|
+
[name_parts.last, :all].compact.uniq.each do |cmd_type|
|
36
|
+
[name_parts.first, :all].compact.uniq.each do |cmd_class|
|
37
|
+
if Kontena::Callback.callbacks.fetch(cmd_class, {}).fetch(cmd_type, nil)
|
38
|
+
Kontena::Callback.callbacks[cmd_class][cmd_type].each do |cb|
|
39
|
+
if cb.instance_methods.include?(:after_load)
|
40
|
+
cb.new(where).after_load
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.callback_matcher(cmd_class = nil, cmd_type = nil)
|
49
|
+
unless cmd_class
|
50
|
+
if @command_class.nil?
|
51
|
+
return nil
|
52
|
+
else
|
53
|
+
return [@command_class, @command_type]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
@command_class = cmd_class.to_sym
|
57
|
+
@command_type = cmd_type.to_sym
|
58
|
+
[@command_class, @command_type]
|
59
|
+
end
|
60
|
+
|
61
|
+
def run_callbacks(state)
|
62
|
+
if self.class.respond_to?(:callback_matcher) && !self.class.callback_matcher.compact.empty?
|
63
|
+
Kontena::Callback.run_callbacks(self.class.callback_matcher, state, self)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Overwrite Clamp's banner command. Calling banner multiple times
|
68
|
+
# will now add lines to the banner message instead of overwriting
|
69
|
+
# the whole message. This is useful if callbacks add banner messages.
|
70
|
+
#
|
71
|
+
# @param [String] message
|
72
|
+
def self.banner(msg, extra_feed = true)
|
73
|
+
self.description = [self.description, extra_feed ? "\n#{msg}" : msg].compact.join("\n")
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.requires_current_master
|
77
|
+
banner "#{Kontena.pastel.green("Requires current master")}: This command requires that you have selected a current master using 'kontena master auth' or 'kontena master use'. You can also use the environment variable KONTENA_URL to specify the master address or KONTENA_MASTER=master_name to override the current_master setting."
|
78
|
+
@requires_current_master = true
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.requires_current_grid
|
82
|
+
banner "#{Kontena.pastel.green("Requires current grid")}: This command requires that you have selected a grid as the current grid using 'kontena grid use' or by setting KONTENA_GRID environment variable."
|
83
|
+
@requires_current_grid = true
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.requires_current_account_token
|
87
|
+
banner "#{Kontena.pastel.green("Requires account authentication")}: This command requires that you have authenticated to Kontena Cloud using 'kontena cloud auth'"
|
88
|
+
@requires_current_account_token = true
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
def self.requires_current_master?
|
93
|
+
@requires_current_master ||= false
|
94
|
+
end
|
95
|
+
|
96
|
+
def verify_current_master
|
97
|
+
Kontena::Cli::Config.instance.require_current_master if self.class.requires_current_master?
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.requires_current_grid?
|
101
|
+
@requires_current_grid ||= false
|
102
|
+
end
|
103
|
+
|
104
|
+
def verify_current_grid
|
105
|
+
Kontena::Cli::Config.instance.require_current_grid if self.class.requires_current_grid?
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.requires_current_account_token?
|
109
|
+
@requires_current_account_token ||= false
|
110
|
+
end
|
111
|
+
|
112
|
+
def verify_current_account_token
|
113
|
+
retried ||= false
|
114
|
+
Kontena::Cli::Config.instance.require_current_account_token if self.class.requires_current_account_token?
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.requires_current_master_token
|
118
|
+
@requires_current_master_token = true
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.requires_current_master_token?
|
122
|
+
@requires_current_master_token ||= false
|
123
|
+
end
|
124
|
+
|
125
|
+
def verify_current_master_token
|
126
|
+
return nil unless self.class.requires_current_master_token?
|
127
|
+
retried ||= false
|
128
|
+
Kontena::Cli::Config.instance.require_current_master_token
|
129
|
+
rescue Kontena::Cli::Config::TokenExpiredError
|
130
|
+
success = Kontena::Client.new(
|
131
|
+
Kontena::Cli::Config.instance.current_master,
|
132
|
+
Kontena::Cli::Config.instance.current_master.token
|
133
|
+
).refresh_token
|
134
|
+
if success && !retried
|
135
|
+
retried = true
|
136
|
+
retry
|
137
|
+
else
|
138
|
+
raise Kontena::Cli::Config::TokenExpiredError, "The access token has expired and refresh failed. Try authenticating again, use: kontena master auth"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def help_requested?
|
143
|
+
return true if @arguments.include?('--help')
|
144
|
+
return true if @arguments.include?('-h')
|
145
|
+
false
|
146
|
+
end
|
147
|
+
|
148
|
+
def run(arguments)
|
149
|
+
ENV["DEBUG"] && puts("Running #{self} -- callback matcher = '#{self.class.callback_matcher.map(&:to_s).join(' ')}'")
|
150
|
+
@arguments = arguments
|
151
|
+
|
152
|
+
run_callbacks :before_parse unless help_requested?
|
153
|
+
|
154
|
+
parse @arguments
|
155
|
+
|
156
|
+
unless help_requested?
|
157
|
+
verify_current_master
|
158
|
+
verify_current_master_token
|
159
|
+
verify_current_grid
|
160
|
+
run_callbacks :before
|
161
|
+
end
|
162
|
+
|
163
|
+
begin
|
164
|
+
@result = execute
|
165
|
+
@exit_code = @result.kind_of?(FalseClass) ? 1 : 0
|
166
|
+
rescue SystemExit => exc
|
167
|
+
@result = exc.status == 0
|
168
|
+
@exit_code = exc.status
|
169
|
+
end
|
170
|
+
run_callbacks :after unless help_requested?
|
171
|
+
exit(@exit_code) if @exit_code.to_i > 0
|
172
|
+
@result
|
173
|
+
end
|
4
174
|
end
|
175
|
+
|
176
|
+
require_relative 'callback'
|
data/lib/kontena/main_command.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'clamp'
|
2
|
-
require_relative 'command'
|
3
|
-
require_relative 'util'
|
4
2
|
require_relative 'cli/common'
|
3
|
+
require_relative 'util'
|
4
|
+
require_relative 'command'
|
5
|
+
require_relative 'callback'
|
5
6
|
require_relative 'cli/bytes_helper'
|
6
7
|
require_relative 'cli/grid_options'
|
7
8
|
require_relative 'cli/app_command'
|
8
|
-
require_relative 'cli/register_command'
|
9
9
|
require_relative 'cli/login_command'
|
10
10
|
require_relative 'cli/logout_command'
|
11
11
|
require_relative 'cli/whoami_command'
|
@@ -20,15 +20,17 @@ require_relative 'cli/external_registry_command'
|
|
20
20
|
require_relative 'cli/app_command'
|
21
21
|
require_relative 'cli/etcd_command'
|
22
22
|
require_relative 'cli/vault_command'
|
23
|
-
require_relative 'cli/user_command'
|
24
23
|
require_relative 'cli/plugin_command'
|
25
24
|
require_relative 'cli/version_command'
|
26
25
|
require_relative 'cli/stack_command'
|
27
26
|
require_relative 'cli/certificate_command'
|
27
|
+
require_relative 'cli/cloud_command'
|
28
28
|
|
29
29
|
class Kontena::MainCommand < Kontena::Command
|
30
30
|
include Kontena::Util
|
31
31
|
|
32
|
+
subcommand "cloud", "Kontena Cloud specific commands", Kontena::Cli::CloudCommand
|
33
|
+
subcommand "logout", "Logout from Kontena Masters or Kontena Cloud accounts", Kontena::Cli::LogoutCommand
|
32
34
|
subcommand "grid", "Grid specific commands", Kontena::Cli::GridCommand
|
33
35
|
subcommand "app", "App specific commands", Kontena::Cli::AppCommand
|
34
36
|
subcommand "stack", "Stack specific commands", Kontena::Cli::StackCommand if experimental?
|
@@ -42,13 +44,10 @@ class Kontena::MainCommand < Kontena::Command
|
|
42
44
|
subcommand "container", "Container specific commands", Kontena::Cli::ContainerCommand
|
43
45
|
subcommand "etcd", "Etcd specific commands", Kontena::Cli::EtcdCommand
|
44
46
|
subcommand "external-registry", "External registry specific commands", Kontena::Cli::ExternalRegistryCommand
|
45
|
-
subcommand "register", "Register Kontena Account", Kontena::Cli::RegisterCommand
|
46
|
-
subcommand "login", "Login to Kontena Master", Kontena::Cli::LoginCommand
|
47
|
-
subcommand "logout", "Logout from Kontena Master", Kontena::Cli::LogoutCommand
|
48
47
|
subcommand "whoami", "Shows current logged in user", Kontena::Cli::WhoamiCommand
|
49
|
-
subcommand "user", "User related commands", Kontena::Cli::UserCommand
|
50
48
|
subcommand "plugin", "Plugin related commands", Kontena::Cli::PluginCommand
|
51
49
|
subcommand "version", "Show version", Kontena::Cli::VersionCommand
|
50
|
+
subcommand "login", "Login to Kontena Master (removed, use kontena master auth)", Kontena::Cli::LoginCommand
|
52
51
|
|
53
52
|
def execute
|
54
53
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
---
|
2
|
+
oauth2.authorize_endpoint: https://github.com/login/oauth/authorize
|
3
|
+
oauth2.code_requires_basic_auth: false
|
4
|
+
oauth2.token_endpoint: https://github.com/login/oauth/access_token
|
5
|
+
oauth2.token_method: post
|
6
|
+
oauth2.token_post_content_type: application/json
|
7
|
+
oauth2.userinfo_scope: user:email
|
8
|
+
oauth2.userinfo_endpoint: https://api.github.com/user
|
9
|
+
oauth2.userinfo_username_jsonpath: "$..login"
|
10
|
+
oauth2.userinfo_email_jsonpath: "$..email"
|
11
|
+
oauth2.userinfo_user_id_jsonpath: "$..id"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
---
|
2
|
+
oauth2.authorize_endpoint: https://cloud-beta.kontena.io/login/oauth/authorize
|
3
|
+
oauth2.code_requires_basic_auth: false
|
4
|
+
oauth2.token_endpoint: https://auth2.kontena.io/v1/oauth2/token
|
5
|
+
oauth2.token_method: post
|
6
|
+
oauth2.token_post_content_type: application/x-www-form-urlencoded
|
7
|
+
oauth2.userinfo_endpoint: https://auth2.kontena.io/v1/user
|
8
|
+
oauth2.userinfo_username_jsonpath: "$..username"
|
9
|
+
oauth2.userinfo_email_jsonpath: "$..email"
|
10
|
+
oauth2.userinfo_user_id_jsonpath: "$..id"
|
11
|
+
oauth2.userinfo_scope: user
|
data/lib/kontena_cli.rb
CHANGED
@@ -1,6 +1,56 @@
|
|
1
|
-
module Kontena
|
1
|
+
module Kontena
|
2
|
+
# Run a kontena command like it was launched from the command line.
|
3
|
+
#
|
4
|
+
# @example
|
5
|
+
# Kontena.run("grid list --help")
|
6
|
+
#
|
7
|
+
# @param [String] command_line
|
8
|
+
# @return [Fixnum] exit_code
|
9
|
+
def self.run(cmdline = "", returning: :status)
|
10
|
+
require 'shellwords'
|
11
|
+
result = Kontena::MainCommand.new(File.basename(__FILE__)).run(cmdline.shellsplit)
|
12
|
+
return 0 if returning == :status
|
13
|
+
return result if returning == :result
|
14
|
+
rescue SystemExit
|
15
|
+
returning == :status ? $!.status : nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.version
|
19
|
+
"kontena-cli/#{Kontena::Cli::VERSION}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.pastel
|
23
|
+
@pastel ||= Pastel.new(enabled: $stdout.tty?)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.prompt
|
27
|
+
@prompt ||= TTY::Prompt.new(
|
28
|
+
active_color: :cyan,
|
29
|
+
help_color: :white,
|
30
|
+
error_color: :red,
|
31
|
+
interrupt: :exit,
|
32
|
+
prefix: pastel.green('> ')
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.root
|
37
|
+
File.dirname(__dir__)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Monkeypatching string to mimick 'colorize' gem
|
42
|
+
class String
|
43
|
+
def colorize(color_sym)
|
44
|
+
::Kontena.pastel.send(color_sym, self)
|
45
|
+
end
|
46
|
+
end
|
2
47
|
|
3
48
|
require 'ruby_dig'
|
49
|
+
require_relative 'kontena/cli/version'
|
50
|
+
require_relative 'kontena/cli/common'
|
51
|
+
require_relative 'kontena/command'
|
4
52
|
require_relative 'kontena/client'
|
5
53
|
require_relative 'kontena/plugin_manager'
|
6
54
|
require_relative 'kontena/main_command'
|
55
|
+
require_relative 'kontena/cli/spinner'
|
56
|
+
|
@@ -4,40 +4,12 @@ require "kontena/cli/apps/deploy_command"
|
|
4
4
|
|
5
5
|
describe Kontena::Cli::Apps::DeployCommand do
|
6
6
|
include FixturesHelpers
|
7
|
+
include ClientHelpers
|
7
8
|
|
8
9
|
let(:subject) do
|
9
10
|
described_class.new(File.basename($0))
|
10
11
|
end
|
11
12
|
|
12
|
-
let(:settings) do
|
13
|
-
{'current_server' => 'alias',
|
14
|
-
'servers' => [
|
15
|
-
{'name' => 'some_master', 'url' => 'some_master'},
|
16
|
-
{'name' => 'alias', 'url' => 'someurl', 'token' => token}
|
17
|
-
]
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
let(:settings_without_api_url) do
|
22
|
-
{'current_server' => 'alias',
|
23
|
-
'servers' => [
|
24
|
-
{'name' => 'alias', 'token' => token}
|
25
|
-
]
|
26
|
-
}
|
27
|
-
end
|
28
|
-
|
29
|
-
let(:settings_without_token) do
|
30
|
-
{'current_server' => 'alias',
|
31
|
-
'servers' => [
|
32
|
-
{'name' => 'alias', 'url' => 'url'}
|
33
|
-
]
|
34
|
-
}
|
35
|
-
end
|
36
|
-
|
37
|
-
let(:token) do
|
38
|
-
'1234567'
|
39
|
-
end
|
40
|
-
|
41
13
|
let(:docker_compose_yml) do
|
42
14
|
fixture('docker-compose.yml')
|
43
15
|
end
|
@@ -64,10 +36,6 @@ describe Kontena::Cli::Apps::DeployCommand do
|
|
64
36
|
}
|
65
37
|
end
|
66
38
|
|
67
|
-
let(:client) do
|
68
|
-
double
|
69
|
-
end
|
70
|
-
|
71
39
|
let(:options) do
|
72
40
|
double({prefix: false, file: false, service: nil})
|
73
41
|
end
|
@@ -88,21 +56,24 @@ describe Kontena::Cli::Apps::DeployCommand do
|
|
88
56
|
|
89
57
|
context 'when api_url is nil' do
|
90
58
|
it 'raises error' do
|
91
|
-
allow(subject).to receive(:
|
59
|
+
allow(subject.config).to receive(:current_master).and_return(
|
60
|
+
Kontena::Cli::Config::Server.new
|
61
|
+
)
|
92
62
|
expect{subject.run([])}.to raise_error(ArgumentError)
|
93
63
|
end
|
94
64
|
end
|
95
65
|
|
96
66
|
context 'when token is nil' do
|
97
67
|
it 'raises error' do
|
98
|
-
allow(subject).to receive(:
|
68
|
+
allow(subject.config).to receive(:current_master).and_return(
|
69
|
+
Kontena::Cli::Config::Server.new(url: 'http://foo.com')
|
70
|
+
)
|
99
71
|
expect{subject.run([])}.to raise_error(ArgumentError)
|
100
72
|
end
|
101
73
|
end
|
102
74
|
|
103
75
|
context 'when api url and token are valid' do
|
104
76
|
before(:each) do
|
105
|
-
allow(subject).to receive(:settings).and_return(settings)
|
106
77
|
allow(File).to receive(:exists?).and_return(true)
|
107
78
|
allow(File).to receive(:read).with("#{Dir.getwd}/kontena.yml").and_return(kontena_yml)
|
108
79
|
allow(File).to receive(:read).with("#{Dir.getwd}/docker-compose.yml").and_return(docker_compose_yml)
|
@@ -113,7 +84,6 @@ describe Kontena::Cli::Apps::DeployCommand do
|
|
113
84
|
end
|
114
85
|
|
115
86
|
it 'reads ./kontena.yml file by default' do
|
116
|
-
allow(subject).to receive(:settings).and_return(settings)
|
117
87
|
expect(File).to receive(:read).with("#{Dir.getwd}/kontena.yml").and_return(kontena_yml)
|
118
88
|
subject.run([])
|
119
89
|
end
|
@@ -147,7 +117,7 @@ describe Kontena::Cli::Apps::DeployCommand do
|
|
147
117
|
'env' => ['MYSQL_ADMIN_PASSWORD=password', 'TEST_ENV_VAR=test', 'TEST_ENV_VAR2=test3'],
|
148
118
|
}
|
149
119
|
|
150
|
-
expect(subject).to receive(:create_service).with(
|
120
|
+
expect(subject).to receive(:create_service).with(duck_type(:access_token), '1', hash_including(data))
|
151
121
|
subject.run([])
|
152
122
|
end
|
153
123
|
end
|
@@ -167,7 +137,7 @@ describe Kontena::Cli::Apps::DeployCommand do
|
|
167
137
|
'env' => ['MYSQL_ADMIN_PASSWORD=password', 'TEST_ENV_VAR=test']
|
168
138
|
}
|
169
139
|
|
170
|
-
expect(subject).to receive(:create_service).with(
|
140
|
+
expect(subject).to receive(:create_service).with(duck_type(:access_token), '1', hash_including(data))
|
171
141
|
subject.run([])
|
172
142
|
end
|
173
143
|
end
|
@@ -191,7 +161,7 @@ describe Kontena::Cli::Apps::DeployCommand do
|
|
191
161
|
]
|
192
162
|
}
|
193
163
|
|
194
|
-
expect(subject).to receive(:create_service).with(
|
164
|
+
expect(subject).to receive(:create_service).with(duck_type(:access_token), '1', hash_including(data))
|
195
165
|
subject.run([])
|
196
166
|
end
|
197
167
|
|
@@ -204,7 +174,7 @@ describe Kontena::Cli::Apps::DeployCommand do
|
|
204
174
|
'container_count' => nil,
|
205
175
|
'stateful' => true,
|
206
176
|
}
|
207
|
-
expect(subject).to receive(:create_service).with(
|
177
|
+
expect(subject).to receive(:create_service).with(duck_type(:access_token), '1', hash_including(data))
|
208
178
|
|
209
179
|
subject.run([])
|
210
180
|
end
|
@@ -222,15 +192,15 @@ describe Kontena::Cli::Apps::DeployCommand do
|
|
222
192
|
'links' => [{ 'name' => 'kontena-test-mysql', 'alias' => 'mysql' }],
|
223
193
|
'ports' => [{ 'ip' => '0.0.0.0','container_port' => '80', 'node_port' => '80', 'protocol' => 'tcp' }]
|
224
194
|
}
|
225
|
-
expect(subject).to receive(:create_service).with(
|
195
|
+
expect(subject).to receive(:create_service).with(duck_type(:access_token), '1', hash_including(data))
|
226
196
|
|
227
197
|
subject.run([])
|
228
198
|
end
|
229
199
|
|
230
200
|
it 'deploys services' do
|
231
201
|
allow(subject).to receive(:current_dir).and_return('kontena-test')
|
232
|
-
expect(subject).to receive(:deploy_service).with(
|
233
|
-
expect(subject).to receive(:deploy_service).with(
|
202
|
+
expect(subject).to receive(:deploy_service).with(duck_type(:access_token), 'kontena-test-mysql', {})
|
203
|
+
expect(subject).to receive(:deploy_service).with(duck_type(:access_token), 'kontena-test-wordpress', {})
|
234
204
|
subject.run([])
|
235
205
|
end
|
236
206
|
|
@@ -42,7 +42,7 @@ describe Kontena::Cli::Apps::ScaleCommand do
|
|
42
42
|
|
43
43
|
it 'scales given service' do
|
44
44
|
allow(File).to receive(:read).with("#{Dir.getwd}/kontena.yml").and_return(kontena_yml_no_instances)
|
45
|
-
expect(subject).to receive(:scale_service).with(
|
45
|
+
expect(subject).to receive(:scale_service).with(duck_type(:access_token),'kontena-test-wordpress',3)
|
46
46
|
subject.run(['wordpress', 3])
|
47
47
|
end
|
48
48
|
|