Skip to content
Permalink
Browse files

[input/amazon-textract] - send Amazon access keys via process.env

  • Loading branch information
marianorodriguez committed Jan 20, 2020
1 parent cbcea75 commit e48b69514ee12ec393896776a644b46b4c32f5b6
@@ -27,7 +27,9 @@
"env": {
"NODE_DEBUG": "pipeline",
"GOOGLE_APPLICATION_CREDENTIALS": "${workspaceRoot}/***.json",
"OCP_APIM_SUBSCRIPTION_KEY": ""
"OCP_APIM_SUBSCRIPTION_KEY": "",
"AWS_ACCESS_KEY_ID": "",
"AWS_SECRET_ACCESS_KEY": "",
},
"outputCapture": "std"
}
@@ -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");
* you may not use this file except in compliance with the License.
@@ -34,6 +34,10 @@ export class ProcessManager {
apiKey: string,
endpoint: string,
},
amazonTextract: {
accessKeyId: string,
secretAccessKey: string,
},
},
): void {
logger.info('Processing ' + doc);
@@ -44,6 +48,9 @@ export class ProcessManager {
} else if (credentials.msCognitiveServices.apiKey) {
process.env.OCP_APIM_SUBSCRIPTION_KEY = credentials.msCognitiveServices.apiKey;
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[] = [
@@ -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");
* you may not use this file except in compliance with the License.
@@ -340,6 +340,10 @@ export class ApiServer {
apiKey: 'msApiKey' in req.body && req.body.msApiKey,
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);
@@ -73,9 +73,18 @@ export default {
const formData = new FormData();
formData.append('file', file, file.name);
formData.append('config', configuration);
formData.append('gvCredentials', credentials.googleVision);
formData.append('msApiKey', credentials.msApiKey);
formData.append('msEndpoint', credentials.msEndpoint);

if (credentials.googleVision) {
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);
},
getDocumentStatus(docID) {
@@ -21,7 +21,13 @@
solo
></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"
:flat="true"
:hide-details="true"
@@ -62,6 +68,27 @@
v-model="msEndpoint"
/>
</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>
@@ -116,6 +143,8 @@ export default {
gvCredentials: null,
msApiKey: null,
msEndpoint: 'https://westeurope.api.cognitive.microsoft.com/',
awsAccessKeyId: null,
awsSecretAccessKey: null,
loading: false,
processStatus: [],
processStatusCompleted: false,
@@ -142,7 +171,9 @@ export default {
!this.file ||
(this.customConfig.extractor.img === 'google-vision' && !this.gvCredentials) ||
(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))
);
},
/*
@@ -256,6 +287,8 @@ export default {
googleVision: this.gvCredentials,
msApiKey: this.msApiKey,
msEndpoint: this.msEndpoint,
awsAccessKeyId: this.awsAccessKeyId,
awsSecretAccessKey: this.awsSecretAccessKey,
},
})
.then(() => {
@@ -58,14 +58,19 @@ export class AmazonTextractExtractor extends Extractor {

constructor(config: 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({
accessKeyId: '',
secretAccessKey: '',
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: 'us-east-1',
});

}

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

0 comments on commit e48b695

Please sign in to comment.
You can’t perform that action at this time.