Class: Aspera::Cli::Plugins::Shares
- Defined in:
- lib/aspera/cli/plugins/shares.rb
Overview
Plugin for Aspera Shares v1
Constant Summary collapse
- NODE_API_PATH =
path for node API after base url
'node_api'- ADMIN_API_PATH =
path for node admin after base url
'api/v1'- SAML_IMPORT_MANDATORY =
%w[id name_id].freeze
- SAML_IMPORT_ALLOWED =
%w[email given_name surname].concat(SAML_IMPORT_MANDATORY).freeze
- ACTIONS =
i[health files admin].freeze
- USR_GRP_SETTINGS =
common to users and groups
i[transfer_settings ].freeze
Constants inherited from Base
Base::ALL_OPS, Base::GLOBAL_OPS, Base::INSTANCE_OPS, Base::MAX_ITEMS, Base::MAX_PAGES, Base::REGEX_LOOKUP_ID_BY_FIELD
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #execute_action ⇒ Object
-
#initialize(**_) ⇒ Shares
constructor
A new instance of Shares.
-
#wizard(wizard, app_url) ⇒ Hash
:preset_value, :test_args.
Methods inherited from BasicAuth
#basic_auth_api, #basic_auth_params, declare_options
Methods inherited from Base
#add_manual_header, #config, declare_options, #do_bulk_operation, #entity_execute, #formatter, #instance_identifier, #list_entities_limit_offset_total_count, #lookup_entity_by_field, #options, #persistency, #query_read_delete, #transfer, #value_create_modify
Constructor Details
#initialize(**_) ⇒ Shares
Returns a new instance of Shares.
54 55 56 |
# File 'lib/aspera/cli/plugins/shares.rb', line 54 def initialize(**_) super end |
Class Method Details
.detect(address_or_url) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/aspera/cli/plugins/shares.rb', line 16 def detect(address_or_url) address_or_url = "https://#{address_or_url}" unless address_or_url.match?(%r{^[a-z]{1,6}://}) api = Rest.new(base_url: address_or_url, redirect_max: 1) found = false begin # shall fail: shares requires auth, but we check error message # TODO: use ping instead ? api.read("#{NODE_API_PATH}/app") rescue RestCallError => e found = true if e.response.code.to_s.eql?('401') && e.response.body.eql?('{"error":{"user_message":"API user authentication failed"}}') end return unless found version = 'unknown' test_page = api.call(operation: 'GET', subpath: 'login') if (m = test_page[:http].body.match(/\(v(1\..*)\)/)) version = m[1] end return { version: version, url: address_or_url } end |
Instance Method Details
#execute_action ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/aspera/cli/plugins/shares.rb', line 65 def execute_action command = .get_next_command(ACTIONS, aliases: {repository: :files}) case command when :health nagios = Nagios.new begin res = Rest .new(base_url: "#{options.get_option(:url, mandatory: true)}/#{NODE_API_PATH}") .call( operation: 'GET', subpath: 'ping', headers: {'content-type': Rest::MIME_JSON} ) raise Error, 'Shares not detected' unless res[:http].body.eql?(' ') nagios.add_ok('shares api', 'accessible') rescue StandardError => e nagios.add_critical('API', e.to_s) end return nagios.result when :files api_shares_node = basic_auth_api(NODE_API_PATH) repo_command = .get_next_command(Node::COMMANDS_SHARES) return Node .new(context: context, api: api_shares_node) .execute_action(repo_command) when :admin api_shares_admin = basic_auth_api(ADMIN_API_PATH) admin_command = .get_next_command(i[node share transfer_settings user group].freeze) case admin_command when :node return entity_execute(api: api_shares_admin, entity: 'data/nodes') when :share share_command = .get_next_command(i[ ].concat(ALL_OPS)) case share_command when *ALL_OPS return entity_execute( api: api_shares_admin, entity: 'data/shares', command: share_command, display_fields: %w[id name node_id directory percent_free] ) when :user_permissions, :group_permissions share_id = instance_identifier return entity_execute(api: api_shares_admin, entity: "data/shares/#{share_id}/#{share_command}") end when :transfer_settings xfer_settings_command = .get_next_command(i[show modify]) return entity_execute( api: api_shares_admin, entity: 'data/transfer_settings', command: xfer_settings_command, is_singleton: true ) when :user, :group entity_type = admin_command entities_location = .get_next_command(i[all local ldap saml]) entities_prefix = entities_location.eql?(:all) ? '' : "#{entities_location}_" entities_path = "data/#{entities_prefix}#{entity_type}s" entity_commands = nil case entities_location when :all entity_commands = i[list show delete] entity_commands.concat(USR_GRP_SETTINGS) entity_commands.push(:users) if entity_type.eql?(:group) entity_commands.freeze when :local entity_commands = i[list show delete create modify] entity_commands.push(:users) if entity_type.eql?(:group) entity_commands.freeze when :ldap entity_commands = i[add].freeze when :saml entity_commands = i[import].freeze end entity_verb = .get_next_command(entity_commands) case entity_verb when *ALL_OPS # list, show, delete, create, modify display_fields = entity_type.eql?(:user) ? %w[id username first_name last_name email] : nil display_fields.push(:directory_user) if entity_type.eql?(:user) && entities_location.eql?(:all) return entity_execute( api: api_shares_admin, entity: entities_path, command: entity_verb, display_fields: display_fields ) when *USR_GRP_SETTINGS # transfer_settings, app_authorizations, share_permissions group_id = instance_identifier entities_path = "#{entities_path}/#{group_id}/#{entity_verb}" return entity_execute(api: api_shares_admin, entity: entities_path, is_singleton: !entity_verb.eql?(:share_permissions)) when :import # saml return do_bulk_operation(command: entity_verb, descr: 'user information') do |entity_parameters| entity_parameters = entity_parameters.transform_keys{ |k| k.gsub(/\s+/, '_').downcase} Aspera.assert_type(entity_parameters, Hash) SAML_IMPORT_MANDATORY.each{ |p| raise "missing mandatory field: #{p}" if entity_parameters[p].nil?} entity_parameters.each_key do |p| raise "unsupported field: #{p}, use: #{SAML_IMPORT_ALLOWED.join(',')}" unless SAML_IMPORT_ALLOWED.include?(p) end api_shares_admin.create("#{entities_path}/import", entity_parameters) end when :add # ldap return do_bulk_operation(command: entity_verb, descr: "#{entity_type} name", values: String) do |entity_name| api_shares_admin.create(entities_path, {entity_type=>entity_name}) end when :users # group return entity_execute(api: api_shares_admin, entity: "#{entities_path}/#{instance_identifier}/#{entities_prefix}users") else Aspera.error_unexpected_value(entity_verb) end end end end |
#wizard(wizard, app_url) ⇒ Hash
Returns :preset_value, :test_args.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/aspera/cli/plugins/shares.rb', line 43 def wizard(wizard, app_url) return { preset_value: { url: app_url, username: .get_option(:username, mandatory: true), password: .get_option(:password, mandatory: true) }, test_args: 'files browse /' } end |