Skip to content

Commit

Permalink
[input/amazon-textract] - send Amazon access keys via process.env
Browse files Browse the repository at this point in the history
  • Loading branch information
marianorodriguez committed Jan 20, 2020
1 parent cbcea75 commit e48b695
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .vscode/launch.json
Expand Up @@ -27,7 +27,9 @@
"env": { "env": {
"NODE_DEBUG": "pipeline", "NODE_DEBUG": "pipeline",
"GOOGLE_APPLICATION_CREDENTIALS": "${workspaceRoot}/***.json", "GOOGLE_APPLICATION_CREDENTIALS": "${workspaceRoot}/***.json",
"OCP_APIM_SUBSCRIPTION_KEY": "" "OCP_APIM_SUBSCRIPTION_KEY": "",
"AWS_ACCESS_KEY_ID": "",
"AWS_SECRET_ACCESS_KEY": "",
}, },
"outputCapture": "std" "outputCapture": "std"
} }
Expand Down
9 changes: 8 additions & 1 deletion api/server/src/ProcessManager.ts
@@ -1,5 +1,5 @@
/** /**
* Copyright 2019 AXA Group Operations S.A. * Copyright 2020 AXA Group Operations S.A.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,6 +34,10 @@ export class ProcessManager {
apiKey: string, apiKey: string,
endpoint: string, endpoint: string,
}, },
amazonTextract: {
accessKeyId: string,
secretAccessKey: string,
},
}, },
): void { ): void {
logger.info('Processing ' + doc); logger.info('Processing ' + doc);
Expand All @@ -44,6 +48,9 @@ export class ProcessManager {
} else if (credentials.msCognitiveServices.apiKey) { } else if (credentials.msCognitiveServices.apiKey) {
process.env.OCP_APIM_SUBSCRIPTION_KEY = credentials.msCognitiveServices.apiKey; process.env.OCP_APIM_SUBSCRIPTION_KEY = credentials.msCognitiveServices.apiKey;
process.env.OCP_APIM_ENDPOINT = credentials.msCognitiveServices.endpoint; process.env.OCP_APIM_ENDPOINT = credentials.msCognitiveServices.endpoint;
} else if (credentials.amazonTextract.accessKeyId && credentials.amazonTextract.secretAccessKey) {
process.env.AWS_ACCESS_KEY_ID = credentials.amazonTextract.accessKeyId;
process.env.AWS_SECRET_ACCESS_KEY = credentials.amazonTextract.secretAccessKey;
} }


const args: string[] = [ const args: string[] = [
Expand Down
6 changes: 5 additions & 1 deletion api/server/src/api.ts
@@ -1,5 +1,5 @@
/** /**
* Copyright 2019 AXA Group Operations S.A. * Copyright 2020 AXA Group Operations S.A.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -340,6 +340,10 @@ export class ApiServer {
apiKey: 'msApiKey' in req.body && req.body.msApiKey, apiKey: 'msApiKey' in req.body && req.body.msApiKey,
endpoint: 'msEndpoint' in req.body && req.body.msEndpoint, endpoint: 'msEndpoint' in req.body && req.body.msEndpoint,
}, },
amazonTextract: {
accessKeyId: 'awsAccessKeyId' in req.body && req.body.awsAccessKeyId,
secretAccessKey: 'awsSecretAccessKey' in req.body && req.body.awsSecretAccessKey,
},
}; };


this.fileManager.newBinder(docId, doc.path, config.path, outputPath, docName); this.fileManager.newBinder(docId, doc.path, config.path, outputPath, docName);
Expand Down
15 changes: 12 additions & 3 deletions demo/vue-viewer/src/services/DocumentServices.js
Expand Up @@ -73,9 +73,18 @@ export default {
const formData = new FormData(); const formData = new FormData();
formData.append('file', file, file.name); formData.append('file', file, file.name);
formData.append('config', configuration); formData.append('config', configuration);
formData.append('gvCredentials', credentials.googleVision);
formData.append('msApiKey', credentials.msApiKey); if (credentials.googleVision) {
formData.append('msEndpoint', credentials.msEndpoint); formData.append('gvCredentials', credentials.googleVision);
}
if (credentials.msApiKey) {
formData.append('msApiKey', credentials.msApiKey);
formData.append('msEndpoint', credentials.msEndpoint);
}
if (credentials.awsAccessKeyId && credentials.awsSecretAccessKey) {
formData.append('awsAccessKeyId', credentials.awsAccessKeyId);
formData.append('awsSecretAccessKey', credentials.awsSecretAccessKey);
}
return apiClient.post('/document', formData); return apiClient.post('/document', formData);
}, },
getDocumentStatus(docID) { getDocumentStatus(docID) {
Expand Down
37 changes: 35 additions & 2 deletions demo/vue-viewer/src/views/Upload.vue
Expand Up @@ -21,7 +21,13 @@
solo solo
></v-select> ></v-select>
<v-select <v-select
:items="['tesseract', 'abbyy', 'google-vision', 'ms-cognitive-services']" :items="[
'tesseract',
'abbyy',
'google-vision',
'ms-cognitive-services',
'amazon-textract',
]"
v-model="defaultConfig.extractor.img" v-model="defaultConfig.extractor.img"
:flat="true" :flat="true"
:hide-details="true" :hide-details="true"
Expand Down Expand Up @@ -62,6 +68,27 @@
v-model="msEndpoint" v-model="msEndpoint"
/> />
</div> </div>
<div
style="padding-left: 60px; text-align: left"
class="selectOptionExtractor"
v-if="defaultConfig.extractor.img === 'amazon-textract'"
>
<legend><sup>*</sup>access_key_id:</legend>
<input
style="border-style: groove"
id="awsKeyId"
name="awsKeyId"
v-model="awsAccessKeyId"
/>

<legend><sup>*</sup>secret_access_key:</legend>
<input
style="border-style: groove"
id="awsSecretKey"
name="awsSecretKey"
v-model="awsSecretAccessKey"
/>
</div>
</fieldset> </fieldset>


<fieldset> <fieldset>
Expand Down Expand Up @@ -116,6 +143,8 @@ export default {
gvCredentials: null, gvCredentials: null,
msApiKey: null, msApiKey: null,
msEndpoint: 'https://westeurope.api.cognitive.microsoft.com/', msEndpoint: 'https://westeurope.api.cognitive.microsoft.com/',
awsAccessKeyId: null,
awsSecretAccessKey: null,
loading: false, loading: false,
processStatus: [], processStatus: [],
processStatusCompleted: false, processStatusCompleted: false,
Expand All @@ -142,7 +171,9 @@ export default {
!this.file || !this.file ||
(this.customConfig.extractor.img === 'google-vision' && !this.gvCredentials) || (this.customConfig.extractor.img === 'google-vision' && !this.gvCredentials) ||
(this.customConfig.extractor.img === 'ms-cognitive-services' && (this.customConfig.extractor.img === 'ms-cognitive-services' &&
!(this.msApiKey && this.msEndpoint)) !(this.msApiKey && this.msEndpoint)) ||
(this.customConfig.extractor.img === 'amazon-textract' &&
!(this.awsAccessKeyId && this.awsSecretAccessKey))
); );
}, },
/* /*
Expand Down Expand Up @@ -256,6 +287,8 @@ export default {
googleVision: this.gvCredentials, googleVision: this.gvCredentials,
msApiKey: this.msApiKey, msApiKey: this.msApiKey,
msEndpoint: this.msEndpoint, msEndpoint: this.msEndpoint,
awsAccessKeyId: this.awsAccessKeyId,
awsSecretAccessKey: this.awsSecretAccessKey,
}, },
}) })
.then(() => { .then(() => {
Expand Down
13 changes: 9 additions & 4 deletions server/src/input/amazon-textract/AmazonTextractExtractor.ts
Expand Up @@ -58,14 +58,19 @@ export class AmazonTextractExtractor extends Extractor {


constructor(config: Config) { constructor(config: Config) {
super(config); super(config);

if (!process.env.AWS_ACCESS_KEY_ID) {
throw new Error(`Required environment variable AWS_ACCESS_KEY_ID not found. Make sure you set it as 'AWS_ACCESS_KEY_ID=<KEY>' before running the tool.`);
}
if (!process.env.AWS_SECRET_ACCESS_KEY) {
throw new Error(`Required environment variable AWS_SECRET_ACCESS_KEY not found. Make sure you set it as 'AWS_SECRET_ACCESS_KEY=<KEY>' before running the tool.`);
}
this.textract = new Textract({ this.textract = new Textract({
accessKeyId: '', accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: '', secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: 'us-east-1', region: 'us-east-1',
}); });

} }

public async run(inputFile: string): Promise<Document> { public async run(inputFile: string): Promise<Document> {
let rotationCorrection: RotationCorrection = { let rotationCorrection: RotationCorrection = {
fileName: inputFile, fileName: inputFile,
Expand Down

0 comments on commit e48b695

Please sign in to comment.