@awsless/awsless 0.0.535 → 0.0.536

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.js CHANGED
@@ -1564,6 +1564,10 @@ var SitesSchema = z32.record(
1564
1564
  origins: z32.string().array().default(["*"]),
1565
1565
  methods: z32.enum(["GET", "DELETE", "HEAD", "OPTIONS", "PATCH", "POST", "PUT", "ALL"]).array().default(["ALL"])
1566
1566
  }).optional().describe("Specify the cors headers."),
1567
+ auth: z32.object({
1568
+ username: z32.string().describe("Basic auth username"),
1569
+ password: z32.string().describe("Basic auth password")
1570
+ }).optional().describe("Enable basic authentication for the site"),
1567
1571
  security: z32.object({
1568
1572
  // contentSecurityPolicy: z.object({
1569
1573
  // override: z.boolean().default(false),
@@ -4736,13 +4740,16 @@ var getCacheControl = (file) => {
4736
4740
  var getContentType = (file) => {
4737
4741
  return contentType(extname2(file)) || "text/html; charset=utf-8";
4738
4742
  };
4739
- var getViewerRequestFunctionCode = (domain2, bucket, functionUrl) => {
4743
+ var getViewerRequestFunctionCode = (domain2, bucket, functionUrl, basicAuth) => {
4740
4744
  return $resolve([bucket?.bucketRegionalDomainName, functionUrl?.functionUrl], (bucketDomain, lambdaUrl) => {
4741
4745
  return CF_FUNC_WRAP([
4742
4746
  // --------------------------------------------------------
4743
4747
  // Block direct access to cloudfront.
4744
4748
  domain2 ? BLOCK_DIRECT_ACCESS_TO_CLOUDFRONT : "",
4745
4749
  // --------------------------------------------------------
4750
+ // Basic Authentication
4751
+ basicAuth ? BASIC_AUTH_CHECK(basicAuth.username, basicAuth.password) : "",
4752
+ // --------------------------------------------------------
4746
4753
  // Define functions.
4747
4754
  bucketDomain ? GET_PREFIXES : "",
4748
4755
  bucketDomain ? SET_S3_ORIGIN : "",
@@ -4775,6 +4782,18 @@ if (event.request.headers.host.value.includes('cloudfront.net')) {
4775
4782
  statusDescription: 'Forbidden'
4776
4783
  };
4777
4784
  }`;
4785
+ var BASIC_AUTH_CHECK = (username, password) => `
4786
+ var auth = event.request.headers.authorization && event.request.headers.authorization.value;
4787
+ if (!auth || !auth.startsWith('Basic ') || atob(auth.slice(6)) !== '${username}:${password}') {
4788
+ return {
4789
+ statusCode: 401,
4790
+ headers: {
4791
+ 'www-authenticate': {
4792
+ value: 'Basic realm="Protected"'
4793
+ }
4794
+ }
4795
+ };
4796
+ }`;
4778
4797
  var SET_S3_ORIGIN = `
4779
4798
  function setS3Origin(s3Domain) {
4780
4799
  const origin = {
@@ -4787,8 +4806,8 @@ function setS3Origin(s3Domain) {
4787
4806
  }
4788
4807
  };
4789
4808
 
4790
- console.log("s3 origin")
4791
- console.log(origin)
4809
+ // console.log("s3 origin")
4810
+ // console.log(origin)
4792
4811
  cf.updateRequestOrigin(origin);
4793
4812
  }`;
4794
4813
  var SET_LAMBDA_ORIGIN = `
@@ -5089,7 +5108,7 @@ var siteFeature = defineFeature({
5089
5108
  runtime: `cloudfront-js-2.0`,
5090
5109
  comment: `Viewer Request - ${name}`,
5091
5110
  publish: true,
5092
- code: getViewerRequestFunctionCode(domainName, bucket, functionUrl),
5111
+ code: getViewerRequestFunctionCode(domainName, bucket, functionUrl, props.auth),
5093
5112
  keyValueStoreAssociations: kvs ? [kvs.arn] : void 0
5094
5113
  });
5095
5114
  const distribution = new $15.aws.cloudfront.Distribution(group, "distribution", {
@@ -959,6 +959,10 @@ var SitesSchema = z29.record(
959
959
  origins: z29.string().array().default(["*"]),
960
960
  methods: z29.enum(["GET", "DELETE", "HEAD", "OPTIONS", "PATCH", "POST", "PUT", "ALL"]).array().default(["ALL"])
961
961
  }).optional().describe("Specify the cors headers."),
962
+ auth: z29.object({
963
+ username: z29.string().describe("Basic auth username"),
964
+ password: z29.string().describe("Basic auth password")
965
+ }).optional().describe("Enable basic authentication for the site"),
962
966
  security: z29.object({
963
967
  // contentSecurityPolicy: z.object({
964
968
  // override: z.boolean().default(false),
Binary file
Binary file
@@ -1 +1 @@
1
- 067ac22da538619c808461cfb4c14803a7a8917d
1
+ 8446d078f922ef61f32bfa9a1e660975640f784c
Binary file