Class: Uricp::OrbitAuth
- Inherits:
-
Object
- Object
- Uricp::OrbitAuth
- Defined in:
- lib/uricp/orbit_auth.rb
Constant Summary collapse
- AuthenticationFailure =
Class.new(ArgumentError)
Class Method Summary collapse
- .add_auth_to_optionparser(app) ⇒ Object
- .add_auth_token(options) ⇒ Object
- .validate_options(options) ⇒ Object
Instance Method Summary collapse
-
#initialize(auth_uri, auth_id, auth_key) ⇒ OrbitAuth
constructor
A new instance of OrbitAuth.
- #storage_url ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize(auth_uri, auth_id, auth_key) ⇒ OrbitAuth
Returns a new instance of OrbitAuth.
6 7 8 9 10 |
# File 'lib/uricp/orbit_auth.rb', line 6 def initialize(auth_uri, auth_id, auth_key) @auth_uri = auth_uri @auth_id = auth_id @auth_key = auth_key end |
Class Method Details
.add_auth_to_optionparser(app) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/uricp/orbit_auth.rb', line 54 def self.add_auth_to_optionparser(app) app.on('--auth-token AUTH_TOKEN', 'Use AUTH_TOKEN for non-local requests') app.on('--auth-user AUTH_USER', 'Use AUTH_USER for authentication') app.on('--auth-key AUTH_KEY', 'Use AUTH_KEY for authentication') end |
.add_auth_token(options) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/uricp/orbit_auth.rb', line 40 def self.add_auth_token() if ['auth-user'] orbit_credentials = new(['auth_uri'], ['auth-user'], ['auth-key']) ['authenticator'] = orbit_credentials.method(:token) elsif ['auth-token'] orbit_token = ['auth-token'] ['authenticator'] = -> { orbit_token } end .delete('auth-key') .delete('auth-user') .delete('auth-token') end |
.validate_options(options) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/uricp/orbit_auth.rb', line 25 def self.() if ['auth-token'] && (['auth-key'] || ['auth-user']) raise ::OptionParser::NeedlessArgument, 'use either key based or token based authentication' end if ['auth-key'].nil? ^ ['auth-user'].nil? raise ::OptionParser::MissingArgument, "'auth-user' requires 'auth-key'" end if (['auth-token'] || ['auth-user']) && ['auth_uri'].nil? raise ::OptionParser::NeedlessArgument, 'authentication is for http uris only' end end |
Instance Method Details
#storage_url ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/uricp/orbit_auth.rb', line 12 def storage_url @storage_url || begin authenticate @storage_url end end |
#token ⇒ Object
20 21 22 23 |
# File 'lib/uricp/orbit_auth.rb', line 20 def token authenticate @token end |