datadog_backup 1.0.0.alpha.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +4 -1
- data/.github/workflows/rspec_and_release.yml +18 -18
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +21 -2
- data/Gemfile +1 -0
- data/bin/datadog_backup +4 -2
- data/datadog_backup.gemspec +3 -3
- data/lib/datadog_backup/core.rb +4 -1
- data/lib/datadog_backup/monitors.rb +2 -1
- data/lib/datadog_backup/version.rb +1 -1
- data/spec/datadog_backup/cli_spec.rb +32 -17
- data/spec/datadog_backup/core_spec.rb +45 -43
- data/spec/datadog_backup/dashboards_spec.rb +5 -2
- data/spec/datadog_backup/local_filesystem_spec.rb +44 -24
- data/spec/datadog_backup/monitors_spec.rb +7 -2
- data/spec/datadog_backup_bin_spec.rb +3 -3
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87d2e5b0ee44a9ed7bffb1a107952b611664f370e0a67ae45b0500792f96c6b8
|
4
|
+
data.tar.gz: 1a8ea6c234a891633ed663dbc8ca7b0245d88894e962ec33b8692b5e2420cd35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8690d5d8e99a3ec8339da986238cd8a83b6686ea93206d0bcfdb6c170585bec416ff170cfdb6927784e5362efb20557a3669143e7ff647fa8fe7a73f426a1ad0
|
7
|
+
data.tar.gz: 92c0fbeed3341c843d68a031dfacf875cc2261fbbc0b1ffe99b37a33504a2f8f9cdc7a5a6fa3f79dd2bd923562e6a4611976ec9765235c7765567bbc61276dad
|
data/.github/dependabot.yml
CHANGED
@@ -9,8 +9,11 @@ updates:
|
|
9
9
|
directory: "/" # Location of package manifests
|
10
10
|
schedule:
|
11
11
|
interval: "daily"
|
12
|
+
commit-message:
|
13
|
+
prefix: "fix"
|
14
|
+
prefix-development: "chore"
|
15
|
+
include: "scope"
|
12
16
|
- package-ecosystem: "github-actions"
|
13
17
|
directory: "/" # Location of package manifests
|
14
18
|
schedule:
|
15
19
|
interval: "daily"
|
16
|
-
|
@@ -7,36 +7,36 @@ on:
|
|
7
7
|
|
8
8
|
jobs:
|
9
9
|
rspec:
|
10
|
-
|
11
|
-
|
10
|
+
strategy:
|
11
|
+
fail-fast: false
|
12
|
+
matrix:
|
13
|
+
os: [ubuntu-latest, macos-latest]
|
14
|
+
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
|
15
|
+
ruby: [2.6, 2.7]
|
16
|
+
runs-on: ${{ matrix.os }}
|
12
17
|
steps:
|
13
18
|
- uses: actions/checkout@v2
|
14
|
-
- name: Set up Ruby
|
15
|
-
uses:
|
19
|
+
- name: Set up Ruby
|
20
|
+
uses: ruby/setup-ruby@v1
|
16
21
|
with:
|
17
|
-
ruby-version:
|
22
|
+
ruby-version: ${{ matrix.ruby }}
|
23
|
+
bundler-cache: true
|
18
24
|
- name: Test with Rspec
|
19
25
|
run: |
|
20
|
-
|
21
|
-
bundle install --jobs 4 --retry 3
|
22
|
-
bundle exec rspec --format documentation
|
26
|
+
bundle exec rspec --format documentation --require spec_helper
|
23
27
|
release:
|
24
28
|
if: github.event_name == 'push'
|
25
29
|
needs: rspec
|
26
30
|
runs-on: ubuntu-latest
|
27
|
-
|
31
|
+
env:
|
32
|
+
BUNDLE_DEPLOYMENT: true
|
28
33
|
steps:
|
29
34
|
- uses: actions/checkout@v2
|
30
|
-
- name: Set up Ruby
|
31
|
-
uses:
|
35
|
+
- name: Set up Ruby
|
36
|
+
uses: ruby/setup-ruby@v1
|
32
37
|
with:
|
33
|
-
ruby-version: 2.7
|
34
|
-
|
35
|
-
run: |
|
36
|
-
gem install --no-document bundler
|
37
|
-
bundle config set deployment 'true'
|
38
|
-
bundle config set without 'development test'
|
39
|
-
bundle install --jobs 4 --retry 3
|
38
|
+
ruby-version: 2.7
|
39
|
+
bundler-cache: true
|
40
40
|
- name: Zip
|
41
41
|
run : |
|
42
42
|
zip -r datadog_backup.zip ./*
|
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require: rubocop-rspec
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,28 @@
|
|
1
|
-
|
1
|
+
## [1.0.2](https://github.com/scribd/datadog_backup/compare/v1.0.1...v1.0.2) (2021-05-06)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* **deps:** bump rexml from 3.2.4 to 3.2.5 ([15efa8c](https://github.com/scribd/datadog_backup/commit/15efa8c58953d450311fc8e5f125bf7e12401af4))
|
7
|
+
|
8
|
+
## [1.0.1](https://github.com/scribd/datadog_backup/compare/v1.0.0...v1.0.1) (2021-03-26)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* dependabot syntax for github ([4214001](https://github.com/scribd/datadog_backup/commit/42140015976ec2d0f4d2fce6e4c3214bb590c967))
|
14
|
+
|
15
|
+
# [1.0.0](https://github.com/scribd/datadog_backup/compare/v0.11.0...v1.0.0) (2021-03-02)
|
16
|
+
|
17
|
+
|
18
|
+
### Bug Fixes
|
19
|
+
|
20
|
+
* handle gets with no result ([8d016a1](https://github.com/scribd/datadog_backup/commit/8d016a1858b44d374a0dff121c71340bf18062e0))
|
2
21
|
|
3
22
|
|
4
23
|
### Features
|
5
24
|
|
6
|
-
* If resource doesn't exist in Datadog, the resource is recreated. ([
|
25
|
+
* If resource doesn't exist in Datadog, the resource is recreated. ([18ba241](https://github.com/scribd/datadog_backup/commit/18ba24183e136f9d899351bbb0999aba2c22308f))
|
7
26
|
|
8
27
|
|
9
28
|
### BREAKING CHANGES
|
data/Gemfile
CHANGED
data/bin/datadog_backup
CHANGED
@@ -55,8 +55,10 @@ def prereqs
|
|
55
55
|
opts.on('--dashboards-only') do
|
56
56
|
@options[:resources] = [DatadogBackup::Dashboards]
|
57
57
|
end
|
58
|
-
opts.on(
|
59
|
-
|
58
|
+
opts.on(
|
59
|
+
'--json',
|
60
|
+
'format backups as JSON instead of YAML. Does not impact `diffs` nor `restore`, but do not mix formats in the same backup-dir.'
|
61
|
+
) do
|
60
62
|
@options[:output_format] = :json
|
61
63
|
end
|
62
64
|
opts.on('--no-color', 'removes colored output from diff format') do
|
data/datadog_backup.gemspec
CHANGED
@@ -19,12 +19,12 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^spec/})
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_dependency 'amazing_print', '1.
|
23
|
-
spec.add_dependency 'concurrent-ruby', '1.1.
|
22
|
+
spec.add_dependency 'amazing_print', '1.3.0'
|
23
|
+
spec.add_dependency 'concurrent-ruby', '1.1.8'
|
24
24
|
spec.add_dependency 'concurrent-ruby-edge', '0.6.0'
|
25
25
|
spec.add_dependency 'deepsort', '0.4.5'
|
26
26
|
spec.add_dependency 'diffy', '3.4.0'
|
27
|
-
spec.add_dependency 'dogapi', '1.
|
27
|
+
spec.add_dependency 'dogapi', '1.45.0'
|
28
28
|
|
29
29
|
spec.add_development_dependency 'bundler'
|
30
30
|
spec.add_development_dependency 'pry'
|
data/lib/datadog_backup/core.rb
CHANGED
@@ -47,6 +47,9 @@ module DatadogBackup
|
|
47
47
|
with_200 do
|
48
48
|
api_service.request(Net::HTTP::Get, "/api/#{api_version}/#{api_resource_name}/#{id}", nil, nil, false)
|
49
49
|
end
|
50
|
+
rescue RuntimeError => e
|
51
|
+
return {} if e.message.include?('Request failed with error ["404"')
|
52
|
+
raise e.message
|
50
53
|
end
|
51
54
|
|
52
55
|
def get_all
|
@@ -99,8 +102,8 @@ module DatadogBackup
|
|
99
102
|
if e.message.include?('Request failed with error ["404"')
|
100
103
|
new_id = create(body).fetch('id')
|
101
104
|
|
102
|
-
get_and_write_file(new_id)
|
103
105
|
FileUtils.rm(find_file_by_id(id))
|
106
|
+
get_and_write_file(new_id)
|
104
107
|
else
|
105
108
|
raise e.message
|
106
109
|
end
|
@@ -27,7 +27,8 @@ module DatadogBackup
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def get_by_id(id)
|
30
|
-
|
30
|
+
monitor = all_monitors.select { |monitor| monitor['id'].to_s == id.to_s }.first
|
31
|
+
monitor.nil? ? {} : except(monitor)
|
31
32
|
end
|
32
33
|
|
33
34
|
def initialize(options)
|
@@ -19,10 +19,10 @@ describe DatadogBackup::Cli do
|
|
19
19
|
resources: [DatadogBackup::Dashboards]
|
20
20
|
}
|
21
21
|
end
|
22
|
-
let(:cli) {
|
22
|
+
let(:cli) { described_class.new(options) }
|
23
23
|
let(:dashboards) { DatadogBackup::Dashboards.new(options) }
|
24
24
|
|
25
|
-
before
|
25
|
+
before do
|
26
26
|
allow(cli).to receive(:resource_instances).and_return([dashboards])
|
27
27
|
end
|
28
28
|
|
@@ -39,18 +39,28 @@ describe DatadogBackup::Cli do
|
|
39
39
|
}
|
40
40
|
]
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
|
+
before do
|
43
44
|
dashboards.write_file('{"text": "diff"}', "#{tempdir}/dashboards/stillthere.json")
|
44
45
|
dashboards.write_file('{"text": "diff"}', "#{tempdir}/dashboards/alsostillthere.json")
|
45
46
|
dashboards.write_file('{"text": "diff"}', "#{tempdir}/dashboards/deleted.json")
|
46
47
|
|
47
48
|
allow(client_double).to receive(:instance_variable_get).with(:@dashboard_service).and_return(api_service_double)
|
48
|
-
allow(api_service_double).to receive(:request).with(Net::HTTP::Get,
|
49
|
+
allow(api_service_double).to receive(:request).with(Net::HTTP::Get,
|
50
|
+
'/api/v1/dashboard',
|
51
|
+
nil,
|
52
|
+
nil,
|
49
53
|
false).and_return(all_boards)
|
50
|
-
allow(api_service_double).to receive(:request).with(Net::HTTP::Get,
|
54
|
+
allow(api_service_double).to receive(:request).with(Net::HTTP::Get,
|
55
|
+
'/api/v1/dashboard/stillthere',
|
56
|
+
nil,
|
57
|
+
nil,
|
58
|
+
false).and_return(['200', {}])
|
59
|
+
allow(api_service_double).to receive(:request).with(Net::HTTP::Get,
|
60
|
+
'/api/v1/dashboard/alsostillthere',
|
61
|
+
nil,
|
62
|
+
nil,
|
51
63
|
false).and_return(['200', {}])
|
52
|
-
allow(api_service_double).to receive(:request).with(Net::HTTP::Get, '/api/v1/dashboard/alsostillthere', nil,
|
53
|
-
nil, false).and_return(['200', {}])
|
54
64
|
end
|
55
65
|
|
56
66
|
it 'deletes the file locally as well' do
|
@@ -61,16 +71,18 @@ describe DatadogBackup::Cli do
|
|
61
71
|
end
|
62
72
|
|
63
73
|
describe '#diffs' do
|
64
|
-
|
74
|
+
subject { cli.diffs }
|
75
|
+
|
76
|
+
before do
|
65
77
|
dashboards.write_file('{"text": "diff"}', "#{tempdir}/dashboards/diffs1.json")
|
66
78
|
dashboards.write_file('{"text": "diff"}', "#{tempdir}/dashboards/diffs2.json")
|
67
79
|
dashboards.write_file('{"text": "diff"}', "#{tempdir}/dashboards/diffs3.json")
|
68
80
|
allow(dashboards).to receive(:get_by_id).and_return({ 'text' => 'diff2' })
|
69
81
|
allow(cli).to receive(:initialize_client).and_return(client_double)
|
70
82
|
end
|
71
|
-
|
83
|
+
|
72
84
|
it {
|
73
|
-
|
85
|
+
expect(subject).to include(
|
74
86
|
" ---\n id: diffs1\n ---\n-text: diff2\n+text: diff\n",
|
75
87
|
" ---\n id: diffs3\n ---\n-text: diff2\n+text: diff\n",
|
76
88
|
" ---\n id: diffs2\n ---\n-text: diff2\n+text: diff\n"
|
@@ -79,14 +91,14 @@ describe DatadogBackup::Cli do
|
|
79
91
|
end
|
80
92
|
|
81
93
|
describe '#restore' do
|
82
|
-
|
94
|
+
subject { cli.restore }
|
95
|
+
|
96
|
+
before do
|
83
97
|
dashboards.write_file('{"text": "diff"}', "#{tempdir}/dashboards/diffs1.json")
|
84
98
|
allow(dashboards).to receive(:get_by_id).and_return({ 'text' => 'diff2' })
|
85
99
|
allow(cli).to receive(:initialize_client).and_return(client_double)
|
86
100
|
end
|
87
101
|
|
88
|
-
subject { cli.restore }
|
89
|
-
|
90
102
|
example 'starts interactive restore' do
|
91
103
|
allow($stdin).to receive(:gets).and_return('q')
|
92
104
|
|
@@ -101,21 +113,24 @@ describe DatadogBackup::Cli do
|
|
101
113
|
expect(dashboards).to receive(:update).with('diffs1', { 'text' => 'diff' })
|
102
114
|
subject
|
103
115
|
end
|
116
|
+
|
104
117
|
example 'download' do
|
105
118
|
allow($stdin).to receive(:gets).and_return('d')
|
106
119
|
expect(dashboards).to receive(:write_file).with(%({\n "text": "diff2"\n}), "#{tempdir}/dashboards/diffs1.json")
|
107
120
|
subject
|
108
121
|
end
|
122
|
+
|
109
123
|
example 'skip' do
|
110
124
|
allow($stdin).to receive(:gets).and_return('s')
|
111
|
-
expect(dashboards).
|
112
|
-
expect(dashboards).
|
125
|
+
expect(dashboards).not_to receive(:write_file)
|
126
|
+
expect(dashboards).not_to receive(:update)
|
113
127
|
subject
|
114
128
|
end
|
129
|
+
|
115
130
|
example 'quit' do
|
116
131
|
allow($stdin).to receive(:gets).and_return('q')
|
117
|
-
expect(dashboards).
|
118
|
-
expect(dashboards).
|
132
|
+
expect(dashboards).not_to receive(:write_file)
|
133
|
+
expect(dashboards).not_to receive(:update)
|
119
134
|
expect { subject }.to raise_error(SystemExit)
|
120
135
|
end
|
121
136
|
end
|
@@ -7,7 +7,7 @@ describe DatadogBackup::Core do
|
|
7
7
|
let(:client_double) { double }
|
8
8
|
let(:tempdir) { Dir.mktmpdir }
|
9
9
|
let(:core) do
|
10
|
-
|
10
|
+
described_class.new(
|
11
11
|
action: 'backup',
|
12
12
|
api_service: api_service_double,
|
13
13
|
client: client_double,
|
@@ -21,6 +21,7 @@ describe DatadogBackup::Core do
|
|
21
21
|
|
22
22
|
describe '#client' do
|
23
23
|
subject { core.client }
|
24
|
+
|
24
25
|
it { is_expected.to eq client_double }
|
25
26
|
end
|
26
27
|
|
@@ -41,14 +42,15 @@ describe DatadogBackup::Core do
|
|
41
42
|
end
|
42
43
|
|
43
44
|
describe '#diff' do
|
44
|
-
|
45
|
+
subject { core.diff('diff') }
|
46
|
+
|
47
|
+
before do
|
45
48
|
allow(core).to receive(:get_by_id).and_return({ 'text' => 'diff1', 'extra' => 'diff1' })
|
46
49
|
core.write_file('{"text": "diff2", "extra": "diff2"}', "#{tempdir}/core/diff.json")
|
47
50
|
end
|
48
51
|
|
49
|
-
subject { core.diff('diff') }
|
50
52
|
it {
|
51
|
-
|
53
|
+
expect(subject).to eq <<~EOF
|
52
54
|
---
|
53
55
|
-extra: diff1
|
54
56
|
-text: diff1
|
@@ -60,11 +62,13 @@ describe DatadogBackup::Core do
|
|
60
62
|
|
61
63
|
describe '#except' do
|
62
64
|
subject { core.except({ a: :b, b: :c }) }
|
65
|
+
|
63
66
|
it { is_expected.to eq({ a: :b, b: :c }) }
|
64
67
|
end
|
65
68
|
|
66
69
|
describe '#initialize' do
|
67
70
|
subject { core }
|
71
|
+
|
68
72
|
it 'makes the subdirectories' do
|
69
73
|
expect(FileUtils).to receive(:mkdir_p).with("#{tempdir}/core")
|
70
74
|
subject
|
@@ -73,60 +77,65 @@ describe DatadogBackup::Core do
|
|
73
77
|
|
74
78
|
describe '#myclass' do
|
75
79
|
subject { core.myclass }
|
80
|
+
|
76
81
|
it { is_expected.to eq 'core' }
|
77
82
|
end
|
78
83
|
|
79
84
|
describe '#create' do
|
80
85
|
subject { core.create({ 'a' => 'b' }) }
|
86
|
+
|
81
87
|
example 'it calls Dogapi::APIService.request' do
|
82
88
|
stub_const('Dogapi::APIService::API_VERSION', 'v1')
|
83
89
|
allow(core).to receive(:api_service).and_return(api_service_double)
|
84
90
|
allow(core).to receive(:api_version).and_return('v1')
|
85
91
|
allow(core).to receive(:api_resource_name).and_return('dashboard')
|
86
|
-
expect(api_service_double).to receive(:request).with(Net::HTTP::Post,
|
87
|
-
|
92
|
+
expect(api_service_double).to receive(:request).with(Net::HTTP::Post,
|
93
|
+
'/api/v1/dashboard',
|
94
|
+
nil,
|
95
|
+
{ 'a' => 'b' },
|
96
|
+
true).and_return(['200', { 'id' => 'whatever-id-abc' }])
|
88
97
|
subject
|
89
98
|
end
|
90
99
|
end
|
91
100
|
|
92
101
|
describe '#update' do
|
93
102
|
subject { core.update('abc-123-def', { 'a' => 'b' }) }
|
103
|
+
|
94
104
|
example 'it calls Dogapi::APIService.request' do
|
95
105
|
stub_const('Dogapi::APIService::API_VERSION', 'v1')
|
96
106
|
allow(core).to receive(:api_service).and_return(api_service_double)
|
97
107
|
allow(core).to receive(:api_version).and_return('v1')
|
98
108
|
allow(core).to receive(:api_resource_name).and_return('dashboard')
|
99
|
-
expect(api_service_double).to receive(:request).with(Net::HTTP::Put,
|
100
|
-
|
101
|
-
|
109
|
+
expect(api_service_double).to receive(:request).with(Net::HTTP::Put,
|
110
|
+
'/api/v1/dashboard/abc-123-def',
|
111
|
+
nil,
|
112
|
+
{ 'a' => 'b' },
|
113
|
+
true).and_return(['200', { 'id' => 'whatever-id-abc' }])
|
102
114
|
subject
|
103
115
|
end
|
104
116
|
end
|
105
117
|
|
106
118
|
describe '#restore' do
|
107
|
-
before
|
119
|
+
before do
|
108
120
|
allow(core).to receive(:api_service).and_return(api_service_double)
|
109
121
|
allow(core).to receive(:api_version).and_return('api-version-string')
|
110
122
|
allow(core).to receive(:api_resource_name).and_return('api-resource-name-string')
|
111
|
-
allow(api_service_double).to receive(:request).with(
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
nil,
|
122
|
-
nil,
|
123
|
-
false
|
124
|
-
).and_return(['404', { error: :blahblah_not_found }])
|
123
|
+
allow(api_service_double).to receive(:request).with(Net::HTTP::Get,
|
124
|
+
'/api/api-version-string/api-resource-name-string/abc-123-def',
|
125
|
+
nil,
|
126
|
+
nil,
|
127
|
+
false).and_return(['200', { test: :ok }])
|
128
|
+
allow(api_service_double).to receive(:request).with(Net::HTTP::Get,
|
129
|
+
'/api/api-version-string/api-resource-name-string/bad-123-id',
|
130
|
+
nil,
|
131
|
+
nil,
|
132
|
+
false).and_return(['404', { error: :blahblah_not_found }])
|
125
133
|
allow(core).to receive(:load_from_file_by_id).and_return({ 'load' => 'ok' })
|
126
134
|
end
|
127
135
|
|
128
136
|
context 'when id exists' do
|
129
137
|
subject { core.restore('abc-123-def') }
|
138
|
+
|
130
139
|
example 'it calls out to update' do
|
131
140
|
expect(core).to receive(:update).with('abc-123-def', { 'load' => 'ok' })
|
132
141
|
subject
|
@@ -134,27 +143,20 @@ describe DatadogBackup::Core do
|
|
134
143
|
end
|
135
144
|
|
136
145
|
context 'when id does not exist' do
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
nil,
|
150
|
-
{ 'load' => 'ok' },
|
151
|
-
true
|
152
|
-
).and_return(
|
153
|
-
['200', { 'id' => 'my-new-id' }]
|
154
|
-
)
|
146
|
+
subject { core.restore('bad-123-id') }
|
147
|
+
|
148
|
+
before do
|
149
|
+
allow(api_service_double).to receive(:request).with(Net::HTTP::Put,
|
150
|
+
'/api/api-version-string/api-resource-name-string/bad-123-id',
|
151
|
+
nil, { 'load' => 'ok' },
|
152
|
+
true).and_return(['404', { 'Error' => 'my not found' }])
|
153
|
+
allow(api_service_double).to receive(:request).with(Net::HTTP::Post,
|
154
|
+
'/api/api-version-string/api-resource-name-string',
|
155
|
+
nil,
|
156
|
+
{ 'load' => 'ok' },
|
157
|
+
true).and_return(['200', { 'id' => 'my-new-id' }])
|
155
158
|
end
|
156
159
|
|
157
|
-
subject { core.restore('bad-123-id') }
|
158
160
|
example 'it calls out to create then saves the new file and deletes the new file' do
|
159
161
|
expect(core).to receive(:create).with({ 'load' => 'ok' }).and_return({ 'id' => 'my-new-id' })
|
160
162
|
expect(core).to receive(:get_and_write_file).with('my-new-id')
|
@@ -7,7 +7,7 @@ describe DatadogBackup::Dashboards do
|
|
7
7
|
let(:client_double) { double }
|
8
8
|
let(:tempdir) { Dir.mktmpdir }
|
9
9
|
let(:dashboards) do
|
10
|
-
|
10
|
+
described_class.new(
|
11
11
|
action: 'backup',
|
12
12
|
client: client_double,
|
13
13
|
backup_dir: tempdir,
|
@@ -59,7 +59,8 @@ describe DatadogBackup::Dashboards do
|
|
59
59
|
'title' => 'example dashboard'
|
60
60
|
}
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
|
+
before do
|
63
64
|
allow(client_double).to receive(:instance_variable_get).with(:@dashboard_service).and_return(api_service_double)
|
64
65
|
allow(api_service_double).to receive(:request).with(Net::HTTP::Get, '/api/v1/dashboard', nil, nil,
|
65
66
|
false).and_return(all_boards)
|
@@ -108,11 +109,13 @@ describe DatadogBackup::Dashboards do
|
|
108
109
|
|
109
110
|
describe '#except' do
|
110
111
|
subject { dashboards.except({ :a => :b, 'modified_at' => :c, 'url' => :d }) }
|
112
|
+
|
111
113
|
it { is_expected.to eq({ a: :b }) }
|
112
114
|
end
|
113
115
|
|
114
116
|
describe '#get_by_id' do
|
115
117
|
subject { dashboards.get_by_id('abc-123-def') }
|
118
|
+
|
116
119
|
it { is_expected.to eq board_abc_123_def }
|
117
120
|
end
|
118
121
|
end
|
@@ -27,55 +27,61 @@ describe DatadogBackup::LocalFilesystem do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
describe '#all_files' do
|
30
|
-
|
30
|
+
subject { core.all_files }
|
31
|
+
|
32
|
+
before do
|
31
33
|
File.new("#{tempdir}/all_files.json", 'w')
|
32
34
|
end
|
33
35
|
|
34
|
-
after
|
36
|
+
after do
|
35
37
|
FileUtils.rm "#{tempdir}/all_files.json"
|
36
38
|
end
|
37
39
|
|
38
|
-
subject { core.all_files }
|
39
40
|
it { is_expected.to eq(["#{tempdir}/all_files.json"]) }
|
40
41
|
end
|
41
42
|
|
42
43
|
describe '#all_file_ids_for_selected_resources' do
|
43
|
-
|
44
|
+
subject { core.all_file_ids_for_selected_resources }
|
45
|
+
|
46
|
+
before do
|
44
47
|
Dir.mkdir("#{tempdir}/dashboards")
|
45
48
|
Dir.mkdir("#{tempdir}/monitors")
|
46
49
|
File.new("#{tempdir}/dashboards/all_files.json", 'w')
|
47
50
|
File.new("#{tempdir}/monitors/12345.json", 'w')
|
48
51
|
end
|
49
52
|
|
50
|
-
after
|
53
|
+
after do
|
51
54
|
FileUtils.rm "#{tempdir}/dashboards/all_files.json"
|
52
55
|
FileUtils.rm "#{tempdir}/monitors/12345.json"
|
53
56
|
end
|
54
57
|
|
55
|
-
subject { core.all_file_ids_for_selected_resources }
|
56
58
|
it { is_expected.to eq(['all_files']) }
|
57
59
|
end
|
58
60
|
|
59
61
|
describe '#class_from_id' do
|
60
|
-
|
62
|
+
subject { core.class_from_id('abc-123-def') }
|
63
|
+
|
64
|
+
before do
|
61
65
|
core.write_file('abc', "#{tempdir}/core/abc-123-def.json")
|
62
66
|
end
|
63
67
|
|
64
|
-
after
|
68
|
+
after do
|
65
69
|
FileUtils.rm "#{tempdir}/core/abc-123-def.json"
|
66
70
|
end
|
67
|
-
|
71
|
+
|
68
72
|
it { is_expected.to eq DatadogBackup::Core }
|
69
73
|
end
|
70
74
|
|
71
75
|
describe '#dump' do
|
72
76
|
context ':json' do
|
73
77
|
subject { core.dump({ a: :b }) }
|
78
|
+
|
74
79
|
it { is_expected.to eq(%({\n "a": "b"\n})) }
|
75
80
|
end
|
76
81
|
|
77
82
|
context ':yaml' do
|
78
83
|
subject { core_yaml.dump({ 'a' => 'b' }) }
|
84
|
+
|
79
85
|
it { is_expected.to eq(%(---\na: b\n)) }
|
80
86
|
end
|
81
87
|
end
|
@@ -83,80 +89,94 @@ describe DatadogBackup::LocalFilesystem do
|
|
83
89
|
describe '#filename' do
|
84
90
|
context ':json' do
|
85
91
|
subject { core.filename('abc-123-def') }
|
92
|
+
|
86
93
|
it { is_expected.to eq("#{tempdir}/core/abc-123-def.json") }
|
87
94
|
end
|
88
95
|
|
89
96
|
context ':yaml' do
|
90
97
|
subject { core_yaml.filename('abc-123-def') }
|
98
|
+
|
91
99
|
it { is_expected.to eq("#{tempdir}/core/abc-123-def.yaml") }
|
92
100
|
end
|
93
101
|
end
|
94
102
|
|
95
103
|
describe '#file_type' do
|
96
|
-
|
104
|
+
subject { core.file_type("#{tempdir}/file_type.json") }
|
105
|
+
|
106
|
+
before do
|
97
107
|
File.new("#{tempdir}/file_type.json", 'w')
|
98
108
|
end
|
99
109
|
|
100
|
-
after
|
110
|
+
after do
|
101
111
|
FileUtils.rm "#{tempdir}/file_type.json"
|
102
112
|
end
|
103
113
|
|
104
|
-
subject { core.file_type("#{tempdir}/file_type.json") }
|
105
114
|
it { is_expected.to eq :json }
|
106
115
|
end
|
107
116
|
|
108
117
|
describe '#find_file_by_id' do
|
109
|
-
|
118
|
+
subject { core.find_file_by_id('find_file') }
|
119
|
+
|
120
|
+
before do
|
110
121
|
File.new("#{tempdir}/find_file.json", 'w')
|
111
122
|
end
|
112
123
|
|
113
|
-
after
|
124
|
+
after do
|
114
125
|
FileUtils.rm "#{tempdir}/find_file.json"
|
115
126
|
end
|
116
127
|
|
117
|
-
subject { core.find_file_by_id('find_file') }
|
118
128
|
it { is_expected.to eq "#{tempdir}/find_file.json" }
|
119
129
|
end
|
120
130
|
|
121
131
|
describe '#load_from_file' do
|
122
132
|
context ':json' do
|
123
133
|
subject { core.load_from_file(%({\n "a": "b"\n}), :json) }
|
134
|
+
|
124
135
|
it { is_expected.to eq('a' => 'b') }
|
125
136
|
end
|
126
137
|
|
127
138
|
context ':yaml' do
|
128
139
|
subject { core.load_from_file(%(---\na: b\n), :yaml) }
|
140
|
+
|
129
141
|
it { is_expected.to eq('a' => 'b') }
|
130
142
|
end
|
131
143
|
end
|
132
144
|
|
133
145
|
describe '#load_from_file_by_id' do
|
134
146
|
context 'written in json read in yaml mode' do
|
135
|
-
before(:example) { core.write_file(%({"a": "b"}), "#{tempdir}/core/abc-123-def.json") }
|
136
|
-
after(:example) { FileUtils.rm "#{tempdir}/core/abc-123-def.json" }
|
137
|
-
|
138
147
|
subject { core_yaml.load_from_file_by_id('abc-123-def') }
|
148
|
+
|
149
|
+
before { core.write_file(%({"a": "b"}), "#{tempdir}/core/abc-123-def.json") }
|
150
|
+
|
151
|
+
after { FileUtils.rm "#{tempdir}/core/abc-123-def.json" }
|
152
|
+
|
139
153
|
it { is_expected.to eq('a' => 'b') }
|
140
154
|
end
|
141
|
-
context 'written in yaml read in json mode' do
|
142
|
-
before(:example) { core.write_file(%(---\na: b), "#{tempdir}/core/abc-123-def.yaml") }
|
143
|
-
after(:example) { FileUtils.rm "#{tempdir}/core/abc-123-def.yaml" }
|
144
155
|
|
156
|
+
context 'written in yaml read in json mode' do
|
145
157
|
subject { core.load_from_file_by_id('abc-123-def') }
|
158
|
+
|
159
|
+
before { core.write_file(%(---\na: b), "#{tempdir}/core/abc-123-def.yaml") }
|
160
|
+
|
161
|
+
after { FileUtils.rm "#{tempdir}/core/abc-123-def.yaml" }
|
162
|
+
|
146
163
|
it { is_expected.to eq('a' => 'b') }
|
147
164
|
end
|
148
165
|
|
149
166
|
context 'Integer as parameter' do
|
150
|
-
before(:example) { core.write_file(%(---\na: b), "#{tempdir}/core/12345.yaml") }
|
151
|
-
after(:example) { FileUtils.rm "#{tempdir}/core/12345.yaml" }
|
152
|
-
|
153
167
|
subject { core.load_from_file_by_id(12_345) }
|
168
|
+
|
169
|
+
before { core.write_file(%(---\na: b), "#{tempdir}/core/12345.yaml") }
|
170
|
+
|
171
|
+
after { FileUtils.rm "#{tempdir}/core/12345.yaml" }
|
172
|
+
|
154
173
|
it { is_expected.to eq('a' => 'b') }
|
155
174
|
end
|
156
175
|
end
|
157
176
|
|
158
177
|
describe '#write_file' do
|
159
178
|
subject { core.write_file('abc123', "#{tempdir}/core/abc-123-def.json") }
|
179
|
+
|
160
180
|
let(:file_like_object) { double }
|
161
181
|
|
162
182
|
it 'writes a file to abc-123-def.json' do
|
@@ -7,7 +7,7 @@ describe DatadogBackup::Monitors do
|
|
7
7
|
let(:client_double) { double }
|
8
8
|
let(:tempdir) { Dir.mktmpdir }
|
9
9
|
let(:monitors) do
|
10
|
-
|
10
|
+
described_class.new(
|
11
11
|
action: 'backup',
|
12
12
|
client: client_double,
|
13
13
|
backup_dir: tempdir,
|
@@ -49,7 +49,7 @@ describe DatadogBackup::Monitors do
|
|
49
49
|
]
|
50
50
|
end
|
51
51
|
|
52
|
-
before
|
52
|
+
before do
|
53
53
|
allow(client_double).to receive(:instance_variable_get).with(:@monitor_svc).and_return(api_service_double)
|
54
54
|
allow(api_service_double).to receive(:request).with(Net::HTTP::Get, '/api/v1/monitor', nil, nil,
|
55
55
|
false).and_return(all_monitors)
|
@@ -59,6 +59,7 @@ describe DatadogBackup::Monitors do
|
|
59
59
|
|
60
60
|
describe '#all_monitors' do
|
61
61
|
subject { monitors.all_monitors }
|
62
|
+
|
62
63
|
it { is_expected.to eq [monitor_description] }
|
63
64
|
end
|
64
65
|
|
@@ -102,16 +103,20 @@ describe DatadogBackup::Monitors do
|
|
102
103
|
|
103
104
|
describe '#filename' do
|
104
105
|
subject { monitors.filename(123_455) }
|
106
|
+
|
105
107
|
it { is_expected.to eq("#{tempdir}/monitors/123455.json") }
|
106
108
|
end
|
107
109
|
|
108
110
|
describe '#get_by_id' do
|
109
111
|
context 'Integer' do
|
110
112
|
subject { monitors.get_by_id(123_455) }
|
113
|
+
|
111
114
|
it { is_expected.to eq monitor_description }
|
112
115
|
end
|
116
|
+
|
113
117
|
context 'String' do
|
114
118
|
subject { monitors.get_by_id('123455') }
|
119
|
+
|
115
120
|
it { is_expected.to eq monitor_description }
|
116
121
|
end
|
117
122
|
end
|
@@ -18,13 +18,13 @@ describe 'bin/datadog_backup' do
|
|
18
18
|
i.close
|
19
19
|
end
|
20
20
|
|
21
|
-
Timeout.timeout(
|
21
|
+
Timeout.timeout(2.0) do
|
22
22
|
oe.each do |v|
|
23
23
|
output += v
|
24
24
|
end
|
25
25
|
end
|
26
26
|
rescue Timeout::Error
|
27
|
-
LOGGER.warn "Timing out #{t.inspect} after
|
27
|
+
LOGGER.warn "Timing out #{t.inspect} after 2 second"
|
28
28
|
Process.kill(15, pid)
|
29
29
|
ensure
|
30
30
|
status = t.value
|
@@ -47,7 +47,7 @@ describe 'bin/datadog_backup' do
|
|
47
47
|
it "dies unless given ENV[#{v}]" do
|
48
48
|
ClimateControl.env[v] = nil
|
49
49
|
_, status = run_bin('backup')
|
50
|
-
expect(status).
|
50
|
+
expect(status).not_to be_success
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
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: 1.0.
|
4
|
+
version: 1.0.2
|
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: 2021-
|
12
|
+
date: 2021-05-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: amazing_print
|
@@ -17,28 +17,28 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - '='
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 1.
|
20
|
+
version: 1.3.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - '='
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 1.
|
27
|
+
version: 1.3.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: concurrent-ruby
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - '='
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 1.1.
|
34
|
+
version: 1.1.8
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - '='
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 1.1.
|
41
|
+
version: 1.1.8
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: concurrent-ruby-edge
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,14 +87,14 @@ dependencies:
|
|
87
87
|
requirements:
|
88
88
|
- - '='
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
version: 1.
|
90
|
+
version: 1.45.0
|
91
91
|
type: :runtime
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
95
|
- - '='
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version: 1.
|
97
|
+
version: 1.45.0
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
99
|
name: bundler
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- ".github/dependabot.yml"
|
136
136
|
- ".github/workflows/rspec_and_release.yml"
|
137
137
|
- ".gitignore"
|
138
|
+
- ".rubocop.yml"
|
138
139
|
- CHANGELOG.md
|
139
140
|
- CODE_OF_CONDUCT.md
|
140
141
|
- Gemfile
|
@@ -183,11 +184,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
183
184
|
version: '0'
|
184
185
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
185
186
|
requirements:
|
186
|
-
- - "
|
187
|
+
- - ">="
|
187
188
|
- !ruby/object:Gem::Version
|
188
|
-
version:
|
189
|
+
version: '0'
|
189
190
|
requirements: []
|
190
|
-
rubygems_version: 3.1.
|
191
|
+
rubygems_version: 3.1.6
|
191
192
|
signing_key:
|
192
193
|
specification_version: 4
|
193
194
|
summary: A utility to backup and restore Datadog accounts
|