diplomatic_bag 2.2.1 → 2.2.2

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
  SHA256:
3
- metadata.gz: 641df0432390b52215d6063148e94b402ea200fa5a424ca2499c98aa8ba2d88a
4
- data.tar.gz: 4a0ddc8cc86c54a6e52ed1a6b387a21ed206c1fc2743196b3e143cc06db169b7
3
+ metadata.gz: 313e9bcc3a63667959e8cf0782357d2dc0a20e98879d20743f90cc470fab7fcb
4
+ data.tar.gz: ea7b73ede3b6d3b08e350b90fa2bf86415273ec25f744762c0ca8c1d6a23390a
5
5
  SHA512:
6
- metadata.gz: 0f1568f519ef9b7b685bd07905b60ba441051a928c3ec11e0a1b1ae5bae0c4ff15096749c6ac55a52d82a2d34640b99558b5a5bd1cd708e383dfbd59a19240a3
7
- data.tar.gz: 34193eac2e23dff911c8c8845a0998102f0a88bafd5e4d9104c29c184d2d934bfd1bd376217a240cf76383efd25787a3779070f449045c0f73db998087ecf960
6
+ metadata.gz: 746d01ce05942b34c25d60e6997e980b763764ebb3807692c212e36c104987d98297666f863bc899055ae172717c06777c3408ab3307d586a4614505eb2cead5
7
+ data.tar.gz: 24d806c41db58b9b764881723d14dcafd0b46f066b6359cd53ff2b80f6f48cceec48a14d733e0bb9ff068954283275f04afa16c70c985599b98f900fbcd6f79c
data/bin/consul-cli ADDED
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+ # rubocop:disable all
3
+
4
+ require 'diplomatic_bag'
5
+ require 'optparse'
6
+
7
+ def syntax
8
+ printf "USAGE: #{$PROGRAM_NAME} [[action]] [[options]]\n\n" \
9
+ "\t#{$PROGRAM_NAME} services list [options]\n" \
10
+ "\t#{$PROGRAM_NAME} service status <service-name> [options]\n" \
11
+ "\t#{$PROGRAM_NAME} info [options]\n" \
12
+ "\t#{$PROGRAM_NAME} nodes list-duplicate-id [options]\n\n" \
13
+ "Options:\n" \
14
+ "\t-a, --http-addr\t\tThe `address` and port of the Consul HTTP agent\n" \
15
+ "\t-d, --datacenter\tName of the datacenter to query\n" \
16
+ "\t-f, --format\t\tOutput format (json|text)\n" \
17
+ "\t-t, --token\t\tACL token to use in the request\n"
18
+ exit 0
19
+ end
20
+
21
+ def launch_query(arguments, options)
22
+ case arguments[0]
23
+ when 'services'
24
+ if arguments[1] == 'list'
25
+ DiplomaticBag.get_all_services_status(options)
26
+ else
27
+ syntax
28
+ exit 0
29
+ end
30
+ when 'service'
31
+ if arguments[1] == 'status'
32
+ DiplomaticBag.get_services_info(arguments[2], options)
33
+ else
34
+ syntax
35
+ exit 0
36
+ end
37
+ when 'info'
38
+ DiplomaticBag.consul_info(options)
39
+ when 'nodes'
40
+ if arguments[1] == 'list-duplicate-id'
41
+ DiplomaticBag.get_duplicate_node_id(options)
42
+ else
43
+ syntax
44
+ exit 0
45
+ end
46
+ else
47
+ syntax
48
+ exit 0
49
+ end
50
+ end
51
+
52
+ def parse_as_text(input, indent)
53
+ case input
54
+ when Array
55
+ input.each do |v|
56
+ parse_as_text(v, indent)
57
+ end
58
+ when Hash
59
+ input.each do |k, v|
60
+ print "#{indent}#{k}:\n"
61
+ parse_as_text(v, indent+' ')
62
+ end
63
+ else
64
+ print "#{indent}#{input}\n"
65
+ end
66
+ end
67
+
68
+ options = {http_addr: ENV['CONSUL_HTTP_ADDR'] || 'localhost:8500'}
69
+ params = {}
70
+ output = {}
71
+
72
+ OptionParser.new do |opts|
73
+ opts.banner = "USAGE: #{$PROGRAM_NAME} -a [[action]] [[options]]"
74
+
75
+ opts.on('-h', '--help', 'Show help') do
76
+ syntax
77
+ end
78
+
79
+ opts.on("-a", "--http-addr [CONSUL_URL]", "The `address` and port of the Consul HTTP agent") do |server|
80
+ options[:http_addr] = server
81
+ end
82
+
83
+ opts.on("-d", "--datacenter [DATACENTER]", "Name of the datacenter to query (services option)") do |dc|
84
+ params[:dcs] = dc
85
+ end
86
+
87
+ opts.on("-f", "--format TYPE", [:json, :txt], "Output format") do |format|
88
+ params[:format] = format
89
+ end
90
+
91
+ opts.on("-t", "--token [TOKEN]", "ACL token to use in the request") do |token|
92
+ options[:token] = token
93
+ end
94
+ end.parse!
95
+
96
+ options[:http_addr] = "http://#{options[:http_addr]}" unless options[:http_addr].start_with? 'http'
97
+
98
+ if params[:dcs]
99
+ dcs = DiplomaticBag.get_datacenters_list(params[:dcs].split(','), options)
100
+ dcs.each do |dc|
101
+ options[:dc] = dc
102
+ output[dc] = launch_query(ARGV, options)
103
+ end
104
+ else
105
+ output = launch_query(ARGV, options)
106
+ end
107
+ case params[:format]
108
+ when :json
109
+ puts JSON.pretty_generate(output) unless output == {}
110
+ else
111
+ parse_as_text(output, '') unless output == {}
112
+ end
113
+
114
+ # rubocop:enable all
@@ -1,3 +1,3 @@
1
1
  module Diplomat
2
- VERSION = '2.2.1'.freeze
2
+ VERSION = '2.2.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diplomatic_bag
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Benoit
@@ -14,16 +14,16 @@ dependencies:
14
14
  name: diplomat
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
19
+ version: 2.2.2
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 2.2.2
27
27
  description: Toolbox for Consul
28
28
  email:
29
29
  - n.benoit@criteo.com
@@ -33,6 +33,7 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - LICENSE
35
35
  - README.md
36
+ - bin/consul-cli
36
37
  - features/configuration.feature
37
38
  - features/step_definitions/setup_diplomat.rb
38
39
  - features/step_definitions/test_key_value.rb