33
33
# Invoking lambda from the Ruby SDK:
34
34
# https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Lambda/Client.html#invoke_async-instance_method
35
35
#
36
- def lambda_handler ( event :, context :)
36
+ def lambda_handler ( event :, _context :)
37
37
$logger. info ( event )
38
38
39
39
validate_variables ( event )
40
40
41
41
records = ( event [ 'Records' ] || [ ] )
42
42
records . each do |record |
43
- bucket_name = record . dig ( 's3' , 'bucket' , 'name' )
44
- object_key = record . dig ( 's3' , 'object' , 'key' )
45
- process_record ( event , bucket_name , object_key )
43
+ bucket_name = record . dig ( 's3' , 'bucket' , 'name' )
44
+ object_key = record . dig ( 's3' , 'object' , 'key' )
45
+ process_record ( event , bucket_name , object_key )
46
46
end
47
47
48
48
$logger. info ( 'Lambda completed successfully!' )
@@ -51,18 +51,18 @@ def lambda_handler(event:, context:)
51
51
##
52
52
# Process a S3 record that was passed via the event
53
53
#
54
- def process_record ( event , bucket_name , object_key )
54
+ def process_record ( _event , bucket_name , object_key )
55
55
return if bucket_name . nil? || object_key . nil?
56
56
57
57
record_contents = get_record_contents ( bucket_name , object_key )
58
58
hdf = record_contents [ 'data' ]
59
59
filename = object_key . split ( '/' ) . last
60
60
$logger. info ( "Processing file (#{ object_key } ) with filename (#{ filename } )" )
61
61
62
- record_contents [ 'eval_tags' ] = record_contents [ 'eval_tags' ] . nil? ? 'HeimdallPusher' : record_contents [ 'eval_tags' ] + ' ,HeimdallPusher'
62
+ record_contents [ 'eval_tags' ] = record_contents [ 'eval_tags' ] . nil? ? 'HeimdallPusher' : " #{ record_contents [ 'eval_tags' ] } ,HeimdallPusher"
63
63
64
64
# Save to Heimdall
65
- heimdall_user_password = get_heimdall_password
65
+ heimdall_user_password = heimdall_password
66
66
user_id , token = get_heimdall_api_token ( heimdall_user_password )
67
67
push_to_heimdall ( filename , hdf , user_id , token , record_contents [ 'eval_tags' ] )
68
68
@@ -82,29 +82,29 @@ def save_hdf_to_bucket(hdf, bucket_name, filename)
82
82
$logger. info ( 'Saving processed HDF to bucket.' )
83
83
s3_client = Aws ::S3 ::Client . new
84
84
s3_client . put_object ( {
85
- body : StringIO . new ( hdf . to_json ) ,
86
- bucket : bucket_name ,
87
- key : "hdf/#{ filename } " ,
88
- } )
85
+ body : StringIO . new ( hdf . to_json ) ,
86
+ bucket : bucket_name ,
87
+ key : "hdf/#{ filename } "
88
+ } )
89
89
end
90
90
91
91
def save_results_to_bucket ( results , bucket_name , filename )
92
92
$logger. info ( 'Saving processed result to bucket.' )
93
93
s3_client = Aws ::S3 ::Client . new
94
94
s3_client . put_object ( {
95
- body : StringIO . new ( results . to_json ) ,
96
- bucket : bucket_name ,
97
- key : "processed/#{ filename } " ,
98
- } )
95
+ body : StringIO . new ( results . to_json ) ,
96
+ bucket : bucket_name ,
97
+ key : "processed/#{ filename } "
98
+ } )
99
99
end
100
100
101
101
def remove_unprocessed_from_bucket ( bucket_name , object_key )
102
102
$logger. info ( 'Removing unprocessed result from bucket.' )
103
103
s3_client = Aws ::S3 ::Client . new
104
104
s3_client . delete_object ( {
105
- bucket : bucket_name ,
106
- key : object_key ,
107
- } )
105
+ bucket : bucket_name ,
106
+ key : object_key
107
+ } )
108
108
end
109
109
110
110
##
@@ -136,7 +136,7 @@ def validate_variables(event)
136
136
# specifying the SSM_ENDPOINT variable will allow reaching
137
137
# SSM parameter store properly.
138
138
#
139
- def get_heimdall_password
139
+ def heimdall_password
140
140
$logger. info ( 'Fetching Heimdall Password Secret from SSM parameter store...' )
141
141
ssm_client = nil
142
142
@@ -165,8 +165,8 @@ def get_heimdall_password
165
165
def get_heimdall_api_token ( heimdall_user_password )
166
166
$logger. info ( 'Getting token from Heimdall Server...' )
167
167
payload = {
168
- ' email' : ENV [ 'HEIMDALL_API_USER' ] ,
169
- ' password' : heimdall_user_password
168
+ email : ENV [ 'HEIMDALL_API_USER' ] ,
169
+ password : heimdall_user_password
170
170
}
171
171
resp = Net ::HTTP . post (
172
172
URI ( "#{ ENV [ 'HEIMDALL_URL' ] } /authn/login" ) ,
@@ -205,11 +205,11 @@ def push_to_heimdall(filename, hdf, user_id, token, eval_tags)
205
205
$logger. info ( 'Pushing HDF results to Heimdall Server...' )
206
206
url = URI ( "#{ ENV [ 'HEIMDALL_URL' ] } /evaluations" )
207
207
payload = {
208
- ' data' : UploadIO . new ( StringIO . new ( hdf . to_json ) , 'application/json' , filename ) ,
209
- ' filename' : filename ,
210
- ' userId' : user_id ,
211
- ' public' : ENV [ 'HEIMDALL_PUBLIC' ] || 'true' ,
212
- ' evaluationTags' : eval_tags
208
+ data : UploadIO . new ( StringIO . new ( hdf . to_json ) , 'application/json' , filename ) ,
209
+ filename : filename ,
210
+ userId : user_id ,
211
+ public : ENV [ 'HEIMDALL_PUBLIC' ] || 'true' ,
212
+ evaluationTags : eval_tags
213
213
}
214
214
request = Net ::HTTP ::Post ::Multipart . new ( url . path , payload )
215
215
request [ 'Authorization' ] = "Bearer #{ token } "
0 commit comments