UNPKG

@aws/cloudfront-hosting-toolkit

Version:

CloudFront Hosting Toolkit offers the convenience of a managed frontend hosting service while retaining full control over the hosting and deployment infrastructure to make it your own.

24 lines (23 loc) 887 B
import { validate as validateArn } from "@aws-sdk/util-arn-parser"; export function validateBucketNameMiddleware() { return (next) => async (args) => { const { input: { Bucket }, } = args; if (typeof Bucket === "string" && !validateArn(Bucket) && Bucket.indexOf("/") >= 0) { const err = new Error(`Bucket name shouldn't contain '/', received '${Bucket}'`); err.name = "InvalidBucketName"; throw err; } return next({ ...args }); }; } export const validateBucketNameMiddlewareOptions = { step: "initialize", tags: ["VALIDATE_BUCKET_NAME"], name: "validateBucketNameMiddleware", override: true, }; export const getValidateBucketNamePlugin = (unused) => ({ applyToStack: (clientStack) => { clientStack.add(validateBucketNameMiddleware(), validateBucketNameMiddlewareOptions); }, });