kontena-cli 0.16.0.pre4 → 0.16.0.pre5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36e047ed9eeab9703d96bf167ae05ae212a8d696
4
- data.tar.gz: 4c947a57f0d149044c1aa255e317db8115d2e305
3
+ metadata.gz: 24c6e241c38b9d4dece50e6d97443dc68d7a4e38
4
+ data.tar.gz: 9fdd643f7b747b5898d1d40a651f98dba8b216aa
5
5
  SHA512:
6
- metadata.gz: dd2d2120ea3c23cfb2d3be1d867ec2b05475a9c6f9abfa689efe9ff6682ea6740ff10079163c104a7f3fcc65a818ce2fb688a48fea6f8703cc4a8bb4248bebd0
7
- data.tar.gz: 86e61055eb8c0c34e0569c5bc26ae0f96055cca0dc90c3c6f8eaacae09752c7409ae666ca038a1a6a0ef8ce03b44327eec08d72e5ef383fd0215fd7d88937f9e
6
+ metadata.gz: 185b33efb5684e45c185af579c6c777a824fdb0a04db46f48dc470f1ba1c57577fa9cbc2a797c853913e07ec9b18708ef92a86ca6f8305c5fc7dc0e61b2611c4
7
+ data.tar.gz: 2278e96ea747b84bea482dc92b62dbdd799f890067978881084aa2b1cd77a7af4713cbffb27fc3f8545b81d6e3fa1a158fb5255550287ff529c62d08cc647984
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.16.0.pre4
1
+ 0.16.0.pre5
@@ -0,0 +1,28 @@
1
+ module Kontena::Cli::Master::Token
2
+ module Common
3
+
4
+ def token_data_to_hash(data)
5
+ output = {
6
+ id: data["id"],
7
+ token_type: data["token_type"] || data["grant_type"],
8
+ scopes: data["scopes"],
9
+ user_id: data["user"]["id"],
10
+ user_email: data["user"]["email"],
11
+ user_name: data["user"]["name"],
12
+ server_name: data["server"]["name"]
13
+ }
14
+ if data["token_type"] == "bearer"
15
+ output[:access_token_last_four] = data["access_token_last_four"]
16
+ output[:refresh_token_last_four] = data["refresh_token_last_four"]
17
+ output[:token_type] = data["token_type"]
18
+ output[:access_token] = data["access_token"] if data["access_token"]
19
+ output[:refresh_token] = data["refresh_token"] if data["refresh_token"]
20
+ output[:expires_in] = data["expires_in"]
21
+ else
22
+ output[:code] = data["code"]
23
+ output[:token_type] = data["grant_type"]
24
+ end
25
+ output
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,41 @@
1
+ require_relative 'common'
2
+
3
+ module Kontena::Cli::Master::Token
4
+ class CreateCommand < Kontena::Command
5
+
6
+ include Kontena::Cli::Common
7
+ include Common
8
+
9
+ requires_current_master
10
+ requires_current_master_token
11
+
12
+ option ['-s', '--scopes'], '[SCOPES]', "Comma separated list of access scopes for the generated token", default: 'user'
13
+ option ['-e', '--expires-in'], '[SECONDS]', "Access token expiration time. Use 0 for never.", default: '7200'
14
+ option ['-c', '--code'], :flag, "Generate an authorization code"
15
+ option ['--id'], :flag, "Only output the token ID"
16
+ option ['--token'], :flag, "Only output the access_token (or authorization code)"
17
+
18
+ def execute
19
+ params = {
20
+ response_type: self.code? ? 'code' : 'token',
21
+ scope: self.scopes,
22
+ expires_in: self.expires_in
23
+ }
24
+ data = token_data_to_hash(client.post("/oauth2/authorize", params))
25
+
26
+ if self.id?
27
+ puts data[:id]
28
+ exit 0
29
+ end
30
+
31
+ if self.token?
32
+ puts data[:access_token] || data[:code]
33
+ exit 0
34
+ end
35
+
36
+ data.each do |key, value|
37
+ puts "%26.26s : %s" % [key, value]
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,40 @@
1
+ require_relative 'common'
2
+
3
+ module Kontena::Cli::Master::Token
4
+ class CurrentCommand < Kontena::Command
5
+
6
+ include Kontena::Cli::Common
7
+ include Common
8
+
9
+ requires_current_master
10
+ requires_current_master_token
11
+
12
+ option '--token', :flag, "Only output access token"
13
+ option '--refresh-token', :flag, "Only output refresh token"
14
+ option '--expires-in', :flag, "Only output expires in seconds"
15
+
16
+ def execute
17
+ if self.token?
18
+ puts current_master.token.access_token
19
+ exit 0
20
+ end
21
+
22
+ if self.refresh_token?
23
+ if current_master.token.refresh_token
24
+ puts current_master.token.refresh_token
25
+ end
26
+ exit 0
27
+ end
28
+
29
+ if self.expires_in?
30
+ if current_master.token.expires_at.to_i > 0
31
+ puts Time.now.utc.to_i - current_master.token.expires_at
32
+ end
33
+ exit 0
34
+ end
35
+
36
+ Kontena.run("master token show #{current_master.token.access_token}")
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,28 @@
1
+ require_relative 'common'
2
+
3
+ module Kontena::Cli::Master::Token
4
+ class ListCommand < Kontena::Command
5
+
6
+ include Kontena::Cli::Common
7
+ include Common
8
+
9
+ requires_current_master
10
+ requires_current_master_token
11
+
12
+ def execute
13
+ rows = []
14
+ puts "%-26s %-18s %-11s %-10s %-20s" % ["ID", "TOKEN_TYPE", "TOKEN_LAST4", "EXPIRES_IN", "SCOPES"]
15
+ client.get("/oauth2/tokens")["tokens"].each do |row_data|
16
+ data = token_data_to_hash(row_data)
17
+ puts "%-26s %-18s %-11s %-10s %-20s" % [
18
+ data[:id],
19
+ data[:token_type],
20
+ data[:access_token_last_four],
21
+ data[:expires_in],
22
+ data[:scopes]
23
+ ]
24
+ end
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,19 @@
1
+ module Kontena::Cli::Master::Token
2
+ class RemoveCommand < Kontena::Command
3
+
4
+ parameter "TOKEN_OR_ID", "Access token or access token id"
5
+
6
+ option ['-f', '--force'], :flag, "Don't ask questions"
7
+
8
+ include Kontena::Cli::Common
9
+
10
+ requires_current_master
11
+ requires_current_master_token
12
+
13
+ def execute
14
+ confirm
15
+ client.delete("/oauth2/tokens/#{token_or_id}")
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,24 @@
1
+ require_relative 'common'
2
+
3
+ module Kontena::Cli::Master::Token
4
+ class ShowCommand < Kontena::Command
5
+
6
+ parameter "TOKEN_OR_ID", "Access token or access token id"
7
+
8
+ include Kontena::Cli::Common
9
+ include Common
10
+
11
+ requires_current_master
12
+ requires_current_master_token
13
+
14
+ def execute
15
+ data = client.get("/oauth2/tokens/#{token_or_id}")
16
+ output = token_data_to_hash(data)
17
+ output.each do |key, value|
18
+ puts "%26.26s : %s" % [key, value]
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+
@@ -0,0 +1,18 @@
1
+ require_relative 'token/list_command'
2
+ require_relative 'token/remove_command'
3
+ require_relative 'token/create_command'
4
+ require_relative 'token/current_command'
5
+ require_relative 'token/show_command'
6
+
7
+ module Kontena::Cli::Master
8
+ class TokenCommand < Kontena::Command
9
+ subcommand ["list", "ls"], "List access tokens", Kontena::Cli::Master::Token::ListCommand
10
+ subcommand ["rm", "remove"], "Remove / revoke an access token", Kontena::Cli::Master::Token::RemoveCommand
11
+ subcommand "show", "Display access token", Kontena::Cli::Master::Token::ShowCommand
12
+ subcommand "current", "Display current access token", Kontena::Cli::Master::Token::CurrentCommand
13
+ subcommand "create", "Generate an access token", Kontena::Cli::Master::Token::CreateCommand
14
+
15
+ def execute
16
+ end
17
+ end
18
+ end
@@ -7,6 +7,7 @@ require_relative 'master/config_command'
7
7
  require_relative 'master/login_command'
