doggy 2.0.29 → 2.0.30

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: 91c2b9cacf34931798638f66cd8b715c7a82fe90
4
- data.tar.gz: fcc7987e9cb35c25fe11aeaeb300837417cda15b
3
+ metadata.gz: 665ef43b3af2fce1b6ce594bdbd7abb681b7c776
4
+ data.tar.gz: 775570e213d753cd8aac9d92f7a38c1dd9533b34
5
5
  SHA512:
6
- metadata.gz: 20dc45a9c05aa91769f94f02dbf99431476826926b89d6380aa0dd3aaf9581ac70fc17fb9b6fbaf75c5c9d9cb00ddb6a6160b544483641cda9cf7bdf975372b2
7
- data.tar.gz: fd65d752b941303a69f195b9c1de9f3db838c230771fb31ffcc01b2f71a0366f2d14b8649fb6a86cc86e1fcdc9a1f75c6b71fffb701042a8ae5c0b64886bec51
6
+ metadata.gz: a18b022fc91c4afe36754ea188488bcee89ab9931462c5c6143c2890da1f714660a60433f9852c1d543558133167fac76af0df828367491626bc02ff04cc9540
7
+ data.tar.gz: 79a52ce5dd756d4d2cbd3afbf0f7a3d263f107f90780f7a98539cea96c63dfc5ed8a6106f05e3ba264c2a7a6f26b4b24f72a76dcf988c391d6a3885a7d884b00
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- doggy (2.0.27)
4
+ doggy (2.0.30)
5
5
  json (~> 1.8.3)
6
6
  parallel (~> 1.6.1)
7
7
  rugged (~> 0.23.2)
@@ -9,60 +9,26 @@ module Doggy
9
9
 
10
10
  def run
11
11
  resource = resource_by_param
12
- resource.read_only = false
13
12
  return Doggy.ui.error("Could not find resource with #{ @param }") unless resource
14
13
 
15
- Dir.chdir(File.dirname(resource.path)) do
16
- if resource.class.to_s.downcase =~ /dashboard/
17
- forked_resource = fork(resource)
18
- system("open '#{ forked_resource.human_edit_url }'")
19
-
20
- wait_for_edit
21
-
22
- new_resource = Doggy::Models::Dashboard.find(forked_resource.id)
23
- new_resource.id = resource.id
24
- new_resource.title = resource.title
25
- new_resource.description = resource.description
26
- new_resource.path = resource.path
27
- new_resource.save_local
28
-
29
- forked_resource.destroy
30
- elsif resource.class.to_s.downcase =~ /screen/
31
- forked_resource = fork(resource)
32
- system("open '#{ forked_resource.human_edit_url }'")
33
-
34
- wait_for_edit
35
-
36
- new_resource = Doggy::Models::Screen.find(forked_resource.id)
37
- new_resource.id = resource.id
38
- new_resource.board_title = resource.board_title
39
- new_resource.path = resource.path
40
- new_resource.save_local
41
-
42
- forked_resource.destroy
43
- elsif resource.class.to_s.downcase =~ /monitor/
44
- forked_resource = fork(resource)
45
- system("open '#{ forked_resource.human_edit_url }'")
46
-
47
- wait_for_edit
48
-
49
- new_resource = Doggy::Models::Monitor.find(forked_resource.id)
50
- new_resource.id = resource.id
51
- new_resource.name = resource.name
52
- new_resource.path = resource.path
53
- new_resource.save_local
54
-
55
- forked_resource.destroy
56
- else
57
- system("open '#{ resource.human_edit_url }'")
58
-
59
- wait_for_edit
60
-
61
- new_resource = resource.class.find(resource.id)
62
- new_resource.path = resource.path
63
- new_resource.save_local
64
- end
14
+ forked_resource = fork(resource)
15
+ system("open '#{ forked_resource.human_edit_url }'")
16
+ wait_for_edit
17
+
18
+ new_resource = Doggy::Model.infer_type(resource.attributes).find(forked_resource.id)
19
+ new_resource.id = resource.id
20
+ if new_resource.is_a?(Doggy::Models::Dashboard)
21
+ new_resource.title = resource.title
22
+ new_resource.description = resource.description
23
+ elsif new_resource.is_a?(Doggy::Models::Monitor)
24
+ new_resource.name = resource.name
25
+ elsif new_resource.is_a?(Doggy::Models::Screen)
26
+ new_resource.board_title = resource.board_title
65
27
  end
28
+ new_resource.path = resource.path
29
+ new_resource.save_local
30
+
31
+ forked_resource.destroy
66
32
  end
