-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch from websocket to http in Atc::Aws::FixityCheck class; Also re…
…factor code to simplify swapping between WEBSOCKET and HTTP fixity check methods
- Loading branch information
Showing
6 changed files
with
91 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
class Atc::Aws::FixityCheck | ||
def initialize(stored_object, stream_id) | ||
def initialize(stored_object, fixity_check_identifier) | ||
@bucket_name = stored_object.storage_provider.container_name | ||
@object_path = stored_object.path | ||
@fixity_checksum_algorithm = stored_object.source_object.fixity_checksum_algorithm | ||
@stream_id = stream_id | ||
@fixity_check_identifier = fixity_check_identifier | ||
end | ||
|
||
# Returns an array with the checksum, object size, and (if something went wrong) an error error_message. | ||
# If there is an error, checksum and object size will be nil. If there is not an error, | ||
# checksum and object size will be non-nil and error will be nil. | ||
# @return [Array(String, Integer, String)] A 3-element array containing: [checksum, object_size, error_message] | ||
def fixity_checksum_object_size | ||
aws_fixity_check_response = | ||
aws_fixity_websocket_channel_stream(@bucket_name, | ||
@object_path, | ||
@fixity_checksum_algorithm.name.downcase, | ||
@stream_id) | ||
case aws_fixity_check_response['type'] | ||
when 'fixity_check_complete' | ||
[aws_fixity_check_response['data']['checksum_hexdigest'], aws_fixity_check_response['data']['object_size'], nil] | ||
when 'fixity_check_error' | ||
# if only want to return the error from the AWS fixity response, without data, | ||
# use the following commented-out line instead of the last line | ||
# [nil, nil, aws_fixity_check_response['data']['error_message']] | ||
[nil, nil, response_data_as_string(aws_fixity_check_response)] | ||
end | ||
end | ||
|
||
def response_data_as_string(aws_fixity_check_response) | ||
# AWS response data contains, among other things, the error message | ||
"AWS error response with the following data: #{aws_fixity_check_response['data']} " | ||
end | ||
|
||
def aws_fixity_websocket_channel_stream(bucket_name, | ||
object_path, | ||
checksum_algorithm_name, | ||
job_identifier) | ||
# Response received (Hash) is returned as-is. | ||
remote_fixity_check = Atc::Aws::RemoteFixityCheck.new(CHECK_PLEASE['ws_url'], CHECK_PLEASE['auth_token']) | ||
remote_fixity_check.perform(job_identifier, bucket_name, object_path, checksum_algorithm_name) | ||
response = Atc::Aws::RemoteFixityCheck.new( | ||
CHECK_PLEASE['http_base_url'], CHECK_PLEASE['ws_url'], CHECK_PLEASE['auth_token'] | ||
).perform( | ||
@fixity_check_identifier, @bucket_name, | ||
@object_path, @fixity_checksum_algorithm.name.downcase, | ||
Atc::Aws::RemoteFixityCheck::HTTP | ||
) | ||
[response['checksum_hexdigest'], response['object_size'], response['error_message']] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters