Class: Jungle::Auth
- Inherits:
-
Object
- Object
- Jungle::Auth
- Defined in:
- lib/jungle/client.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(access_key_id = nil, secret_access_key = nil) ⇒ Auth
constructor
Return a new Auth
access_key_id
is an AWS access key (20 bytes long)secret_access_key
is an AWS secret access key used to compute HMAC:SHA1 (40 bytes). -
#security_params(method, path) ⇒ Object
Return the security params for the given request
method
is the HTTP method.
Constructor Details
#initialize(access_key_id = nil, secret_access_key = nil) ⇒ Auth
Return a new Auth
+access_key_id+ is an AWS access key (20 bytes long)
+secret_access_key+ is an AWS secret access key used to compute HMAC:SHA1 (40 bytes)
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'lib/jungle/client.rb', line 397 def initialize(access_key_id = nil, secret_access_key = nil) if access_key_id.nil? && secret_access_key.nil? # get credentials from config file config_file = Auth.config_file || "jungle.yml" config_file_contents = File.open(config_file).read config = YAML::load(config_file_contents) access_key_id = config['jungle']['access_key_id'] secret_access_key = config['jungle']['secret_access_key'] else raise(InvalidArgument, 'access_key_id must be 20 bytes') unless access_key_id.size == 20 raise(InvalidArgument, 'secret_access_key must be 40 bytes') unless secret_access_key.size == 40 end @access_key_id = access_key_id @secret_access_key = secret_access_key end |
Class Method Details
.config_file ⇒ Object
390 391 392 |
# File 'lib/jungle/client.rb', line 390 def self.config_file @config_file end |
.config_file=(file) ⇒ Object
386 387 388 |
# File 'lib/jungle/client.rb', line 386 def self.config_file=(file) @config_file = file end |
Instance Method Details
#security_params(method, path) ⇒ Object
Return the security params for the given request
+method+ is the HTTP method. One of GET, POST, PUT, DELETE
+path+ is the full REST url, e.g. http://example.com/foo?bar=baz
418 419 420 421 422 423 424 425 |
# File 'lib/jungle/client.rb', line 418 def security_params(method, path) params = base_params(method, path) signed_canonical_string = hmac_signature(canonical_string(params), @secret_access_key) params.merge({'signed_canonical_string' => signed_canonical_string, 'auth_string' => "AWS #{@access_key_id}:#{signed_canonical_string}"}) end |