wavefront-cli 6.0.0 → 8.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +12 -7
- data/.travis.yml +4 -5
- data/HISTORY.md +34 -1
- data/README.md +3 -4
- data/lib/wavefront-cli/account.rb +119 -0
- data/lib/wavefront-cli/alert.rb +29 -0
- data/lib/wavefront-cli/base.rb +10 -12
- data/lib/wavefront-cli/cloudintegration.rb +12 -0
- data/lib/wavefront-cli/commands/.rubocop.yml +12 -6
- data/lib/wavefront-cli/commands/account.rb +61 -0
- data/lib/wavefront-cli/commands/alert.rb +1 -0
- data/lib/wavefront-cli/commands/base.rb +1 -1
- data/lib/wavefront-cli/commands/cloudintegration.rb +4 -1
- data/lib/wavefront-cli/commands/proxy.rb +2 -1
- data/lib/wavefront-cli/commands/query.rb +4 -1
- data/lib/wavefront-cli/commands/role.rb +44 -0
- data/lib/wavefront-cli/commands/spy.rb +0 -5
- data/lib/wavefront-cli/commands/usergroup.rb +7 -11
- data/lib/wavefront-cli/commands/write.rb +7 -2
- data/lib/wavefront-cli/config.rb +3 -1
- data/lib/wavefront-cli/controller.rb +6 -66
- data/lib/wavefront-cli/display/account.rb +122 -0
- data/lib/wavefront-cli/display/alert.rb +8 -0
- data/lib/wavefront-cli/display/base.rb +1 -1
- data/lib/wavefront-cli/display/cloudintegration.rb +15 -2
- data/lib/wavefront-cli/display/printer/long.rb +6 -1
- data/lib/wavefront-cli/display/proxy.rb +16 -0
- data/lib/wavefront-cli/display/role.rb +66 -0
- data/lib/wavefront-cli/display/settings.rb +1 -0
- data/lib/wavefront-cli/display/usergroup.rb +18 -14
- data/lib/wavefront-cli/event.rb +2 -0
- data/lib/wavefront-cli/exception_handler.rb +87 -0
- data/lib/wavefront-cli/externallink.rb +4 -6
- data/lib/wavefront-cli/helpers/load_file.rb +1 -1
- data/lib/wavefront-cli/opt_handler.rb +5 -3
- data/lib/wavefront-cli/output/hcl/base.rb +1 -1
- data/lib/wavefront-cli/proxy.rb +5 -0
- data/lib/wavefront-cli/query.rb +13 -7
- data/lib/wavefront-cli/role.rb +54 -0
- data/lib/wavefront-cli/serviceaccount.rb +0 -6
- data/lib/wavefront-cli/spy.rb +0 -8
- data/lib/wavefront-cli/usergroup.rb +8 -8
- data/lib/wavefront-cli/version.rb +1 -1
- data/lib/wavefront-cli/write.rb +33 -11
- data/spec/.rubocop.yml +13 -6
- data/spec/support/minitest_assertions.rb +2 -4
- data/spec/test_mixins/delete.rb +1 -2
- data/spec/wavefront-cli/account_spec.rb +303 -0
- data/spec/wavefront-cli/alert_spec.rb +28 -0
- data/spec/wavefront-cli/cloudintegration_spec.rb +19 -6
- data/spec/wavefront-cli/commands/write_spec.rb +1 -1
- data/spec/wavefront-cli/config_spec.rb +1 -1
- data/spec/wavefront-cli/controller_spec.rb +2 -0
- data/spec/wavefront-cli/event_spec.rb +1 -1
- data/spec/wavefront-cli/output/csv/query_spec.rb +1 -1
- data/spec/wavefront-cli/output/wavefront/query_spec.rb +2 -2
- data/spec/wavefront-cli/query_spec.rb +20 -3
- data/spec/wavefront-cli/role_spec.rb +187 -0
- data/spec/wavefront-cli/serviceaccount_spec.rb +3 -3
- data/spec/wavefront-cli/usergroup_spec.rb +48 -43
- data/spec/wavefront-cli/write_spec.rb +44 -0
- data/wavefront-cli.gemspec +6 -6
- metadata +27 -36
- data/lib/wavefront-cli/commands/user.rb +0 -54
- data/lib/wavefront-cli/display/user.rb +0 -103
- data/lib/wavefront-cli/user.rb +0 -92
- data/spec/wavefront-cli/resources/responses/user-list.json +0 -1
- data/spec/wavefront-cli/user_spec.rb +0 -311
| @@ -0,0 +1,54 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require_relative 'base'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module WavefrontCli
         | 
| 6 | 
            +
              #
         | 
| 7 | 
            +
              # CLI coverage for the v2 'role' API.
         | 
| 8 | 
            +
              #
         | 