8
8
  require_relative 'master/join_command'
9
9
  require_relative 'master/audit_log_command'
10
+ require_relative 'master/token_command'
10
11
 
11
12
  if ENV["DEV"]
12
13
  begin
@@ -22,6 +23,7 @@ class Kontena::Cli::MasterCommand < Kontena::Command
22
23
  subcommand "users", "Users specific commands", Kontena::Cli::Master::UsersCommand
23
24
  subcommand "current", "Show current master details", Kontena::Cli::Master::CurrentCommand
24
25
  subcommand "login", "Authenticate to Kontena Master", Kontena::Cli::Master::LoginCommand
26
+ subcommand "token", "Manage Kontena Master access tokens", Kontena::Cli::Master::TokenCommand
25
27
  subcommand "join", "Join Kontena Master using an invitation code", Kontena::Cli::Master::JoinCommand
26
28
  subcommand "audit-log", "Show master audit logs", Kontena::Cli::Master::AuditLogCommand
27
29
 
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.0.pre4
4
+ version: 0.16.0.pre5
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-09-27 00:00:00.000000000 Z
11
+ date: 2016-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -313,6 +313,13 @@ files:
313
313
  - lib/kontena/cli/master/join_command.rb
314
314
  - lib/kontena/cli/master/list_command.rb
315
315
  - lib/kontena/cli/master/login_command.rb
316
+ - lib/kontena/cli/master/token/common.rb
317
+ - lib/kontena/cli/master/token/create_command.rb
318
+ - lib/kontena/cli/master/token/current_command.rb
319
+ - lib/kontena/cli/master/token/list_command.rb
320
+ - lib/kontena/cli/master/token/remove_command.rb
321
+ - lib/kontena/cli/master/token/show_command.rb
322
+ - lib/kontena/cli/master/token_command.rb
316
323
  - lib/kontena/cli/master/use_command.rb
317
324
  - lib/kontena/cli/master/users/invite_command.rb
318
325
  - lib/kontena/cli/master/users/list_command.rb