67
33
 
68
34
  private
@@ -89,16 +55,16 @@ module Doggy
89
55
  end
90
56
 
91
57
  def wait_for_edit
92
- while !Doggy.ui.yes?('Are you done editing?') do
58
+ while !Doggy.ui.yes?('Are you done editing?(Y/N)') do
93
59
  Doggy.ui.say "run, rabbit run / dig that hole, forget the sun / and when at last the work is done / don't sit down / it's time to dig another one"
94
60
  end
95
61
  end
96
62
 
97
63
  def fork(resource)
98
- salt = (0...12).map { (65 + rand(26)).chr.downcase }.join
99
-
64
+ salt = random_word
100
65
  forked_resource = resource.dup
101
66
  forked_resource.id = nil
67
+ forked_resource.refute_read_only!
102
68
  if resource.class.to_s.downcase =~ /dashboard/
103
69
  forked_resource.title = "[#{ salt }] " + forked_resource.title
104
70
  forked_resource.description = "[fork of #{ resource.id }] " + forked_resource.title
@@ -112,6 +78,10 @@ module Doggy
112
78
  forked_resource.save
113
79
  forked_resource
114
80
  end
81
+
82
+ def random_word
83
+ (0...12).map { (65 + rand(26)).chr.downcase }.join
84
+ end
115
85
  end
116
86
  end
117
87
 
@@ -6,20 +6,29 @@ module Doggy
6
6
  "This will override changes in Datadog if they have not been sycned to the dog repository. "\
7
7
  "Do you want to proceed?(Y/N)"
8
8
 
9
- def initialize(options)
9
+ def initialize(options, ids)
10
10
  @options = options
11
+ @ids = ids
11
12
  end
12
13
 
13
14
  def run
14
- if @options['all_objects'] && !Doggy.ui.yes?(WARNING_MESSAGE)
15
- Doggy.ui.say "Operation cancelled"
16
- return
15
+ if @ids.empty?
16
+ if @options['all_objects'] && !Doggy.ui.yes?(WARNING_MESSAGE)
17
+ Doggy.ui.say "Operation cancelled"
18
+ return
19
+ end
20
+ push_resources('dashboards', Models::Dashboard) if @options['dashboards']
21
+ push_resources('monitors', Models::Monitor) if @options['monitors']
22
+ push_resources('screens', Models::Screen) if @options['screens']
23
+ else
24
+ Doggy::Model.all_local_resources.each do |resource|
25
+ next unless @ids.include?(resource.id.to_s)
26
+ Doggy.ui.say "Pushing #{ resource.path }"
27
+ resource.ensure_read_only!
28
+ resource.save
29
+ end
17
30
  end
18
31
 
19
- push_resources('dashboards', Models::Dashboard) if @options['dashboards']
20
- push_resources('monitors', Models::Monitor) if @options['monitors']
21
- push_resources('screens', Models::Screen) if @options['screens']
22
-
23
32
  Doggy::Model.emit_shipit_deployment
24
33
  end
25
34
 
data/lib/doggy/cli.rb CHANGED
@@ -31,8 +31,8 @@ module Doggy
31
31
  method_option "screens", type: :boolean, default: true, desc: 'Pull screens'
32
32
  method_option "all_objects", type: :boolean, default: false, desc: 'Push all objects even if they are not changed'
33
33
 
34
- def push
35
- CLI::Push.new(options.dup).run
34
+ def push(*ids)
35
+ CLI::Push.new(options.dup, ids).run
36
36
  end
37
37
 
38
38
  desc "mute OBJECT_ID OBJECT_ID OBJECT_ID", "Mutes monitor on DataDog"
data/lib/doggy/model.rb CHANGED
@@ -9,8 +9,6 @@ module Doggy
9
9
  class Model
10
10
  include Virtus.model
11
11
 
12
- attribute :read_only, Boolean
13
-
14
12
  # This stores the path on disk. We don't define it as a model attribute so
15
13
  # it doesn't get serialized.
16
14
  attr_accessor :path
@@ -96,9 +94,10 @@ module Doggy
96
94
  end
97
95
 
98
96
  def infer_type(attributes)
99
- return Models::Dashboard if attributes['graphs']
100
- return Models::Monitor if attributes['message']
101
- return Models::Screen if attributes['board_title']
97
+ has_key = ->(key) { attributes.has_key?(key.to_s) || attributes.has_key?(key.to_sym) }
98
+ return Models::Dashboard if has_key.call('graphs')
99
+ return Models::Monitor if has_key.call('message')
100
+ return Models::Screen if has_key.call('board_title')
102
101
  end
