@@ -17,6 +17,11 @@ const opensearchResponse = require("../api/response/opensearch");
17
17
const path = require ( "path" ) ;
18
18
19
19
let Secrets ;
20
+
21
+ const getSecret = ( key ) => {
22
+ return process . env [ key . toUpperCase ( ) ] || Secrets [ key ] ;
23
+ } ;
24
+
20
25
/**
21
26
* Handler for download file set endpoint
22
27
*/
@@ -136,7 +141,7 @@ function derivativeKey(doc) {
136
141
137
142
async function getDownloadLink ( doc ) {
138
143
const clientParams = { } ;
139
- const bucket = Secrets . pyramid_bucket ;
144
+ const bucket = getSecret ( " pyramid_bucket" ) ;
140
145
const key = derivativeKey ( doc ) ;
141
146
142
147
const getObjectParams = {
@@ -200,16 +205,16 @@ const IIIFImageRequest = async (doc) => {
200
205
} ;
201
206
202
207
async function processAVDownload ( doc , email , referer ) {
203
- const stepFunctionConfig = Secrets . step_function_endpoint
204
- ? { endpoint : Secrets . step_function_endpoint }
208
+ const stepFunctionConfig = getSecret ( " step_function_endpoint" )
209
+ ? { endpoint : getSecret ( " step_function_endpoint" ) }
205
210
: { } ;
206
211
const client = new SFNClient ( stepFunctionConfig ) ;
207
212
208
213
const fileSet = doc . _source ;
209
214
const url = new URL ( fileSet . streaming_url ) ;
210
215
211
216
const sourceLocation = s3Location ( fileSet . streaming_url ) ;
212
- const destinationBucket = Secrets . media_convert_destination_bucket ;
217
+ const destinationBucket = getSecret ( " media_convert_destination_bucket" ) ;
213
218
const fileSetId = path . parse ( url . pathname ) . name ;
214
219
const fileSetLabel = fileSet . label ;
215
220
const workId = fileSet . work_id ;
@@ -224,14 +229,16 @@ async function processAVDownload(doc, email, referer) {
224
229
const filename = isAudio ( doc ) ? `${ fileSetId } .mp3` : `${ fileSetId } .mp4` ;
225
230
226
231
var params = {
227
- stateMachineArn : Secrets . av_download_state_machine_arn ,
232
+ stateMachineArn : getSecret ( " av_download_state_machine_arn" ) ,
228
233
input : JSON . stringify ( {
229
234
configuration : {
230
- startAudioTranscodeFunction : Secrets . start_audio_transcode_function ,
231
- startTranscodeFunction : Secrets . start_transcode_function ,
232
- transcodeStatusFunction : Secrets . transcode_status_function ,
233
- getDownloadLinkFunction : Secrets . get_download_link_function ,
234
- sendTemplatedEmailFunction : Secrets . send_templated_email_function ,
235
+ startAudioTranscodeFunction : getSecret (
236
+ "start_audio_transcode_function"
237
+ ) ,
238
+ startTranscodeFunction : getSecret ( "start_transcode_function" ) ,
239
+ transcodeStatusFunction : getSecret ( "transcode_status_function" ) ,
240
+ getDownloadLinkFunction : getSecret ( "get_download_link_function" ) ,
241
+ sendTemplatedEmailFunction : getSecret ( "send_templated_email_function" ) ,
235
242
} ,
236
243
transcodeInput : {
237
244
settings : settings ,
@@ -248,8 +255,8 @@ async function processAVDownload(doc, email, referer) {
248
255
} ,
249
256
sendEmailInput : {
250
257
to : email ,
251
- template : Secrets . av_download_email_template ,
252
- from : Secrets . repository_email ,
258
+ template : getSecret ( " av_download_email_template" ) ,
259
+ from : getSecret ( " repository_email" ) ,
253
260
params : {
254
261
downloadLink : "" ,
255
262
fileSetId,
@@ -280,7 +287,7 @@ async function processAVDownload(doc, email, referer) {
280
287
281
288
function s3Location ( streaming_url ) {
282
289
const url = new URL ( streaming_url ) ;
283
- return `s3://${ Secrets . streaming_bucket } ${ url . pathname } ` ;
290
+ return `s3://${ getSecret ( " streaming_bucket" ) } ${ url . pathname } ` ;
284
291
}
285
292
286
293
function invalidRequest ( code , message ) {
0 commit comments