Module: VeracodeApiSigning::Utils
- Included in:
- HMACAuth, Plugins::FaradayMiddleware
- Defined in:
- lib/veracode_api_signing/utils.rb
Instance Method Summary collapse
-
#generate_nonce ⇒ String
Nonce string.
-
#get_current_timestamp ⇒ Integer
Current epoch time * 1000 rounded.
-
#get_host_from_url(url) ⇒ String
Just returns the host.
-
#get_path_and_params_from_url(url) ⇒ String
Returns the the path and params formatted, or an empty String.
- #get_scheme_from_url(url) ⇒ Object
- #parsed_url(url) ⇒ Object
Instance Method Details
#generate_nonce ⇒ String
Returns nonce string.
14 15 16 |
# File 'lib/veracode_api_signing/utils.rb', line 14 def generate_nonce SecureRandom.hex(16) end |
#get_current_timestamp ⇒ Integer
Returns current epoch time * 1000 rounded.
9 10 11 |
# File 'lib/veracode_api_signing/utils.rb', line 9 def Time.now.utc.to_i * 1000.round end |
#get_host_from_url(url) ⇒ String
Returns just returns the host.
22 23 24 |
# File 'lib/veracode_api_signing/utils.rb', line 22 def get_host_from_url(url) parsed_url(url).host end |
#get_path_and_params_from_url(url) ⇒ String
Returns the the path and params formatted, or an empty String
34 35 36 37 38 39 40 41 42 |
# File 'lib/veracode_api_signing/utils.rb', line 34 def get_path_and_params_from_url(url) uri = parsed_url(url) path = uri.path params = uri.query return "" if (path.nil? || path.empty?) && params.nil? built_url = URI::HTTPS.build(path: path, query: params) built_url.request_uri end |
#get_scheme_from_url(url) ⇒ Object
49 50 51 |
# File 'lib/veracode_api_signing/utils.rb', line 49 def get_scheme_from_url(url) parsed_url(url).scheme.to_s end |
#parsed_url(url) ⇒ Object
53 54 55 |
# File 'lib/veracode_api_signing/utils.rb', line 53 def parsed_url(url) URI(url) end |