-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Job Launcher - CVAT S3 bucket limitations (#1379)
* add storage params cvat dto * disable GCS and fix tests * Add error message and test * Improve error checks and messages * use storage data class for hcaptcha
- Loading branch information
Showing
7 changed files
with
326 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
packages/apps/job-launcher/server/src/common/enums/storage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/apps/job-launcher/server/src/common/utils/storage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { BadRequestException } from '@nestjs/common'; | ||
import { StorageDataDto } from '../../modules/job/job.dto'; | ||
import { AWSRegions, StorageProviders } from '../enums/storage'; | ||
import { ErrorBucket } from '../constants/errors'; | ||
|
||
export function generateBucketUrl(storageData: StorageDataDto): string { | ||
if (!storageData.bucketName) { | ||
throw new BadRequestException(ErrorBucket.EmptyBucket); | ||
} | ||
switch (storageData.provider) { | ||
case StorageProviders.AWS: | ||
if (!storageData.region) { | ||
throw new BadRequestException(ErrorBucket.EmptyRegion); | ||
} | ||
if (!isRegion(storageData.region)) { | ||
throw new BadRequestException(ErrorBucket.InvalidRegion); | ||
} | ||
return `https://${storageData.bucketName}.s3.${ | ||
storageData.region | ||
}.amazonaws.com${ | ||
storageData.path ? `/${storageData.path.replace(/\/$/, '')}` : '' | ||
}`; | ||
// case StorageProviders.GCS: | ||
// return `https://${s3Data.bucketName}.storage.googleapis.com${ | ||
// s3Data.path ? `/${s3Data.path}` : '' | ||
// }`; | ||
default: | ||
throw new BadRequestException(ErrorBucket.InvalidProvider); | ||
} | ||
} | ||
|
||
function isRegion(value: string): value is AWSRegions { | ||
return Object.values(AWSRegions).includes(value as AWSRegions); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
2b9372e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
job-launcher-server – ./packages/apps/job-launcher/server
job-launcher-server-git-develop-humanprotocol.vercel.app
job-launcher-server-nine.vercel.app
job-launcher-server-humanprotocol.vercel.app
stg-job-launcher-server.vercel.app