| 9 | 
            +
              class Role < WavefrontCli::Base
         | 
| 10 | 
            +
                alias do_permissions do_describe
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def do_create
         | 
| 13 | 
            +
                  wf.create({ name: options[:'<name>'],
         | 
| 14 | 
            +
                              description: options[:description],
         | 
| 15 | 
            +
                              permissions: options[:permission] }.compact)
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                def do_accounts
         | 
| 19 | 
            +
                  things_with_role(:account, options[:'<id>'])
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def do_groups
         | 
| 23 | 
            +
                  things_with_role(:usergroup, options[:'<id>'])
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                def do_give_to
         | 
| 27 | 
            +
                  wf.add_assignees(options[:'<id>'], options[:'<member>'])
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                def do_take_from
         | 
| 31 | 
            +
                  wf.remove_assignees(options[:'<id>'], options[:'<member>'])
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                def do_grant
         | 
| 35 | 
            +
                  wf.grant(options[:'<permission>'], Array(options[:'<id>']))
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                def do_revoke
         | 
| 39 | 
            +
                  wf.revoke(options[:'<permission>'], Array(options[:'<id>']))
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                private
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                # Search for objects of the given type with the given role
         | 
| 45 | 
            +
                #
         | 
| 46 | 
            +
                def things_with_role(thing, role)
         | 
| 47 | 
            +
                  require 'wavefront-sdk/search'
         | 
| 48 | 
            +
                  wfs = Wavefront::Search.new(mk_creds, mk_opts)
         | 
| 49 | 
            +
                  wfs.search(thing,
         | 
| 50 | 
            +
                             conds_to_query(["roles~#{role}"]),
         | 
| 51 | 
            +
                             limit: :all, sort_field: :id)
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
              end
         | 
| 54 | 
            +
            end
         | 
| @@ -173,20 +173,14 @@ module WavefrontCli | |
| 173 173 |  | 
| 174 174 | 
             
                def validate_groups
         | 
| 175 175 | 
             
                  options[:group].each { |g| wf_usergroup_id?(g) }
         | 
| 176 | 
            -
                rescue Wavefront::Exception::InvalidUserGroupId => e
         | 
| 177 | 
            -
                  raise e, 'Invalid usergroup ID'
         | 
| 178 176 | 
             
                end
         | 
| 179 177 |  | 
| 180 178 | 
             
                def validate_tokens
         | 
| 181 179 | 
             
                  options[:usertoken].each { |t| wf_apitoken_id?(t) }
         | 
| 182 | 
            -
                rescue Wavefront::Exception::InvalidApiTokenId => e
         | 
| 183 | 
            -
                  raise e, 'Invalid API token'
         | 
| 184 180 | 
             
                end
         | 
| 185 181 |  | 
| 186 182 | 
             
                def validate_perms
         | 
| 187 183 | 
             
                  options[:permission].each { |p| wf_permission?(p) }
         | 
| 188 | 
            -
                rescue Wavefront::Exception::InvalidPermission => e
         | 
| 189 | 
            -
                  raise e, 'Invalid permission'
         | 
| 190 184 | 
             
                end
         | 
| 191 185 |  | 
| 192 186 | 
             
                def descriptive_name
         | 
    
        data/lib/wavefront-cli/spy.rb
    CHANGED
    
    
| @@ -12,27 +12,27 @@ module WavefrontCli | |
| 12 12 | 
             
                end
         | 
| 13 13 |  | 
| 14 14 | 
             
                alias do_users do_describe
         | 
| 15 | 
            +
                alias do_roles do_describe
         | 
| 15 16 | 
             
                alias do_permissions do_describe
         | 
| 16 17 |  | 
| 17 18 | 
             
                def do_create
         | 
| 18 | 
            -
                  wf.create(name: options[:'<name>'],
         | 
| 19 | 
            -
                            permissions: options[:permission])
         | 
| 19 | 
            +
                  wf.create(name: options[:'<name>'], roleIDs: options[:roleid])
         | 
| 20 20 | 
             
                end
         | 
| 21 21 |  | 
| 22 | 
            -
                def  | 
| 22 | 
            +
                def do_add_to
         | 
| 23 23 | 
             
                  wf.add_users_to_group(options[:'<id>'], options[:'<user>'])
         | 
| 24 24 | 
             
                end
         | 
| 25 25 |  | 
| 26 | 
            -
                def  | 
| 26 | 
            +
                def do_remove_from
         | 
| 27 27 | 
             
                  wf.remove_users_from_group(options[:'<id>'], options[:'<user>'])
         | 
| 28 28 | 
             
                end
         | 
| 29 29 |  | 
| 30 | 
            -
                def  | 
| 31 | 
            -
                  wf. | 
| 30 | 
            +
                def do_add_role
         | 
