kontena-plugin-cloud 1.0.0.pre2 → 1.0.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ba51db007412d9c1f0cc5153e7972712627866d
4
- data.tar.gz: dfb686674f831a540a732277ed44bdd824a2d3b1
3
+ metadata.gz: 7fe648ee714646b76fb23bd31751256927e044e9
4
+ data.tar.gz: 9ab66ab2e50fb24adf89f64152959bdf8e7154c4
5
5
  SHA512:
6
- metadata.gz: 37d98e085cf4ca833fb93152d9be9e178c54c04c743093b2233c247f5b1debef5c6b3cef310c1d789aefe9d9387f2c2cf80a149bb33af49a3fc62ec65d7cf6a9
7
- data.tar.gz: 949e677350a6b488bd7c7984f757733acb70e9b570baf55400d886539b82da49218465a5747a70eabb5cd6c897c5496d5e1b091dc233683456cc026a1fc0de11
6
+ metadata.gz: 16f399f82c72551f2da6070ec900ef6042be9556a21c408ea36618e0e356acb2fb952b1248e0889b41e8754bb12c15c8573093165f2680fa11f2d9924e9bf132
7
+ data.tar.gz: 4e43e60a3e1366efaa9781e65c0e034eed587bab9f680dcadf2c0f6b7120e7e29a689de67b6e1a42b5a09342f2bc30dcb082497ac81360e06d544564a43dd115
@@ -1,7 +1,7 @@
1
1
  module Kontena
2
2
  module Plugin
3
3
  module Cloud
4
- VERSION = "1.0.0.pre2"
4
+ VERSION = "1.0.0.pre3"
5
5
 
6
6
  module Organization
7
7
  module User; end
@@ -10,6 +10,7 @@ module Kontena
10
10
  end
11
11
 
12
12
  module Platform
13
+ module User; end
13
14
  module TrustedSubnet; end
14
15
  end
15
16
 
@@ -22,7 +22,7 @@ class Kontena::Plugin::Platform::CreateCommand < Kontena::Command
22
22
 
23
23
  platform = nil
24
24
  spinner "Creating platform #{pastel.cyan(name)} to region #{pastel.cyan(region)}" do
25
- platform = create_platform(name, organization, initial_size, region)['data']
25
+ platform = create_platform(name, organization, initial_size, region)
26
26
  end
27
27
  spinner "Waiting for platform #{pastel.cyan(name)} to come online" do
28
28
  while !platform.online? do
@@ -36,7 +36,7 @@ class Kontena::Plugin::Platform::CreateCommand < Kontena::Command
36
36
  # @param [Kontena::Cli::Models::Platform] platform
37
37
  def use_platform(platform)
38
38
  platform_name = "#{organization}/#{name}"
39
- login_to_platform(platform_name, platform.dig('attributes', 'url'))
39
+ login_to_platform(platform_name, platform.url)
40
40
  spinner "Switching to use platform #{pastel.cyan(platform_name)}" do
41
41
  config.current_grid = name
42
42
  config.write
@@ -72,10 +72,10 @@ class Kontena::Plugin::Platform::CreateCommand < Kontena::Command
72
72
 
73
73
  def create_platform(name, organization, initial_size, region)
74
74
  data = {
75
- attributes: { "name": name, "initial-size": initial_size },
75
+ attributes: { "name" => name, "initial-size" => initial_size },
76
76
  relationships: {
77
77
  region: {
78
- "data": { "type": "region", "id": region }
78
+ "data" => { "type" => "region", "id" => region }
79
79
  }
80
80
  }
81
81
  }
