wavefront-sdk 5.0.1 → 5.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +32 -0
  3. data/.rubocop.yml +7 -37
  4. data/.travis.yml +4 -4
  5. data/HISTORY.md +19 -0
  6. data/lib/wavefront-sdk/cloudintegration.rb +31 -0
  7. data/lib/wavefront-sdk/core/api.rb +2 -2
  8. data/lib/wavefront-sdk/core/exception.rb +2 -0
  9. data/lib/wavefront-sdk/credentials.rb +28 -9
  10. data/lib/wavefront-sdk/defs/version.rb +3 -1
  11. data/lib/wavefront-sdk/derivedmetric.rb +2 -4
  12. data/lib/wavefront-sdk/distribution.rb +2 -0
  13. data/lib/wavefront-sdk/ingestionpolicy.rb +4 -0
  14. data/lib/wavefront-sdk/notificant.rb +0 -2
  15. data/lib/wavefront-sdk/paginator/post.rb +1 -1
  16. data/lib/wavefront-sdk/proxy.rb +10 -0
  17. data/lib/wavefront-sdk/savedsearch.rb +4 -0
  18. data/lib/wavefront-sdk/support/mixins.rb +1 -1
  19. data/lib/wavefront-sdk/support/parse_time.rb +1 -1
  20. data/lib/wavefront-sdk/user.rb +4 -4
  21. data/lib/wavefront-sdk/validators.rb +13 -0
  22. data/lib/wavefront-sdk/writers/core.rb +2 -2
  23. data/spec/.rubocop.yml +9 -40
  24. data/spec/support/minitest_assertions.rb +5 -11
  25. data/spec/test_mixins/general.rb +6 -0
  26. data/spec/wavefront-sdk/alert_spec.rb +0 -2
  27. data/spec/wavefront-sdk/cloudintegration_spec.rb +38 -0
  28. data/spec/wavefront-sdk/core/api_spec.rb +9 -1
  29. data/spec/wavefront-sdk/core/logger_spec.rb +3 -3
  30. data/spec/wavefront-sdk/credentials_spec.rb +5 -4
  31. data/spec/wavefront-sdk/dashboard_spec.rb +0 -2
  32. data/spec/wavefront-sdk/misc_spec.rb +18 -0
  33. data/spec/wavefront-sdk/notificant_spec.rb +27 -0
  34. data/spec/wavefront-sdk/proxy_spec.rb +6 -0
  35. data/spec/wavefront-sdk/validators_spec.rb +6 -0
  36. data/spec/wavefront-sdk/writers/core_spec.rb +1 -1
  37. data/wavefront-sdk.gemspec +6 -6
  38. metadata +20 -20
  39. data/spec/test_mixins/update_keys.rb +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4f8e6e99d7124c4a1654be470312d6749c475d0cfbc23b33c72962d13fe0e1e
4
- data.tar.gz: d2f43cb3bf00ddacce6cd24e92578d9876cfcbfa6b05cbdf6db68a5fbba732d9
3
+ metadata.gz: 0fc4311b2322403ef715d9a62c5f84712accb5ed1ee9e5350e0bbcb6237fe631
4
+ data.tar.gz: f2fb99d1f35d601a619f0e7135f8b22ea0b22d0697752af5a265132d867216bb
5
5
  SHA512:
6
- metadata.gz: b01743fb3be2eaa72ff58f857eac4f640354ec6264436e764b0f5852b987a54f16d5fde57235b29b3c7ed5623ebca1894d467da1624f56fb8a185c5becded20c
7
- data.tar.gz: 81953b85f6638f802619f8481f70a0e98129f26139ed06d70c28ce100b266dfd13fa1279112698e13a7ecf74364d781608ad3e20feb9c4451ef21070e511516a
6
+ metadata.gz: a2e79e3ce013f9fcdc3e28d7e111c586746e65ae341b0187b44b3908d29d81ae9aa8f0723d8eeea239c27f9976b232aa2acf2ecda92b797b0c45f25dc9e9c612
7
+ data.tar.gz: 20f3124667013b4f1212df12c6e04c235e7dfda24e3f0ac9a87ba4c4a4884d96d11f1a855d460f8026d65d8a35754d7a2f5d0bf705f13456dea066d0faee7822
@@ -0,0 +1,32 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+ runs-on: ubuntu-latest
19
+ strategy:
20
+ matrix:
21
+ ruby-version: [2.4.10, 2.5.8, 2.6.6, 2.7.2]
22
+ steps:
23
+ - uses: actions/checkout@v2
24
+ - name: Set up Ruby
25
+ uses: ruby/setup-ruby@v1
26
+ with:
27
+ ruby-version: ${{ matrix.ruby-version }}
28
+ bundler-cache: true
29
+ - name: Install dependencies
30
+ run: bundle install
31
+ - name: Run tests
32
+ run: bundle exec rake
@@ -2,47 +2,17 @@
2
2
 
3
3
  AllCops:
4
4
  TargetRubyVersion: 2.4
5
+ NewCops: enable
5
6
 
