kennel 1.81.2 → 1.82.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kennel/api.rb +22 -0
- data/lib/kennel/models/dashboard.rb +0 -1
- data/lib/kennel/models/record.rb +0 -1
- data/lib/kennel/syncer.rb +4 -20
- data/lib/kennel/tasks.rb +8 -1
- data/lib/kennel/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97ae92e1ab137731096bbedde401059fc2b8d411ff667df489056f05a3cf42aa
|
4
|
+
data.tar.gz: c48683c4888e16da817885a44a876638086c32e8e370aaf16553c31b7fde0136
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89f7a44c794130ecd4a4238ace5846d050412fd923cc5ae358cb469370c3dd380569bffe991b2251bc80baf4e183bd765591295b043ffc51fd88c5593b723f21
|
7
|
+
data.tar.gz: 4a9eece67d3f0e0cf8dd56a21440ce585397d531c4aa82d1d4c3d43db08169b57dd1e982ba74e68326ae61ed8278ac4d5fed7eefe8f6979dcf5a3c3a3e98ceb0
|
data/lib/kennel/api.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Kennel
|
3
|
+
# encapsulates knowledge around how the api works
|
3
4
|
class Api
|
5
|
+
CACHE_FILE = "tmp/cache/details"
|
6
|
+
|
4
7
|
def initialize(app_key, api_key)
|
5
8
|
@app_key = app_key
|
6
9
|
@api_key = api_key
|
@@ -49,8 +52,27 @@ module Kennel
|
|
49
52
|
request :delete, "/api/v1/#{api_resource}/#{id}", params: { force: "true" }, ignore_404: true
|
50
53
|
end
|
51
54
|
|
55
|
+
def fill_details!(api_resource, list)
|
56
|
+
return unless api_resource == "dashboard"
|
57
|
+
details_cache do |cache|
|
58
|
+
Utils.parallel(list) { |a| fill_detail!(api_resource, a, cache) }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
52
62
|
private
|
53
63
|
|
64
|
+
# Make diff work even though we cannot mass-fetch definitions
|
65
|
+
def fill_detail!(api_resource, a, cache)
|
66
|
+
args = [api_resource, a.fetch(:id)]
|
67
|
+
full = cache.fetch(args, a.fetch(:modified_at)) { show(*args) }
|
68
|
+
a.merge!(full)
|
69
|
+
end
|
70
|
+
|
71
|
+
def details_cache(&block)
|
72
|
+
cache = FileCache.new CACHE_FILE, Kennel::VERSION
|
73
|
+
cache.open(&block)
|
74
|
+
end
|
75
|
+
|
54
76
|
def request(method, path, body: nil, params: {}, ignore_404: false)
|
55
77
|
params = params.merge(application_key: @app_key, api_key: @api_key)
|
56
78
|
query = Faraday::FlatParamsEncoder.encode(params)
|
@@ -5,7 +5,6 @@ module Kennel
|
|
5
5
|
include TemplateVariables
|
6
6
|
include OptionalValidations
|
7
7
|
|
8
|
-
API_LIST_INCOMPLETE = true
|
9
8
|
DASHBOARD_DEFAULTS = { template_variables: [] }.freeze
|
10
9
|
READONLY_ATTRIBUTES = superclass::READONLY_ATTRIBUTES + [
|
11
10
|
:author_handle, :author_name, :modified_at, :url, :is_read_only, :notify_list
|
data/lib/kennel/models/record.rb
CHANGED
data/lib/kennel/syncer.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Kennel
|
3
3
|
class Syncer
|
4
|
-
CACHE_FILE = "tmp/cache/details" # keep in sync with .travis.yml caching
|
5
4
|
TRACKING_FIELDS = [:message, :description].freeze
|
6
5
|
DELETE_ORDER = ["dashboard", "slo", "monitor"].freeze # dashboards references monitors + slos, slos reference monitors
|
7
6
|
|
@@ -117,10 +116,10 @@ module Kennel
|
|
117
116
|
end
|
118
117
|
end
|
119
118
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
119
|
+
# fill details of things we need to compare
|
120
|
+
detailed = Hash.new { |h, k| h[k] = [] }
|
121
|
+
items.each { |e, a| detailed[a[:api_resource]] << a if e }
|
122
|
+
detailed.each { |api_resource, actuals| @api.fill_details! api_resource, actuals }
|
124
123
|
|
125
124
|
# pick out things to update or delete
|
126
125
|
items.each do |e, a|
|
@@ -140,21 +139,6 @@ module Kennel
|
|
140
139
|
@delete.sort_by! { |_, _, a| DELETE_ORDER.index a.fetch(:api_resource) }
|
141
140
|
end
|
142
141
|
|
143
|
-
# Make diff work even though we cannot mass-fetch definitions
|
144
|
-
def fill_details(a, cache)
|
145
|
-
resource = a.fetch(:api_resource)
|
146
|
-
args = [resource, a.fetch(:id)]
|
147
|
-
full = cache.fetch(args, a[:modified] || a.fetch(:modified_at)) do
|
148
|
-
@api.show(*args)
|
149
|
-
end
|
150
|
-
a.merge!(full)
|
151
|
-
end
|
152
|
-
|
153
|
-
def details_cache(&block)
|
154
|
-
cache = FileCache.new CACHE_FILE, Kennel::VERSION
|
155
|
-
cache.open(&block)
|
156
|
-
end
|
157
|
-
|
158
142
|
def download_definitions
|
159
143
|
Utils.parallel(Models::Record.subclasses.map(&:api_resource)) do |api_resource|
|
160
144
|
results = @api.list(api_resource, with_downtimes: false) # lookup monitors without adding unnecessary downtime information
|
data/lib/kennel/tasks.rb
CHANGED
@@ -132,8 +132,15 @@ namespace :kennel do
|
|
132
132
|
else
|
133
133
|
Kennel::Models::Record.subclasses.map(&:api_resource)
|
134
134
|
end
|
135
|
+
api = Kennel.send(:api)
|
136
|
+
list = nil
|
137
|
+
|
135
138
|
resources.each do |resource|
|
136
|
-
Kennel.
|
139
|
+
Kennel::Progress.progress("Downloading #{resource}") do
|
140
|
+
list = api.list(resource)
|
141
|
+
api.fill_details!(resource, list)
|
142
|
+
end
|
143
|
+
list.each do |r|
|
137
144
|
Kennel.out.puts JSON.pretty_generate(r)
|
138
145
|
end
|
139
146
|
end
|
data/lib/kennel/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kennel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.82.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02
|
11
|
+
date: 2021-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|