kontena-cli 0.13.4 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/kontena-cli.gemspec +2 -0
  4. data/lib/kontena/cli/app_command.rb +2 -0
  5. data/lib/kontena/cli/apps/common.rb +80 -74
  6. data/lib/kontena/cli/apps/config_command.rb +29 -0
  7. data/lib/kontena/cli/apps/deploy_command.rb +12 -81
  8. data/lib/kontena/cli/apps/docker_helper.rb +3 -3
  9. data/lib/kontena/cli/apps/init_command.rb +0 -3
  10. data/lib/kontena/cli/apps/list_command.rb +2 -3
  11. data/lib/kontena/cli/apps/logs_command.rb +2 -3
  12. data/lib/kontena/cli/apps/monitor_command.rb +3 -4
  13. data/lib/kontena/cli/apps/remove_command.rb +4 -4
  14. data/lib/kontena/cli/apps/restart_command.rb +2 -3
  15. data/lib/kontena/cli/apps/scale_command.rb +3 -5
  16. data/lib/kontena/cli/apps/service_generator.rb +123 -0
  17. data/lib/kontena/cli/apps/service_generator_v2.rb +26 -0
  18. data/lib/kontena/cli/apps/show_command.rb +1 -2
  19. data/lib/kontena/cli/apps/start_command.rb +2 -3
  20. data/lib/kontena/cli/apps/stop_command.rb +2 -3
  21. data/lib/kontena/cli/apps/yaml/reader.rb +150 -0
  22. data/lib/kontena/cli/apps/yaml/service_extender.rb +60 -0
  23. data/lib/kontena/cli/apps/yaml/validations.rb +79 -0
  24. data/lib/kontena/cli/apps/yaml/validator.rb +55 -0
  25. data/lib/kontena/cli/apps/yaml/validator_v2.rb +74 -0
  26. data/lib/kontena/cli/common.rb +23 -0
  27. data/lib/kontena/cli/etcd/remove_command.rb +2 -0
  28. data/lib/kontena/cli/grids/remove_command.rb +2 -0
  29. data/lib/kontena/cli/grids/users/remove_command.rb +3 -0
  30. data/lib/kontena/cli/master/azure/create_command.rb +0 -2
  31. data/lib/kontena/cli/master/packet/create_command.rb +42 -0
  32. data/lib/kontena/cli/master/packet_command.rb +14 -0
  33. data/lib/kontena/cli/master/upcloud/create_command.rb +39 -0
  34. data/lib/kontena/cli/master/upcloud_command.rb +13 -0
  35. data/lib/kontena/cli/master/users/remove_command.rb +3 -0
  36. data/lib/kontena/cli/master/users/roles/remove_command.rb +2 -0
  37. data/lib/kontena/cli/master_command.rb +4 -0
  38. data/lib/kontena/cli/node_command.rb +4 -0
  39. data/lib/kontena/cli/nodes/azure/create_command.rb +0 -2
  40. data/lib/kontena/cli/nodes/list_command.rb +4 -8
  41. data/lib/kontena/cli/nodes/packet/create_command.rb +35 -0
  42. data/lib/kontena/cli/nodes/packet/restart_command.rb +17 -0
  43. data/lib/kontena/cli/nodes/packet/terminate_command.rb +20 -0
  44. data/lib/kontena/cli/nodes/packet_command.rb +15 -0
  45. data/lib/kontena/cli/nodes/remove_command.rb +2 -0
  46. data/lib/kontena/cli/nodes/show_command.rb +3 -1
  47. data/lib/kontena/cli/nodes/upcloud/create_command.rb +33 -0
  48. data/lib/kontena/cli/nodes/upcloud/restart_command.rb +20 -0
  49. data/lib/kontena/cli/nodes/upcloud/terminate_command.rb +20 -0
  50. data/lib/kontena/cli/nodes/upcloud_command.rb +15 -0
  51. data/lib/kontena/cli/registry/remove_command.rb +3 -0
  52. data/lib/kontena/cli/services/remove_command.rb +2 -0
  53. data/lib/kontena/cli/services/services_helper.rb +1 -0
  54. data/lib/kontena/cli/vault/list_command.rb +2 -0
  55. data/lib/kontena/cli/vault/read_command.rb +2 -0
  56. data/lib/kontena/cli/vault/remove_command.rb +4 -0
  57. data/lib/kontena/cli/vault/update_command.rb +8 -1
  58. data/lib/kontena/cli/vault/write_command.rb +2 -0
  59. data/lib/kontena/cli/vpn/remove_command.rb +3 -0
  60. data/lib/kontena/machine/azure/master_provisioner.rb +2 -2
  61. data/lib/kontena/machine/azure/node_provisioner.rb +7 -4
  62. data/lib/kontena/machine/digital_ocean/node_provisioner.rb +1 -1
  63. data/lib/kontena/machine/packet.rb +17 -0
  64. data/lib/kontena/machine/packet/cloudinit.yml +66 -0
  65. data/lib/kontena/machine/packet/cloudinit_master.yml +118 -0
  66. data/lib/kontena/machine/packet/master_provisioner.rb +93 -0
  67. data/lib/kontena/machine/packet/node_destroyer.rb +42 -0
  68. data/lib/kontena/machine/packet/node_provisioner.rb +77 -0
  69. data/lib/kontena/machine/packet/node_restarter.rb +41 -0
  70. data/lib/kontena/machine/packet/packet_common.rb +89 -0
  71. data/lib/kontena/machine/upcloud.rb +9 -0
  72. data/lib/kontena/machine/upcloud/cloudinit.yml +64 -0
  73. data/lib/kontena/machine/upcloud/cloudinit_master.yml +118 -0
  74. data/lib/kontena/machine/upcloud/master_provisioner.rb +136 -0
  75. data/lib/kontena/machine/upcloud/node_destroyer.rb +82 -0
  76. data/lib/kontena/machine/upcloud/node_provisioner.rb +119 -0
  77. data/lib/kontena/machine/upcloud/node_restarter.rb +47 -0
  78. data/lib/kontena/machine/upcloud/upcloud_common.rb +70 -0
  79. data/lib/kontena/scripts/completer +8 -3
  80. data/spec/fixtures/docker-compose_v2.yml +10 -0
  81. data/spec/fixtures/kontena-invalid.yml +4 -0
  82. data/spec/fixtures/kontena-with-variables.yml +19 -0
  83. data/spec/fixtures/kontena.yml +2 -2
  84. data/spec/fixtures/kontena_v2.yml +35 -0
  85. data/spec/kontena/cli/app/common_spec.rb +39 -101
  86. data/spec/kontena/cli/app/deploy_command_spec.rb +37 -388
  87. data/spec/kontena/cli/app/docker_helper_spec.rb +4 -4
  88. data/spec/kontena/cli/app/service_generator_spec.rb +374 -0
  89. data/spec/kontena/cli/app/service_generator_v2_spec.rb +74 -0
  90. data/spec/kontena/cli/app/yaml/reader_spec.rb +249 -0
  91. data/spec/kontena/cli/app/yaml/service_extender_spec.rb +104 -0
  92. data/spec/kontena/cli/app/yaml/validator_spec.rb +263 -0
  93. data/spec/kontena/cli/app/yaml/validator_v2_spec.rb +309 -0
  94. data/spec/kontena/cli/common_spec.rb +39 -1
  95. data/spec/kontena/cli/master/users/remove_command_spec.rb +9 -0
  96. data/spec/kontena/cli/master/users/roles/remove_command_spec.rb +2 -0
  97. metadata +86 -2