6
7
  Metrics/ClassLength:
7
8
  Max: 150
8
9
 
9
- # New cops
10
- #
11
- Lint/RaiseException:
12
- Enabled: true
13
- Lint/StructNewOverride:
14
- Enabled: true
15
- Style/ExponentialNotation:
16
- Enabled: true
17
- Style/HashEachMethods:
18
- Enabled: true
19
- Style/HashTransformKeys:
20
- Enabled: true
21
- Style/HashTransformValues:
22
- Enabled: true
23
- Layout/EmptyLinesAroundAttributeAccessor:
24
- Enabled: true
25
- Layout/SpaceAroundMethodCallOperator:
26
- Enabled: true
27
- Style/SlicingWithRange:
28
- Enabled: true
29
- Lint/DeprecatedOpenSSLConstant:
30
- Enabled: true
31
- Lint/MixedRegexpCaptureTypes:
32
- Enabled: true
33
- Style/RedundantRegexpCharacterClass:
34
- Enabled: true
35
- Style/RedundantRegexpEscape:
36
- Enabled: true
37
- Style/AccessorGrouping:
38
- Enabled: true
39
- Style/BisectedAttrAccessor:
40
- Enabled: true
41
- Style/RedundantAssignment:
42
- Enabled: true
43
- Style/RedundantFetchBlock:
44
- Enabled: true
45
-
46
10
  # Is nothing sacred?
47
11
  Layout/LineLength:
48
12
  Max: 80
13
+
14
+ Style/StringConcatenation:
15
+ Enabled: false
16
+
17
+ Style/OptionalBooleanParameter:
18
+ Enabled: false
@@ -2,9 +2,9 @@ language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
4
  - 2.4.9
5
- - 2.5.7
6
- - 2.6.5
7
- - 2.7.0
5
+ - 2.5.8
6
+ - 2.6.6
7
+ - 2.7.2
8
8
  before_install: gem install bundler --no-document
9
9
  deploy:
10
10
  provider: rubygems
@@ -14,7 +14,7 @@ deploy:
14
14
  on:
15
15
  tags: true
16
16
  repo: snltd/wavefront-sdk
17
- ruby: 2.6.5
17
+ ruby: 2.6.6
18
18
  notifications:
19
19
  email: false
20
20
  slack:
data/HISTORY.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.3.1 (2020-12-11)
4
+ * Fix error when renaming ingestion policies, and improve testing which should
5
+ have caught the problem in the first place.
6
+
7
+ ## 5.3.0 (2020-10-10)
8
+ * Add `Wavefront::Proxy#shutdown` which can shut down a proxy via the API.
9
+
10
+ ## 5.2.1 (2020-09-18)
11
+ * Remove necessity for user to `require 'pathname'`
12
+
13
+ ## 5.2.0 (2020-09-03)
14
+ * Add `:raise_on_no_profile` option to `Wavefront::Credentials` constructor
15
+ options. If this is true and a specific config stanza is requested but not
16
+ found, `Wavefront::Exception::MissingConfigProfile` is thrown.
17
+
18
+ ## 5.1.0 (2020-08-15)
19
+ * Add `create_aws_external_id`, `delete_aws_external_id`, and
20
+ `confirm_aws_external_id` methods to `Wavefront::CloudIntegration`.
21
+
3
22
  ## 5.0.1 (2020-07-08)
4
23
  * Reinstate `Wavefront::Role#grant` and `Wavefront::Role#revoke`, which were
5
24
  accidentally removed prior to release of 5.0.0.
@@ -101,5 +101,36 @@ module Wavefront
101
101
  wf_cloudintegration_id?(id)
102
102
  api.post([id, 'undelete'].uri_concat)
103
103
  end
104
+
105
+ # POST /api/v2/cloudintegration/awsExternalIdCreate an external id
106
+ # @return [Wavefront::Response]
107
+ #
108
+ def create_aws_external_id
109
+ api.post('awsExternalId', nil, 'application/json')
110
+ end
111
+
112
+ # DELETE /api/v2/cloudintegration/awsExternalId/{id}DELETEs an external id
113
+ # that was created by Wavefront
114
+ # @param id [String] AWS external ID
115
+ # @return [Wavefront::Response]
116
+ #
117
+ def delete_aws_external_id(external_id)
118
+ wf_aws_external_id?(external_id)
119
+ api.delete(['awsExternalId', external_id].uri_concat)
120
+ end
121
+
122
+ # GET /api/v2/cloudintegration/awsExternalId/{id}GETs (confirms) a valid
123
+ # external id that was created by Wavefront
124
+ # @param id [String] AWS external ID
125
+ # @return [Wavefront::Response]
126
+ #
127
+ def confirm_aws_external_id(external_id)
128
+ wf_aws_external_id?(external_id)
129
+ api.get(['awsExternalId', external_id].uri_concat)
130
+ end
131
+
132
+ def update_keys
133
+ %i[name]
134
+ end
104
135
  end
105
136
  end
@@ -81,9 +81,9 @@ module Wavefront
81
81
  (time.to_f * 1000).round
