Module: Shrine::Plugins::AwsLambda::AttacherClassMethods
- Defined in:
- lib/shrine/plugins/aws_lambda.rb
Instance Method Summary collapse
-
#lambda_authorize(headers, body) ⇒ Array, false
Parses the payload of the Lambda request to the ‘callbackUrl` and loads the Shrine Attacher from the received context.
-
#lambda_process(attacher_class, record_class, record_id, name, file_data) ⇒ Object
Loads the attacher from the data, and triggers its instance AWS Lambda processing method.
Instance Method Details
#lambda_authorize(headers, body) ⇒ Array, false
Parses the payload of the Lambda request to the ‘callbackUrl` and loads the Shrine Attacher from the received context. Fetches the signing key from the attacher’s record metadata and uses it for calculating the signature of the received from Lambda request. Then it compares the calculated and received signatures, returning an error if the signatures mismatch.
If the signatures are equal, it returns the attacher and the hash of the parsed result from Lambda, else - it returns false.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/shrine/plugins/aws_lambda.rb', line 89 def (headers, body) result = JSON.parse(body) context = result['context'] context_record = context['record'] record_class = context_record[0] record_id = context_record[1] record = Object.const_get(record_class).find(record_id) attacher_name = context['name'] attacher = record.__send__(:"#{attacher_name}_attacher") return false unless signature_matched?(attacher, headers, body) [attacher, result] end |
#lambda_process(attacher_class, record_class, record_id, name, file_data) ⇒ Object
Loads the attacher from the data, and triggers its instance AWS Lambda processing method. Intended to be used in a background job.
62 63 64 65 66 67 68 69 |
# File 'lib/shrine/plugins/aws_lambda.rb', line 62 def lambda_process(attacher_class, record_class, record_id, name, file_data) attacher_class = Object.const_get(attacher_class) record = Object.const_get(record_class).find(record_id) # if using Active Record attacher = attacher_class.retrieve(model: record, name: name, file: file_data) attacher.lambda_process attacher end |