Class: FilestackSecurity
- Inherits:
-
Object
- Object
- FilestackSecurity
- Defined in:
- lib/filestack/models/filestack_security.rb
Overview
This class represents a Filestack Security object that you must passed in with your calls if your account has security enabled. You can manage your Filestack app's security and secret by logging into the Filestack Dev portal.
Constant Summary
- DEFAULT_EXPIRY =
3600
Instance Attribute Summary collapse
-
#policy ⇒ Object
Returns the value of attribute policy.
-
#signature ⇒ Object
Returns the value of attribute signature.
Instance Method Summary collapse
-
#generate(secret, options) ⇒ Object
Generate the security policy and signature given a string and options.
-
#initialize(secret, options: {}) ⇒ FilestackSecurity
constructor
Initialize FilestackSecurity object.
-
#sign_url(url) ⇒ String
Sign the URL by appending policy and signature URL parameters.
Constructor Details
#initialize(secret, options: {}) ⇒ FilestackSecurity
Initialize FilestackSecurity object
37 38 39 |
# File 'lib/filestack/models/filestack_security.rb', line 37 def initialize(secret, options: {}) generate(secret, ) end |
Instance Attribute Details
#policy ⇒ Object
Returns the value of attribute policy
14 15 16 |
# File 'lib/filestack/models/filestack_security.rb', line 14 def policy @policy end |
#signature ⇒ Object
Returns the value of attribute signature
14 15 16 |
# File 'lib/filestack/models/filestack_security.rb', line 14 def signature @signature end |
Instance Method Details
#generate(secret, options) ⇒ Object
Generate the security policy and signature given a string and options
45 46 47 48 49 |
# File 'lib/filestack/models/filestack_security.rb', line 45 def generate(secret, ) policy_json = create_policy_string() @policy = Base64.urlsafe_encode64(policy_json) @signature = OpenSSL::HMAC.hexdigest('sha256', secret, policy) end |
#sign_url(url) ⇒ String
Sign the URL by appending policy and signature URL parameters
56 57 58 |
# File 'lib/filestack/models/filestack_security.rb', line 56 def sign_url(url) format('%s&policy=%s&signature=%s', url, policy, signature) end |