82
82
  end
83
83
 
84
- # doing a PUT to update an object requires only a certain subset of
84
+ # Doing a PUT to update an object requires only a certain subset of
85
85
  # the keys returned by #describe(). This method takes the
86
- # existing description of an object and turns it into a new has
86
+ # existing description of an object and turns it into a new hash
87
87
  # which can be PUT.
88
88
  #
89
89
  # @param old [Hash] a hash of the existing object
@@ -12,6 +12,7 @@ module Wavefront
12
12
  class InvalidAlertId < RuntimeError; end
13
13
  class InvalidAlertSeverity < RuntimeError; end
14
14
  class InvalidApiTokenId < RuntimeError; end
15
+ class InvalidAwsExternalId < RuntimeError; end
15
16
  class InvalidConfigFile < RuntimeError; end
16
17
  class InvalidCloudIntegrationId < RuntimeError; end
17
18
  class InvalidDashboardId < RuntimeError; end
@@ -54,6 +55,7 @@ module Wavefront
54
55
  class InvalidUserGroupId < RuntimeError; end
55
56
  class InvalidVersion < RuntimeError; end
56
57
  class InvalidWebhookId < RuntimeError; end
58
+ class MissingConfigProfile < RuntimeError; end
57
59
  class NetworkTimeout < RuntimeError; end
58
60
  class NotImplemented < RuntimeError; end
59
61
  class SocketError < RuntimeError; end
@@ -31,11 +31,16 @@ module Wavefront
31
31
  # @param options [Hash] keys may be 'file', which
32
32
  # specifies a config file which will be loaded and parsed. If
33
33
  # no file is supplied, those listed above will be used.;
34
- # and/or 'profile' which select a profile section from 'file'
34
+ # and/or 'profile' which select a profile section from 'file'.
35
+ # Specify the key :raise_noprofile to have an exception thrown
36
+ # if a given profile cannot be found. Otherwise that is ignored and
37
+ # options are built from other sources.
35
38
  #
36
39
  def initialize(options = {})
37
- raw = load_from_file(cred_files(options), options[:profile] ||
38
- 'default')
40
+ @raise_noprofile = options[:raise_on_no_profile] || false
41
+ raw = load_from_file(real_files(cred_files(options)),
42
+ options[:profile] || 'default')
43
+
39
44
  populate(env_override(raw))
40
45
  end
41
46
 
@@ -80,31 +85,45 @@ module Wavefront
80
85
  end
81
86
  end
82
87
 
88
+ def real_files(files)
89
+ files.select { |f| f.exist? && f.file? }
90
+ end
91
+
83
92
  # @param files [Array][Pathname] a list of ini-style config files
84
93
  # @param profile [String] a profile name
94
+ # @param disallow_missing [Bool] whether or not to raise an exception if
95
+ # we are given a profile but can't find it.
85
96
  # @return [Hash] the given profile from the given list of files.
86
97
  # If multiple files match, the last one will be used
87
98
  #
88
99
  def load_from_file(files, profile = 'default')
89
100
  ret = {}
101
+ profiles_found = conf_files_found = 0
90
102
 
91
103
  files.each do |f|
92
- next unless f.exist? && f.file?
93
-
94
104
  ret = load_profile(f, profile)
105
+ conf_files_found += 1
106
+ profiles_found += 1 unless ret.empty?
95
107
  ret[:file] = f
96
108
  end
97
109
 
110
+ raise_on_missing_profile(profile, profiles_found, conf_files_found)
98
111
  ret
99
112
  end
100
113
 
101
- # Load in an (optionally) given section of an ini-style
102
- # configuration file not there, we don't consider that an error.
114
+ def raise_on_missing_profile(profile, profiles_found, conf_files_found)
115
+ return true unless @raise_noprofile
116
+ return true unless profiles_found.zero? && conf_files_found.positive?
117
+
118
+ raise Wavefront::Exception::MissingConfigProfile, profile
119
+ end
120
+
121
+ # Load in an (optionally) given section of an ini-style configuration
122
+ # file. If the section is not there, we don't consider that an error.
103
123
  #
104
124
  # @param file [Pathname] the file to read
105
125
  # @param profile [String] the section in the config to read
106
- # @return [Hash] options loaded from file. Each key becomes a
107
- # symbol
126
+ # @return [Hash] options loaded from file. Each key becomes a symbol
108
127
  #
109
128
  def load_profile(file, profile = 'default')
110
129
  IniFile.load(file)[profile].each_with_object({}) do |(k, v), memo|
@@ -1,4 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- WF_SDK_VERSION = '5.0.1'
3
+ require 'pathname'
4
+
5
+ WF_SDK_VERSION = '5.3.1'
4
6
  WF_SDK_LOCATION = Pathname.new(__dir__).parent.parent.parent
@@ -112,11 +112,9 @@ module Wavefront
112
112
  wf_derivedmetric_id?(id)
113
113
  end
114
114
 
115
- private
116
-
117
115
  def update_keys