@@ -0,0 +1,50 @@
1
+ class Kontena::Plugin::Platform::User::AddCommand < Kontena::Command
2
+ include Kontena::Cli::Common
3
+ include Kontena::Plugin::Platform::Common
4
+
5
+ requires_current_account_token
6
+
7
+ parameter "NAME", "Platform name"
8
+ parameter "[USERNAME] ...", "List of usernames to add"
9
+ option ["--role", "-r"], "ROLE", "Role to grant for users"
10
+
11
+ def execute
12
+ require_platform(name)
13
+ platform = find_platform_by_name(current_grid, current_organization)
14
+ self.username_list = prompt_users(platform) if self.username_list.count == 0
15
+ add_users(platform, username_list)
16
+ end
17
+
18
+ def prompt_users(platform)
19
+ organization_members = cloud_client.get("/organizations/#{current_organization}/members")['data']
20
+ platform_members = cloud_client.get("/organizations/#{current_organization}/platforms/#{platform.id}/relationships/users")['data']
21
+ users = organization_members.map do |u|
22
+ username = u.dig('attributes', 'username')
23
+ if !platform_members.any?{|m| m['id'] == username }
24
+ username
25
+ end
26
+ end.compact
27
+ exit_with_error("All organization members are already added to platform") if users.size == 0
28
+ prompt.multi_select("Choose users:") do |menu|
29
+ users.each do |username|
30
+ menu.choice username, username
31
+ end
32
+ end
33
+ end
34
+
35
+ def add_users(platform, usernames)
36
+ users = []
37
+ usernames.each do |u|
38
+ user = {
39
+ type: 'users',
40
+ id: u
41
+ }
42
+ user[:meta] = { role: role } if role
43
+ users << user
44
+ end
45
+ spinner "Adding users to platform #{pastel.cyan(name)}" do
46
+ data = {data: users}
47
+ cloud_client.post("/organizations/#{current_organization}/platforms/#{platform.id}/relationships/users", data)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,26 @@
1
+ class Kontena::Plugin::Platform::User::ListCommand < Kontena::Command
2
+ include Kontena::Cli::Common
3
+ include Kontena::Plugin::Platform::Common
4
+ include Kontena::Cli::TableGenerator::Helper
5
+
6
+ requires_current_account_token
7
+
8
+ parameter "NAME", "Platform name"
9
+
10
+ def execute
11
+ require_platform(name)
12
+ platform = find_platform_by_name(current_grid, current_organization)
13
+ platform_users = cloud_client.get("/organizations/#{current_organization}/platforms/#{platform.id}/relationships/users")['data']
14
+ print_table(platform_users) do |row|
15
+ row.merge!(row['attributes'].merge(row['meta']))
16
+
17
+ end
18
+ end
19
+
20
+ def fields
21
+ {
22
+ username: 'username',
23
+ role: 'role'
24
+ }
25
+ end
26
+ end
@@ -0,0 +1,49 @@
1
+ class Kontena::Plugin::Platform::User::RemoveCommand < Kontena::Command
2
+ include Kontena::Cli::Common
3
+ include Kontena::Plugin::Platform::Common
4
+
5
+ requires_current_account_token
6
+
7
+ parameter "NAME", "Platform name"
8
+ parameter "[USERNAME] ...", "List of usernames to remove"
9
+
10
+ option "--force", :flag, "Force remove", default: false, attribute_name: :forced
11
+
12
+ def execute
13
+ require_platform(name)
14
+ platform = find_platform_by_name(current_grid, current_organization)
15
+ self.username_list = prompt_users(platform) if self.username_list.count == 0
16
+ confirm_command(self.username_list.join(',')) unless forced?
17
+ remove_users(platform, username_list)
18
+ end
19
+
20
+ def prompt_users(platform)
21
+ platform_members = []
22
+ spinner "Resolving organization #{pastel.cyan(name)} current users" do
23
+ platform_members = cloud_client.get("/organizations/#{current_organization}/platforms/#{platform.id}/relationships/users")['data']
24
+ end
25
+ users = prompt.multi_select("Choose users:") do |menu|
26
+ platform_members.each do |u|
27
+ menu.choice u.dig('attributes', 'username'), u['id']
28
+ end
29
+ end
30
+ if platform_members.size - users.size < 1
31
+ exit_with_error "Cannot remove the last user of the platform"
32
+ end
33
+ users
34
+ end
35
+
36
+ def remove_users(platform, user_ids)
37
+ users = []
38
+ user_ids.each do |u|
39
+ users << {
40
+ type: 'users',
41
+ id: u
42
+ }
43
+ end
44
+ spinner "Removing users from platform #{pastel.cyan(name)}" do
45
+ data = {data: users}
46
+ cloud_client.delete("/organizations/#{current_organization}/platforms/#{platform.id}/relationships/users", data)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,14 @@
1
+ require_relative 'common'
2
+
3
+ require_relative 'user/list_command'
4
+ require_relative 'user/add_command'
5
+ require_relative 'user/remove_command'
6
+ class Kontena::Plugin::Platform::UserCommand < Kontena::Command
7
+ include Kontena::Plugin::Platform
8
+ subcommand ['list', 'ls'], 'List platform users', User::ListCommand
9
+ subcommand 'add', 'Add users to platform', User::AddCommand
10
+ subcommand ['remove', 'rm'], 'Remove users from platform', User::RemoveCommand
11
+
12
+ def execute
13
+ end
14
+ end
@@ -1,4 +1,7 @@
1
+ require_relative 'platform/user_command'
2
+
1
3
  class Kontena::Plugin::PlatformCommand < Kontena::Command
4
+ include Kontena::Plugin::Platform
2
5
 
3
6
  subcommand ['list', 'ls'], 'List platforms', load_subcommand('kontena/plugin/platform/list_command')
4
7
  subcommand ['use', 'switch'], 'Use/switch local scope to platform', load_subcommand('kontena/plugin/platform/use_command')
@@ -9,6 +12,7 @@ class Kontena::Plugin::PlatformCommand < Kontena::Command
9
12
  subcommand 'health', 'Show platform health', load_subcommand('kontena/plugin/platform/health_command')
10
13
  subcommand 'trusted-subnet', 'Trusted subnet specific commands', load_subcommand('kontena/plugin/platform/trusted_subnet_command')
11
14
  subcommand 'import-grid', 'Import grid as Kontena Platform', load_subcommand('kontena/plugin/platform/import_grid_command')
15
+ subcommand 'user', 'User management commands', UserCommand
12
16
 
13
17
  def execute
14
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kontena-plugin-cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre2
4
+ version: 1.0.0.pre3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kontena, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-12 00:00:00.000000000 Z
11
+ date: 2017-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kontena-cli
@@ -95,6 +95,10 @@ files:
95
95
  - lib/kontena/plugin/platform/trusted_subnet/remove_command.rb
96
96
  - lib/kontena/plugin/platform/trusted_subnet_command.rb
97
97
  - lib/kontena/plugin/platform/use_command.rb
98
+ - lib/kontena/plugin/platform/user/add_command.rb
99
+ - lib/kontena/plugin/platform/user/list_command.rb
100
+ - lib/kontena/plugin/platform/user/remove_command.rb
101
+ - lib/kontena/plugin/platform/user_command.rb
98
102
  - lib/kontena/plugin/platform_command.rb
99
103
  - lib/kontena_cli_plugin.rb
100
104
  homepage: https://kontena.io