feat(techdocs): updates aws variables access

This commit is contained in:
Remi
2020-12-21 14:37:28 +01:00
parent 0661c4f725
commit 80b60862af
5 changed files with 40 additions and 25 deletions
+6 -1
View File
@@ -76,7 +76,12 @@ techdocs:
awsS3:
# An API key is required to write to a storage bucket.
credentials:
$file: '/path/to/aws_application_credentials.json',
accessKeyId:
$env: TECHDOCS_AWSS3_ACCESS_KEY_ID_CREDENTIAL
secretAccessKey:
$env: TECHDOCS_AWSS3_SECRET_ACCESS_KEY_CREDENTIAL
region:
$env: AWSS3_REGION
# AWS S3 Bucket Name
bucketName: 'techdocs-storage',
+14 -9
View File
@@ -236,18 +236,18 @@ Create an inline policy for the TechDocs user by using the following policy:
See more details in the section
[Working with Inline Policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage.html).
Now you need to create your credentials file (`.json`) with the `TechDocs` User
credentials:
Now you need to fill in the environment variables with the `TechDocs` User
credentials. You can also specify a region if you want to accesses the resources
in a specific region. Otherwise no region will be selected by default.
```json
{
"accessKeyId": "TECHDOCS_USER_ACCESS_KEY_ID",
"secretAccessKey": "TECHDOCS_USER_SECRET_ACCESS_KEY"
}
```properties
TECHDOCS_AWSS3_ACCESS_KEY_ID_CREDENTIAL="TECHDOCS_ACCESS_KEY_ID"
TECHDOCS_AWSS3_SECRET_ACCESS_KEY_CREDENTIAL="TECHDOCS_SECRET_ACCESS_KEY"
AWSS3_REGION="" // Optional
```
Make it available in your Backstage server and/or your local development server
and set it in the app config techdocs.publisher.awsS3.credentials.
and set it in the app config techdocs.publisher.awsS3.
```yaml
techdocs:
@@ -255,7 +255,12 @@ techdocs:
type: 'awsS3'
awsS3:
credentials:
$file: '/path/to/aws_application_credentials.json'
accessKeyId:
$env: TECHDOCS_AWSS3_ACCESS_KEY_ID_CREDENTIAL
secretAccessKey:
$env: TECHDOCS_AWSS3_SECRET_ACCESS_KEY_CREDENTIAL
region:
$env: AWSS3_REGION
```
**3. That's it!**
@@ -45,7 +45,10 @@ beforeEach(() => {
publisher: {
type: 'awsS3',
awsS3: {
credentials: '{}',
credentials: {
accessKeyId: 'accessKeyId',
secretAccessKey: 'secretAccessKey',
},
bucketName: 'bucketName',
},
},
@@ -21,16 +21,23 @@ import { Entity, EntityName } from '@backstage/catalog-model';
import { Config } from '@backstage/config';
import { getHeadersForFileExtension, getFileTreeRecursively } from './helpers';
import { PublisherBase, PublishRequest } from './types';
import { CredentialsOptions } from 'aws-sdk/lib/credentials';
import { ManagedUpload } from 'aws-sdk/clients/s3';
import fs from 'fs';
export class AwsS3Publish implements PublisherBase {
static fromConfig(config: Config, logger: Logger): PublisherBase {
let credentials = '';
let region = null;
let accessKeyId = null;
let secretAccessKey = null;
let bucketName = '';
try {
credentials = config.getString('techdocs.publisher.awsS3.credentials');
accessKeyId = config.getString(
'techdocs.publisher.awsS3.credentials.accessKeyId',
);
secretAccessKey = config.getString(
'techdocs.publisher.awsS3.credentials.secretAccessKey',
);
region = config.getOptionalString('techdocs.publisher.awsS3.region');
bucketName = config.getString('techdocs.publisher.awsS3.bucketName');
} catch (error) {
throw new Error(
@@ -40,17 +47,9 @@ export class AwsS3Publish implements PublisherBase {
);
}
let credentialsJson = {};
try {
credentialsJson = JSON.parse(credentials);
} catch (err) {
throw new Error(
'Error in parsing techdocs.publisher.awsS3.credentials config to JSON.',
);
}
const storageClient = new aws.S3({
credentials: credentialsJson as CredentialsOptions,
credentials: { accessKeyId, secretAccessKey },
...(region && { region }),
});
// Check if the defined bucket exists. Being able to connect means the configuration is good
@@ -90,7 +90,10 @@ describe('Publisher', () => {
publisher: {
type: 'awsS3',
awsS3: {
credentials: '{}',
credentials: {
accessKeyId: 'accessKeyId',
secretAccessKey: 'secretAccessKey',
},
bucketName: 'bucketName',
},
},