Class: OCI::BaseSigner
- Inherits:
-
Object
- Object
- OCI::BaseSigner
- Defined in:
- lib/oci/base_signer.rb
Overview
The base class for other classes which are meant to generate a signature
Direct Known Subclasses
Auth::Internal::AuthTokenRequestSigner, Auth::Signers::SecurityTokenSigner, Signer
Constant Summary collapse
- SIGNING_STRATEGY_ENUM =
enum to define the signing strategy
[STANDARD = 'standard'.freeze, OBJECT_STORAGE = 'object_storage'.freeze].freeze
- SIGNATURE_VERSION =
The Oracle Cloud Infrastructure API signature version
'1'.freeze
- GENERIC_HEADERS =
%i[date (request-target) host].freeze
- BODY_HEADERS =
%i[content-length content-type x-content-sha256].freeze
Instance Method Summary collapse
-
#initialize(api_key, private_key_content, pass_phrase: nil, signing_strategy: STANDARD, headers_to_sign_in_all_requests: GENERIC_HEADERS, body_headers_to_sign: BODY_HEADERS) ⇒ BaseSigner
constructor
Creates a BaseSigner.
-
#sign(method, uri, headers, body, operation_signing_strategy = :standard) ⇒ Object
Generates the correct signature and adds it to the headers that are passed in.
Constructor Details
#initialize(api_key, private_key_content, pass_phrase: nil, signing_strategy: STANDARD, headers_to_sign_in_all_requests: GENERIC_HEADERS, body_headers_to_sign: BODY_HEADERS) ⇒ BaseSigner
Creates a BaseSigner
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/oci/base_signer.rb', line 30 def initialize( api_key, private_key_content, pass_phrase: nil, signing_strategy: STANDARD, headers_to_sign_in_all_requests: GENERIC_HEADERS, body_headers_to_sign: BODY_HEADERS ) raise 'Missing required parameter api_key.' unless api_key raise 'Missing required parameter private_key_content.' unless private_key_content @key_id = api_key @private_key_content = private_key_content @pass_phrase = pass_phrase @signing_strategy = signing_strategy @headers_to_sign_all_requests = headers_to_sign_in_all_requests @body_headers_to_sign = body_headers_to_sign @operation_header_mapping = { options: [], get: headers_to_sign_in_all_requests, head: headers_to_sign_in_all_requests, delete: headers_to_sign_in_all_requests, put: headers_to_sign_in_all_requests + body_headers_to_sign, post: headers_to_sign_in_all_requests + body_headers_to_sign, patch: headers_to_sign_in_all_requests + body_headers_to_sign } end |
Instance Method Details
#sign(method, uri, headers, body, operation_signing_strategy = :standard) ⇒ Object
Generates the correct signature and adds it to the headers that are passed in. Also injects any required headers that might be missing.
68 69 70 71 72 73 74 75 |
# File 'lib/oci/base_signer.rb', line 68 def sign(method, uri, headers, body, operation_signing_strategy = :standard) 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, operation_signing_strategy) signature = compute_signature(headers, method, path, operation_signing_strategy) (headers, method, signature, operation_signing_strategy) unless signature.nil? end |