kontena-cli 0.16.0 → 0.16.1.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/kontena/callbacks/master/deploy/60_configure_auth_provider_after_deploy.rb +9 -8
- data/lib/kontena/cli/apps/service_generator.rb +2 -1
- data/lib/kontena/cli/cloud/master/add_command.rb +10 -0
- data/lib/kontena/cli/cloud/master/update_command.rb +1 -7
- data/lib/kontena/cli/common.rb +1 -1
- data/lib/kontena/cli/config.rb +5 -0
- data/lib/kontena/cli/master/init_cloud_command.rb +9 -4
- data/lib/kontena/cli/master/login_command.rb +25 -18
- data/lib/kontena/cli/services/create_command.rb +2 -1
- data/lib/kontena/cli/services/update_command.rb +2 -1
- data/lib/kontena/cli/vpn/config_command.rb +1 -0
- data/lib/kontena/client.rb +3 -3
- data/spec/kontena/config_spec.rb +33 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a140696639e10214728770220b852bd2c1278bb0
|
4
|
+
data.tar.gz: 4493f5eda8a877cde4e939041982b5f902df3b45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35927d1ad63168a93767327ecb4a781c9367b06d5649e68986f89bc454bd4f011ec6151d82bfd4cf1d7a706508ab7ba0d7a6d7c70cd96f1e04a8863a00058efc
|
7
|
+
data.tar.gz: 9f403db6a2463f36ed270c49ce1867b4de8e77f4b8ed75e3abe3d8e10422f0a41e719ae5f641b9f1606d20eba4e0e6c042dd631fc276fe536c77b7eb8ef707d0
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.16.
|
1
|
+
0.16.1.rc1
|
@@ -6,12 +6,17 @@ module Kontena
|
|
6
6
|
|
7
7
|
matches_commands 'master create'
|
8
8
|
|
9
|
-
def
|
10
|
-
|
9
|
+
def init_cloud_args
|
10
|
+
args = []
|
11
|
+
args << '--force'
|
12
|
+
args << "--cloud-master-id #{command.cloud_master_id}" if command.cloud_master_id
|
13
|
+
args << "--provider #{command.result[:provider]}" if command.result[:provider]
|
14
|
+
args << "--version #{command.result[:version]}" if command.result[:version]
|
15
|
+
args.join(' ')
|
11
16
|
end
|
12
17
|
|
13
18
|
def configure_auth_provider
|
14
|
-
Kontena.run("master init-cloud
|
19
|
+
Kontena.run("master init-cloud #{init_cloud_args}")
|
15
20
|
end
|
16
21
|
|
17
22
|
def after
|
@@ -24,11 +29,7 @@ module Kontena
|
|
24
29
|
return
|
25
30
|
end
|
26
31
|
|
27
|
-
|
28
|
-
configure_auth_provider_using_id(command.cloud_master_id)
|
29
|
-
else
|
30
|
-
configure_auth_provider
|
31
|
-
end
|
32
|
+
configure_auth_provider
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'yaml'
|
2
|
+
require 'shellwords'
|
2
3
|
require_relative '../services/services_helper'
|
3
4
|
|
4
5
|
module Kontena::Cli::Apps
|
@@ -36,7 +37,7 @@ module Kontena::Cli::Apps
|
|
36
37
|
data['cpu_shares'] = options['cpu_shares'] if options['cpu_shares']
|
37
38
|
data['volumes'] = options['volumes'] || []
|
38
39
|
data['volumes_from'] = options['volumes_from'] || []
|
39
|
-
data['cmd'] = options['command']
|
40
|
+
data['cmd'] = Shellwords.split(options['command']) if options['command']
|
40
41
|
data['affinity'] = options['affinity'] || []
|
41
42
|
data['user'] = options['user'] if options['user']
|
42
43
|
data['stateful'] = options['stateful'] == true
|
@@ -94,6 +94,16 @@ module Kontena::Cli::Cloud::Master
|
|
94
94
|
response = spinner "Retrieving Master information from Kontena Cloud using id" do
|
95
95
|
get_existing(self.cloud_master_id)
|
96
96
|
end
|
97
|
+
if response && response.kind_of?(Hash) && response.has_key?('data') && response['data']['attributes']
|
98
|
+
if (self.provider && response['data']['attributes']['provider'] != self.provider) || (self.version && response['data']['attributes']['version'] != self.version)
|
99
|
+
spinner "Updating provider and version attributes to Kontena Cloud master" do
|
100
|
+
args = []
|
101
|
+
args << "--provider #{self.provider.shellescape}" if self.provider
|
102
|
+
args << "--version #{self.version.shellescape}" if self.version
|
103
|
+
Kontena.run("cloud master update #{args.join(' ')}")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
97
107
|
else
|
98
108
|
response = spinner "Registering current Kontena Master '#{current_master.name}' #{" as '#{new_name}' " unless new_name == current_master.name}to Kontena Cloud" do
|
99
109
|
register(new_name, current_master.url)
|
@@ -38,13 +38,7 @@ module Kontena::Cli::Cloud::Master
|
|
38
38
|
|
39
39
|
response = cloud_client.put(
|
40
40
|
"master",
|
41
|
-
{ data: { attributes: attrs.reject{ |k, _| ['client-id', 'client-secret'].include?(k) } } }
|
42
|
-
{},
|
43
|
-
cloud_client.basic_auth_header(
|
44
|
-
attrs["client-id"],
|
45
|
-
attrs["client-secret"]
|
46
|
-
),
|
47
|
-
false
|
41
|
+
{ data: { attributes: attrs.reject{ |k, _| ['client-id', 'client-secret'].include?(k) } } }
|
48
42
|
)
|
49
43
|
|
50
44
|
if response
|
data/lib/kontena/cli/common.rb
CHANGED
@@ -359,7 +359,7 @@ module Kontena
|
|
359
359
|
pastel.green('at'),
|
360
360
|
pastel.yellow(server.url),
|
361
361
|
pastel.green('as'),
|
362
|
-
pastel.yellow(server.username)
|
362
|
+
pastel.yellow(server.token.username || server.username)
|
363
363
|
].join(' ')
|
364
364
|
else
|
365
365
|
puts pastel.cyan("Not authenticated to current master #{server.name}")
|
data/lib/kontena/cli/config.rb
CHANGED
@@ -81,6 +81,11 @@ module Kontena
|
|
81
81
|
server = Server.new(server_data)
|
82
82
|
end
|
83
83
|
server.account ||= 'master'
|
84
|
+
if servers.find { |s| s['name'] == server.name}
|
85
|
+
server.name = "#{server.name}-2"
|
86
|
+
server.name.succ! until servers.find { |s| s['name'] == server.name }.nil?
|
87
|
+
logger.debug "Renamed server to #{server.name} because a duplicate was found in config"
|
88
|
+
end
|
84
89
|
servers << server
|
85
90
|
end
|
86
91
|
|
@@ -5,17 +5,22 @@ module Kontena::Cli::Master
|
|
5
5
|
|
6
6
|
banner "Configures the current Kontena Master to use Kontena Cloud services and authentication"
|
7
7
|
|
8
|
-
option '--force', :flag,
|
9
|
-
option '--cloud-master-id', '[ID]',
|
8
|
+
option '--force', :flag, "Don't ask questions"
|
9
|
+
option '--cloud-master-id', '[ID]', "Use existing cloud master ID"
|
10
|
+
option '--provider', '[NAME]', "Set master provider name"
|
11
|
+
option '--version', '[VERSION]', "Set master version"
|
10
12
|
|
11
13
|
requires_current_master
|
14
|
+
requires_current_master_token
|
12
15
|
requires_current_account_token
|
13
16
|
|
14
17
|
def execute
|
15
18
|
args = ["--current"]
|
16
19
|
args << "--force" if self.force?
|
17
|
-
args
|
18
|
-
|
20
|
+
args += ["--cloud-master-id", self.cloud_master_id.shellescape] if self.cloud_master_id
|
21
|
+
args += ["--provider", self.provider.shellescape] if self.provider
|
22
|
+
args += ["--version", self.version.shellescape] if self.version
|
23
|
+
Kontena.run("cloud master add #{args.join(' ')}")
|
19
24
|
end
|
20
25
|
end
|
21
26
|
end
|
@@ -39,6 +39,7 @@ module Kontena::Cli::Master
|
|
39
39
|
unless self.join || self.force?
|
40
40
|
if auth_works?(server)
|
41
41
|
config.write
|
42
|
+
config.reset_instance
|
42
43
|
display_login_info(only: :master) unless self.no_login_info?
|
43
44
|
exit 0
|
44
45
|
end
|
@@ -117,23 +118,26 @@ module Kontena::Cli::Master
|
|
117
118
|
def use_authorization_code(server, code)
|
118
119
|
vspinner "Exchanging authorization code for an access token from Kontena Master" do
|
119
120
|
client = Kontena::Client.new(server.url, server.token)
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
server.
|
130
|
-
|
131
|
-
refresh_token: response['refresh_token'],
|
132
|
-
expires_at: response['expires_in'].to_i > 0 ? Time.now.utc.to_i + response['expires_in'].to_i : nil,
|
133
|
-
)
|
121
|
+
begin
|
122
|
+
response = client.exchange_code(code)
|
123
|
+
rescue StandardError => ex
|
124
|
+
ENV["DEBUG"] && puts("#{ex}\n#{ex.backtrace.join(" \n")}")
|
125
|
+
exit_with_error "Code exchange failed: #{ex}"
|
126
|
+
end
|
127
|
+
|
128
|
+
if response['server'] && response['server']['name']
|
129
|
+
server.name ||= response['server']['name']
|
130
|
+
server.username = response['user']['name'] || response['user']['email']
|
131
|
+
config.current_server = server.name
|
134
132
|
else
|
135
|
-
raise Kontena::Errors::StandardError.new(500, 'Code exchange
|
133
|
+
raise Kontena::Errors::StandardError.new(500, 'Code exchange invalid response')
|
136
134
|
end
|
135
|
+
|
136
|
+
server.token = Kontena::Cli::Config::Token.new(
|
137
|
+
access_token: response['access_token'],
|
138
|
+
refresh_token: response['refresh_token'],
|
139
|
+
expires_at: response['expires_in'].to_i > 0 ? Time.now.utc.to_i + response['expires_in'].to_i : nil,
|
140
|
+
)
|
137
141
|
end
|
138
142
|
true
|
139
143
|
end
|
@@ -166,17 +170,20 @@ module Kontena::Cli::Master
|
|
166
170
|
|
167
171
|
def get_authorization_url(web_server_port = nil)
|
168
172
|
authorization_url = nil
|
173
|
+
|
174
|
+
http_client = Kontena::Client.new(self.url)
|
175
|
+
|
169
176
|
vspinner "Sending authentication request to receive an authorization URL" do
|
170
|
-
|
177
|
+
http_client.request(
|
171
178
|
http_method: :get,
|
172
179
|
path: build_auth_url_path(web_server_port),
|
173
180
|
expects: [501, 400, 302, 403],
|
174
181
|
auth: false
|
175
182
|
)
|
176
183
|
|
177
|
-
case
|
184
|
+
case http_client.last_response.status
|
178
185
|
when 302
|
179
|
-
authorization_url =
|
186
|
+
authorization_url = http_client.last_response.headers['Location']
|
180
187
|
when 501
|
181
188
|
exit_with_error "Authentication provider not configured"
|
182
189
|
when 403
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'services_helper'
|
2
|
+
require 'shellwords'
|
2
3
|
|
3
4
|
module Kontena::Cli::Services
|
4
5
|
class CreateCommand < Kontena::Command
|
@@ -71,7 +72,7 @@ module Kontena::Cli::Services
|
|
71
72
|
data[:env] = env_list unless env_list.empty?
|
72
73
|
data[:secrets] = parse_secrets(secret_list)
|
73
74
|
data[:container_count] = instances if instances
|
74
|
-
data[:cmd] =
|
75
|
+
data[:cmd] = Shellwords.split(cmd) if cmd
|
75
76
|
data[:user] = user if user
|
76
77
|
data[:image] = parse_image(image) if image
|
77
78
|
data[:privileged] = privileged?
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'services_helper'
|
2
|
+
require 'shellwords'
|
2
3
|
|
3
4
|
module Kontena::Cli::Services
|
4
5
|
class UpdateCommand < Kontena::Command
|
@@ -63,7 +64,7 @@ module Kontena::Cli::Services
|
|
63
64
|
data[:env] = env_list unless env_list.empty?
|
64
65
|
data[:secrets] = parse_secrets(secret_list) unless secret_list.empty?
|
65
66
|
data[:container_count] = instances if instances
|
66
|
-
data[:cmd] =
|
67
|
+
data[:cmd] = Shellwords.split(cmd) if cmd
|
67
68
|
data[:user] = user if user
|
68
69
|
data[:image] = parse_image(image) if image
|
69
70
|
data[:privileged] = privileged?
|
@@ -10,6 +10,7 @@ module Kontena::Cli::Vpn
|
|
10
10
|
stdout, stderr = client(require_token).post("containers/#{current_grid}/vpn/vpn-1/exec", payload)
|
11
11
|
if linux?
|
12
12
|
stdout << "\n"
|
13
|
+
stdout << "script-security 2 system\n"
|
13
14
|
stdout << "up /etc/openvpn/update-resolv-conf\n"
|
14
15
|
stdout << "down /etc/openvpn/update-resolv-conf\n"
|
15
16
|
end
|
data/lib/kontena/client.rb
CHANGED
@@ -56,9 +56,9 @@ module Kontena
|
|
56
56
|
@http_client = Excon.new(
|
57
57
|
api_url,
|
58
58
|
omit_default_port: true,
|
59
|
-
connect_timeout: ENV["EXCON_CONNECT_TIMEOUT"]
|
60
|
-
read_timeout: ENV["EXCON_READ_TIMEOUT"]
|
61
|
-
write_timeout: ENV["EXCON_WRITE_TIMEOUT"]
|
59
|
+
connect_timeout: ENV["EXCON_CONNECT_TIMEOUT"] ? ENV["EXCON_CONNECT_TIMEOUT"].to_i : 5,
|
60
|
+
read_timeout: ENV["EXCON_READ_TIMEOUT"] ? ENV["EXCON_READ_TIMEOUT"].to_i : 30,
|
61
|
+
write_timeout: ENV["EXCON_WRITE_TIMEOUT"] ? ENV["EXCON_WRITE_TIMEOUT"].to_i : 5
|
62
62
|
)
|
63
63
|
|
64
64
|
@default_headers = {
|
data/spec/kontena/config_spec.rb
CHANGED
@@ -3,9 +3,9 @@ require_relative '../spec_helper'
|
|
3
3
|
# Lots of coverage already in Common spec
|
4
4
|
describe Kontena::Cli::Config do
|
5
5
|
|
6
|
-
|
7
|
-
let(:subject) { described_class.instance }
|
6
|
+
let(:subject) { described_class.instance }
|
8
7
|
|
8
|
+
context 'base' do
|
9
9
|
before(:each) do
|
10
10
|
allow(File).to receive(:exist?).and_return(false)
|
11
11
|
allow(File).to receive(:write).and_return(true)
|
@@ -52,6 +52,37 @@ describe Kontena::Cli::Config do
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
+
context 'duplicates' do
|
56
|
+
before(:each) do
|
57
|
+
allow(File).to receive(:exist?).and_return(true)
|
58
|
+
allow(File).to receive(:readable?).and_return(true)
|
59
|
+
allow(File).to receive(:write).and_return(true)
|
60
|
+
allow(File).to receive(:read).and_return <<-EOB
|
61
|
+
{"current_server": "test123",
|
62
|
+
"servers" : [
|
63
|
+
{
|
64
|
+
"name": "test123",
|
65
|
+
"url": "https://foo.example.com"
|
66
|
+
},
|
67
|
+
{
|
68
|
+
"name": "test123",
|
69
|
+
"url": "https://foo2.example.com"
|
70
|
+
}
|
71
|
+
]
|
72
|
+
}
|
73
|
+
EOB
|
74
|
+
|
75
|
+
subject.class.reset_instance
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'renames duplicate entries on load' do
|
79
|
+
puts subject.servers.inspect
|
80
|
+
expect(subject.servers.size).to eq 2
|
81
|
+
expect(subject.servers.first.name).not_to eq subject.servers.last.name
|
82
|
+
expect(subject.servers.last.name).to eq "test123-2"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
55
86
|
describe 'Token' do
|
56
87
|
let(:subject) { Kontena::Cli::Config::Token.new(access_token: 'abcd', expires_at: Time.now.utc - 100) }
|
57
88
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kontena-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.16.
|
4
|
+
version: 0.16.1.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kontena, Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -466,9 +466,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
466
466
|
version: 2.0.0
|
467
467
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
468
468
|
requirements:
|
469
|
-
- - "
|
469
|
+
- - ">"
|
470
470
|
- !ruby/object:Gem::Version
|
471
|
-
version:
|
471
|
+
version: 1.3.1
|
472
472
|
requirements: []
|
473
473
|
rubyforge_project:
|
474
474
|
rubygems_version: 2.5.1
|