@@ -0,0 +1,13 @@
1
+
2
+ module Kontena::Cli::Master
3
+
4
+ require_relative 'upcloud/create_command'
5
+
6
+ class UpcloudCommand < Clamp::Command
7
+
8
+ subcommand "create", "Create a new Upcloud master", Upcloud::CreateCommand
9
+
10
+ def execute
11
+ end
12
+ end
13
+ end
@@ -5,10 +5,13 @@ module Kontena::Cli::Master::Users
5
5
  include Kontena::Cli::Common
6
6
 
7
7
  parameter "EMAIL ...", "List of emails"
8
+ option "--force", :flag, "Force remove", default: false, attribute_name: :forced
8
9
 
9
10
  def execute
10
11
  require_api_url
11
12
  token = require_token
13
+ confirm unless forced?
14
+
12
15
  email_list.each do |email|
13
16
  begin
14
17
  client(token).delete("users/#{email}")
@@ -6,11 +6,13 @@ module Kontena::Cli::Master::Users::Roles
6
6
 
7
7
  parameter "ROLE", "Role name"
8
8
  parameter "USER ...", "List of users"
9
+ option "--force", :flag, "Force remove", default: false, attribute_name: :forced
9
10
 
10
11
 
11
12
  def execute
12
13
  require_api_url
