Class: FilestackSecurity

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(secret, options: {}) ⇒ FilestackSecurity

Initialize FilestackSecurity object

Parameters:

  • secret (String)

    Your filestack security secret

  • options (Hash)

    Hash of options: call: The calls that you allow this policy to

    make, e.g convert, exif, pick, read, remove,
    stat, store, write, writeUrl

    container: (regex) store must match container

    that the files will be stored under
    

    expiry: (timestamp) epoch_timestamp expire,

    defaults to 1hr

    handle: specific file this policy can access maxSize: (number) maximum file size in bytes

    that can be stored by requests with policy
    

    minSize: (number) minimum file size in bytes

    that can be stored by requests with policy
    

    path: (regex) store must match the path that

    the files will be stored under.

    url: (regex) subset of external URL domains

    that are allowed to be image/document
    sources for processing


37
38
39
# File 'lib/filestack/models/filestack_security.rb', line 37

def initialize(secret, options: {})
  generate(secret, options)
end

Instance Attribute Details

#policyObject

Returns the value of attribute policy



14
15
16
# File 'lib/filestack/models/filestack_security.rb', line 14

def policy
  @policy
end

#signatureObject

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

Parameters:

  • secret (String)

    Your filestack security secret

  • options (Hash)

    Hash of options - see constructor



45
46
47
48
49
# File 'lib/filestack/models/filestack_security.rb', line 45

def generate(secret, options)
  policy_json = create_policy_string(options)
  @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

Parameters:

  • url (String)

    The URL to sign

Returns:

  • (String)


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