Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/datadog_backup/dashboards.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ def backup
Concurrent::Promises.zip(*futures).value!
end

def get_by_id(id)
begin
dashboard = except(get(id))
rescue Faraday::ResourceNotFound => e
dashboard = {}
end
except(dashboard)
end

def initialize(options)
super(options)
@banlist = %w[modified_at url].freeze
Expand Down
4 changes: 1 addition & 3 deletions lib/datadog_backup/resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ def restore(id)
body = load_from_file_by_id(id)
begin
update(id, body)
rescue RuntimeError => e
raise e.message unless e.message.include?('update failed with error 404')

rescue Faraday::ResourceNotFound => e
create_newly(id, body)
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/datadog_backup/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
allow(resources).to receive(:api_resource_name).and_return('api-resource-name-string')
stubs.get('/api/api-version-string/api-resource-name-string/abc-123-def') { respond_with200({ 'test' => 'ok' }) }
stubs.get('/api/api-version-string/api-resource-name-string/bad-123-id') do
[404, {}, { 'error' => 'blahblah_not_found' }]
raise Faraday::ResourceNotFound
end
allow(resources).to receive(:load_from_file_by_id).and_return({ 'load' => 'ok' })
end
Expand All @@ -126,7 +126,7 @@
before do
allow(resources).to receive(:load_from_file_by_id).and_return({ 'load' => 'ok' })
stubs.put('/api/api-version-string/api-resource-name-string/bad-123-id') do
[404, {}, { 'error' => 'id not found' }]
raise Faraday::ResourceNotFound
end
stubs.post('/api/api-version-string/api-resource-name-string', { 'load' => 'ok' }) do
respond_with200({ 'id' => 'my-new-id' })
Expand Down
2 changes: 1 addition & 1 deletion spec/datadog_backup/synthetics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@

before do
synthetics.write_file(synthetics.dump({ 'name' => 'restore-invalid-id', 'type' => 'api' }), synthetics.filename('restore-invalid-id'))
stubs.put('/api/v1/synthetics/tests/api/restore-invalid-id') { [404, {}, ''] }
stubs.put('/api/v1/synthetics/tests/api/restore-invalid-id') { raise Faraday::ResourceNotFound }
stubs.post('/api/v1/synthetics/tests/api') { respond_with200({ 'public_id' => 'restore-valid-id' }) }
allow(synthetics).to receive(:create).and_call_original
allow(synthetics).to receive(:all).and_return([api_test, browser_test, { 'public_id' => 'restore-valid-id', 'type' => 'api' }])
Expand Down