Class: OCI::Signer

Inherits:
Object
  • Object
show all
Defined in:
lib/oci/signer.rb

Overview

Used to sign HTTP requests as required by Oracle Cloud Infrastructure.

Constant Summary collapse

SIGNING_STRATEGY_ENUM =

enum to define the signing strategy

[STANDARD = 'standard', OBJECT_STORAGE = 'object_storage']
SIGNATURE_VERSION =

The Oracle Cloud Infrastructure API signature version

"1"

Instance Method Summary collapse

Constructor Details

#initialize(user, fingerprint, tenancy, private_key_file, pass_phrase: nil, private_key_content: nil, signing_strategy: STANDARD) ⇒ Signer

Creates a Signer



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/oci/signer.rb', line 30

def initialize(user, fingerprint, tenancy, private_key_file, pass_phrase:nil, private_key_content:nil, signing_strategy:STANDARD)
  fail 'Missing required parameter user.' unless user
  fail 'Missing required parameter fingerprint.' unless fingerprint
  fail 'Missing required parameter tenancy.' unless tenancy
  fail 'Missing required parameter private_key_file or private_key_content.' unless private_key_file || private_key_content

  @key_id = tenancy + "/" + user + "/" + fingerprint
  @private_key_file = private_key_file
  @private_key_content = private_key_content
  @pass_phrase = pass_phrase
  @signing_strategy = signing_strategy
end

Instance Method Details

#sign(method, uri, headers, body) ⇒ Object

Generates the correct signature and adds it to the headers that are passed in. Also injects any required headers that might be missing.



51
52
53
54
55
56
57
58
59
60
# File 'lib/oci/signer.rb', line 51

def sign(method, uri, headers, body)
  method = method.to_sym.downcase
  uri = URI(uri)
  path = uri.query.nil? ? uri.path : "#{uri.path}?#{uri.query}"
  inject_missing_headers(method, headers, body, uri)
  signature = compute_signature(headers, method, path)
  unless signature.nil?
    inject_authorization_header(headers, method, signature)
  end
end