Skip to content

Commit 879ec4a

Browse files
authored
refactor(webui): Rename S3Manager to StreamFilesS3Manager; namespace stream-output AWS env vars. (#2195)
1 parent 40a9d99 commit 879ec4a

7 files changed

Lines changed: 49 additions & 16 deletions

File tree

components/webui/server/.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ PRESTO_SCHEMA=default
1818
# Security
1919
RATE_LIMIT=1000
2020

21+
# S3
22+
CLP_STREAM_OUTPUT_AWS_ACCESS_KEY_ID=
23+
CLP_STREAM_OUTPUT_AWS_SECRET_ACCESS_KEY=
24+

components/webui/server/src/plugins/app/S3Manager/index.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
S3Client,
44
} from "@aws-sdk/client-s3";
55
import {getSignedUrl} from "@aws-sdk/s3-request-presigner";
6+
import {AwsCredentialIdentity} from "@smithy/types";
67
import {Nullable} from "@webui/common/utility-types";
78
import fp from "fastify-plugin";
89

@@ -19,11 +20,17 @@ class S3Manager {
1920
/**
2021
* @param region
2122
* @param [profile]
23+
* @param [credentials]
2224
*/
23-
constructor (region: string, profile: Nullable<string>) {
25+
constructor (
26+
region: string,
27+
profile: Nullable<string>,
28+
credentials: Nullable<AwsCredentialIdentity>
29+
) {
2430
this.#s3Client = new S3Client({
2531
region,
2632
...((null !== profile) && {profile}),
33+
...((null !== credentials) && {credentials}),
2734
});
2835
}
2936

@@ -60,25 +67,34 @@ class S3Manager {
6067

6168
declare module "fastify" {
6269
interface FastifyInstance {
63-
S3Manager?: S3Manager;
70+
StreamFilesS3Manager?: S3Manager;
6471
}
6572
}
6673

6774
export default fp(
6875
(fastify) => {
69-
const region = settings.StreamFilesS3Region;
70-
const profile = settings.StreamFilesS3Profile;
76+
const region = settings.StreamFilesS3Region as Nullable<string>;
77+
const profile = settings.StreamFilesS3Profile as Nullable<string>;
7178

7279
// Only decorate if the region is set (i.e. s3 support is configured in package)
73-
// Disable no-unnecessary-condition since linter doesn't understand that settings
74-
// values are not hardcoded.
75-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
7680
if (null !== region && "" !== region) {
81+
const {
82+
CLP_STREAM_OUTPUT_AWS_ACCESS_KEY_ID: accessKeyId,
83+
CLP_STREAM_OUTPUT_AWS_SECRET_ACCESS_KEY: secretAccessKey,
84+
} = fastify.config;
85+
7786
fastify.log.info(
7887
{region, profile},
79-
"Initializing S3Manager"
88+
"Initializing StreamFilesS3Manager"
89+
);
90+
const credentials = (accessKeyId && secretAccessKey) ?
91+
{accessKeyId, secretAccessKey} :
92+
null;
93+
94+
fastify.decorate(
95+
"StreamFilesS3Manager",
96+
new S3Manager(region, profile, credentials)
8097
);
81-
fastify.decorate("S3Manager", new S3Manager(region, profile));
8298
}
8399
},
84100
);

components/webui/server/src/plugins/external/env.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ declare module "fastify" {
1010
USER: string;
1111
CLP_DB_USER: string;
1212
CLP_DB_PASS: string;
13+
CLP_STREAM_OUTPUT_AWS_ACCESS_KEY_ID: string;
14+
CLP_STREAM_OUTPUT_AWS_SECRET_ACCESS_KEY: string;
1315
PRESTO_CATALOG: string;
1416
PRESTO_SCHEMA: string;
1517
RATE_LIMIT: number;
@@ -56,6 +58,16 @@ const schema = {
5658
type: "string",
5759
},
5860

61+
// S3
62+
CLP_STREAM_OUTPUT_AWS_ACCESS_KEY_ID: {
63+
type: "string",
64+
default: "",
65+
},
66+
CLP_STREAM_OUTPUT_AWS_SECRET_ACCESS_KEY: {
67+
type: "string",
68+
default: "",
69+
},
70+
5971
// Presto
6072
PRESTO_CATALOG: {
6173
type: "string",

components/webui/server/src/routes/api/stream-files/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
6969
}
7070
}
7171

72-
if (fastify.hasDecorator("S3Manager") && "undefined" !== typeof fastify.S3Manager) {
73-
streamMetadata.path = await fastify.S3Manager.getPreSignedUrl(
72+
if (fastify.hasDecorator("StreamFilesS3Manager") &&
73+
"undefined" !== typeof fastify.StreamFilesS3Manager) {
74+
streamMetadata.path = await fastify.StreamFilesS3Manager.getPreSignedUrl(
7475
`s3://${settings.StreamFilesS3PathPrefix}${streamMetadata.path}`
7576
);
7677
} else {

tools/deployment/package-helm/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: "v2"
22
name: "clp"
3-
version: "0.3.2-dev.1"
3+
version: "0.3.2-dev.2"
44
description: "A Helm chart for CLP's (Compressed Log Processor) package deployment"
55
type: "application"
66
appVersion: "0.12.1-dev"

tools/deployment/package-helm/templates/webui-deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ spec:
6161
value: {{ .Values.clpConfig.webui.rate_limit | quote }}
6262
{{- with .Values.clpConfig.stream_output.storage }}
6363
{{- if and (eq .type "s3") (eq .s3_config.aws_authentication.type "credentials") }}
64-
- name: "AWS_ACCESS_KEY_ID"
64+
- name: "CLP_STREAM_OUTPUT_AWS_ACCESS_KEY_ID"
6565
value: {{ .s3_config.aws_authentication.credentials.access_key_id | quote }}
66-
- name: "AWS_SECRET_ACCESS_KEY"
66+
- name: "CLP_STREAM_OUTPUT_AWS_SECRET_ACCESS_KEY"
6767
value: {{ .s3_config.aws_authentication.credentials.secret_access_key | quote }}
6868
{{- end }}{{/* if and (eq .type "s3")
6969
(eq .s3_config.aws_authentication.type "credentials") */}}

tools/deployment/package/docker-compose-all.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ services:
366366
<<: *service_defaults
367367
hostname: "webui"
368368
environment:
369-
AWS_ACCESS_KEY_ID: "${CLP_STREAM_OUTPUT_AWS_ACCESS_KEY_ID:-}"
370-
AWS_SECRET_ACCESS_KEY: "${CLP_STREAM_OUTPUT_AWS_SECRET_ACCESS_KEY:-}"
369+
CLP_STREAM_OUTPUT_AWS_ACCESS_KEY_ID: "${CLP_STREAM_OUTPUT_AWS_ACCESS_KEY_ID:-}"
370+
CLP_STREAM_OUTPUT_AWS_SECRET_ACCESS_KEY: "${CLP_STREAM_OUTPUT_AWS_SECRET_ACCESS_KEY:-}"
371371
CLP_DB_PASS: "${CLP_DB_PASS:?Please set a value.}"
372372
CLP_DB_USER: "${CLP_DB_USER:-clp-user}"
373373
HOST: "0.0.0.0"

0 commit comments

Comments
 (0)