118
- %i[id name query tags additionalInformation
119
- includeObsoleteMetrics processRateMinutes minutes]
116
+ %i[name query tags additionalInformation includeObsoleteMetrics
117
+ processRateMinutes minutes]
120
118
  end
121
119
  end
122
120
  end
@@ -65,6 +65,7 @@ module Wavefront
65
65
  raise Wavefront::Exception::InvalidDistribution
66
66
  end
67
67
 
68
+ # rubocop:disable Metrics/AbcSize
68
69
  def dist_hash(dist)
69
70
  dist.dup.tap do |d|
70
71
  d[:interval] = distribution_interval(dist)
@@ -75,6 +76,7 @@ module Wavefront
75
76
  d[:opttags] = tags_or_nothing(opts[:tags])
76
77
  end
77
78
  end
79
+ # rubocop:enable Metrics/AbcSize
78
80
 
79
81
  def distribution_timestamp(dist)
80
82
  parse_time(dist.fetch(:ts, Time.now))
@@ -81,5 +81,9 @@ module Wavefront
81
81
  api.put(id, hash_for_update(describe(id).response, body),
82
82
  'application/json')
83
83
  end
84
+
85
+ def update_keys
86
+ %i[name]
87
+ end
84
88
  end
85
89
  end
@@ -83,8 +83,6 @@ module Wavefront
83
83
  api.post(['test', id].uri_concat, nil)
84
84
  end
85
85
 
86
- private
87
-
88
86
  def update_keys
89
87
  %i[id contentType method description title template triggers
90
88
  recipient customHttpHeaders emailSubject isHtmlContent]
@@ -50,7 +50,7 @@ module Wavefront
50
50
  def body_as(desired, args, index = 1)
51
51
  body = args[index]
52
52
 
53
- return args if body.class == desired
53
+ return args if body.instance_of?(desired)
54
54
 
55
55
  args[index] = body_as_json(body)
56
56
  args
@@ -86,5 +86,15 @@ module Wavefront
86
86
  wf_proxy_id?(id)
87
87
  api.put(id, payload)
88
88
  end
89
+
90
+ # Shutdown a proxy. Requires proxy >=5.x. Might not be effective if you
91
+ # have something like systemd or SMF restarting a failed proxy.
92
+ # @param id [String] ID of the proxy
93
+ # @return [Wavefront::Response]
94
+ #
95
+ def shutdown(id)
96
+ wf_proxy_id?(id)
97
+ api.put(id, { shutdown: true }, 'application/json')
98
+ end
89
99
  end
90
100
  end
@@ -80,5 +80,9 @@ module Wavefront
80
80
  api.get(['type', entitytype].uri_concat, offset: offset,
81
81
  limit: limit)
82
82
  end
83
+
84
+ def update_keys
85
+ %i[query entityType]
86
+ end
83
87
  end
84
88
  end
@@ -23,7 +23,7 @@ module Wavefront
23
23
  # @raise Wavefront::InvalidTimestamp
24
24
  #
25
25
  def parse_time(time, in_ms = false)
26
- return relative_time(time, in_ms) if time.to_s =~ /^[\-+]/
26
+ return relative_time(time, in_ms) if time.to_s.match?(/^[\-+]/)
27
27
 
28
28
  ParseTime.new(time, in_ms).parse!
29
29
  end
@@ -34,7 +34,7 @@ module Wavefront
34
34
  # @return [Fixnum] timestamp
35
35
  #
36
36
  def parse_time_string
37
- return t.to_i if t =~ /^\d+$/
37
+ return t.to_i if t.match?(/^\d+$/)
38
38
 
39
39
  @t = Time.parse("#{t} #{Time.now.getlocal.zone}")
40
40
  parse_time_time
@@ -297,6 +297,10 @@ module Wavefront
297
297
  raise NoMethodError
298
298
  end
299
299
 
300
+ def update_keys
301
+ %i[identifier groups userGroups]
302
+ end
303
+
300
304
  private
301
305
 
302
306
  def response_looks_right?(body_obj)
@@ -311,9 +315,5 @@ module Wavefront
311
315
 
312
316
  items.fetch(:message, 'no message from API')
313
317
  end
314
-
315
- def update_keys
316
- %i[identifier groups userGroups]
317
- end
318
318
  end
319
319
  end
@@ -626,6 +626,19 @@ module Wavefront
626
626
 
627
627
  raise Wavefront::Exception::InvalidRoleId, id
628
628
  end
629
+
630
+ # Ensure the given argument is a valid AWS external ID, used in the AWS
631
+ # cloud integration.
632
+ # @param id [String] the external ID to validate
633
+ # @return true if the external ID is valid
634
+ # @raise Wavefront::Exception::InvalidAwsExternalId if the external ID is
635
+ # not valid
636
+ #
637
+ def wf_aws_external_id?(id)
638
+ return true if id.is_a?(String) && id =~ /^[a-z0-9A-Z]{16}$/
639
+
640
+ raise Wavefront::Exception::InvalidAwsExternalId, id
641
+ end
629
642
  end
630
643
  # rubocop:enable Metrics/ModuleLength
