diff --git a/.env.shadow b/.env.shadow index a806be4..38ffba5 100644 --- a/.env.shadow +++ b/.env.shadow @@ -5,4 +5,5 @@ AWS_BUCKET_REGION=region AWS_ACCESS_KEY_ID=access_key AWS_SECRET_ACCESS_KEY=secret_key AWS_BUCKET_NAME=bucket_name +AWS_BUCKET_PATH= EXPIRES_IN=3600 diff --git a/src/config.ts b/src/config.ts index a0b0f42..096337d 100644 --- a/src/config.ts +++ b/src/config.ts @@ -8,7 +8,7 @@ export const envFormat = z.object({ AWS_ACCESS_KEY_ID: z.string().optional(), AWS_SECRET_ACCESS_KEY: z.string().optional(), AWS_BUCKET_NAME: z.string(), - AWS_BUCKET_PATH: z.string(), + AWS_BUCKET_PATH: z.string().optional(), EXPIRES_IN: z.coerce.number() }); @@ -24,11 +24,15 @@ if (config.AWS_ACCESS_KEY_ID && config.AWS_SECRET_ACCESS_KEY) { }; } +if (config.AWS_BUCKET_PATH?.length && !config.AWS_BUCKET_PATH.endsWith('/')) { + throw new Error('Configuration error: AWS_BUCKET_PATH must end with "/" if specified'); +} + export default { PORT: config.PORT, AWS_BUCKET_REGION: config.AWS_BUCKET_REGION, AWS_BUCKET_NAME: config.AWS_BUCKET_NAME, - AWS_BUCKET_PATH: config.AWS_BUCKET_PATH, + AWS_BUCKET_PATH: config.AWS_BUCKET_PATH || '', EXPIRES_IN: config.EXPIRES_IN, AWS_CREDENTIALS: awsCredentials, }; diff --git a/src/datasources/ConsoleEvent/index.ts b/src/datasources/ConsoleEvent/index.ts index dd98a7b..f569b4a 100644 --- a/src/datasources/ConsoleEvent/index.ts +++ b/src/datasources/ConsoleEvent/index.ts @@ -14,7 +14,7 @@ export class ConsoleEvent { logByTestExecutionIdDataLoader = new DataLoader>( (ids) => Promise.all(ids.map(async (testExecutionId) => { const bucketName = config.AWS_BUCKET_NAME; - const bucketPath = config.AWS_BUCKET_PATH || ''; + const bucketPath = config.AWS_BUCKET_PATH; const json = await S3Service.getObject(bucketName, `${bucketPath}${testExecutionId}/console/console-logs.json`); const parsed = parseLogFile(json); return Object.fromEntries( diff --git a/src/datasources/NetworkEvent.ts b/src/datasources/NetworkEvent.ts index ceb0717..da8902f 100644 --- a/src/datasources/NetworkEvent.ts +++ b/src/datasources/NetworkEvent.ts @@ -14,7 +14,7 @@ export class NetworkEvent { networkEventsByTestExecutionIdDataLoader = new DataLoader>( (ids) => Promise.all(ids.map(async (testExecutionId) => { const bucketName = config.AWS_BUCKET_NAME; - const bucketPath = config.AWS_BUCKET_PATH || ''; + const bucketPath = config.AWS_BUCKET_PATH; const events = await S3Service.getObject(bucketName, `${bucketPath}${testExecutionId}/har/network-events.har`); const mappedEvents = mapNetworkEvents(events, testExecutionId); diff --git a/src/datasources/Screenshot.ts b/src/datasources/Screenshot.ts index 06fc9b5..7580b3d 100644 --- a/src/datasources/Screenshot.ts +++ b/src/datasources/Screenshot.ts @@ -14,7 +14,7 @@ export class Screenshot { screenshotByTestExecutionIdDataLoader = new DataLoader>( (ids) => Promise.all(ids.map(async (testExecutionId) => { const bucketName = config.AWS_BUCKET_NAME; - const bucketPath = config.AWS_BUCKET_PATH || ''; + const bucketPath = config.AWS_BUCKET_PATH; const screenshots = await S3Service.listObjects(bucketName, `${bucketPath}${testExecutionId}/screenshots/`); return mapScreenshots(screenshots, testExecutionId) })) diff --git a/src/datasources/Snapshot.ts b/src/datasources/Snapshot.ts index 06e851b..b7c5d07 100644 --- a/src/datasources/Snapshot.ts +++ b/src/datasources/Snapshot.ts @@ -14,7 +14,7 @@ export class Snapshot { snapshotByTestExecutionIdDataLoader = new DataLoader>( (ids) => Promise.all(ids.map(async (testExecutionId) => { const bucketName = config.AWS_BUCKET_NAME; - const bucketPath = config.AWS_BUCKET_PATH || ''; + const bucketPath = config.AWS_BUCKET_PATH; const snapshots = await S3Service.getObject(bucketName, `${bucketPath}${testExecutionId}/snapshots/snapshot-metadata.json`); const mappedSnapshots = mapSnapshots(snapshots, testExecutionId); return mappedSnapshots; diff --git a/src/datasources/StepEvent.ts b/src/datasources/StepEvent.ts index 59ca58b..3caaa2c 100644 --- a/src/datasources/StepEvent.ts +++ b/src/datasources/StepEvent.ts @@ -14,7 +14,7 @@ export class StepEvent { stepByTestExecutionIdDataLoader = new DataLoader>( (ids) => Promise.all(ids.map(async (testExecutionId) => { const bucketName = config.AWS_BUCKET_NAME; - const bucketPath = config.AWS_BUCKET_PATH || ''; + const bucketPath = config.AWS_BUCKET_PATH; const [steps, results] = await Promise.all([ S3Service.getObject(bucketName, `${bucketPath}${testExecutionId}/cypress/out.json`), this.context.dataSources.testResults.getResultsByTestExecutionId(testExecutionId), diff --git a/src/datasources/TestCodeRevision.ts b/src/datasources/TestCodeRevision.ts index 7468890..7dc3606 100644 --- a/src/datasources/TestCodeRevision.ts +++ b/src/datasources/TestCodeRevision.ts @@ -36,7 +36,7 @@ export class TestCodeRevision { cicdDataByRunIdDataLoader = new DataLoader( (ids) => Promise.all(ids.map(async (runId) => { const bucketName = config.AWS_BUCKET_NAME; - const bucketPath = config.AWS_BUCKET_PATH || ''; + const bucketPath = config.AWS_BUCKET_PATH; const cicdRaw = await S3Service.getObject(bucketName, `${bucketPath}${runId}/logs/cicd.json`) const cicd = CicdSchema.parse(cicdRaw); return cicd; diff --git a/src/datasources/TestExecution.ts b/src/datasources/TestExecution.ts index 6745ac4..ba7d818 100644 --- a/src/datasources/TestExecution.ts +++ b/src/datasources/TestExecution.ts @@ -15,7 +15,7 @@ export class TestExecution { first?: number | null, after?: string | null; }) { const bucketName = config.AWS_BUCKET_NAME; - const bucketPath = config.AWS_BUCKET_PATH || ''; + const bucketPath = config.AWS_BUCKET_PATH; const results = await S3Service.listSubFolders(bucketName, `${bucketPath}${id}/`); const testExecutionIds = results @@ -29,7 +29,7 @@ export class TestExecution { async getById(id: string) { const bucketName = config.AWS_BUCKET_NAME; - const bucketPath = config.AWS_BUCKET_PATH || ''; + const bucketPath = config.AWS_BUCKET_PATH; const [runId, requestId] = id.split('/'); const results = await S3Service.getObject(bucketName, `${bucketPath}${runId}/${requestId}/cypress/results.json`) as {startedTestsAt: string, endedTestsAt: string}; diff --git a/src/datasources/TestResults.ts b/src/datasources/TestResults.ts index fa6e84a..e4912ac 100644 --- a/src/datasources/TestResults.ts +++ b/src/datasources/TestResults.ts @@ -32,7 +32,7 @@ export class TestResults { resultsByTestExecutionIdDataLoader = new DataLoader( (ids) => Promise.all(ids.map(async (testExecutionId) => { const bucketName = config.AWS_BUCKET_NAME; - const bucketPath = config.AWS_BUCKET_PATH || ''; + const bucketPath = config.AWS_BUCKET_PATH; const rawResults = await S3Service.getObject(bucketName, `${bucketPath}${testExecutionId}/cypress/results.json`) const results = ResultsSchema.parse(rawResults); return results; diff --git a/src/datasources/TestRun.ts b/src/datasources/TestRun.ts index 5e2b23a..c714985 100644 --- a/src/datasources/TestRun.ts +++ b/src/datasources/TestRun.ts @@ -15,7 +15,7 @@ export class TestRun { first?: number | null, after?: string | null; }) { const bucketName = config.AWS_BUCKET_NAME; - const bucketPath = config.AWS_BUCKET_PATH || ''; + const bucketPath = config.AWS_BUCKET_PATH; const results = await S3Service.listSubFolders(bucketName, `${bucketPath}`); const testExecutionIds = results