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

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

Constant Summary collapse

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

Constants inherited from Aspera::Cli::Plugin

Aspera::Cli::Plugin::ALL_OPS, Aspera::Cli::Plugin::GLOBAL_OPS, Aspera::Cli::Plugin::INSTANCE_OPS

Instance Method Summary collapse

Methods inherited from BasicAuthPlugin

#basic_auth_api

Methods inherited from Aspera::Cli::Plugin

#config, #entity_action, #entity_command, #format, #options, #transfer

Constructor Details

#initialize(env) ⇒ Bss



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

def initialize(env)
  super(env)
  if env.has_key?(:bss_api)
    @api_bss=env[:bss_api]
  end
end

Instance Method Details

#all_fields(name) ⇒ Object



21
22
23
# File 'lib/aspera/cli/plugins/bss.rb', line 21

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

#execute_actionObject



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 25

def execute_action
  if @api_bss.nil?
    key = self.options.get_option(:password,:mandatory)
    @api_bss=Rest.new(
    base_url: 'https://dashboard.bss.asperasoft.com/platform',
    headers: {cookie: "_dashboard_key=#{key}"})
  end
  command=self.options.get_next_command(ACTIONS)
  case command
  when :subscription
    command=self.options.get_next_command([:find,:show, :instances])
    object='bssSubscriptions'
    case command
    when :find
      query = self.options.get_option(:query,:mandatory) # AOC_ORGANIZATION_QUERY AOC_USER_EMAIL
      value = self.options.get_option(:value,:mandatory)
      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 = self.options.get_option(:id,:mandatory)
      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 = self.options.get_option(:id,:mandatory)
      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