631
644
  end
@@ -138,8 +138,8 @@ module Wavefront
138
138
  end
139
139
 
140
140
  def log_invalid_point(rawpoint, exception)
141
- logger.log('Invalid point, skipping.', :info)
142
- logger.log(exception.class, :info)
141
+ logger.log('Invalid point, skipping.', :warn)
142
+ logger.log(exception.class, :warn)
143
143
  logger.log(format('Invalid point: %<rawpoint>s (%<message>s)',
144
144
  rawpoint: rawpoint,
145
145
  message: exception.to_s), :debug)
@@ -1,54 +1,23 @@
1
- # Offense count: 64
1
+ AllCops:
2
+ NewCops: enable
3
+
2
4
  Metrics/AbcSize:
3
5
  Max: 64
4
6
 
5
- # Offense count: 5
6
7
  # Configuration parameters: CountComments.
7
8
  Metrics/ClassLength:
8
9
  Max: 400
9
10
 
10
- # Offense count: 46
11
11
  # Configuration parameters: CountComments, ExcludedMethods.
12
12
  Metrics/MethodLength:
13
13
  Max: 39
14
14
 
15
- # New cops
16
- #
17
- Lint/RaiseException:
18
- Enabled: true
19
- Lint/StructNewOverride:
20
- Enabled: true
21
- Style/ExponentialNotation:
22
- Enabled: true
23
- Style/HashEachMethods:
24
- Enabled: true
25
- Style/HashTransformKeys:
26
- Enabled: true
27
- Style/HashTransformValues:
28
- Enabled: true
29
- Layout/EmptyLinesAroundAttributeAccessor:
30
- Enabled: true
31
- Layout/SpaceAroundMethodCallOperator:
32
- Enabled: true
33
- Style/SlicingWithRange:
34
- Enabled: true
35
- Lint/DeprecatedOpenSSLConstant:
36
- Enabled: true
37
- Lint/MixedRegexpCaptureTypes:
38
- Enabled: true
39
- Style/RedundantRegexpCharacterClass:
40
- Enabled: true
41
- Style/RedundantRegexpEscape:
42
- Enabled: true
43
- Style/AccessorGrouping:
44
- Enabled: true
45
- Style/BisectedAttrAccessor:
46
- Enabled: true
47
- Style/RedundantAssignment:
48
- Enabled: true
49
- Style/RedundantFetchBlock:
50
- Enabled: true
51
-
52
15
  # Is nothing sacred?
53
16
  Layout/LineLength:
54
17
  Max: 80
18
+
19
+ Style/StringConcatenation:
20
+ Enabled: false
21
+
22
+ Style/OptionalBooleanParameter:
23
+ Enabled: false
@@ -95,18 +95,12 @@ module Minitest
95
95
  end
96
96
 
97
97
  def header_lookup(type)
98
- ctype = case type
99
- when :plain
100
- 'text/plain'
101
- when :json
102
- 'application/json'
103
- when :octet
104
- 'application/octet-stream'
105
- when :form
106
- 'application/x-www-form-urlencoded'
107
- end
98
+ ctypes = { plain: 'text/plain',
99
+ json: 'application/json',
100
+ octet: 'application/octet-stream',
101
+ form: 'application/x-www-form-urlencoded' }
108
102
 
109
- { 'Content-Type': ctype, Accept: 'application/json' }
103
+ { 'Content-Type': ctypes[type], Accept: 'application/json' }
110
104
  end
111
105
  end
112
106
  end
@@ -65,6 +65,7 @@ module WavefrontTest
65
65
  module Update
66
66
  def test_update
67
67
  [payload].flatten.each do |p|
68
+ # passes payload through as-is
68
69
  assert_puts("/api/v2/#{api_class}/#{id}", p) do
69
70
  wf.update(id, p, false)
70
71
  end
@@ -73,6 +74,11 @@ module WavefrontTest
73
74
  assert_raises(ArgumentError) { wf.update }
74
75
  end
75
76
  end
77
+
78
+ def test_update_keys
79
+ assert_instance_of Array, wf.update_keys
80
+ assert(wf.update_keys.all? { |k| k.is_a?(Symbol) })
81
+ end
76
82
  end
77
83
 
78
84
  module Clone
@@ -4,7 +4,6 @@
4
4
  require_relative '../spec_helper'
5
5
  require_relative '../test_mixins/acl'
6
6
  require_relative '../test_mixins/tag'
7
- require_relative '../test_mixins/update_keys'
8
7
  require_relative '../test_mixins/general'
9
8
 
10
9
  # Unit tests for Alert class
@@ -20,7 +19,6 @@ class WavefrontAlertTest < WavefrontTestBase
20
19
  include WavefrontTest::List
21
20
  include WavefrontTest::Tag
22
21
  include WavefrontTest::Update
23
- include WavefrontTest::UpdateKeys
24
22
 
25
23
  def test_snooze
26
24
  assert_posts("/api/v2/alert/#{id}/snooze") { wf.snooze(id) }
