Skip to content

Commit

Permalink
Merge pull request #311 from bojanbass/feature/add-generator-options
Browse files Browse the repository at this point in the history
Add all possible options to generator
  • Loading branch information
bojanbass authored Jun 4, 2023
2 parents 116064c + 6fa8655 commit e50d9cf
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 23 deletions.
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ This will make the necessary changes to nx.json in your workspace to use nx-aws-

There are two ways to set-up plugin options, using `nx.json` or `Environment variables`. Here is a list of all possible options:

| Parameter | Description | Environment variable / .env | `nx.json` | Example |
| ----------------- | ------------------------------------------------------------------------------------------------------ | ------------------------------- | -------------------- | ------------------------------ |
| Access Key Id | AWS Access Key Id. | `NXCACHE_AWS_ACCESS_KEY_ID` | `awsAccessKeyId` | my-id |
| Secret Access Key | AWS Secret Access Key | `NXCACHE_AWS_SECRET_ACCESS_KEY` | `awsSecretAccessKey` | my-key |
| Profile | The configuration profile to use | `NXCACHE_AWS_PROFILE` | `awsProfile` | profile-1 |
| Endpoint | The fully qualified endpoint of the webservice if a custom endpoint is needed (e.g. when using MinIO). | `NXCACHE_AWS_ENDPOINT` | `awsEndpoint` | http://custom.de-eu.myhost.com |
| Bucket | The bucket name where cache files are stored or retrieved (can contain sub-paths as well). | `NXCACHE_AWS_BUCKET` | `awsBucket` | bucket-name/sub-path |
| Region | The AWS region to which this client will send requests. | `NXCACHE_AWS_REGION` | `awsRegion` | eu-central-1 |
| Force Path Style | Whether to force path style URLs for S3 objects (e.g. when using MinIO). | `NXCACHE_AWS_FORCE_PATH_STYLE` | `awsForcePathStyle` | true |
| Parameter | Description | Environment variable / .env | `nx.json` | Example |
| ----------------- | --------------------------------------------------------------------------------------------------- | ------------------------------- | -------------------- | ------------------------------ |
| Access Key Id | Access Key Id. | `NXCACHE_AWS_ACCESS_KEY_ID` | `awsAccessKeyId` | my-id |
| Secret Access Key | Secret Access Key. | `NXCACHE_AWS_SECRET_ACCESS_KEY` | `awsSecretAccessKey` | my-key |
| Profile | Configuration profile to use (applied only if Access Key Id and Secret Access Key are not set). | `NXCACHE_AWS_PROFILE` | `awsProfile` | profile-1 |
| Endpoint | Fully qualified endpoint of the web service if a custom endpoint is needed (e.g. when using MinIO). | `NXCACHE_AWS_ENDPOINT` | `awsEndpoint` | http://custom.de-eu.myhost.com |
| Region | Region to which this client will send requests. | `NXCACHE_AWS_REGION` | `awsRegion` | eu-central-1 |
| Bucket | Bucket name where cache files are stored or retrieved (can contain sub-paths as well). | `NXCACHE_AWS_BUCKET` | `awsBucket` | bucket-name/sub-path |
| Force Path Style | Whether to force path style URLs for S3 objects (e.g. when using MinIO). | `NXCACHE_AWS_FORCE_PATH_STYLE` | `awsForcePathStyle` | true |

