datadog_backup 3.0.0.alpha.2 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec_and_release.yml +0 -2
- data/.gitignore +3 -1
- data/.rubocop.yml +36 -77
- data/CHANGELOG.md +39 -0
- data/README.md +2 -2
- data/bin/datadog_backup +7 -5
- data/datadog_backup.gemspec +3 -4
- data/lib/datadog_backup/cli.rb +47 -51
- data/lib/datadog_backup/dashboards.rb +21 -16
- data/lib/datadog_backup/deprecations.rb +4 -5
- data/lib/datadog_backup/local_filesystem.rb +4 -5
- data/lib/datadog_backup/monitors.rb +16 -13
- data/lib/datadog_backup/options.rb +1 -0
- data/lib/datadog_backup/resources.rb +176 -0
- data/lib/datadog_backup/synthetics.rb +68 -0
- data/lib/datadog_backup/thread_pool.rb +1 -0
- data/lib/datadog_backup/version.rb +1 -1
- data/lib/datadog_backup.rb +3 -3
- data/release.config.js +4 -0
- data/spec/datadog_backup/cli_spec.rb +67 -46
- data/spec/datadog_backup/core_spec.rb +72 -51
- data/spec/datadog_backup/dashboards_spec.rb +17 -32
- data/spec/datadog_backup/deprecations_spec.rb +7 -9
- data/spec/datadog_backup/local_filesystem_spec.rb +42 -42
- data/spec/datadog_backup/monitors_spec.rb +13 -29
- data/spec/datadog_backup/synthetics_spec.rb +258 -0
- data/spec/datadog_backup_bin_spec.rb +17 -15
- data/spec/spec_helper.rb +69 -5
- metadata +13 -21
- data/Gemfile.lock +0 -118
- data/lib/datadog_backup/core.rb +0 -148
- data/spec/datadog_backup_spec.rb +0 -6
@@ -3,20 +3,15 @@
|
|
3
3
|
require 'open3'
|
4
4
|
require 'timeout'
|
5
5
|
|
6
|
-
describe 'bin/datadog_backup' do
|
6
|
+
describe 'bin/datadog_backup' do # rubocop:disable RSpec/DescribeClass
|
7
7
|
# Contract Or[nil,String] => self
|
8
|
-
def run_bin(
|
8
|
+
def run_bin(env = {}, args = '')
|
9
9
|
status = nil
|
10
10
|
output = ''
|
11
11
|
cmd = "bin/datadog_backup #{args}"
|
12
|
-
Open3.popen2e(cmd) do |
|
12
|
+
Open3.popen2e(env, cmd) do |_i, oe, t|
|
13
13
|
pid = t.pid
|
14
14
|
|
15
|
-
if input
|
16
|
-
i.puts input
|
17
|
-
i.close
|
18
|
-
end
|
19
|
-
|
20
15
|
Timeout.timeout(4.0) do
|
21
16
|
oe.each do |v|
|
22
17
|
output += v
|
@@ -43,16 +38,23 @@ describe 'bin/datadog_backup' do
|
|
43
38
|
|
44
39
|
required_vars.map do |v|
|
45
40
|
it "dies unless given ENV[#{v}]" do
|
46
|
-
|
47
|
-
_, status = run_bin('backup')
|
41
|
+
myenv = env.dup.tap { |h| h.delete(v) }
|
42
|
+
_, status = run_bin(myenv, 'backup')
|
48
43
|
expect(status).not_to be_success
|
49
44
|
end
|
50
45
|
end
|
51
46
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
47
|
+
describe 'help' do
|
48
|
+
subject(:bin) { run_bin(env, '--help') }
|
49
|
+
|
50
|
+
it 'prints usage' do
|
51
|
+
out_err, _status = bin
|
52
|
+
expect(out_err).to match(/Usage: DD_API_KEY=/)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'exits cleanly' do
|
56
|
+
_out_err, status = bin
|
57
|
+
expect(status).to be_success
|
58
|
+
end
|
57
59
|
end
|
58
60
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -11,22 +11,66 @@ $stdout = File.new('/dev/null', 'w+')
|
|
11
11
|
require 'tmpdir'
|
12
12
|
require 'datadog_backup'
|
13
13
|
|
14
|
-
|
15
|
-
|
16
14
|
SPEC_ROOT = __dir__
|
17
15
|
WORK_ROOT = File.expand_path(File.join(SPEC_ROOT, '..'))
|
18
16
|
|
19
17
|
RSpec.configure do |config|
|
18
|
+
# rspec-expectations config goes here. You can use an alternate
|
19
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
20
|
+
# assertions if you prefer.
|
20
21
|
config.expect_with :rspec do |expectations|
|
22
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
23
|
+
# and `failure_message` of custom matchers include text for helper methods
|
24
|
+
# defined using `chain`, e.g.:
|
25
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
26
|
+
# # => "be bigger than 2 and smaller than 4"
|
27
|
+
# ...rather than:
|
28
|
+
# # => "be bigger than 2"
|
21
29
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
22
30
|
end
|
31
|
+
|
32
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
33
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
23
34
|
config.mock_with :rspec do |mocks|
|
35
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
36
|
+
# a real object. This is generally recommended, and will default to
|
37
|
+
# `true` in RSpec 4.
|
24
38
|
mocks.verify_partial_doubles = true
|
25
39
|
end
|
26
40
|
|
27
|
-
|
28
|
-
|
41
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
42
|
+
# have no way to turn it off -- the option exists only for backwards
|
43
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
44
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
45
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
46
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
47
|
+
|
48
|
+
# The settings below are suggested to provide a good initial experience
|
49
|
+
# with RSpec, but feel free to customize to your heart's content.
|
50
|
+
# This allows you to limit a spec run to individual examples or groups
|
51
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
52
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
53
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
54
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
55
|
+
config.filter_run_when_matching :focus
|
56
|
+
|
57
|
+
# Allows RSpec to persist some state between runs in order to support
|
58
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
59
|
+
# you configure your source control system to ignore this file.
|
60
|
+
config.example_status_persistence_file_path = 'spec/examples.txt'
|
61
|
+
|
62
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
63
|
+
# recommended. For more details, see:
|
64
|
+
# https://relishapp.com/rspec/rspec-core/docs/configuration/zero-monkey-patching-mode
|
65
|
+
config.disable_monkey_patching!
|
29
66
|
|
67
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
68
|
+
# be too noisy due to issues in dependencies.
|
69
|
+
config.warnings = true
|
70
|
+
|
71
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
72
|
+
# file, and it's useful to allow more verbose output when running an
|
73
|
+
# individual spec file.
|
30
74
|
if config.files_to_run.one?
|
31
75
|
# Use the documentation formatter for detailed output,
|
32
76
|
# unless a formatter has already been configured
|
@@ -34,7 +78,27 @@ RSpec.configure do |config|
|
|
34
78
|
config.default_formatter = 'doc'
|
35
79
|
end
|
36
80
|
|
37
|
-
|
81
|
+
# Print the 10 slowest examples and example groups at the
|
82
|
+
# end of the spec run, to help surface which specs are running
|
83
|
+
# particularly slow.
|
84
|
+
config.profile_examples = 10
|
85
|
+
|
86
|
+
# Run specs in random order to surface order dependencies. If you find an
|
87
|
+
# order dependency and want to debug it, you can fix the order by providing
|
88
|
+
# the seed, which is printed after each run.
|
89
|
+
# --seed 1234
|
90
|
+
config.order = :random
|
38
91
|
|
92
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
93
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
94
|
+
# test failures related to randomization by passing the same `--seed` value
|
95
|
+
# as the one that triggered the failure.
|
39
96
|
Kernel.srand config.seed
|
97
|
+
|
98
|
+
# Make RSpec available throughout the rspec unit test suite
|
99
|
+
config.expose_dsl_globally = true
|
100
|
+
end
|
101
|
+
|
102
|
+
def respond_with200(body)
|
103
|
+
[200, {}, body]
|
40
104
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datadog_backup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kamran Farhadi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-09-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: amazing_print
|
@@ -110,7 +110,7 @@ dependencies:
|
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
|
-
name:
|
113
|
+
name: guard-rspec
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
116
|
- - ">="
|
@@ -124,7 +124,7 @@ dependencies:
|
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
|
-
name: pry
|
127
|
+
name: pry
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
130
|
- - ">="
|
@@ -138,7 +138,7 @@ dependencies:
|
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '0'
|
140
140
|
- !ruby/object:Gem::Dependency
|
141
|
-
name:
|
141
|
+
name: pry-byebug
|
142
142
|
requirement: !ruby/object:Gem::Requirement
|
143
143
|
requirements:
|
144
144
|
- - ">="
|
@@ -210,7 +210,6 @@ files:
|
|
210
210
|
- CHANGELOG.md
|
211
211
|
- CODE_OF_CONDUCT.md
|
212
212
|
- Gemfile
|
213
|
-
- Gemfile.lock
|
214
213
|
- Guardfile
|
215
214
|
- LICENSE
|
216
215
|
- README.md
|
@@ -224,12 +223,13 @@ files:
|
|
224
223
|
- images/demo.yml
|
225
224
|
- lib/datadog_backup.rb
|
226
225
|
- lib/datadog_backup/cli.rb
|
227
|
-
- lib/datadog_backup/core.rb
|
228
226
|
- lib/datadog_backup/dashboards.rb
|
229
227
|
- lib/datadog_backup/deprecations.rb
|
230
228
|
- lib/datadog_backup/local_filesystem.rb
|
231
229
|
- lib/datadog_backup/monitors.rb
|
232
230
|
- lib/datadog_backup/options.rb
|
231
|
+
- lib/datadog_backup/resources.rb
|
232
|
+
- lib/datadog_backup/synthetics.rb
|
233
233
|
- lib/datadog_backup/thread_pool.rb
|
234
234
|
- lib/datadog_backup/version.rb
|
235
235
|
- release.config.js
|
@@ -239,13 +239,14 @@ files:
|
|
239
239
|
- spec/datadog_backup/deprecations_spec.rb
|
240
240
|
- spec/datadog_backup/local_filesystem_spec.rb
|
241
241
|
- spec/datadog_backup/monitors_spec.rb
|
242
|
+
- spec/datadog_backup/synthetics_spec.rb
|
242
243
|
- spec/datadog_backup_bin_spec.rb
|
243
|
-
- spec/datadog_backup_spec.rb
|
244
244
|
- spec/spec_helper.rb
|
245
245
|
homepage: https://github.com/scribd/datadog_backup
|
246
246
|
licenses:
|
247
247
|
- MIT
|
248
|
-
metadata:
|
248
|
+
metadata:
|
249
|
+
rubygems_mfa_required: 'true'
|
249
250
|
post_install_message:
|
250
251
|
rdoc_options: []
|
251
252
|
require_paths:
|
@@ -257,21 +258,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
257
258
|
version: '2.7'
|
258
259
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
259
260
|
requirements:
|
260
|
-
- - "
|
261
|
+
- - ">="
|
261
262
|
- !ruby/object:Gem::Version
|
262
|
-
version:
|
263
|
+
version: '0'
|
263
264
|
requirements: []
|
264
265
|
rubygems_version: 3.1.6
|
265
266
|
signing_key:
|
266
267
|
specification_version: 4
|
267
268
|
summary: A utility to backup and restore Datadog accounts
|
268
|
-
test_files:
|
269
|
-
- spec/datadog_backup/cli_spec.rb
|
270
|
-
- spec/datadog_backup/core_spec.rb
|
271
|
-
- spec/datadog_backup/dashboards_spec.rb
|
272
|
-
- spec/datadog_backup/deprecations_spec.rb
|
273
|
-
- spec/datadog_backup/local_filesystem_spec.rb
|
274
|
-
- spec/datadog_backup/monitors_spec.rb
|
275
|
-
- spec/datadog_backup_bin_spec.rb
|
276
|
-
- spec/datadog_backup_spec.rb
|
277
|
-
- spec/spec_helper.rb
|
269
|
+
test_files: []
|
data/Gemfile.lock
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
datadog_backup (3.0.0.alpha.1)
|
5
|
-
amazing_print
|
6
|
-
concurrent-ruby
|
7
|
-
deepsort
|
8
|
-
diffy
|
9
|
-
faraday
|
10
|
-
faraday-retry
|
11
|
-
|
12
|
-
GEM
|
13
|
-
remote: https://rubygems.org/
|
14
|
-
specs:
|
15
|
-
amazing_print (1.4.0)
|
16
|
-
ast (2.4.2)
|
17
|
-
byebug (11.1.3)
|
18
|
-
coderay (1.1.3)
|
19
|
-
concurrent-ruby (1.1.10)
|
20
|
-
deepsort (0.4.5)
|
21
|
-
diff-lcs (1.5.0)
|
22
|
-
diffy (3.4.2)
|
23
|
-
faraday (2.5.2)
|
24
|
-
faraday-net_http (>= 2.0, < 3.1)
|
25
|
-
ruby2_keywords (>= 0.0.4)
|
26
|
-
faraday-net_http (3.0.0)
|
27
|
-
faraday-retry (2.0.0)
|
28
|
-
faraday (~> 2.0)
|
29
|
-
ffi (1.15.5)
|
30
|
-
formatador (1.1.0)
|
31
|
-
guard (2.18.0)
|
32
|
-
formatador (>= 0.2.4)
|
33
|
-
listen (>= 2.7, < 4.0)
|
34
|
-
lumberjack (>= 1.0.12, < 2.0)
|
35
|
-
nenv (~> 0.1)
|
36
|
-
notiffany (~> 0.0)
|
37
|
-
pry (>= 0.13.0)
|
38
|
-
shellany (~> 0.0)
|
39
|
-
thor (>= 0.18.1)
|
40
|
-
guard-compat (1.2.1)
|
41
|
-
guard-rspec (4.7.3)
|
42
|
-
guard (~> 2.1)
|
43
|
-
guard-compat (~> 1.1)
|
44
|
-
rspec (>= 2.99.0, < 4.0)
|
45
|
-
json (2.6.2)
|
46
|
-
listen (3.7.1)
|
47
|
-
rb-fsevent (~> 0.10, >= 0.10.3)
|
48
|
-
rb-inotify (~> 0.9, >= 0.9.10)
|
49
|
-
lumberjack (1.2.8)
|
50
|
-
method_source (1.0.0)
|
51
|
-
nenv (0.3.0)
|
52
|
-
notiffany (0.1.3)
|
53
|
-
nenv (~> 0.1)
|
54
|
-
shellany (~> 0.0)
|
55
|
-
parallel (1.22.1)
|
56
|
-
parser (3.1.2.1)
|
57
|
-
ast (~> 2.4.1)
|
58
|
-
pry (0.14.1)
|
59
|
-
coderay (~> 1.1)
|
60
|
-
method_source (~> 1.0)
|
61
|
-
pry-byebug (3.10.1)
|
62
|
-
byebug (~> 11.0)
|
63
|
-
pry (>= 0.13, < 0.15)
|
64
|
-
rainbow (3.1.1)
|
65
|
-
rb-fsevent (0.11.1)
|
66
|
-
rb-inotify (0.10.1)
|
67
|
-
ffi (~> 1.0)
|
68
|
-
regexp_parser (2.5.0)
|
69
|
-
rexml (3.2.5)
|
70
|
-
rspec (3.11.0)
|
71
|
-
rspec-core (~> 3.11.0)
|
72
|
-
rspec-expectations (~> 3.11.0)
|
73
|
-
rspec-mocks (~> 3.11.0)
|
74
|
-
rspec-core (3.11.0)
|
75
|
-
rspec-support (~> 3.11.0)
|
76
|
-
rspec-expectations (3.11.0)
|
77
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
78
|
-
rspec-support (~> 3.11.0)
|
79
|
-
rspec-mocks (3.11.1)
|
80
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
81
|
-
rspec-support (~> 3.11.0)
|
82
|
-
rspec-support (3.11.0)
|
83
|
-
rubocop (1.35.1)
|
84
|
-
json (~> 2.3)
|
85
|
-
parallel (~> 1.10)
|
86
|
-
parser (>= 3.1.2.1)
|
87
|
-
rainbow (>= 2.2.2, < 4.0)
|
88
|
-
regexp_parser (>= 1.8, < 3.0)
|
89
|
-
rexml (>= 3.2.5, < 4.0)
|
90
|
-
rubocop-ast (>= 1.20.1, < 2.0)
|
91
|
-
ruby-progressbar (~> 1.7)
|
92
|
-
unicode-display_width (>= 1.4.0, < 3.0)
|
93
|
-
rubocop-ast (1.21.0)
|
94
|
-
parser (>= 3.1.1.0)
|
95
|
-
rubocop-rspec (2.12.1)
|
96
|
-
rubocop (~> 1.31)
|
97
|
-
ruby-progressbar (1.11.0)
|
98
|
-
ruby2_keywords (0.0.5)
|
99
|
-
shellany (0.0.1)
|
100
|
-
thor (1.2.1)
|
101
|
-
unicode-display_width (2.2.0)
|
102
|
-
|
103
|
-
PLATFORMS
|
104
|
-
ruby
|
105
|
-
x86_64-linux
|
106
|
-
|
107
|
-
DEPENDENCIES
|
108
|
-
bundler
|
109
|
-
datadog_backup!
|
110
|
-
guard-rspec
|
111
|
-
pry
|
112
|
-
pry-byebug
|
113
|
-
rspec
|
114
|
-
rubocop
|
115
|
-
rubocop-rspec
|
116
|
-
|
117
|
-
BUNDLED WITH
|
118
|
-
2.3.20
|
data/lib/datadog_backup/core.rb
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'diffy'
|
4
|
-
require 'deepsort'
|
5
|
-
require 'faraday'
|
6
|
-
require 'faraday/retry'
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
module DatadogBackup
|
11
|
-
class Core
|
12
|
-
include ::DatadogBackup::LocalFilesystem
|
13
|
-
include ::DatadogBackup::Options
|
14
|
-
|
15
|
-
@@retry_options = {
|
16
|
-
max: 5,
|
17
|
-
interval: 0.05,
|
18
|
-
interval_randomness: 0.5,
|
19
|
-
backoff_factor: 2
|
20
|
-
}
|
21
|
-
|
22
|
-
def api_service
|
23
|
-
conn ||= Faraday.new(
|
24
|
-
url: api_url,
|
25
|
-
headers: {
|
26
|
-
'DD-API-KEY' => ENV.fetch('DD_API_KEY'),
|
27
|
-
'DD-APPLICATION-KEY' => ENV.fetch('DD_APP_KEY')
|
28
|
-
}
|
29
|
-
) do |faraday|
|
30
|
-
faraday.request :json
|
31
|
-
faraday.request :retry, @@retry_options
|
32
|
-
faraday.response(:logger, LOGGER, {headers: true, bodies: LOGGER.debug?, log_level: :debug}) do | logger |
|
33
|
-
logger.filter(/(DD-API-KEY:)([^&]+)/, '\1[REDACTED]')
|
34
|
-
logger.filter(/(DD-APPLICATION-KEY:)([^&]+)/, '\1[REDACTED]')
|
35
|
-
end
|
36
|
-
faraday.response :raise_error
|
37
|
-
faraday.response :json
|
38
|
-
faraday.adapter Faraday.default_adapter
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def api_url
|
43
|
-
ENV.fetch('DD_SITE_URL', "https://api.datadoghq.com/")
|
44
|
-
end
|
45
|
-
|
46
|
-
def api_version
|
47
|
-
raise 'subclass is expected to implement #api_version'
|
48
|
-
end
|
49
|
-
|
50
|
-
def api_resource_name
|
51
|
-
raise 'subclass is expected to implement #api_resource_name'
|
52
|
-
end
|
53
|
-
|
54
|
-
def backup
|
55
|
-
raise 'subclass is expected to implement #backup'
|
56
|
-
end
|
57
|
-
|
58
|
-
# Returns the diffy diff.
|
59
|
-
# Optionally, supply an array of keys to remove from comparison
|
60
|
-
def diff(id)
|
61
|
-
current = except(get_by_id(id)).deep_sort.to_yaml
|
62
|
-
filesystem = except(load_from_file_by_id(id)).deep_sort.to_yaml
|
63
|
-
result = ::Diffy::Diff.new(current, filesystem, include_plus_and_minus_in_html: true).to_s(diff_format)
|
64
|
-
LOGGER.debug("Compared ID #{id} and found #{result}")
|
65
|
-
result
|
66
|
-
end
|
67
|
-
|
68
|
-
# Returns a hash with banlist elements removed
|
69
|
-
def except(hash)
|
70
|
-
hash.tap do # tap returns self
|
71
|
-
@banlist.each do |key|
|
72
|
-
hash.delete(key) # delete returns the value at the deleted key, hence the tap wrapper
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def get(id)
|
78
|
-
params = {}
|
79
|
-
headers = {}
|
80
|
-
response = api_service.get("/api/#{api_version}/#{api_resource_name}/#{id}", params, headers)
|
81
|
-
body_with_2xx(response)
|
82
|
-
end
|
83
|
-
|
84
|
-
def get_all
|
85
|
-
params = {}
|
86
|
-
headers = {}
|
87
|
-
response = api_service.get("/api/#{api_version}/#{api_resource_name}", params, headers)
|
88
|
-
body_with_2xx(response)
|
89
|
-
end
|
90
|
-
|
91
|
-
def get_and_write_file(id)
|
92
|
-
write_file(dump(get_by_id(id)), filename(id))
|
93
|
-
end
|
94
|
-
|
95
|
-
def get_by_id(id)
|
96
|
-
except(get(id))
|
97
|
-
end
|
98
|
-
|
99
|
-
def initialize(options)
|
100
|
-
@options = options
|
101
|
-
@banlist = []
|
102
|
-
::FileUtils.mkdir_p(mydir)
|
103
|
-
end
|
104
|
-
|
105
|
-
def myclass
|
106
|
-
self.class.to_s.split(':').last.downcase
|
107
|
-
end
|
108
|
-
|
109
|
-
# Calls out to Datadog and checks for a '200' response
|
110
|
-
def create(body)
|
111
|
-
headers = {}
|
112
|
-
response = api_service.post("/api/#{api_version}/#{api_resource_name}", body, headers)
|
113
|
-
body = body_with_2xx(response)
|
114
|
-
LOGGER.warn "Successfully created #{body.fetch('id')} in datadog."
|
115
|
-
body
|
116
|
-
end
|
117
|
-
|
118
|
-
# Calls out to Datadog and checks for a '200' response
|
119
|
-
def update(id, body)
|
120
|
-
headers = {}
|
121
|
-
response = api_service.put("/api/#{api_version}/#{api_resource_name}/#{id}", body, headers)
|
122
|
-
body = body_with_2xx(response)
|
123
|
-
LOGGER.warn 'Successfully restored #{id} to datadog.'
|
124
|
-
body
|
125
|
-
end
|
126
|
-
|
127
|
-
def restore(id)
|
128
|
-
body = load_from_file_by_id(id)
|
129
|
-
begin
|
130
|
-
update(id, body)
|
131
|
-
rescue RuntimeError => e
|
132
|
-
if e.message.include?('update failed with error 404')
|
133
|
-
new_id = create(body).fetch('id')
|
134
|
-
|
135
|
-
FileUtils.rm(find_file_by_id(id))
|
136
|
-
get_and_write_file(new_id)
|
137
|
-
else
|
138
|
-
raise e.message
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def body_with_2xx(response)
|
144
|
-
raise "#{caller_locations(1,1)[0].label} failed with error #{response.status}" unless response.status.to_s =~ /^2/
|
145
|
-
response.body
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|