13
14
  token = require_token
15
+ confirm unless forced?
14
16
 
15
17
  user_list.each do |email|
16
18
  begin
@@ -1,6 +1,8 @@
1
1
  require_relative 'master/vagrant_command'
2
2
  require_relative 'master/aws_command'
3
3
  require_relative 'master/digital_ocean_command'
4
+ require_relative 'master/packet_command'
5
+ require_relative 'master/upcloud_command'
4
6
  require_relative 'master/azure_command'
5
7
  require_relative 'master/use_command'
6
8
  require_relative 'master/list_command'
@@ -12,6 +14,8 @@ class Kontena::Cli::MasterCommand < Clamp::Command
12
14
  subcommand "vagrant", "Vagrant specific commands", Kontena::Cli::Master::VagrantCommand
13
15
  subcommand "aws", "AWS specific commands", Kontena::Cli::Master::AwsCommand
14
16
  subcommand "digitalocean", "DigitalOcean specific commands", Kontena::Cli::Master::DigitalOceanCommand
17
+ subcommand "packet", "Packet specific commands", Kontena::Cli::Master::PacketCommand
18
+ subcommand "upcloud", "Upcloud specific commands", Kontena::Cli::Master::UpcloudCommand
15
19
  subcommand "azure", "Azure specific commands", Kontena::Cli::Master::AzureCommand
16
20
  subcommand ["list", "ls"], "List masters where client has logged in", Kontena::Cli::Master::ListCommand
17
21
  subcommand "use", "Switch to use selected master", Kontena::Cli::Master::UseCommand
@@ -8,6 +8,8 @@ require_relative 'nodes/label_command'
8
8
 
9
9
  require_relative 'nodes/vagrant_command'
10
10
  require_relative 'nodes/digital_ocean_command'
11
+ require_relative 'nodes/packet_command'
12
+ require_relative 'nodes/upcloud_command'
11
13
  require_relative 'nodes/aws_command'
12
14
  require_relative 'nodes/azure_command'
13
15
 
@@ -23,6 +25,8 @@ class Kontena::Cli::NodeCommand < Clamp::Command
23
25
 
24
26
  subcommand "vagrant", "Vagrant specific commands", Kontena::Cli::Nodes::VagrantCommand
25
27
  subcommand "digitalocean", "DigitalOcean specific commands", Kontena::Cli::Nodes::DigitalOceanCommand
28
+ subcommand "packet", "Packet specific commands", Kontena::Cli::Nodes::PacketCommand
29
+ subcommand "upcloud", "Upcloud specific commands", Kontena::Cli::Nodes::UpcloudCommand
26
30
  subcommand "aws", "AWS specific commands", Kontena::Cli::Nodes::AwsCommand
27
31
  subcommand "azure", "Azure specific commands", Kontena::Cli::Nodes::AzureCommand
28
32
 
@@ -9,7 +9,6 @@ module Kontena::Cli::Nodes::Azure
9
9
  option "--network", "NETWORK", "Virtual Network name"
10
10
  option "--subnet", "SUBNET", "Subnet name"
11
11
  option "--ssh-key", "SSH KEY", "SSH private key file", required: true
12
- option "--password", "PASSWORD", "Password"
13
12
  option "--location", "LOCATION", "Location", default: 'West Europe'
14
13
  option "--version", "VERSION", "Define installed Kontena version", default: 'latest'
15
14
 
@@ -26,7 +25,6 @@ module Kontena::Cli::Nodes::Azure
26
25
  master_uri: api_url,
27
26
  grid_token: grid['token'],
28
27
  grid: current_grid,
29
- password: password,
30
28
  ssh_key: ssh_key,
31
29
  name: name,
32
30
  size: size,
@@ -31,17 +31,13 @@ module Kontena::Cli::Nodes
31
31
  end
32
32
  else
33
33
  nodes = client(token).get("grids/#{current_grid}/nodes")
