datadog_backup 1.0.4 → 1.0.5

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
  SHA256:
3
- metadata.gz: 7caee2d991c55f7dfc74c86ede132f8668a84a9a3e03edf6804c887e4134f8c3
4
- data.tar.gz: 3db5f4353abb8b193477ad34695d8aaa147ed0dd0757bb2e4ee7d39f02ee55c3
3
+ metadata.gz: 618459125bc84a9d8c48eb2ffb3256163378d26af4d80e92f2c1033110ae9467
4
+ data.tar.gz: 619212b26a22764af2050375426f19edba44563b867ded709d33a00384468fd9
5
5
  SHA512:
6
- metadata.gz: 9c192d88ef8ed33736649a9e9672bf92e09f043d92e9909393bc327773e11de011afa22afebc0d000253cfafa25de76aa31c88cb8a903a537b389acbdc9142c2
7
- data.tar.gz: f3029bf8449950a2584f0b6e6aa68ed359726e890cd5d399fb5fb715863a2a230d4f07cbfb1e23b67c4d4ae0cecdef3b875b98feae2c49073ad6f33e8edfa5ea
6
+ metadata.gz: e029e80229c35796bcd28432af89a7c39172b646c4e880dff8df9e1b5ccfb299706ee9b466fe1c5500126fbd03097dd3da4ef0da91d7ee77e256c8c2657c1a2c
7
+ data.tar.gz: 635beff60e9a93d5946c8e88f4a9ac8e11b56f08d0b03f045814ec0f799714eebc7f2b0d1fa665807151524469aebe024e7954cffd6a8b57a898d9da97f6d74c
data/.gitignore CHANGED
@@ -119,3 +119,5 @@ spec/helpers/failures.txt
119
119
  backup/
120
120
 
121
121
  .envrc
