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.
8 9 10 11 12 |
# File 'lib/uricp/orbit_auth.rb', line 8 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
56 57 58 59 60 61 62 63 |
# File 'lib/uricp/orbit_auth.rb', line 56 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
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/uricp/orbit_auth.rb', line 42 def self.add_auth_token() if ['auth-user'] orbit_credentials = self.new(['auth_uri'], ['auth-user'], ['auth-key']) ['authenticator'] = orbit_credentials.method(:token) elsif ['auth-token'] orbit_token = ['auth-token'] ['authenticator'] = lambda { orbit_token } end .delete('auth-key') .delete('auth-user') .delete('auth-token') end |
.validate_options(options) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/uricp/orbit_auth.rb', line 27 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
14 15 16 17 18 19 20 |
# File 'lib/uricp/orbit_auth.rb', line 14 def storage_url @storage_url || begin authenticate @storage_url end end |
#token ⇒ Object
22 23 24 25 |
# File 'lib/uricp/orbit_auth.rb', line 22 def token authenticate @token end |