34
- puts "%-70s %-10s %-40s" % ['Name', 'Status', 'Labels']
34
+ puts "%-70s %-10s %-10s %-40s" % ['Name', 'Status', 'Initial', 'Labels']
35
35
  nodes = nodes['nodes'].sort_by{|n| n['node_number'] }
36
36
  nodes.each do |node|
37
- if node['connected']
38
- status = 'online'
39
- else
40
- status = 'offline'
41
- end
42
- puts "%-70.70s %-10s %-40s" % [
37
+ puts "%-70.70s %-10s %-10s %-40s" % [
43
38
  node['name'],
44
- status,
39
+ node['connected'] ? 'online' : 'offline',
40
+ node['initial_member'] ? 'yes' : 'no',
45
41
  (node['labels'] || ['-']).join(",")
46
42
  ]
47
43
  end
@@ -0,0 +1,35 @@
1
+ module Kontena::Cli::Nodes::Packet
2
+ class CreateCommand < Clamp::Command
3
+ include Kontena::Cli::Common
4
+ include Kontena::Cli::GridOptions
5
+
6
+ parameter "[NAME]", "Node name"
7
+ option "--token", "TOKEN", "Packet API token", required: true
8
+ option "--project", "PROJECT ID", "Packet project id", required: true
9
+ option "--type", "TYPE", "Server type (baremetal_0, baremetal_1, ..)", default: 'baremetal_0', attribute_name: :plan
10
+ option "--facility", "FACILITY CODE", "Facility", default: 'ams1'
11
+ option "--billing", "BILLING", "Billing cycle", default: 'hourly'
12
+ option "--ssh-key", "PATH", "Path to ssh public key (optional)"
13
+ option "--version", "VERSION", "Define installed Kontena version", default: 'latest'
14
+
15
+ def execute
16
+ require_api_url
17
+ require_current_grid
18
+
19
+ require 'kontena/machine/packet'
20
+ grid = client(require_token).get("grids/#{current_grid}")
21
+ provisioner = Kontena::Machine::Packet::NodeProvisioner.new(client(require_token), token)
22
+ provisioner.run!(
23
+ master_uri: api_url,
24
+ grid_token: grid['token'],
25
+ grid: current_grid,
26
+ project: project,
27
+ billing: billing,
28
+ ssh_key: ssh_key,
29
+ plan: plan,
30
+ facility: facility,
31
+ version: version
32
+ )
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,17 @@
1
+ module Kontena::Cli::Nodes::Packet
2
+ class RestartCommand < Clamp::Command
3
+ include Kontena::Cli::Common
4
+ include Kontena::Cli::GridOptions
5
+
6
+ parameter "NAME", "Node name"
7
+ option "--token", "TOKEN", "Packet API token", required: true
8
+ option "--project", "PROJECT ID", "Packet project id", required: true
9
+
10
+ def execute
11
+ require 'kontena/machine/packet'
12
+
13
+ restarter = Kontena::Machine::Packet::NodeRestarter.new(token)
14
+ restarter.run!(project, name)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ module Kontena::Cli::Nodes::Packet
2
+ class TerminateCommand < Clamp::Command
3
+ include Kontena::Cli::Common
4
+ include Kontena::Cli::GridOptions
5
+
6
+ parameter "NAME", "Node name"
7
+ option "--token", "TOKEN", "Packet API token", required: true
8
+ option "--project", "PROJECT ID", "Packet project id", required: true
9
+
10
+ def execute
11
+ require_api_url
12
+ require_current_grid
13
+
14
+ require 'kontena/machine/packet'
15
+ grid = client(require_token).get("grids/#{current_grid}")
16
+ destroyer = Kontena::Machine::Packet::NodeDestroyer.new(client(require_token), token)
17
+ destroyer.run!(grid, project, name)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'packet/create_command'
2
+ require_relative 'packet/restart_command'
3
+ require_relative 'packet/terminate_command'
4
+
5
+ module Kontena::Cli::Nodes
6
+ class PacketCommand < Clamp::Command
7
+
8
+ subcommand "create", "Create a new Packet node", Packet::CreateCommand
9
+ subcommand "restart", "Restart a Packet node", Packet::RestartCommand
10
+ subcommand "terminate", "Terminate a Packet node", Packet::TerminateCommand
11
+
12
+ def execute
13
+ end
14
+ end
15
+ end
@@ -4,11 +4,13 @@ module Kontena::Cli::Nodes
4
4
  include Kontena::Cli::GridOptions
5
5
 
6
6
  parameter "NODE_ID", "Node id"
7
+ option "--force", :flag, "Force remove", default: false, attribute_name: :forced
7
8
 
8
9
  def execute
9
10
  require_api_url
10
11
  require_current_grid
11
12
  token = require_token
13
+ confirm_command(node_id) unless forced?
12
14
 
13
15
  client(token).delete("grids/#{current_grid}/nodes/#{node_id}")
14
16
  end
@@ -14,15 +14,17 @@ module Kontena::Cli::Nodes
14
14
  node = client(token).get("grids/#{current_grid}/nodes/#{node_id}")
15
15
  puts "#{node['name']}:"
16
16
  puts " id: #{node['id']}"
17
+ puts " agent version: #{node['agent_version']}"
17
18
  puts " connected: #{node['connected'] ? 'yes': 'no'}"
18
19
  puts " last connect: #{node['updated_at']}"
19
20
  puts " last seen: #{node['last_seen_at']}"
20
21
  puts " public ip: #{node['public_ip']}"
21
22
  puts " private ip: #{node['private_ip']}"
22
- puts " overlay network: 10.81.#{node['node_number']}.0/24"
23
+ puts " overlay ip: 10.81.0.#{node['node_number']}"
23
24
  puts " os: #{node['os']}"
24
25
  puts " driver: #{node['driver']}"
25
26
  puts " kernel: #{node['kernel_version']}"
27
+ puts " initial node: #{node['initial_member'] ? 'yes' : 'no'}"
26
28
  puts " labels:"
27
29
  if node['labels']
28
30
  node['labels'].each{|l| puts " - #{l}"}
@@ -0,0 +1,33 @@
1
+ module Kontena::Cli::Nodes::Upcloud
2
+ class CreateCommand < Clamp::Command
3
+ include Kontena::Cli::Common
4
+ include Kontena::Cli::GridOptions
5
+
6
+ parameter "[NAME]", "Node name"
7
+ option "--username", "USER", "Upcloud username", required: true
8
+ option "--password", "PASS", "Upcloud password", required: true
9
+ option "--ssh-key", "SSH_KEY", "Path to ssh public key", required: true
10
+ option "--plan", "PLAN", "Server size", default: '1xCPU-1GB'
11
+ option "--zone", "ZONE", "Zone", default: 'fi-hel1'
12
+ option "--version", "VERSION", "Define installed Kontena version", default: 'latest'
13
+
14
+ def execute
15
+ require_api_url
16
+ require_current_grid
17
+
18
+ require 'kontena/machine/upcloud'
19
+ grid = client(require_token).get("grids/#{current_grid}")
20
+ provisioner = Kontena::Machine::Upcloud::NodeProvisioner.new(client(require_token), username, password)
21
+ provisioner.run!(
22
+ master_uri: api_url,
23
+ grid_token: grid['token'],
24
+ grid: current_grid,
25
+ ssh_key: ssh_key,
26
+ name: name,
27
+ plan: plan,
28
+ zone: zone,
29
+ version: version
30
+ )
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,20 @@
1
+ module Kontena::Cli::Nodes::Upcloud
2
+ class RestartCommand < Clamp::Command
3
+ include Kontena::Cli::Common
4
+ include Kontena::Cli::GridOptions
5
+
6
+ parameter "NAME", "Node name"
7
+ option "--username", "USER", "Upcloud username", required: true
8
+ option "--password", "PASS", "Upcloud password", required: true
9
+
10
+ def execute
11
+ require_api_url
12
+ require_current_grid
13
+
14
+ require 'kontena/machine/upcloud'
15
+
16
+ restarter = Kontena::Machine::Upcloud::NodeRestarter.new(username, password)
17
+ restarter.run!(name)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module Kontena::Cli::Nodes::Upcloud
2
+ class TerminateCommand < Clamp::Command
3
+ include Kontena::Cli::Common
4
+ include Kontena::Cli::GridOptions
5
+
6
+ parameter "NAME", "Node name"
7
+ option "--username", "USER", "Upcloud username", required: true
8
+ option "--password", "PASS", "Upcloud password", required: true
9
+
10
+ def execute
11
+ require_api_url
12
+ require_current_grid
13
+
14
+ require 'kontena/machine/upcloud'
15
+ grid = client(require_token).get("grids/#{current_grid}")
16
+ destroyer = Kontena::Machine::Upcloud::NodeDestroyer.new(client(require_token), username, password)
17
+ destroyer.run!(grid, name)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'upcloud/create_command'
2
+ require_relative 'upcloud/restart_command'
3
+ require_relative 'upcloud/terminate_command'
4
+
5
+ module Kontena::Cli::Nodes
6
+ class UpcloudCommand < Clamp::Command
7
+
8
+ subcommand "create", "Create a new Upcloud node", Upcloud::CreateCommand
9
+ subcommand "restart", "Restart Upcloud node", Upcloud::RestartCommand
10
+ subcommand "terminate", "Terminate Upcloud node", Upcloud::TerminateCommand
11
+
12
+ def execute
13
+ end
14
+ end
15
+ end
@@ -2,9 +2,12 @@ module Kontena::Cli::Registry
2
2
  class RemoveCommand < Clamp::Command
3
3
  include Kontena::Cli::Common
4
4
 
5
+ option "--force", :flag, "Force remove", default: false, attribute_name: :forced
6
+
5
7
  def execute
6
8
  require_api_url
7
9
  token = require_token
10
+ confirm unless forced?
8
11
 
9
12
  registry = client(token).get("services/#{current_grid}/registry") rescue nil
10
13
  abort("Docker Registry service does not exist") if registry.nil?
@@ -6,10 +6,12 @@ module Kontena::Cli::Services
6
6
  include ServicesHelper
7
7
 
8
8
  parameter "NAME", "Service name"
9
+ option "--force", :flag, "Force remove", default: false, attribute_name: :forced
9
10
 
10
11
  def execute
11
12
  require_api_url
12
13
  token = require_token
14
+ confirm_command(name) unless forced?
13
15
 
14
16
  result = client(token).delete("services/#{parse_service_id(name)}")
15
17
  end
@@ -202,6 +202,7 @@ module Kontena
202
202
  # @param [String] name
203
203
  def wait_for_deploy_to_finish(token, name)
204
204
  ShellSpinner " " do
205
+ sleep 1 # wait for master to process deploy request and change state to 'deploying'
205
206
  until client(token).get("services/#{name}")['state'] != 'deploying' do
206
207
  sleep 1
207
208
  end
@@ -5,6 +5,8 @@ module Kontena::Cli::Vault
5
5
 
6
6
  def execute
7
7
  require_api_url
8
+ require_current_grid
9
+
8
10
  token = require_token
9
11
  result = client(token).get("grids/#{current_grid}/secrets")
10
12
 
@@ -7,6 +7,8 @@ module Kontena::Cli::Vault
7
7
 
8
8
  def execute
9
9
  require_api_url
10
+ require_current_grid
11
+
10
12
  token = require_token
11
13
  result = client(token).get("secrets/#{current_grid}/#{name}")
12
14
  puts "#{result['name']}:"
@@ -4,9 +4,13 @@ module Kontena::Cli::Vault
4
4
  include Kontena::Cli::GridOptions
5
5
 
6
6
  parameter "NAME", "Secret name"
7
+ option "--force", :flag, "Force remove", default: false, attribute_name: :forced
7
8
 
8
9
  def execute
9
10
  require_api_url
11
+ require_current_grid
12
+ confirm_command(name) unless forced?
13
+
10
14
  token = require_token
11
15
  client(token).delete("secrets/#{current_grid}/#{name}")
12
16
  end
@@ -4,16 +4,23 @@ module Kontena::Cli::Vault
4
4
 
5
5
  parameter 'NAME', 'Secret name'
6
6
  parameter '[VALUE]', 'Secret value'
7
+ option ['-u', '--upsert'], :flag, 'Create secret unless already exists', default: false
7
8
 
8
9
  def execute
9
10
  require_api_url
11
+ require_current_grid
12
+
10
13
  token = require_token
11
14
  secret = value
12
15
  if secret.to_s == ''
13
16
  secret = STDIN.read
14
17
  end
15
18
  abort('No value provided') if secret.to_s == ''
16
- data = {value: secret}
19
+ data = {
20
+ name: name,
21
+ value: secret,
22
+ upsert: upsert?
23
+ }
17
24
  client(token).put("grids/#{current_grid}/secrets/#{name}", data)
18
25
  end
19
26
  end