Module: Compliance::API::Login::AutomateServer
- Defined in:
- lib/bundles/inspec-compliance/api/login.rb
Class Method Summary collapse
- .login(options) ⇒ Object
- .store_access_token(options, token) ⇒ Object
-
.verify_thor_options(o) ⇒ Object
Automate login requires ‘–ent`, `–user`, and either `–token` or `–dctoken`.
Class Method Details
.login(options) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/bundles/inspec-compliance/api/login.rb', line 31 def self.login() () ['url'] = ['server'] + '/compliance' token = ['dctoken'] || ['token'] store_access_token(, token) end |
.store_access_token(options, token) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/bundles/inspec-compliance/api/login.rb', line 39 def self.store_access_token(, token) token_type = if ['token'] 'usertoken' else 'dctoken' end config = Compliance::Configuration.new config.clean config['automate'] = {} config['automate']['ent'] = ['ent'] config['automate']['token_type'] = token_type config['server'] = ['url'] config['user'] = ['user'] config['insecure'] = ['insecure'] || false config['server_type'] = ['server_type'].to_s config['token'] = token config['version'] = Compliance::API.version(config) config.store config end |
.verify_thor_options(o) ⇒ Object
Automate login requires ‘–ent`, `–user`, and either `–token` or `–dctoken`
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/bundles/inspec-compliance/api/login.rb', line 65 def self.(o) error_msg = [] error_msg.push('Please specify a user using `--user=\'USER\'`') if o['user'].nil? error_msg.push('Please specify an enterprise using `--ent=\'automate\'`') if o['ent'].nil? if o['token'].nil? && o['dctoken'].nil? error_msg.push('Please specify a token using `--token=\'AUTOMATE_TOKEN\'` or `--dctoken=\'DATA_COLLECTOR_TOKEN\'`') end raise ArgumentError, error_msg.join("\n") unless error_msg.empty? end |