> **Important:** `Environment variables` take precedence over `nx.json` options (introduced in v3.0.0)!
Expand All @@ -51,11 +51,10 @@ There are two ways to set-up plugin options, using `nx.json` or `Environment var
...
"awsAccessKeyId": "key",
"awsSecretAccessKey": "secret",
"awsProfile": "profile-1",
"awsEndpoint": "http://custom.de-eu.myhost.com",
"awsBucket": "bucket-name/sub-path",
"awsRegion": "eu-central-1",
"awsForcePathStyle": "true",
"awsForcePathStyle": true,
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion packages/nx-aws-cache/src/generators/init/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ function updateNxJson(tree: Tree, options: InitGeneratorSchema): void {
runner: '@nx-aws-plugin/nx-aws-cache',
options: {
...currentOptions,
...(options.awsBucket ? { awsBucket: options.awsBucket } : {}),
...(options.awsAccessKeyId ? { awsAccessKeyId: options.awsAccessKeyId } : {}),
...(options.awsSecretAccessKey ? { awsSecretAccessKey: options.awsSecretAccessKey } : {}),
...(options.awsProfile ? { awsProfile: options.awsProfile } : {}),
...(options.awsEndpoint ? { awsEndpoint: options.awsEndpoint } : {}),
...(options.awsRegion ? { awsRegion: options.awsRegion } : {}),
...(options.awsBucket ? { awsBucket: options.awsBucket } : {}),
...(options.awsForcePathStyle ? { awsForcePathStyle: options.awsForcePathStyle } : {}),
},
},
};
Expand Down
5 changes: 5 additions & 0 deletions packages/nx-aws-cache/src/generators/init/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export interface InitGeneratorSchema {
awsAccessKeyId?: string;
awsSecretAccessKey?: string;
awsProfile?: string;
awsEndpoint?: string;
awsRegion?: string;
awsBucket?: string;
awsForcePathStyle?: boolean;
}
31 changes: 28 additions & 3 deletions packages/nx-aws-cache/src/generators/init/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,40 @@
"title": "Add AWS S3 Cache configuration to NX workspace",
"type": "object",
"properties": {
"awsAccessKeyId": {
"type": "string",
"description": "AWS Access Key Id",
"x-prompt": "AWS Access Key Id"
},
"awsSecretAccessKey": {
"type": "string",
"description": "AWS Secret Access Key",
"x-prompt": "AWS Secret Access Key"
},
"awsProfile": {
"type": "string",
"description": "The configuration profile to use",
"x-prompt": "AWS configuration profile to use"
},
"awsEndpoint": {
"type": "string",
"description": "The fully qualified endpoint of the web service if a custom endpoint is needed (e.g. when using MinIO)",
"x-prompt": "AWS Endpoint of the web service if a custom endpoint is needed (e.g. when using MinIO)"
},
"awsRegion": {
"type": "string",
"description": "AWS Region",
"x-prompt": "AWS Region (optional - can be defined using Environment variables)"
"description": "AWS region to which this client will send requests",
"x-prompt": "AWS region to which this client will send requests"
},
"awsBucket": {
"type": "string",
"description": "AWS S3 Bucket, where the cached Nx outputs will be stored",
"x-prompt": "AWS Bucket (optional - can be defined using Environment variables)"
"x-prompt": "AWS S3 Bucket, where the cached Nx outputs will be stored"
},
"awsForcePathStyle": {
"type": "boolean",
"description": "Whether to force path style URLs for S3 objects (e.g. when using MinIO)",
"x-prompt": "Whether to force path style URLs for S3 objects (e.g. when using MinIO)"
}
}
}
2 changes: 1 addition & 1 deletion packages/nx-aws-cache/src/tasks-runner/aws-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class AwsCache implements RemoteCache {
);
}

if (options.awsForcePathStyle === 'true') {
if (options.awsForcePathStyle) {
clientConfig.forcePathStyle = true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export interface AwsNxCacheOptions {
awsProfile?: string;
awsRegion?: string;
awsBucket?: string;
awsAccessKeyId?: string;
awsSecretAccessKey?: string;
awsProfile?: string;
awsEndpoint?: string;
awsForcePathStyle?: string;
awsRegion?: string;
awsBucket?: string;
awsForcePathStyle?: boolean;
}
8 changes: 5 additions & 3 deletions packages/nx-aws-cache/src/tasks-runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import { MessageReporter } from './message-reporter';
function getOptions(options: AwsNxCacheOptions) {
return {
awsAccessKeyId: process.env.NXCACHE_AWS_ACCESS_KEY_ID ?? options.awsAccessKeyId,
awsBucket: process.env.NXCACHE_AWS_BUCKET ?? options.awsBucket,
awsRegion: process.env.NXCACHE_AWS_REGION ?? options.awsRegion,
awsSecretAccessKey: process.env.NXCACHE_AWS_SECRET_ACCESS_KEY ?? options.awsSecretAccessKey,
awsProfile: process.env.NXCACHE_AWS_PROFILE ?? options.awsProfile,
awsEndpoint: process.env.NXCACHE_AWS_ENDPOINT ?? options.awsEndpoint,
awsForcePathStyle: process.env.NXCACHE_AWS_FORCE_PATH_STYLE ?? options.awsForcePathStyle,
awsRegion: process.env.NXCACHE_AWS_REGION ?? options.awsRegion,
awsBucket: process.env.NXCACHE_AWS_BUCKET ?? options.awsBucket,
awsForcePathStyle: process.env.NXCACHE_AWS_FORCE_PATH_STYLE
? process.env.NXCACHE_AWS_FORCE_PATH_STYLE === 'true'
: options.awsForcePathStyle,
};
}

Expand Down

0 comments on commit e50d9cf

Please sign in to comment.