122
+
123
+ .vscode
data/.rubocop.yml CHANGED
@@ -1 +1,78 @@
1
- require: rubocop-rspec
1
+ require: rubocop-rspec
2
+
3
+ Gemspec/DateAssignment: # (new in 1.10)
4
+ Enabled: true
5
+ Layout/LineEndStringConcatenationIndentation: # (new in 1.18)
6
+ Enabled: true
7
+ Layout/SpaceBeforeBrackets: # (new in 1.7)
8
+ Enabled: true
9
+ Lint/AmbiguousAssignment: # (new in 1.7)
10
+ Enabled: true
11
+ Lint/DeprecatedConstants: # (new in 1.8)
12
+ Enabled: true
13
+ Lint/DuplicateBranch: # (new in 1.3)
14
+ Enabled: true
15
+ Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1)
16
+ Enabled: true
17
+ Lint/EmptyBlock: # (new in 1.1)
18
+ Enabled: true
19
+ Lint/EmptyClass: # (new in 1.3)
20
+ Enabled: true
21
+ Lint/EmptyInPattern: # (new in 1.16)
22
+ Enabled: true
23
+ Lint/LambdaWithoutLiteralBlock: # (new in 1.8)
24
+ Enabled: true
25
+ Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
26
+ Enabled: true
27
+ Lint/NumberedParameterAssignment: # (new in 1.9)
28
+ Enabled: true
29
+ Lint/OrAssignmentToConstant: # (new in 1.9)
30
+ Enabled: true
31
+ Lint/RedundantDirGlobSort: # (new in 1.8)
32
+ Enabled: true
33
+ Lint/SymbolConversion: # (new in 1.9)
34
+ Enabled: true
35
+ Lint/ToEnumArguments: # (new in 1.1)
36
+ Enabled: true
37
+ Lint/TripleQuotes: # (new in 1.9)
38
+ Enabled: true
39
+ Lint/UnexpectedBlockArity: # (new in 1.5)
40
+ Enabled: true
41
+ Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
42
+ Enabled: true
43
+ Naming/InclusiveLanguage: # (new in 1.18)
44
+ Enabled: true
45
+ Style/ArgumentsForwarding: # (new in 1.1)
46
+ Enabled: true
47
+ Style/CollectionCompact: # (new in 1.2)
48
+ Enabled: true
49
+ Style/DocumentDynamicEvalDefinition: # (new in 1.1)
50
+ Enabled: true
51
+ Style/EndlessMethod: # (new in 1.8)
52
+ Enabled: true
53
+ Style/HashConversion: # (new in 1.10)
54
+ Enabled: true
55
+ Style/HashExcept: # (new in 1.7)
56
+ Enabled: true
57
+ Style/IfWithBooleanLiteralBranches: # (new in 1.9)
58
+ Enabled: true
59
+ Style/InPatternThen: # (new in 1.16)
60
+ Enabled: true
61
+ Style/MultilineInPatternThen: # (new in 1.16)
62
+ Enabled: true
63
+ Style/NegatedIfElseCondition: # (new in 1.2)
64
+ Enabled: true
65
+ Style/NilLambda: # (new in 1.3)
66
+ Enabled: true
67
+ Style/QuotedSymbols: # (new in 1.16)
68
+ Enabled: true
69
+ Style/RedundantArgument: # (new in 1.4)
70
+ Enabled: true
71
+ Style/StringChars: # (new in 1.12)
72
+ Enabled: true
73
+ Style/SwapValues: # (new in 1.1)
74
+ Enabled: true
75
+ RSpec/IdenticalEqualityAssertion: # (new in 2.4)
76
+ Enabled: true
77
+ RSpec/Rails/AvoidSetupHook: # (new in 2.4)
78
+ Enabled: true
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.0.5](https://github.com/scribd/datadog_backup/compare/v1.0.4...v1.0.5) (2021-07-12)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Add documentation for DATADOG_HOST usage ([69acc25](https://github.com/scribd/datadog_backup/commit/69acc2574d17310ee090486ec46cb06ab0f450db))
7
+
1
8
  ## [1.0.4](https://github.com/scribd/datadog_backup/compare/v1.0.3...v1.0.4) (2021-07-08)
2
9
 
3
10
 
data/Gemfile CHANGED
@@ -5,7 +5,6 @@ source 'https://rubygems.org'
5
5
  gemspec
6
6
 
7
7
  group :development, :test do
8
- gem 'climate_control'
9
8
  gem 'guard-rspec'
10
9
  gem 'rspec'
11
10
  gem 'rubocop'
data/Gemfile.lock CHANGED
@@ -4,7 +4,6 @@ PATH
4
4
  datadog_backup (0.6.0)
5
5
  amazing_print (= 1.3.0)
6
6
  concurrent-ruby (= 1.1.9)
7
- concurrent-ruby-edge (= 0.6.0)
8
7
  deepsort (= 0.4.5)
9
8
  diffy (= 3.4.0)
10
9
  dogapi (= 1.45.0)
@@ -14,19 +13,16 @@ GEM
14
13
  specs:
15
14
  amazing_print (1.3.0)
16
15
  ast (2.4.2)
17
- climate_control (1.0.1)
18
16
  coderay (1.1.3)
19
17
  concurrent-ruby (1.1.9)
20
- concurrent-ruby-edge (0.6.0)
21
- concurrent-ruby (~> 1.1.6)
22
18
  deepsort (0.4.5)
23
19
  diff-lcs (1.4.4)
24
20
  diffy (3.4.0)
25
21
  dogapi (1.45.0)
26
22
  multi_json
27
- ffi (1.13.1)
28
- formatador (0.2.5)
29
- guard (2.16.2)
23
+ ffi (1.15.3)
24
+ formatador (0.3.0)
25
+ guard (2.17.0)
30
26
  formatador (>= 0.2.4)
31
27
  listen (>= 2.7, < 4.0)
32
28
  lumberjack (>= 1.0.12, < 2.0)
@@ -40,10 +36,10 @@ GEM
40
36
  guard (~> 2.1)
41
37
  guard-compat (~> 1.1)
42
38
  rspec (>= 2.99.0, < 4.0)
43
- listen (3.2.1)
39
+ listen (3.5.1)
44
40
  rb-fsevent (~> 0.10, >= 0.10.3)
45
41
  rb-inotify (~> 0.9, >= 0.9.10)
46
- lumberjack (1.2.6)
42
+ lumberjack (1.2.8)
47
43
  method_source (1.0.0)
48
44
  multi_json (1.15.0)
49
45
  nenv (0.3.0)
@@ -51,13 +47,13 @@ GEM
51
47
  nenv (~> 0.1)
52
48
  shellany (~> 0.0)
53
49
  parallel (1.20.1)
54
- parser (3.0.1.1)
50
+ parser (3.0.2.0)
55
51
  ast (~> 2.4.1)
56
52
  pry (0.14.1)
57
53
  coderay (~> 1.1)
58
54
  method_source (~> 1.0)
59
55
  rainbow (3.0.0)
60
- rb-fsevent (0.10.4)
56
+ rb-fsevent (0.11.0)
61
57
  rb-inotify (0.10.1)
62
58
  ffi (~> 1.0)
63
59
  regexp_parser (2.1.1)
@@ -66,15 +62,15 @@ GEM
66
62
  rspec-core (~> 3.10.0)
67
63
  rspec-expectations (~> 3.10.0)
68
64
  rspec-mocks (~> 3.10.0)
69
- rspec-core (3.10.0)
65
+ rspec-core (3.10.1)
70
66
  rspec-support (~> 3.10.0)
71
- rspec-expectations (3.10.0)
67
+ rspec-expectations (3.10.1)
72
68
  diff-lcs (>= 1.2.0, < 2.0)
73
69
  rspec-support (~> 3.10.0)
74
- rspec-mocks (3.10.0)
70
+ rspec-mocks (3.10.2)
75
71
  diff-lcs (>= 1.2.0, < 2.0)
76
72
  rspec-support (~> 3.10.0)
77
- rspec-support (3.10.0)
73
+ rspec-support (3.10.2)
78
74
  rubocop (1.18.3)
79
75
  parallel (~> 1.10)
80
76
  parser (>= 3.0.0.0)
@@ -91,7 +87,7 @@ GEM
91
87
  rubocop-ast (>= 1.1.0)
92
88
  ruby-progressbar (1.11.0)
93
89
  shellany (0.0.1)
94
- thor (1.0.1)
90
+ thor (1.1.0)
95
91
  unicode-display_width (2.0.0)
96
92
 
97
93
  PLATFORMS
@@ -99,7 +95,6 @@ PLATFORMS
99
95
 
100
96
  DEPENDENCIES
101
97
  bundler
102
- climate_control
103
98
  datadog_backup!
104
99
  guard-rspec
105
100
  pry
@@ -108,4 +103,4 @@ DEPENDENCIES
108
103
  rubocop-rspec
109
104
 
110
105
  BUNDLED WITH
111
- 2.1.4
106
+ 2.2.21
data/README.md CHANGED
@@ -49,6 +49,18 @@ datadog_backup diffs --backup-dir optional/path/to/backupdir
49
49
  datadog_backup restore --backup-dir optional/path/to/backupdir
50
50
  ```
51
51
 
52
+ ## Environment variables
53
+
54
+ The following environment variables can be set in order to further customize datadog_backup:
55
+
56
+ environment variable | description | default
57
+ ---------------------|--------------------------------------------------------------------------------|--------------------------
58
+ DATADOG_HOST | Describe the API endpoint to connect to (https://api.datadoghq.eu for example) | https://api.datadoghq.com
59
+ http_proxy | Instruct Dogapi to connect via a differnt proxy address | none
60
+ https_proxy | same as http_proxy | none
61
+ dd_proxy_https | same as http_proxy | none
62
+
63
+
52
64
  ### Usage in a Github repo
53
65
 
54
66
  See [example/](https://github.com/scribd/datadog_backup/tree/master/example) for an example implementation as a repo that backs up your Datadog dashboards hourly.
data/bin/datadog_backup CHANGED
@@ -13,25 +13,24 @@ $stdout.sync = $stderr.sync = true
13
13
  LOGGER = Logger.new($stderr) unless defined?(LOGGER)
14
14
  LOGGER.level = Logger::INFO
15
15
 
16
- ##
17
- # Default parameters
18
- @options = {
19
- action: nil,
20
- datadog_api_key: ENV.fetch('DATADOG_API_KEY'),
21
- datadog_app_key: ENV.fetch('DATADOG_APP_KEY'),
22
- backup_dir: File.join(ENV.fetch('PWD'), 'backup'),
23
- diff_format: :color,
24
- resources: [DatadogBackup::Dashboards, DatadogBackup::Monitors],
25
- output_format: :yaml,
26
- force_restore: false,
27
- logger: LOGGER
28
- }
16
+ def fatal(message)
17
+ LOGGER.fatal(message)
18
+ exit 1
19
+ end
20
+
21
+ def options_valid?(options)
22
+ %w[backup diffs restore].include?(options[:action]) &&
23
+ options[:datadog_api_key] &&
24
+ options[:datadog_app_key]
25
+ end
29
26
 
30
- def prereqs
27
+ def prereqs(defaults)
31
28
  ARGV << '--help' if ARGV.empty?
32
29
 
30
+ result = defaults.dup
31
+
33
32
  options = OptionParser.new do |opts|
34
- opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} <backup|diffs|restore>"
33
+ opts.banner = "Usage: DATADOG_API_KEY=abc123 DATADOG_APP_KEY=abc123 #{File.basename($PROGRAM_NAME)} <backup|diffs|restore>"
35
34
  opts.separator ''
36
35
  opts.on_tail('-h', '--help', 'Show this message') do
37
36
  puts opts
@@ -47,40 +46,49 @@ def prereqs
47
46
  LOGGER.level = Logger::ERROR
48
47
  end
49
48
  opts.on('--backup-dir PATH', '`backup` by default') do |path|
50
- @options[:backup_dir] = path
49
+ result[:backup_dir] = path
51
50
  end
52
51
  opts.on('--monitors-only') do
53
- @options[:resources] = [DatadogBackup::Monitors]
52
+ result[:resources] = [DatadogBackup::Monitors]
54
53
  end
55
54
  opts.on('--dashboards-only') do
56
- @options[:resources] = [DatadogBackup::Dashboards]
55
+ result[:resources] = [DatadogBackup::Dashboards]
57
56
  end
58
57
  opts.on(
59
58
  '--json',
60
59
  'format backups as JSON instead of YAML. Does not impact `diffs` nor `restore`, but do not mix formats in the same backup-dir.'
61
60
  ) do
62
- @options[:output_format] = :json
61
+ result[:output_format] = :json
63
62
  end
64
63
  opts.on('--no-color', 'removes colored output from diff format') do
65
- @options[:diff_format] = nil
64
+ result[:diff_format] = nil
66
65
  end
67
66
  opts.on('--diff-format FORMAT', 'one of `color`, `html_simple`, `html`') do |format|
68
- @options[:diff_format] = format.to_sym
67
+ result[:diff_format] = format.to_sym
69
68
  end
70
69
  opts.on('--force-restore', 'force restore to Datadog') do
71
- @options[:force_restore] = true
70
+ result[:force_restore] = true
72
71
  end
73
72
  end
74
73
  options.parse!
75
74
 
76
- @options[:action] = ARGV.first
77
- if %w[backup diffs restore].include?(@options[:action])
78
- else
79
- puts options
80
- exit 0
81
- end
75
+ result[:action] = ARGV.first
76
+ fatal(options) unless options_valid?(result)
77
+ result
82
78
  end
83
79
 
84
- prereqs
80
+ ##
81
+ # Default parameters
82
+ defaults = {
83
+ action: nil,
84
+ datadog_api_key: ENV.fetch('DATADOG_API_KEY', nil),
85
+ datadog_app_key: ENV.fetch('DATADOG_APP_KEY', nil),
86
+ backup_dir: File.join(ENV.fetch('PWD'), 'backup'),
87
+ diff_format: :color,
88
+ resources: [DatadogBackup::Dashboards, DatadogBackup::Monitors],
89
+ output_format: :yaml,
90
+ force_restore: false,
91
+ logger: LOGGER
92
+ }
85
93
 
86
- DatadogBackup::Cli.new(@options).run!
94
+ DatadogBackup::Cli.new(prereqs(defaults)).run!
@@ -21,7 +21,6 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_dependency 'amazing_print', '1.3.0'
23
23
  spec.add_dependency 'concurrent-ruby', '1.1.9'
24
- spec.add_dependency 'concurrent-ruby-edge', '0.6.0'
25
24
  spec.add_dependency 'deepsort', '0.4.5'
26
25
  spec.add_dependency 'diffy', '3.4.0'
27
26
  spec.add_dependency 'dogapi', '1.45.0'
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'concurrent'
4
- require 'concurrent-edge'
5
4
 
6
5
  require 'dogapi'
7
6
 
@@ -48,7 +48,7 @@ module DatadogBackup
48
48
  Concurrent::Promises
49
49
  .zip(*futures)
50
50
  .value!
51
- .reject { |_k, v| v.nil? }
51
+ .compact
52
52
  )
53
53
  end
54
54
 
@@ -49,6 +49,7 @@ module DatadogBackup
49
49
  end
50
50
  rescue RuntimeError => e
51
51
  return {} if e.message.include?('Request failed with error ["404"')
52
+
52
53
  raise e.message
53
54
  end
54
55
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatadogBackup
4
- VERSION = '1.0.4'
4
+ VERSION = '1.0.5'
5
5
  end
@@ -26,6 +26,36 @@ describe DatadogBackup::Cli do
26
26
  allow(cli).to receive(:resource_instances).and_return([dashboards])
27
27
  end
28
28
 
29
+ describe '#initialize_client' do
30
+ subject { described_class.new({ datadog_api_key: 1, datadog_app_key: 1 }).initialize_client }
31
+
32
+ it { is_expected.to be_a(Dogapi::Client) }
33
+
34
+ context 'when the environment variable DATADOG_HOST is set to a custom host like https://api.datadoghq.eu' do
35
+ before do
36
+ stub_const('ENV', 'DATADOG_HOST' => 'https://api.datadoghq.eu')
37
+ end
38
+
39
+ describe 'then #datadog_host is https://api.datadoghq.eu' do
40
+ subject { described_class.new({ datadog_api_key: 1, datadog_app_key: 1 }).initialize_client.datadog_host }
41
+
42
+ it { is_expected.to eq('https://api.datadoghq.eu') }
43
+ end
44
+ end
45
+
46
+ context 'when the environment variable DATADOG_HOST is not set' do
47
+ before do
48
+ stub_const('ENV', {})
49
+ end
50
+
51
+ describe 'then #datadog_host is https://api.datadoghq.eu' do
52
+ subject { described_class.new({ datadog_api_key: 1, datadog_app_key: 1 }).initialize_client.datadog_host }
53
+
54
+ it { is_expected.to eq('https://api.datadoghq.com') }
55
+ end
56
+ end
57
+ end
58
+
29
59
  describe '#backup' do
30
60
  context 'when dashboards are deleted in datadog' do
31
61
  let(:all_boards) do
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'open3'
4
- require 'climate_control'
5
4
  require 'timeout'
6
5
 
7
6
  describe 'bin/datadog_backup' do
@@ -37,23 +36,24 @@ describe 'bin/datadog_backup' do
37
36
  DATADOG_APP_KEY
38
37
  ]
39
38
 
40
- before do
41
- required_vars.each do |v|
42
- ClimateControl.env[v] = v.downcase
43
- end
39
+ env = {}
40
+ required_vars.each do |v|
41
+ env[v] = v.downcase
44
42
  end
45
43
 
44
+
46
45
  required_vars.map do |v|
47
46
  it "dies unless given ENV[#{v}]" do
48
- ClimateControl.env[v] = nil
47
+ stub_const('ENV', env.dup.tap { |h| h.delete(v) })
49
48
  _, status = run_bin('backup')
50
49
  expect(status).not_to be_success
51
50
  end
52
51
  end
53
52
 
54
53
  it 'supplies help' do
54
+ stub_const('ENV', env)
55
55
  out_err, status = run_bin('--help')
56
- expect(out_err).to match(/Usage: datadog_backup/)
56
+ expect(out_err).to match(/Usage: DATADOG_API_KEY=/)
57
57
  expect(status).to be_success
58
58
  end
59
59
  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: 1.0.4
4
+ version: 1.0.5
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-07-08 00:00:00.000000000 Z
12
+ date: 2021-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: amazing_print
@@ -39,20 +39,6 @@ dependencies:
39
39
  - - '='
40
40
  - !ruby/object:Gem::Version
41
41
  version: 1.1.9
42
- - !ruby/object:Gem::Dependency
43
- name: concurrent-ruby-edge
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - '='
47
- - !ruby/object:Gem::Version
48
- version: 0.6.0
49
- type: :runtime
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - '='
54
- - !ruby/object:Gem::Version
55
- version: 0.6.0
56
42
  - !ruby/object:Gem::Dependency
57
43
  name: deepsort
58
44
  requirement: !ruby/object:Gem::Requirement