@@ -37,6 +37,36 @@ class WavefrontCloudIntegrationTest < WavefrontTestBase
37
37
  assert_raises(ArgumentError) { wf.disable }
38
38
  end
39
39
 
40
+ def test_create_aws_external_id
41
+ assert_posts('/api/v2/cloudintegration/awsExternalId', nil, :json) do
42
+ wf.create_aws_external_id
43
+ end
44
+ end
45
+
46
+ def test_delete_aws_external_id
47
+ assert_deletes("/api/v2/cloudintegration/awsExternalId/#{external_id}") do
48
+ wf.delete_aws_external_id(external_id)
49
+ end
50
+
51
+ assert_raises(Wavefront::Exception::InvalidAwsExternalId) do
52
+ wf.delete_aws_external_id(invalid_external_id)
53
+ end
54
+
55
+ assert_raises(ArgumentError) { wf.delete_aws_external_id }
56
+ end
57
+
58
+ def test_confirm_aws_external_id
59
+ assert_gets("/api/v2/cloudintegration/awsExternalId/#{external_id}") do
60
+ wf.confirm_aws_external_id(external_id)
61
+ end
62
+
63
+ assert_raises(Wavefront::Exception::InvalidAwsExternalId) do
64
+ wf.confirm_aws_external_id(invalid_external_id)
65
+ end
66
+
67
+ assert_raises(ArgumentError) { wf.confirm_aws_external_id }
68
+ end
69
+
40
70
  private
41
71
 
42
72
  def id
@@ -62,4 +92,12 @@ class WavefrontCloudIntegrationTest < WavefrontTestBase
62
92
  def api_class
63
93
  'cloudintegration'
64
94
  end
95
+
96
+ def external_id
97
+ 'HqOM4mru5svd3uFp'
98
+ end
99
+
100
+ def invalid_external_id
101
+ '__nonsense__'
102
+ end
65
103
  end
@@ -23,7 +23,15 @@ class WavefrontCoreApiTest < MiniTest::Test
23
23
 
24
24
  def test_hash_for_update
25
25
  wf.instance_variable_set('@update_keys', %i[k1 k2])
26
- body = { k1: 'ov1', k2: 'ov2', k3: 'ov3' }
26
+ body = { k1: 'ov1',
27
+ k2: 'ov2',
28
+ k3: 'ov3',
29
+ customerId: 'test',
30
+ creatorId: 'someone@example.com',
31
+ createUserId: 'someone@example.com',
32
+ updateUserId: 'someone@example.com',
33
+ createdEpochMillis: 1_607_691_387_023,
34
+ updatedEpochMillis: 1_607_691_387_023 }
27
35
  upd = { k2: 'nv1' }
28
36
  assert_equal({ k1: 'ov1', k2: 'nv1' }, wf.hash_for_update(body, upd))
29
37
  end
@@ -41,21 +41,21 @@ class WavefrontLoggerTest < MiniTest::Test
41
41
  end
42
42
 
43
43
  def test_log_logger_debug
44
- l = Wavefront::Logger.new(logger: Logger.new(STDOUT))
44
+ l = Wavefront::Logger.new(logger: Logger.new($stdout))
45
45
  out, err = capture_subprocess_io { l.log('my message', :debug) }
46
46
  assert_match(/DEBUG -- : my message$/, out)
47
47
  assert_empty(err)
48
48
  end
49
49
 
50
50
  def test_log_logger_info
51
- l = Wavefront::Logger.new(logger: Logger.new(STDOUT))
51
+ l = Wavefront::Logger.new(logger: Logger.new($stdout))
52
52
  out, err = capture_subprocess_io { l.log('my message', :info) }
53
53
  assert_match(/INFO -- : my message$/, out)
54
54
  assert_empty(err)
55
55
  end
56
56
 
57
57
  def test_log_logger_error
58
- l = Wavefront::Logger.new(logger: Logger.new(STDOUT))
58
+ l = Wavefront::Logger.new(logger: Logger.new($stdout))
59
59
  out, err = capture_subprocess_io { l.log('my message', :error) }
60
60
  assert_match(/ERROR -- : my message$/, out)
61
61
  assert_empty(err)
@@ -60,9 +60,11 @@ end
60
60
  # Test individual methods. We must override the constructor to do
61
61
  # this.
62
62
  #
63
+ # rubocop:disable Lint/MissingSuper
63
64
  class Giblets < Wavefront::Credentials
64
65
  def initialize; end
65
66
  end
67
+ # rubocop:enable Lint/MissingSuper
66
68
 
67
69
  # And here are the tests
68
70
  #
@@ -153,10 +155,9 @@ class GibletsTest < MiniTest::Test
153
155
  end
154
156
 
155
157
  def test_load_from_file
156
- assert_equal({},
157
- wf.load_from_file(
158
- [Pathname.new('/no/file/1'), Pathname.new('/no/file/2')]
159
- ))
158
+ assert_raises(Wavefront::Exception::InvalidConfigFile) do
159
+ wf.load_from_file([Pathname.new('/nofile/1'), Pathname.new('/nofile/2')])
160
+ end
160
161
 