103
102
 
104
103
  def request(method, url, body = nil)
@@ -176,18 +175,8 @@ module Doggy
176
175
  super(attributes)
177
176
  end
178
177
 
179
- def ensure_read_only!
180
- self.read_only = true
181
- end
182
-
183
178
  def save_local
184
179
  ensure_read_only!
185
- prefix = case self.class.name
186
- when 'Doggy::Models::Dashboard' then 'dash'
187
- when 'Doggy::Models::Monitor' then 'monitor'
188
- when 'Doggy::Models::Screen' then 'screen'
189
- end
190
-
191
180
  @path ||= Doggy.object_root.join("#{prefix}-#{id}.json")
192
181
  File.open(@path, 'w') { |f| f.write(JSON.pretty_generate(to_h)) }
193
182
  end
@@ -11,6 +11,19 @@ module Doggy
11
11
 
12
12
  attribute :graphs, Array[Hash]
13
13
  attribute :template_variables, Array[Hash]
14
+ attribute :read_only, Boolean
15
+
16
+ def prefix
17
+ 'dash'
18
+ end
19
+
20
+ def ensure_read_only!
21
+ self.read_only = true
22
+ end
23
+
24
+ def refute_read_only!
25
+ self.read_only = false
26
+ end
14
27
 
15
28
  def self.resource_url(id = nil)
16
29
  "https://app.datadoghq.com/api/v1/dash".tap do |base_url|
@@ -15,14 +15,15 @@ module Doggy
15
15
  attribute :timeout_h, Integer
16
16
  attribute :escalation_message, String
17
17
  attribute :renotify_interval, Integer
18
+ attribute :locked, Boolean
18
19
 
19
20
  def to_h
20
- return super unless monitor.id && monitor.loading_source == :local
21
-
22
- # Pull remote silenced state. If we don't send this value, Datadog
23
- # assumes that we want to unmute the monitor.
24
- remote_monitor = Monitor.find(monitor.id)
25
- self.silenced = remote_monitor.options.silenced if remote_monitor.options
21
+ if monitor.id && monitor.loading_source == :local
22
+ # Pull remote silenced state. If we don't send this value, Datadog
23
+ # assumes that we want to unmute the monitor.
24
+ remote_monitor = Monitor.find(monitor.id)
25
+ self.silenced = remote_monitor.options.silenced if remote_monitor.options
26
+ end
26
27
  super
27
28
  end
28
29
  end
@@ -38,6 +39,26 @@ module Doggy
38
39
  attribute :type, String
39
40
  attribute :multi, Boolean
40
41
 
42
+ def prefix
43
+ 'monitor'
44
+ end
45
+
46
+ def ensure_read_only!
47
+ if options
48
+ self.options.locked = true
49
+ else
50
+ self.options = Options.new(locked: true)
51
+ end
52
+ end
53
+
54
+ def refute_read_only!
55
+ if options
56
+ self.options.locked = false
57
+ else
58
+ self.options = Options.new(locked: false)
59
+ end
60
+ end
61
+
41
62
  def self.resource_url(id = nil)
42
63
  "https://app.datadoghq.com/api/v1/monitor".tap do |base_url|
43
64
  base_url << "/#{ id }" if id
@@ -83,7 +104,7 @@ module Doggy
83
104
  end
84
105
 
85
106
  def to_h
86
- super.merge(options: options.to_h)
107
+ Doggy::Model.sort_by_key(super.merge(options: options.to_h))
87
108
  end
88
109
 
89
110
  private
@@ -12,6 +12,19 @@ module Doggy
12
12
  attribute :widgets, Array[Hash]
13
13
  attribute :height, String
14
14
  attribute :width, String
15
+ attribute :read_only, Boolean
16
+
17
+ def prefix
18
+ 'screen'
19
+ end
20
+
21
+ def ensure_read_only!
22
+ self.read_only = true
23
+ end
24
+
25
+ def refute_read_only!
26
+ self.read_only = false
27
+ end
15
28
 
16
29
  def self.resource_url(id = nil)
17
30
  "https://app.datadoghq.com/api/v1/screen".tap do |base_url|
data/lib/doggy/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Doggy
4
- VERSION = "2.0.29"
4
+ VERSION = "2.0.30"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doggy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.29
4
+ version: 2.0.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vlad Gorodetsky
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-11-25 00:00:00.000000000 Z
12
+ date: 2016-11-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json