Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ed21ff8

Browse files
✨ use template and archive provider to fill credentials
1 parent 9b45e1a commit ed21ff8

File tree

8 files changed

+28
-99
lines changed

8 files changed

+28
-99
lines changed

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules/
33
terraform.tfstate
44
terraform.tfstate.backup
55
terraform.tfvars
6+
module/functions/basic-auth.zip

‎gulpfile.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@ const { src, dest } = require('gulp')
22
const babel = require('gulp-babel')
33
const concat = require('gulp-concat')
44
const uglify = require('gulp-uglify')
5-
const zip = require('gulp-zip')
65
const rimraf = require('rimraf')
76

8-
const ZIP_FILENAME = 'lambda-edge-basic-auth-function.zip'
9-
const ZIP_DIR = 'module/functions'
7+
const OUTPUT_FILENAME = 'basic-auth.js'
8+
const OUTPUT_DIR = 'module/functions'
109

1110
function build() {
1211
return src('src/**/*.js')
1312
.pipe(babel({
1413
presets: [ '@babel/env' ]
1514
}))
16-
.pipe(concat('basic-auth.js'))
15+
.pipe(concat(OUTPUT_FILENAME))
1716
.pipe(uglify())
18-
.pipe(zip(ZIP_FILENAME))
19-
.pipe(dest(ZIP_DIR))
17+
.pipe(dest(OUTPUT_DIR))
2018
}
2119

2220
function clean(cb) {
23-
return rimraf(`${ZIP_DIR}/${ZIP_FILENAME}`, cb)
21+
return rimraf(`${OUTPUT_DIR}/${OUTPUT_FILENAME}`, cb)
2422
}
2523

2624
function defaultTask() {

‎module/functions/basic-auth.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-383 Bytes
Binary file not shown.

‎module/main.tf

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,28 @@ EOF
5454
# Lambda functions
5555
#
5656

57+
data "template_file" "basic_auth_function" {
58+
template = "${file("${path.module}/functions/basic-auth.js")}"
59+
vars = "${var.basic_auth_credentials}"
60+
}
61+
62+
data "archive_file" "basic_auth_function" {
63+
type = "zip"
64+
output_path = "${path.module}/functions/basic-auth.zip"
65+
66+
source {
67+
content = "${data.template_file.basic_auth_function.rendered}"
68+
filename = "basic-auth.js"
69+
}
70+
}
71+
5772
resource "aws_lambda_function" "basic_auth" {
58-
filename = "${path.module}/functions/lambda-edge-basic-auth-function.zip"
73+
filename = "${path.module}/functions/basic-auth.zip"
5974
function_name = "${var.function_name}"
6075
role = "${aws_iam_role.lambda.arn}"
6176
handler = "basic-auth.handler"
62-
source_code_hash = "${base64sha256(file("${path.module}/functions/lambda-edge-basic-auth-function.zip"))}"
77+
source_code_hash = "${data.archive_file.basic_auth_function.output_base64sha256}"
6378
runtime = "nodejs8.10"
6479
description = "Protect CloudFront distributions with Basic Authentication"
6580
publish = true
6681
}
67-
68-
###
69-
# Secrets
70-
#
71-
72-
resource "aws_secretsmanager_secret" "basic_auth_credentials" {
73-
name_prefix = "lambda-edge-basic-auth-"
74-
description = "Secrets for Basic Authentication used by Lambda@Edge"
75-
}
76-
77-
resource "aws_secretsmanager_secret_version" "basic_auth_credentials" {
78-
secret_id = "${aws_secretsmanager_secret.basic_auth_credentials.id}"
79-
secret_string = "${jsonencode(var.basic_auth_credentials)}"
80-
}

‎package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"gulp-cli": "^2.0.1",
2626
"gulp-concat": "^2.6.1",
2727
"gulp-uglify": "^3.0.1",
28-
"gulp-zip": "^4.2.0",
2928
"rimraf": "^2.6.3"
3029
}
3130
}