161
162
  assert_equal({ file: CONF1 }, wf.load_from_file([CONF1], 'noprofile'))
162
163
 
@@ -4,7 +4,6 @@
4
4
  require_relative '../spec_helper'
5
5
  require_relative '../test_mixins/acl'
6
6
  require_relative '../test_mixins/tag'
7
- require_relative '../test_mixins/update_keys'
8
7
  require_relative '../test_mixins/general'
9
8
 
10
9
  # Unit tests for dashboard class
@@ -18,7 +17,6 @@ class WavefrontDashboardTest < WavefrontTestBase
18
17
  include WavefrontTest::List
19
18
  include WavefrontTest::Tag
20
19
  include WavefrontTest::Update
21
- include WavefrontTest::UpdateKeys
22
20
 
23
21
  def test_favorite
24
22
  assert_posts("/api/v2/dashboard/#{id}/favorite") { wf.favorite(id) }
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../spec_helper'
5
+ require_relative '../../lib/wavefront-sdk/defs/version'
6
+
7
+ # Tests for things that aren't in the SDK itself.
8
+ #
9
+ class WavefrontMiscTest < MiniTest::Test
10
+ # Check the latest version mentioned in the changelog is the version the SDK
11
+ # defines itself as.
12
+ #
13
+ def test_version_vs_history
14
+ history_file = WF_SDK_LOCATION + 'HISTORY.md'
15
+ history_vers = IO.read(history_file).match(/^## (\d+\.\d+\.\d+) \(/)
16
+ assert_equal(WF_SDK_VERSION, history_vers.captures.first)
17
+ end
18
+ end
@@ -10,6 +10,7 @@ class WavefrontNotificantTest < WavefrontTestBase
10
10
  include WavefrontTest::List
11
11
  include WavefrontTest::Delete
12
12
  include WavefrontTest::Describe
13
+ include WavefrontTest::Update
13
14
 
14
15
  def test_test
15
16
  assert_posts("/api/v2/notificant/test/#{id}") { wf.test(id) }
@@ -29,4 +30,30 @@ class WavefrontNotificantTest < WavefrontTestBase
29
30
  def invalid_id
30
31
  '---rubbish---'
31
32
  end
33
+
34
+ def payload
35
+ JSON.parse(%(
36
+ {
37
+ "method": "PAGERDUTY",
38
+ "id": "PE0BEkf4r123yooO",
39
+ "contentType": "",
40
+ "description": "Test target",
41
+ "customerId": "sysdef",
42
+ "title": "Terraform Test Target",
43
+ "recipient": "12345678910111213141516171819202",
44
+ "creatorId": "someone@example.com",
45
+ "updaterId": "someone@example.com",
46
+ "createdEpochMillis": 1604513812010,
47
+ "updatedEpochMillis": 1604513812010,
48
+ "template": "{}",
49
+ "triggers": [
50
+ "ALERT_OPENED",
51
+ "ALERT_RESOLVED"
52
+ ],
53
+ "customHttpHeaders": {},
54
+ "emailSubject": "",
55
+ "isHtmlContent": false
56
+ }
57
+ ), symbolize_names: true)
58
+ end
32
59
  end
@@ -21,6 +21,12 @@ class WavefrontProxyTest < WavefrontTestBase
21
21
  assert_raises(ArgumentError) { wf.rename }
22
22
  end
23
23
 
24
+ def test_shutdown
25
+ assert_puts("/api/v2/proxy/#{id}", { shutdown: true }.to_json, :json) do
26
+ wf.shutdown(id)
27
+ end
28
+ end
29
+
24
30
  private
25
31
 
26
32
  def api_class
@@ -411,4 +411,10 @@ class WavefrontValidatorsTest < MiniTest::Test
411
411
  bad = %w[fa312fb-5ff4-420d-862d-5d6d99ed6bcf thing 123]
412
412
  good_and_bad('wf_role_id?', 'InvalidRoleId', good, bad)
413
413
  end
414
+
415
+ def test_wf_aws_external_id
416
+ good = %w[ah5Z9dkr46jbvLtJ HqOM4mru5svd3uFp c1lBxILCBNxLKdx9]
417
+ bad = %w[h5Z9dkr46jbvLtJ HqOM4mru5svd3uFp3 c!lBx!LC*NxLKdx*]
418
+ good_and_bad('wf_aws_external_id?', 'InvalidAwsExternalId', good, bad)
419
+ end
414
420
  end
@@ -22,7 +22,7 @@ class TestClassNoTags
22
22
  end
23
23
 
24
24
  def logger
25
- Logger.new(STDOUT)
25
+ Logger.new($stdout)
26
26
  end
27
27
 
28
28
  def manage_conn
@@ -23,16 +23,16 @@ Gem::Specification.new do |gem|
23
23
  gem.bindir = 'bin'
24
24
 
25
25
  gem.add_dependency 'addressable', '~> 2.7'
26
- gem.add_dependency 'faraday', '~> 1.0'
26
+ gem.add_dependency 'faraday', '~> 1.1'
27
27
  gem.add_dependency 'inifile', '~> 3.0'
28
28
  gem.add_dependency 'map', '~> 6.6'
29
29
 
30
- gem.add_development_dependency 'minitest', '~> 5.11'
30
+ gem.add_development_dependency 'minitest', '~> 5.14'
31
31
  gem.add_development_dependency 'rake', '~> 13.0'
32
- gem.add_development_dependency 'rubocop', '~> 0.87'
33
- gem.add_development_dependency 'simplecov', '~> 0.16'
34
- gem.add_development_dependency 'spy', '~> 1.0.0'
35
- gem.add_development_dependency 'webmock', '~> 3.7'
32
+ gem.add_development_dependency 'rubocop', '1.0'
33
+ gem.add_development_dependency 'simplecov', '~> 0.18'
34
+ gem.add_development_dependency 'spy', '1.0.0'
35
+ gem.add_development_dependency 'webmock', '~> 3.9'
36
36
  gem.add_development_dependency 'yard', '~> 0.9'
37
37
 
38
38
  gem.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wavefront-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.1
4
+ version: 5.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Fisher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-08 00:00:00.000000000 Z
11
+ date: 2020-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.0'
33
+ version: '1.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.0'
40
+ version: '1.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: inifile
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '5.11'
75
+ version: '5.14'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '5.11'
82
+ version: '5.14'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -98,42 +98,42 @@ dependencies:
98
98
  name: rubocop
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: '0.87'
103
+ version: '1.0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: '0.87'
110
+ version: '1.0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0.16'
117
+ version: '0.18'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0.16'
124
+ version: '0.18'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: spy
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - '='
130
130
  - !ruby/object:Gem::Version
131
131
  version: 1.0.0
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - '='
137
137
  - !ruby/object:Gem::Version
138
138
  version: 1.0.0
139
139
  - !ruby/object:Gem::Dependency
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '3.7'
145
+ version: '3.9'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '3.7'
152
+ version: '3.9'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: yard
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -171,6 +171,7 @@ extensions: []
171
171
  extra_rdoc_files: []
172
172
  files:
173
173
  - ".codeclimate.yml"
174
+ - ".github/workflows/ruby.yml"
174
175
  - ".gitignore"
175
176
  - ".rubocop.yml"
176
177
  - ".travis.yml"
@@ -254,7 +255,6 @@ files:
254
255
  - spec/test_mixins/acl.rb
255
256
  - spec/test_mixins/general.rb
256
257
  - spec/test_mixins/tag.rb
257
- - spec/test_mixins/update_keys.rb
258
258
  - spec/wavefront-sdk/account_spec.rb
259
259
  - spec/wavefront-sdk/alert_spec.rb
260
260
  - spec/wavefront-sdk/api_mixins/user_mixins_spec.rb
@@ -276,6 +276,7 @@ files:
276
276
  - spec/wavefront-sdk/message_spec.rb
277
277
  - spec/wavefront-sdk/metric_helper_spec.rb
278
278
  - spec/wavefront-sdk/metric_spec.rb
279
+ - spec/wavefront-sdk/misc_spec.rb
279
280
  - spec/wavefront-sdk/notificant_spec.rb
280
281
  - spec/wavefront-sdk/paginator/base_spec.rb
281
282
  - spec/wavefront-sdk/paginator/post_spec.rb
@@ -336,8 +337,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
336
337
  - !ruby/object:Gem::Version
337
338
  version: '0'
338
339
  requirements: []
339
- rubyforge_project:
340
- rubygems_version: 2.7.7
340
+ rubygems_version: 3.0.8
341
341
  signing_key:
342
342
  specification_version: 4
343
343
  summary: SDK for Wavefront API v2
@@ -352,7 +352,6 @@ test_files:
352
352
  - spec/test_mixins/acl.rb
353
353
  - spec/test_mixins/general.rb
354
354
  - spec/test_mixins/tag.rb
355
- - spec/test_mixins/update_keys.rb
356
355
  - spec/wavefront-sdk/account_spec.rb
357
356
  - spec/wavefront-sdk/alert_spec.rb
358
357
  - spec/wavefront-sdk/api_mixins/user_mixins_spec.rb
@@ -374,6 +373,7 @@ test_files:
374
373
  - spec/wavefront-sdk/message_spec.rb
375
374
  - spec/wavefront-sdk/metric_helper_spec.rb
376
375
  - spec/wavefront-sdk/metric_spec.rb
376
+ - spec/wavefront-sdk/misc_spec.rb
377
377
  - spec/wavefront-sdk/notificant_spec.rb
378
378
  - spec/wavefront-sdk/paginator/base_spec.rb
379
379
  - spec/wavefront-sdk/paginator/post_spec.rb
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module WavefrontTest
4
- #
5
- # include this into any class which has update keys
6
- #
7
- module UpdateKeys
8
- def test_update_keys
9
- assert_instance_of Array, wf.update_keys
10
- assert(wf.update_keys.all? { |k| k.is_a?(Symbol) })
11
- end
12
- end
13
- end