Merge branch 'develop' into docs/revise-architectural-modules
This commit is contained in:
commit
d289665de9
4 files changed
+31
-12
No files matched your search
@@ -1,7 +1,8 @@
|
|||||||
export interface S3FileServiceOptions {
|
export interface S3FileServiceOptions {
|
||||||
file_url: string
|
file_url: string
|
||||||
access_key_id: string
|
access_key_id?: string
|
||||||
secret_access_key: string
|
secret_access_key?: string
|
||||||
|
authentication_method?: "access-key" | "s3-iam-role"
|
||||||
region: string
|
region: string
|
||||||
bucket: string
|
bucket: string
|
||||||
prefix?: string
|
prefix?: string
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest --passWithNoTests src",
|
"test": "jest --passWithNoTests src",
|
||||||
"test:integration": "jest --forceExit -- integration-tests/**/__tests__/**/*.spec.ts",
|
"test:integration": "jest --forceExit -- integration-tests/__tests__/*.spec.ts",
|
||||||
"build": "rimraf dist && tsc --build ./tsconfig.json",
|
"build": "rimraf dist && tsc --build ./tsconfig.json",
|
||||||
"watch": "tsc --watch"
|
"watch": "tsc --watch"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ type InjectedDependencies = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface S3FileServiceConfig {
|
interface S3FileServiceConfig {
|
||||||
// TODO: We probably don't need this as either the service should return it or we should be able to calculate it.
|
|
||||||
fileUrl: string
|
fileUrl: string
|
||||||
accessKeyId: string
|
accessKeyId?: string
|
||||||
secretAccessKey: string
|
secretAccessKey?: string
|
||||||
|
authenticationMethod?: "access-key" | "s3-iam-role"
|
||||||
region: string
|
region: string
|
||||||
bucket: string
|
bucket: string
|
||||||
prefix?: string
|
prefix?: string
|
||||||
@@ -36,7 +36,6 @@ interface S3FileServiceConfig {
|
|||||||
additionalClientConfig?: Record<string, any>
|
additionalClientConfig?: Record<string, any>
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUTURE: At one point we will probably need to support authenticating with IAM roles instead.
|
|
||||||
export class S3FileService extends AbstractFileProviderService {
|
export class S3FileService extends AbstractFileProviderService {
|
||||||
static identifier = "s3"
|
static identifier = "s3"
|
||||||
protected config_: S3FileServiceConfig
|
protected config_: S3FileServiceConfig
|
||||||
@@ -46,10 +45,23 @@ export class S3FileService extends AbstractFileProviderService {
|
|||||||
constructor({ logger }: InjectedDependencies, options: S3FileServiceOptions) {
|
constructor({ logger }: InjectedDependencies, options: S3FileServiceOptions) {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
|
const authenticationMethod = options.authentication_method ?? "access-key"
|
||||||
|
|
||||||
|
if (
|
||||||
|
authenticationMethod === "access-key" &&
|
||||||
|
(!options.access_key_id || !options.secret_access_key)
|
||||||
|
) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.INVALID_DATA,
|
||||||
|
`Access key ID and secret access key are required when using access key authentication`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
this.config_ = {
|
this.config_ = {
|
||||||
fileUrl: options.file_url,
|
fileUrl: options.file_url,
|
||||||
accessKeyId: options.access_key_id,
|
accessKeyId: options.access_key_id,
|
||||||
secretAccessKey: options.secret_access_key,
|
secretAccessKey: options.secret_access_key,
|
||||||
|
authenticationMethod: authenticationMethod,
|
||||||
region: options.region,
|
region: options.region,
|
||||||
bucket: options.bucket,
|
bucket: options.bucket,
|
||||||
prefix: options.prefix ?? "",
|
prefix: options.prefix ?? "",
|
||||||
@@ -63,11 +75,17 @@ export class S3FileService extends AbstractFileProviderService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected getClient() {
|
protected getClient() {
|
||||||
|
// If none is provided, the SDK will use the default credentials provider chain, see https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-envvars.html
|
||||||
|
const credentials =
|
||||||
|
this.config_.authenticationMethod === "access-key"
|
||||||
|
? {
|
||||||
|
accessKeyId: this.config_.accessKeyId!,
|
||||||
|
secretAccessKey: this.config_.secretAccessKey!,
|
||||||
|
}
|
||||||
|
: undefined
|
||||||
|
|
||||||
const config: S3ClientConfigType = {
|
const config: S3ClientConfigType = {
|
||||||
credentials: {
|
credentials,
|
||||||
accessKeyId: this.config_.accessKeyId,
|
|
||||||
secretAccessKey: this.config_.secretAccessKey,
|
|
||||||
},
|
|
||||||
region: this.config_.region,
|
region: this.config_.region,
|
||||||
endpoint: this.config_.endpoint,
|
endpoint: this.config_.endpoint,
|
||||||
...this.config_.additionalClientConfig,
|
...this.config_.additionalClientConfig,
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ export const syncBrandsWorkflow = createWorkflow(
|
|||||||
() => {
|
() => {
|
||||||
const brands = retrieveBrandsStep()
|
const brands = retrieveBrandsStep()
|
||||||
|
|
||||||
updateBrandsInCmsStep({ brands })
|
createBrandsInCmsStep({ brands })
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in new issue
Block a user