Class: VagrantPlugins::S3Auth::Util::Authenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-s3auth/util/authenticator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAuthenticator

Returns a new instance of Authenticator.



17
18
19
20
21
22
# File 'lib/vagrant-s3auth/util/authenticator.rb', line 17

def initialize
  @access_key = ENV['AWS_ACCESS_KEY_ID']
  @secret_key = ENV['AWS_SECRET_ACCESS_KEY']

  ensure_credentials
end

Class Method Details

.sign(url, method) ⇒ Object



13
14
15
# File 'lib/vagrant-s3auth/util/authenticator.rb', line 13

def self.sign(url, method)
  new.sign(url, method)
end

Instance Method Details

#sign(url, method) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vagrant-s3auth/util/authenticator.rb', line 24

def sign(url, method)
  now = CGI.rfc1123_date(Time.now)
  message = "#{method}\n\n\n#{now}\n#{url.path}"
  signature = Base64.strict_encode64(
    OpenSSL::HMAC.digest('sha1', @secret_key, message))

  {
    date: now,
    authorization: "AWS #{@access_key}:#{signature}"
  }
end