‎src/basic-auth.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ exports.handler = (event, context, callback) => {
44
const request = event.Records[0].cf.request
55
const headers = request.headers
66

7-
const authUser = 'user'
8-
const authPass = 'pass'
7+
const authUser = '${user}'
8+
const authPass = '${password}'
99

1010
const encodedCredentials = new Buffer(`${authUser}:${authPass}`).toString('base64')
1111
const authString = `Basic ${encodedCredentials}`

‎yarn.lock

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -536,24 +536,12 @@ ansi-colors@^1.0.1:
536536
dependencies:
537537
ansi-wrap "^0.1.0"
538538

539-
ansi-cyan@^0.1.1:
540-
version "0.1.1"
541-
resolved "https://registry.yarnpkg.com/ansi-cyan/-/ansi-cyan-0.1.1.tgz#538ae528af8982f28ae30d86f2f17456d2609873"
542-
dependencies:
543-
ansi-wrap "0.1.0"
544-
545539
ansi-gray@^0.1.1:
546540
version "0.1.1"
547541
resolved "https://registry.yarnpkg.com/ansi-gray/-/ansi-gray-0.1.1.tgz#2962cf54ec9792c48510a3deb524436861ef7251"
548542
dependencies:
549543
ansi-wrap "0.1.0"
550544

551-
ansi-red@^0.1.1:
552-
version "0.1.1"
553-
resolved "https://registry.yarnpkg.com/ansi-red/-/ansi-red-0.1.1.tgz#8c638f9d1080800a353c9c28c8a81ca4705d946c"
554-
dependencies:
555-
ansi-wrap "0.1.0"
556-
557545
ansi-regex@^2.0.0:
558546
version "2.1.1"
559547
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
@@ -600,13 +588,6 @@ are-we-there-yet@~1.1.2:
600588
delegates "^1.0.0"
601589
readable-stream "^2.0.6"
602590

603-
arr-diff@^1.0.1:
604-
version "1.1.0"
605-
resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-1.1.0.tgz#687c32758163588fef7de7b36fabe495eb1a399a"
606-
dependencies:
607-
arr-flatten "^1.0.1"
608-
array-slice "^0.2.3"
609-
610591
arr-diff@^4.0.0:
611592
version "4.0.0"
612593
resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-4.0.0.tgz#d6461074febfec71e7e15235761a329a5dc7c520"
@@ -627,10 +608,6 @@ arr-map@^2.0.0, arr-map@^2.0.2:
627608
dependencies:
628609
make-iterator "^1.0.0"
629610

630-
arr-union@^2.0.1:
631-
version "2.1.0"
632-
resolved "https://registry.yarnpkg.com/arr-union/-/arr-union-2.1.0.tgz#20f9eab5ec70f5c7d215b1077b1c39161d292c7d"
633-
634611
arr-union@^3.1.0:
635612
version "3.1.0"
636613
resolved "https://registry.yarnpkg.com/arr-union/-/arr-union-3.1.0.tgz#e39b09aea9def866a8f206e288af63919bae39c4"
@@ -652,10 +629,6 @@ array-last@^1.1.1:
652629
dependencies:
653630
is-number "^4.0.0"
654631

655-
array-slice@^0.2.3:
656-
version "0.2.3"
657-
resolved "https://registry.yarnpkg.com/array-slice/-/array-slice-0.2.3.tgz#dd3cfb80ed7973a75117cdac69b0b99ec86186f5"
658-
659632
array-slice@^1.0.0:
660633
version "1.1.0"
661634
resolved "https://registry.yarnpkg.com/array-slice/-/array-slice-1.1.0.tgz#e368ea15f89bc7069f7ffb89aec3a6c7d4ac22d4"
@@ -763,10 +736,6 @@ browserslist@^4.3.4:
763736
electron-to-chromium "^1.3.103"
764737
node-releases "^1.1.3"
765738

766-
buffer-crc32@~0.2.3:
767-
version "0.2.13"
768-
resolved "https://registry.yarnpkg.com/buffer-crc32/-/buffer-crc32-0.2.13.tgz#0d333e3f00eac50aa1454abd30ef8c2a5d9a7242"
769-
770739
buffer-equal@^1.0.0:
771740
version "1.0.0"
772741
resolved "https://registry.yarnpkg.com/buffer-equal/-/buffer-equal-1.0.0.tgz#59616b498304d556abd466966b22eeda3eca5fbe"
@@ -1168,12 +1137,6 @@ expand-tilde@^2.0.0, expand-tilde@^2.0.2:
11681137
dependencies:
11691138
homedir-polyfill "^1.0.1"
11701139

1171-
extend-shallow@^1.1.2:
1172-
version "1.1.4"
1173-
resolved "https://registry.yarnpkg.com/extend-shallow/-/extend-shallow-1.1.4.tgz#19d6bf94dfc09d76ba711f39b872d21ff4dd9071"
1174-
dependencies:
1175-
kind-of "^1.1.0"
1176-
11771140
extend-shallow@^2.0.1:
11781141
version "2.0.1"
11791142
resolved "https://registry.yarnpkg.com/extend-shallow/-/extend-shallow-2.0.1.tgz#51af7d614ad9a9f610ea1bafbb989d6b1c56890f"
@@ -1326,10 +1289,6 @@ get-caller-file@^1.0.1:
13261289
version "1.0.3"
13271290
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a"
13281291

1329-
get-stream@^3.0.0:
1330-
version "3.0.0"
1331-
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14"
1332-
13331292
get-stream@^4.0.0:
13341293
version "4.1.0"
13351294
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-4.1.0.tgz#c1b255575f3dc21d59bfc79cd3d2b46b1c3a54b5"
@@ -1469,16 +1428,6 @@ gulp-uglify@^3.0.1:
14691428
uglify-js "^3.0.5"
14701429
vinyl-sourcemaps-apply "^0.2.0"
14711430

1472-
gulp-zip@^4.2.0:
1473-
version "4.2.0"
1474-
resolved "https://registry.yarnpkg.com/gulp-zip/-/gulp-zip-4.2.0.tgz#e25e738c41ad0795ad853d1d8aeb1744d2a4ca82"
1475-
dependencies:
1476-
get-stream "^3.0.0"
1477-
plugin-error "^0.1.2"
1478-
through2 "^2.0.1"
1479-
vinyl "^2.1.0"
1480-
yazl "^2.1.0"
1481-
14821431
gulp@^4.0.0:
14831432
version "4.0.0"
14841433
resolved "https://registry.yarnpkg.com/gulp/-/gulp-4.0.0.tgz#95766c601dade4a77ed3e7b2b6dc03881b596366"
@@ -1793,10 +1742,6 @@ just-debounce@^1.0.0:
17931742
version "1.0.0"
17941743
resolved "https://registry.yarnpkg.com/just-debounce/-/just-debounce-1.0.0.tgz#87fccfaeffc0b68cd19d55f6722943f929ea35ea"
17951744

1796-
kind-of@^1.1.0:
1797-
version "1.1.0"
1798-
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-1.1.0.tgz#140a3d2d41a36d2efcfa9377b62c24f8495a5c44"
1799-
18001745
kind-of@^3.0.2, kind-of@^3.0.3, kind-of@^3.2.0:
18011746
version "3.2.2"
18021747
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64"
@@ -2343,16 +2288,6 @@ pinkie@^2.0.0:
23432288
version "2.0.4"
23442289
resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"
23452290

2346-
plugin-error@^0.1.2:
2347-
version "0.1.2"
2348-
resolved "https://registry.yarnpkg.com/plugin-error/-/plugin-error-0.1.2.tgz#3b9bb3335ccf00f425e07437e19276967da47ace"
2349-
dependencies:
2350-
ansi-cyan "^0.1.1"
2351-
ansi-red "^0.1.1"
2352-
arr-diff "^1.0.1"
2353-
arr-union "^2.0.1"
2354-
extend-shallow "^1.1.2"
2355-
23562291
plugin-error@^1.0.1:
23572292
version "1.0.1"
23582293
resolved "https://registry.yarnpkg.com/plugin-error/-/plugin-error-1.0.1.tgz#77016bd8919d0ac377fdcdd0322328953ca5781c"
@@ -2829,7 +2764,7 @@ through2-filter@^3.0.0:
28292764
through2 "~2.0.0"
28302765
xtend "~4.0.0"
28312766

2832-
through2@^2.0.0, through2@^2.0.1, through2@^2.0.3, through2@~2.0.0:
2767+
through2@^2.0.0, through2@^2.0.3, through2@~2.0.0:
28332768
version "2.0.5"
28342769
resolved "https://registry.yarnpkg.com/through2/-/through2-2.0.5.tgz#01c1e39eb31d07cb7d03a96a70823260b23132cd"
28352770
dependencies:
@@ -3031,7 +2966,7 @@ vinyl-sourcemaps-apply@^0.2.0:
30312966
dependencies:
30322967
source-map "^0.5.1"
30332968

3034-
vinyl@^2.0.0, vinyl@^2.1.0:
2969+
vinyl@^2.0.0:
30352970
version "2.2.0"
30362971
resolved "https://registry.yarnpkg.com/vinyl/-/vinyl-2.2.0.tgz#d85b07da96e458d25b2ffe19fece9f2caa13ed86"
30372972
dependencies:
@@ -3136,9 +3071,3 @@ yargs@^7.1.0:
31363071
which-module "^1.0.0"
31373072
y18n "^3.2.1"
31383073
yargs-parser "^5.0.0"
3139-
3140-
yazl@^2.1.0:
3141-
version "2.5.1"
3142-
resolved "https://registry.yarnpkg.com/yazl/-/yazl-2.5.1.tgz#a3d65d3dd659a5b0937850e8609f22fffa2b5c35"
3143-
dependencies:
3144-
buffer-crc32 "~0.2.3"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /