hotdog 0.14.0 → 0.15.0

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: 4f3141bb4b97ec0c63dc50eae72bd1cf5d44c148
4
- data.tar.gz: 548009a66b40670fa5d2a0c3d81616fe1f4c759f
3
+ metadata.gz: ca3cf225477ffccd577b502f07b089096c09151e
4
+ data.tar.gz: c686cbfbf95c690db8f840cbafe0bd85cd74223f
5
5
  SHA512:
6
- metadata.gz: 6e6d38e556cbfcb953e9affa5890ecd34fc9dc91dd5eb5bba48f1ed661d5fbe8b15c87157257f428cf9ddb26aa434f9bea91cdb9f3bf39bb8a4658929af285ad
7
- data.tar.gz: 52b4f24c92001e3ebf55f6a527af9d0f2454476ceba4f46edc307dc72dc30a9787f0cad71a7a23b783c7dab4eee420998f05c7ed1b89faa489369ce42d78c05a
6
+ metadata.gz: 8556bf0dc32a05c44212b5ff7f52c95ced92e1a6cfd669a7cf211dfa86efe55251d2345f0a1ed907e6775a1350f98567382022ef1fd09e3258b02ae1bc30729b
7
+ data.tar.gz: 728f6a9170a8bd680b548b8e060c5317f11c1cb9b664254d2c92fae99e407cbb2c231301a4a831b1f913e32c5ce00154101f9c0164dc5c538bfc298f8d5138f8
@@ -76,14 +76,6 @@ module Hotdog
76
76
  exit(1)
77
77
  end
78
78
 
79
- unless options[:api_key]
80
- raise("DATADOG_API_KEY is not set")
81
- end
82
-
83
- unless options[:application_key]
84
- raise("DATADOG_APPLICATION_KEY is not set")
85
- end
86
-
87
79
  if options[:format] == "ltsv"
88
80
  options[:headers] = true
89
81
  end
@@ -111,6 +103,32 @@ module Hotdog
111
103
  end
112
104
  end
113
105
 
106
+ def api_key()
107
+ if options[:api_key]
108
+ options[:api_key]
109
+ else
110
+ update_api_key!
111
+ if options[:api_key]
112
+ options[:api_key]
113
+ else
114
+ raise("DATADOG_API_KEY is not set")
115
+ end
116
+ end
117
+ end
118
+
119
+ def application_key()
120
+ if options[:application_key]
121
+ options[:application_key]
122
+ else
123
+ update_application_key!
124
+ if options[:application_key]
125
+ options[:application_key]
126
+ else
127
+ raise("DATADOG_APPLICATION_KEY is not set")
128
+ end
129
+ end
130
+ end
131
+
114
132
  private
115
133
  def define_options
116
134
  @optparse.on("--endpoint ENDPOINT", "Datadog API endpoint") do |endpoint|
@@ -231,6 +249,28 @@ module Hotdog
231
249
  end
232
250
  end
233
251
  end
252
+
253
+ def update_api_key!()
254
+ if options[:api_key_command]
255
+ options[:api_key] = IO.popen(options[:api_key_command]).read.strip
256
+ else
257
+ update_keys!
258
+ end
259
+ end
260
+
261
+ def update_application_key!()
262
+ if options[:application_key_command]
263
+ options[:application_key] = IO.popen(options[:application_key_command]).read.strip
264
+ else
265
+ update_keys!
266
+ end
267
+ end
268
+
269
+ def update_keys!()
270
+ if options[:key_command]
271
+ options[:api_key], options[:application_key] = IO.popen(options[:key_command]).read.strip.split(":", 2)
272
+ end
273
+ end
234
274
  end
235
275
  end
236
276
 
@@ -291,7 +291,7 @@ module Hotdog
291
291
  def get_all_tags() #==> Hash<Tag,Array<Host>>
292
292
  endpoint = options[:endpoint]
293
293
  requests = {all_downtime: "/api/v1/downtime", all_tags: "/api/v1/tags/hosts"}
294
- query = URI.encode_www_form(api_key: options[:api_key], application_key: options[:application_key])
294
+ query = URI.encode_www_form(api_key: application.api_key, application_key: application.application_key)
295
295
  begin
296
296
  parallelism = Parallel.processor_count
