Class: Aspera::Cli::Plugins::Bss

Inherits:
BasicAuthPlugin show all
Defined in:
lib/aspera/cli/plugins/bss.rb

Constant Summary collapse

ACTIONS =
%i[subscription].freeze
FIELDS =
{
  'bssSubscriptions' => %w[id name termVolumeGb termMonths trial startDate endDate plan renewalType chargeAgreementNumber customerName]
}.freeze

Constants inherited from Aspera::Cli::Plugin

Aspera::Cli::Plugin::ALL_OPS, Aspera::Cli::Plugin::GLOBAL_OPS, Aspera::Cli::Plugin::INIT_PARAMS, Aspera::Cli::Plugin::INSTANCE_OPS, Aspera::Cli::Plugin::MAX_ITEMS, Aspera::Cli::Plugin::MAX_PAGES, Aspera::Cli::Plugin::REGEX_LOOKUP_ID_BY_FIELD

Instance Method Summary collapse

Methods inherited from BasicAuthPlugin

#basic_auth_api, #basic_auth_params, declare_options

Methods inherited from Aspera::Cli::Plugin

declare_generic_options, #do_bulk_operation, #entity_action, #entity_command, #init_params, #instance_identifier, #old_query_read_delete, #query_option, #query_read_delete, #value_create_modify

Constructor Details

#initialize(**env) ⇒ Bss

Returns a new instance of Bss.



15
16
17
# File 'lib/aspera/cli/plugins/bss.rb', line 15

def initialize(**env)
  super
end

Instance Method Details

#all_fields(name) ⇒ Object



19
20
21
# File 'lib/aspera/cli/plugins/bss.rb', line 19

def all_fields(name)
  return FIELDS[name].join(' ')
end

#execute_actionObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/aspera/cli/plugins/bss.rb', line 23

def execute_action
  if @api_bss.nil?
    key = options.get_option(:password, mandatory: true)
    @api_bss = Rest.new(
      base_url: 'https://dashboard.bss.asperasoft.com/platform',
      headers: {cookie: "_dashboard_key=#{key}"})
  end
  command = options.get_next_command(ACTIONS)
  case command
  when :subscription
    command = options.get_next_command(%i[find show instances])
    object = 'bssSubscriptions'
    case command
    when :find
      query = options.get_option(:query, mandatory: true) # AOC_ORGANIZATION_QUERY AOC_USER_EMAIL
      value = value_create_modify(command: command)
      request = {
        'variables' => {'filter' => {'key' => query, 'value' => value}},
        'query'     => "query($filter: BssSubscriptionFilter!) {#{object}(filter: $filter) { #{all_fields('bssSubscriptions')} } }"
      }
      result = @api_bss.create('graphql', request)[:data]
      # give fields to keep order
      return {type: :object_list, data: result['data'][object], fields: FIELDS['bssSubscriptions']}
    when :show
      id = instance_identifier
      request = {
        'variables' => {'id' => id},
        'query'     => "query($id: ID!) {#{object}(id: $id) { #{all_fields('bssSubscriptions')} roleAssignments(uniqueSubjectId: true) { id subjectId } " \
          'instances { id state planId serviceId ssmSubscriptionId entitlement { id } aocOrganization { id subdomainName name status tier urlId trialExpiresAt ' \
          'users(organizationAdmin: true) { id name email atsAdmin subscriptionAdmin } } } } }'
      }
      result = @api_bss.create('graphql', request)[:data]['data'][object].first
      result.delete('instances')
      return {type: :single_object, data: result}
    when :instances
      id = instance_identifier
      request = {
        'variables' => {'id' => id},
        'query'     => "query($id: ID!) {#{object}(id: $id) { aocOrganization { id subdomainName name status tier urlId trialExpiresAt } } } }"
      }
      result = @api_bss.create('graphql', request)[:data]['data'][object].first
      return {type: :object_list, data: result['instances']}
    end
  end
end