| 31 | 
            +
                  wf.add_roles_to_group(options[:'<id>'], options[:'<role>'])
         | 
| 32 32 | 
             
                end
         | 
| 33 33 |  | 
| 34 | 
            -
                def  | 
| 35 | 
            -
                  wf. | 
| 34 | 
            +
                def do_remove_role
         | 
| 35 | 
            +
                  wf.remove_roles_from_group(options[:'<id>'], options[:'<role>'])
         | 
| 36 36 | 
             
                end
         | 
| 37 37 |  | 
| 38 38 | 
             
                def import_to_create(raw)
         | 
    
        data/lib/wavefront-cli/write.rb
    CHANGED
    
    | @@ -9,15 +9,16 @@ module WavefrontCli | |
| 9 9 | 
             
              #
         | 
| 10 10 | 
             
              class Write < Base
         | 
| 11 11 | 
             
                attr_reader :fmt
         | 
| 12 | 
            +
             | 
| 12 13 | 
             
                include Wavefront::Mixins
         | 
| 13 14 | 
             
                SPLIT_PATTERN = /\s(?=(?:[^"]|"[^"]*")*$)/.freeze
         | 
| 14 15 |  | 
| 15 16 | 
             
                # rubocop:disable Metrics/AbcSize
         | 
| 16 | 
            -
                def do_point
         | 
| 17 | 
            +
                def do_point(value = options[:'<value>'])
         | 
| 17 18 | 
             
                  tags = tags_to_hash(options[:tag])
         | 
| 18 19 |  | 
| 19 20 | 
             
                  p = { path: options[:'<metric>'],
         | 
| 20 | 
            -
                        value:  | 
| 21 | 
            +
                        value: sane_value(value) }
         | 
| 21 22 |  | 
| 22 23 | 
             
                  p[:tags] = tags unless tags.empty?
         | 
| 23 24 | 
             
                  p[:source] = options[:host] if options[:host]
         | 
| @@ -36,6 +37,31 @@ module WavefrontCli | |
| 36 37 | 
             
                  send_point(make_distribution_point(tags_to_hash(options[:tag])))
         | 
| 37 38 | 
             
                end
         | 
| 38 39 |  | 
| 40 | 
            +
                def do_noise
         | 
| 41 | 
            +
                  loop do
         | 
| 42 | 
            +
                    do_point(random_value(options[:min] || -10, options[:max] || 10))
         | 
| 43 | 
            +
                    sleep(sleep_time)
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                def random_value(min, max)
         | 
| 48 | 
            +
                  return min if min == max
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                  rand(max.to_f - min.to_f) + min.to_f
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                def sane_value(value)
         | 
| 54 | 
            +
                  return value if value.is_a?(Numeric)
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                  raise WavefrontCli::Exception::InvalidValue unless value.is_a?(String)
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                  value.delete('\\').to_f
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                def sleep_time
         | 
| 62 | 
            +
                  options[:interval] ? options[:interval].to_f : 1
         | 
| 63 | 
            +
                end
         | 
| 64 | 
            +
             | 
| 39 65 | 
             
                # rubocop:disable Metrics/AbcSize
         | 
| 40 66 | 
             
                def make_distribution_point(tags)
         | 
| 41 67 | 
             
                  { path: options[:'<metric>'],
         | 
| @@ -141,12 +167,10 @@ module WavefrontCli | |
| 141 167 | 
             
                #
         | 
| 142 168 | 
             
                def process_input_file(data)
         | 
| 143 169 | 
             
                  data.each_with_object([]) do |l, a|
         | 
| 144 | 
            -
                     | 
| 145 | 
            -
             | 
| 146 | 
            -
                     | 
| 147 | 
            -
             | 
| 148 | 
            -
                      next
         | 
| 149 | 
            -
                    end
         | 
| 170 | 
            +
                    a.<< process_line(l)
         | 
| 171 | 
            +
                  rescue WavefrontCli::Exception::UnparseableInput => e
         | 
| 172 | 
            +
                    puts "Bad input. #{e.message}."
         | 
| 173 | 
            +
                    next
         | 
| 150 174 | 
             
                  end
         | 
| 151 175 | 
             
                end
         | 
| 152 176 |  | 
| @@ -167,7 +191,7 @@ module WavefrontCli | |
| 167 191 | 
             
                #
         | 
| 168 192 | 
             
                def read_stdin
         | 
| 169 193 | 
             
                  open_connection
         | 
| 170 | 
            -
                   | 
| 194 | 
            +
                  $stdin.each_line { |l| call_write(process_line(l.strip), false) }
         | 
| 171 195 | 
             
                  close_connection
         | 
| 172 196 | 
             
                rescue SystemExit, Interrupt
         | 
| 173 197 | 
             
                  puts 'ctrl-c. Exiting.'
         | 
| @@ -270,7 +294,6 @@ module WavefrontCli | |
| 270 294 | 
             
                # @raise WavefrontCli::Exception::UnparseableInput if the line
         | 
| 271 295 | 
             
                #   doesn't look right
         | 
| 272 296 | 
             
                #
         | 
| 273 | 
            -
                # rubocop:disable Metrics/CyclomaticComplexity
         | 
| 274 297 | 
             
                # rubocop:disable Metrics/MethodLength
         | 
| 275 298 | 
             
                # rubocop:disable Metrics/AbcSize
         | 
| 276 299 | 
             
                def process_line(line)
         | 
| @@ -293,7 +316,6 @@ module WavefrontCli | |
| 293 316 | 
             
                end
         | 
| 294 317 | 
             
                # rubocop:enable Metrics/AbcSize
         | 
| 295 318 | 
             
                # rubocop:enable Metrics/MethodLength
         | 
| 296 | 
            -
                # rubocop:enable Metrics/CyclomaticComplexity
         | 
| 297 319 |  | 
| 298 320 | 
             
                # We can get tags from the file, from the -T option, or both.
         | 
| 299 321 | 
             
                # Merge them, making the -T win if there is a collision.
         | 
    
        data/spec/.rubocop.yml
    CHANGED
    
    | @@ -1,4 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            +
            AllCops:
         | 
| 3 | 
            +
              NewCops: enable
         | 
| 4 | 
            +
             | 
| 2 5 | 
             
            Metrics/MethodLength:
         | 
| 3 6 | 
             
              Max: 30
         | 
| 4 7 |  | 
| @@ -8,9 +11,13 @@ Metrics/AbcSize: | |
| 8 11 | 
             
            Metrics/ClassLength:
         | 
| 9 12 | 
             
              Max: 300
         | 
| 10 13 |  | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
            Style/ | 
| 16 | 
            -
             | 
| 14 | 
            +
            # Is nothing sacred?
         | 
| 15 | 
            +
            Layout/LineLength:
         | 
| 16 | 
            +
              Max: 80
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            Style/IfUnlessModifier:
         | 
| 19 | 
            +
              Enabled: false # because it wants to make lines >80 chars
         | 
| 20 | 
            +
            Style/StringConcatenation:
         | 
| 21 | 
            +
              Enabled: false
         | 
| 22 | 
            +
            Style/OptionalBooleanParameter:
         | 
| 23 | 
            +
              Enabled: false
         | 
| @@ -105,11 +105,9 @@ module Minitest | |
| 105 105 | 
             
                               "performed as no-ops.\n", err)
         | 
| 106 106 | 
             
                end
         | 
| 107 107 |  | 
| 108 | 
            -
                def assert_repeated_output(msg)
         | 
| 108 | 
            +
                def assert_repeated_output(msg, &block)
         | 
| 109 109 | 
             
                  begin
         | 
| 110 | 
            -
                    out, err = capture_io | 
| 111 | 
            -
                      yield
         | 
| 112 | 
            -
                    end
         | 
| 110 | 
            +
                    out, err = capture_io(&block)
         | 
| 113 111 | 
             
                  rescue SystemExit => e
         | 
| 114 112 | 
             
                    puts e.backtrace
         | 
| 115 113 | 
             
                    p e
         | 
    
        data/spec/test_mixins/delete.rb
    CHANGED
    
    | @@ -15,8 +15,7 @@ module WavefrontCliTest | |
| 15 15 |  | 
| 16 16 | 
             
                  assert_noop(
         | 
| 17 17 | 
             
                    "delete #{id}",
         | 
| 18 | 
            -
                     | 
| 19 | 
            -
                    "#{api_path}/#{id}"
         | 
| 18 | 
            +
                    "uri: DELETE https://default.wavefront.com/api/v2/#{api_path}/#{id}"
         | 
| 20 19 | 
             
                  )
         | 
| 21 20 |  | 
| 22 21 | 
             
                  assert_abort_on_missing_creds("delete #{id}")
         | 
| @@ -0,0 +1,303 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
            # frozen_string_literal: true
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            require_relative '../support/command_base'
         | 
| 5 | 
            +
            require_relative '../../lib/wavefront-cli/account'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            # Ensure 'account' commands produce the correct API calls.
         | 
| 8 | 
            +
            #
         | 
| 9 | 
            +
            class AccountEndToEndTest < EndToEndTest
         | 
| 10 | 
            +
              include WavefrontCliTest::List
         | 
| 11 | 
            +
              include WavefrontCliTest::Delete
         | 
| 12 | 
            +
              include WavefrontCliTest::Describe
         | 
| 13 | 
            +
              include WavefrontCliTest::Search
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              def test_role_add_to
         | 
| 16 | 
            +
                quietly do
         | 
| 17 | 
            +
                  assert_cmd_posts("role add to #{id} #{roles.join(' ')}",
         | 
| 18 | 
            +
                                   "/api/v2/account/#{id}/addRoles",
         | 
| 19 | 
            +
                                   roles.to_json)
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                assert_invalid_id("role add to #{invalid_id} #{roles.first}")
         | 
| 23 | 
            +
                assert_invalid_id("role add to #{id} #{invalid_role}")
         | 
| 24 | 
            +
                assert_abort_on_missing_creds("role add to #{id} #{roles.last}")
         | 
| 25 | 
            +
                assert_usage("role add to #{roles.first}")
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              def test_role_remove_from
         | 
| 29 | 
            +
                quietly do
         | 
| 30 | 
            +
                  assert_cmd_posts("role remove from #{id} #{roles.join(' ')}",
         | 
| 31 | 
            +
                                   "/api/v2/account/#{id}/removeRoles",
         | 
| 32 | 
            +
                                   roles.to_json)
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                assert_invalid_id("role remove from #{invalid_id} #{roles.first}")
         | 
| 36 | 
            +
                assert_abort_on_missing_creds("role remove from #{id} #{roles.last}")
         | 
| 37 | 
            +
                assert_usage("role remove from #{roles.first}")
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
              def test_add_group_to
         | 
| 41 | 
            +
                assert_repeated_output("Added '#{id}' to '#{groups.first}'.") do
         | 
| 42 | 
            +
                  assert_cmd_posts("group add to #{id} #{groups.first}",
         | 
| 43 | 
            +
                                   "/api/v2/account/#{id}/addUserGroups",
         | 
| 44 | 
            +
                                   [groups.first].to_json)
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                assert_invalid_id("group add to #{id} #{invalid_group}")
         | 
| 48 | 
            +
                assert_invalid_id("group add to #{invalid_id} #{groups.first}")
         | 
| 49 | 
            +
                assert_abort_on_missing_creds("group add to #{id} #{groups.last}")
         | 
| 50 | 
            +
                assert_usage("group add to #{groups.first}")
         | 
| 51 | 
            +
              end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
              def test_remove_group_from
         | 
| 54 | 
            +
                assert_repeated_output("Removed '#{id}' from '#{groups.first}', " \
         | 
| 55 | 
            +
                                       "'#{groups.last}'.") do
         | 
| 56 | 
            +
                  assert_cmd_posts("group remove from #{id} #{groups.join(' ')}",
         | 
| 57 | 
            +
                                   "/api/v2/account/#{id}/removeUserGroups",
         | 
| 58 | 
            +
                                   groups.to_json)
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                assert_invalid_id("group remove from #{id} #{invalid_group}")
         | 
| 62 | 
            +
                assert_invalid_id("group remove from #{invalid_id} #{groups.first}")
         | 
| 63 | 
            +
                assert_abort_on_missing_creds("group remove from #{id} #{groups.last}")
         | 
| 64 | 
            +
                assert_usage("group remove from #{groups.first}")
         | 
| 65 | 
            +
              end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
              def test_business_functions
         | 
| 68 | 
            +
                quietly do
         | 
| 69 | 
            +
                  assert_cmd_gets("business functions #{id}",
         | 
| 70 | 
            +
                                  "/api/v2/account/#{id}/businessFunctions")
         | 
| 71 | 
            +
                end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                assert_noop("business functions #{id}",
         | 
| 74 | 
            +
                            'uri: GET https://default.wavefront.com/api/v2/account/' \
         | 
| 75 | 
            +
                            "#{id}/businessFunctions")
         | 
| 76 | 
            +
                assert_invalid_id("business functions #{invalid_id}")
         | 
| 77 | 
            +
                assert_abort_on_missing_creds("business functions #{id}")
         | 
| 78 | 
            +
                assert_usage('business functions')
         | 
| 79 | 
            +
              end
         | 
| 80 | 
            +
             | 
| 81 | 
            +
              def test_grant_to
         | 
| 82 | 
            +
                assert_repeated_output("Granted '#{permission}' to '#{id}'.") do
         | 
| 83 | 
            +
                  assert_cmd_posts("grant #{permission} to #{id}",
         | 
| 84 | 
            +
                                   "/api/v2/account/grant/#{permission}",
         | 
| 85 | 
            +
                                   [id].to_json)
         | 
| 86 | 
            +
                end
         | 
| 87 | 
            +
             | 
| 88 | 
            +
                assert_invalid_id("grant #{permission} to #{invalid_id}")
         | 
| 89 | 
            +
                assert_abort_on_missing_creds("grant #{permission} to #{id}")
         | 
| 90 | 
            +
                assert_usage("grant #{permission}")
         | 
| 91 | 
            +
              end
         | 
| 92 | 
            +
             | 
| 93 | 
            +
              def test_revoke_from
         | 
| 94 | 
            +
                assert_repeated_output("Revoked '#{permission}' from '#{id}'.") do
         | 
| 95 | 
            +
                  assert_cmd_posts("revoke #{permission} from #{id}",
         | 
| 96 | 
            +
                                   "/api/v2/account/revoke/#{permission}",
         | 
| 97 | 
            +
                                   [id].to_json)
         | 
| 98 | 
            +
                end
         | 
| 99 | 
            +
             | 
| 100 | 
            +
                out, err = capture_io do
         | 
| 101 | 
            +
                  assert_raises(SystemExit) do
         | 
| 102 | 
            +
                    wf.new("account revoke #{invalid_permission} from #{id}".split)
         | 
| 103 | 
            +
                  end
         | 
| 104 | 
            +
                end
         | 
| 105 | 
            +
             | 
| 106 | 
            +
                assert_empty out
         | 
| 107 | 
            +
                assert_equal("'made_up_permission' is not a valid Wavefront permission.",
         | 
| 108 | 
            +
                             err.strip)
         | 
| 109 | 
            +
             | 
| 110 | 
            +
                assert_invalid_id("revoke #{permission} from #{invalid_id}")
         | 
| 111 | 
            +
                assert_abort_on_missing_creds("revoke #{permission} from #{id}")
         | 
| 112 | 
            +
                assert_usage("revoke #{permission}")
         | 
| 113 | 
            +
              end
         | 
| 114 | 
            +
             | 
| 115 | 
            +
              def test_roles
         | 
| 116 | 
            +
                assert_repeated_output("'#{id}' has no roles.") do
         | 
| 117 | 
            +
                  assert_cmd_gets("roles #{id}", "/api/v2/account/#{id}", [])
         | 
| 118 | 
            +
                end
         | 
| 119 | 
            +
             | 
| 120 | 
            +
                assert_abort_on_missing_creds("roles #{id}")
         | 
| 121 | 
            +
                assert_invalid_id("roles #{invalid_id}")
         | 
| 122 | 
            +
                assert_usage('roles')
         | 
| 123 | 
            +
              end
         | 
| 124 | 
            +
             | 
| 125 | 
            +
              def test_add_ingestionpolicy_to
         | 
| 126 | 
            +
                assert_repeated_output("Added '#{policy}' to '#{id}'.") do
         | 
| 127 | 
            +
                  assert_cmd_posts("ingestionpolicy add to #{id} #{policy}",
         | 
| 128 | 
            +
                                   '/api/v2/account/addingestionpolicy',
         | 
| 129 | 
            +
                                   { ingestionPolicyId: policy,
         | 
| 130 | 
            +
                                     accounts: [id] }.to_json)
         | 
| 131 | 
            +
                end
         | 
| 132 | 
            +
             | 
| 133 | 
            +
                assert_invalid_id("ingestionpolicy add to #{invalid_id} #{policy}")
         | 
| 134 | 
            +
                assert_invalid_id("ingestionpolicy add to #{id} #{invalid_policy}")
         | 
| 135 | 
            +
                assert_abort_on_missing_creds("ingestionpolicy add to #{id} #{policy}")
         | 
| 136 | 
            +
                assert_usage("ingestionpolicy add to #{policy}")
         | 
| 137 | 
            +
              end
         | 
| 138 | 
            +
             | 
| 139 | 
            +
              def test_remove_ingestionpolicy_remove
         | 
| 140 | 
            +
                assert_repeated_output("Removed '#{policy}' from '#{id}'.") do
         | 
| 141 | 
            +
                  assert_cmd_posts("ingestionpolicy remove from #{id} #{policy}",
         | 
| 142 | 
            +
                                   '/api/v2/account/removeingestionpolicies',
         | 
| 143 | 
            +
                                   { ingestionPolicyId: policy,
         | 
| 144 | 
            +
                                     accounts: [id] }.to_json)
         | 
| 145 | 
            +
                end
         | 
| 146 | 
            +
             | 
| 147 | 
            +
                assert_invalid_id("ingestionpolicy remove from #{invalid_id} #{policy}")
         | 
| 148 | 
            +
                assert_invalid_id("ingestionpolicy remove from #{id} #{invalid_policy}")
         | 
| 149 | 
            +
                assert_abort_on_missing_creds("ingestionpolicy remove from #{id} #{policy}")
         | 
| 150 | 
            +
                assert_usage("ingestionpolicy remove from #{policy}")
         | 
| 151 | 
            +
              end
         | 
| 152 | 
            +
             | 
| 153 | 
            +
              def test_ingestionpolicy
         | 
| 154 | 
            +
                assert_repeated_output("'#{id}' has no ingestion policy.") do
         | 
| 155 | 
            +
                  assert_cmd_gets("ingestionpolicy #{id}", "/api/v2/account/#{id}", [])
         | 
| 156 | 
            +
                end
         | 
| 157 | 
            +
             | 
| 158 | 
            +
                assert_abort_on_missing_creds("ingestionpolicy #{id}")
         | 
| 159 | 
            +
                assert_invalid_id("ingestionpolicy #{invalid_id}")
         | 
| 160 | 
            +
                assert_usage('ingestionpolicy')
         | 
| 161 | 
            +
              end
         | 
| 162 | 
            +
             | 
| 163 | 
            +
              def test_groups
         | 
| 164 | 
            +
                assert_repeated_output("'#{id}' does not belong to any groups.") do
         | 
| 165 | 
            +
                  assert_cmd_gets("groups #{id}", "/api/v2/account/#{id}", [])
         | 
| 166 | 
            +
                end
         | 
| 167 | 
            +
             | 
| 168 | 
            +
                assert_invalid_id("groups #{invalid_id}")
         | 
| 169 | 
            +
                assert_abort_on_missing_creds("groups #{id}")
         | 
| 170 | 
            +
                assert_usage('groups')
         | 
| 171 | 
            +
              end
         | 
| 172 | 
            +
             | 
| 173 | 
            +
              def test_permissions
         | 
| 174 | 
            +
                assert_repeated_output("'#{id}' does not have any permissions " \
         | 
| 175 | 
            +
                                       'directly attached.') do
         | 
| 176 | 
            +
                  assert_cmd_gets("permissions #{id}", "/api/v2/account/#{id}", [])
         | 
| 177 | 
            +
                end
         | 
| 178 | 
            +
             | 
| 179 | 
            +
                assert_abort_on_missing_creds("permissions #{id}")
         | 
| 180 | 
            +
                assert_invalid_id("permissions #{invalid_id}")
         | 
| 181 | 
            +
                assert_usage('permissions')
         | 
| 182 | 
            +
              end
         | 
| 183 | 
            +
             | 
| 184 | 
            +
              def test_invite_with_group
         | 
| 185 | 
            +
                expected_body = [{ emailAddress: id,
         | 
| 186 | 
            +
                                   userGroups: [groups.first],
         | 
| 187 | 
            +
                                   groups: [] }].to_json
         | 
| 188 | 
            +
             | 
| 189 | 
            +
                assert_repeated_output("Sent invitation to '#{id}'.") do
         | 
| 190 | 
            +
                  assert_cmd_posts("invite user -g #{groups.first} #{id}",
         | 
| 191 | 
            +
                                   '/api/v2/account/user/invite',
         | 
| 192 | 
            +
                                   expected_body)
         | 
| 193 | 
            +
                end
         | 
| 194 | 
            +
             | 
| 195 | 
            +
                assert_noop("invite user -g #{groups.first} #{id}",
         | 
| 196 | 
            +
                            'uri: POST https://default.wavefront.com/api/v2/account/user' \
         | 
| 197 | 
            +
                            '/invite',
         | 
| 198 | 
            +
                            "body: #{expected_body}")
         | 
| 199 | 
            +
                assert_invalid_id("invite user -g #{groups.first} #{invalid_id}")
         | 
| 200 | 
            +
                assert_abort_on_missing_creds("invite user -g #{groups.first} #{id}")
         | 
| 201 | 
            +
                assert_usage('invite user')
         | 
| 202 | 
            +
              end
         | 
| 203 | 
            +
             | 
| 204 | 
            +
              def test_invite_with_role_and_policy
         | 
| 205 | 
            +
                expected_body = [{ emailAddress: id,
         | 
| 206 | 
            +
                                   roles: roles,
         | 
| 207 | 
            +
                                   ingestionPolicyId: policy,
         | 
| 208 | 
            +
                                   groups: [] }].to_json
         | 
| 209 | 
            +
             | 
| 210 | 
            +
                assert_repeated_output("Sent invitation to '#{id}'.") do
         | 
| 211 | 
            +
                  assert_cmd_posts(
         | 
| 212 | 
            +
                    "invite user -r #{roles.join(' -r ')} -i #{policy} #{id}",
         | 
| 213 | 
            +
                    '/api/v2/account/user/invite',
         | 
| 214 | 
            +
                    expected_body
         | 
| 215 | 
            +
                  )
         | 
| 216 | 
            +
                end
         | 
| 217 | 
            +
             | 
| 218 | 
            +
                assert_noop("invite user -r #{roles.join(' -r ')} -i #{policy} #{id}",
         | 
| 219 | 
            +
                            'uri: POST https://default.wavefront.com/api/v2/account/user' \
         | 
| 220 | 
            +
                            '/invite',
         | 
| 221 | 
            +
                            "body: #{expected_body}")
         | 
| 222 | 
            +
                assert_invalid_id("invite user -m #{permission} #{invalid_id}")
         | 
| 223 | 
            +
                assert_abort_on_missing_creds("invite user -m #{permission} #{id}")
         | 
| 224 | 
            +
                assert_usage('invite user')
         | 
| 225 | 
            +
              end
         | 
| 226 | 
            +
             | 
| 227 | 
            +
              def test_validate
         | 
| 228 | 
            +
                cmd = "validate #{user_list.join(' ')}"
         | 
| 229 | 
            +
             | 
| 230 | 
            +
                quietly do
         | 
| 231 | 
            +
                  assert_cmd_posts(cmd,
         | 
| 232 | 
            +
                                   '/api/v2/account/validateAccounts',
         | 
| 233 | 
            +
                                   user_list.to_json,
         | 
| 234 | 
            +
                                   IO.read(RES_DIR + 'responses' + 'user-validate.json'))
         | 
| 235 | 
            +
                end
         | 
| 236 | 
            +
             | 
| 237 | 
            +
                assert_noop(cmd,
         | 
| 238 | 
            +
                            'uri: POST https://default.wavefront.com/api/v2/account' \
         | 
| 239 | 
            +
                            '/validateAccounts',
         | 
| 240 | 
            +
                            "body: #{user_list.to_json}")
         | 
| 241 | 
            +
                assert_abort_on_missing_creds(cmd)
         | 
| 242 | 
            +
                assert_usage('validate')
         | 
| 243 | 
            +
              end
         | 
| 244 | 
            +
             | 
| 245 | 
            +
              private
         | 
| 246 | 
            +
             | 
| 247 | 
            +
              def id
         | 
| 248 | 
            +
                'someone@example.com'
         | 
| 249 | 
            +
              end
         | 
| 250 | 
            +
             | 
| 251 | 
            +
              def invalid_id
         | 
| 252 | 
            +
                'bad' * 200
         | 
| 253 | 
            +
              end
         | 
| 254 | 
            +
             | 
| 255 | 
            +
              def cmd_word
         | 
| 256 | 
            +
                'account'
         | 
| 257 | 
            +
              end
         | 
| 258 | 
            +
             | 
| 259 | 
            +
              def groups
         | 
| 260 | 
            +
                %w[2659191e-aad4-4302-a94e-9667e1517127
         | 
| 261 | 
            +
                   abcdef12-1234-abcd-1234-abcdef012345]
         | 
| 262 | 
            +
              end
         | 
| 263 | 
            +
             | 
| 264 | 
            +
              def invalid_group
         | 
| 265 | 
            +
                '__bad_group__'
         | 
| 266 | 
            +
              end
         | 
| 267 | 
            +
             | 
| 268 | 
            +
              def roles
         | 
| 269 | 
            +
                %w[87654321-aad4-4302-a94e-9667e1517127
         | 
| 270 | 
            +
                   12345678-1234-abcd-1234-abcdef012345]
         | 
| 271 | 
            +
              end
         | 
| 272 | 
            +
             | 
| 273 | 
            +
              def invalid_role
         | 
| 274 | 
            +
                '__bad_role__'
         | 
| 275 | 
            +
              end
         | 
| 276 | 
            +
             | 
| 277 | 
            +
              def list_response
         | 
| 278 | 
            +
                { items: [{ identifier: 'user1@example.com' },
         | 
| 279 | 
            +
                          { identifier: 'user2@example.com' }] }.to_json
         | 
| 280 | 
            +
              end
         | 
| 281 | 
            +
             | 
| 282 | 
            +
              def permission
         | 
| 283 | 
            +
                'alerts_management'
         | 
| 284 | 
            +
              end
         | 
| 285 | 
            +
             | 
| 286 | 
            +
              def invalid_permission
         | 
| 287 | 
            +
                'made_up_permission'
         | 
| 288 | 
            +
              end
         | 
| 289 | 
            +
             | 
| 290 | 
            +
              def user_list
         | 
| 291 | 
            +
                %w[someone@example.com
         | 
| 292 | 
            +
                   sa:testsysacct
         | 
| 293 | 
            +
                   no-such-thing]
         | 
| 294 | 
            +
              end
         | 
| 295 | 
            +
             | 
| 296 | 
            +
              def policy
         | 
| 297 | 
            +
                'test-policy-1579802191234'
         | 
| 298 | 
            +
              end
         | 
| 299 | 
            +
             | 
| 300 | 
            +
              def invalid_policy
         | 
| 301 | 
            +
                '__some_nonsense_or_other__'
         | 
| 302 | 
            +
              end
         | 
| 303 | 
            +
            end
         |