297
297
  responses = Hash[Parallel.map(requests, in_threads: parallelism) { |name, request_path|
@@ -323,7 +323,7 @@ module Hotdog
323
323
  end
324
324
 
325
325
  def dog()
326
- @dog ||= Dogapi::Client.new(options[:api_key], options[:application_key])
326
+ @dog ||= Dogapi::Client.new(application.api_key, application.application_key)
327
327
  end
328
328
 
329
329
  def split_tag(tag)
@@ -6,7 +6,11 @@ module Hotdog
6
6
  module Commands
7
7
  class Tag < BaseCommand
8
8
  def define_options(optparse, options={})
9
+ default_option(options, :tag_source, "user")
9
10
  default_option(options, :tags, [])
11
+ optparse.on("--source SOURCE") do |v|
12
+ options[:tag_source] = v
13
+ end
10
14
  optparse.on("--tag TAG") do |v|
11
15
  options[:tags] << v
12
16
  end
@@ -20,9 +24,9 @@ module Hotdog
20
24
  # nop
21
25
  else
22
26
  # add all as user tags
23
- code, add_tags = dog.add_tags(host_name, options[:tags], source="user")
27
+ code, add_tags = dog.add_tags(host_name, options[:tags], source=options[:tag_source])
24
28
  if code.to_i / 100 != 2
25
- raise("dog.add_tags(#{host_name.inspect}, #{options[:tags].inspect}, source=\"user\") returns [#{code.inspect}, #{add_tags.inspect}]")
29
+ raise("dog.add_tags(#{host_name.inspect}, #{options[:tags].inspect}, source=#{options[:tag_source].inspect}) returns [#{code.inspect}, #{add_tags.inspect}]")
26
30
  end
27
31
  end
28
32
  end
@@ -6,7 +6,11 @@ module Hotdog
6
6
  module Commands
7
7
  class Untag < BaseCommand
8
8
  def define_options(optparse, options={})
9
+ default_option(options, :tag_source, "user")
9
10
  default_option(options, :tags, [])
11
+ optparse.on("--source SOURCE") do |v|
12
+ options[:tag_source] = v
13
+ end
10
14
  optparse.on("--tag TAG") do |v|
11
15
  options[:tags] << v
12
16
  end
@@ -18,23 +22,23 @@ module Hotdog
18
22
 
19
23
  if options[:tags].empty?
20
24
  # delete all user tags
21
- code, detach_tags = dog.detach_tags(host_name, source="user")
25
+ code, detach_tags = dog.detach_tags(host_name, source=options[:tag_source])
22
26
  if code.to_i / 100 != 2
23
- raise("dog.detach_tags(#{host_name.inspect}, source=\"user\") returns [#{code.inspect}, #{detach_tags.inspect}]")
27
+ raise("dog.detach_tags(#{host_name.inspect}, source=#{options[:tag_source].inspect}) returns [#{code.inspect}, #{detach_tags.inspect}]")
24
28
  end
25
29
  else
26
- code, host_tags = dog.host_tags(host_name, source="user")
30
+ code, host_tags = dog.host_tags(host_name, source=options[:tag_source])
27
31
  if code.to_i / 100 != 2
28
- raise("dog.host_tags(#{host_name.inspect}, source=\"user\") returns [#{code.inspect}, #{host_tags.inspect}]")
32
+ raise("dog.host_tags(#{host_name.inspect}, source=#{options[:tag_source].inspect}) returns [#{code.inspect}, #{host_tags.inspect}]")
29
33
  end
30
34
  old_tags = host_tags["tags"]
31
35
  new_tags = old_tags - options[:tags]
32
36
  if old_tags == new_tags
33
37
  # nop
34
38
  else
35
- code, update_tags = dog.update_tags(host_name, new_tags, source="user")
39
+ code, update_tags = dog.update_tags(host_name, new_tags, source=options[:tag_source])
36
40
  if code.to_i / 100 != 2
37
- raise("dog.update_tags(#{host_name.inspect}, #{new_tags.inspect}, source=\"user\") returns [#{code.inspect}, #{update_tags.inspect}]")
41
+ raise("dog.update_tags(#{host_name.inspect}, #{new_tags.inspect}, source=#{options[:tag_source].inspect}) returns [#{code.inspect}, #{update_tags.inspect}]")
38
42
  end
39
43
  end
40
44
  end
@@ -1,3 +1,3 @@
1
1
  module Hotdog
2
- VERSION = "0.14.0"
2
+ VERSION = "0.15.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotdog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yamashita Yuu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-05 00:00:00.000000000 Z
11
+ date: 2016-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler