Skip to content

Commit

Permalink
Improve codespace secrets approach (#1798)
Browse files Browse the repository at this point in the history
* Make more options setable through env var
* Pass system variables through to docker
* Prompt on codespace creation for suggested keys
  • Loading branch information
ajparsons authored Oct 7, 2024
1 parent 81b00a3 commit f3f8ed9
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .devcontainer/auto-quick-setup/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
{
"name": "theyworkforyou",
"secrets": {
"TWFY_VOTES_URL": {
"description": "URL to the TWFY Votes page"
},
"MAPIT_URL": {
"description": "URL to the MapIt API - defaults to mapit.mysociety.org."
},
"MAPIT_API_KEY": {
"description": "API key for the MapIt API - optional for small numbers of queries."
},
"DEMOCRACYCLUB_TOKEN": {
"description": "API key for the Democracy Club API - only for election postcode lookups."
},
"RECAPTCHA_SITE_KEY": {
"description": "Recaptcha site key. Can use v2 test keys from link.",
"documentationUrl": "https://developers.google.com/recaptcha/docs/faq#:~:text=hidden%3B%20%7D-,I%27d%20like%20to%20run%20automated%20tests%20with%20reCAPTCHA.%20What%20should%20I%20do%3F,-For%20reCAPTCHA%20v3"

},
"RECAPTCHA_SECRET": {
"description": "Recaptcha secret key. Can use v2 test keys from link.",
"documentationUrl": "https://developers.google.com/recaptcha/docs/faq#:~:text=hidden%3B%20%7D-,I%27d%20like%20to%20run%20automated%20tests%20with%20reCAPTCHA.%20What%20should%20I%20do%3F,-For%20reCAPTCHA%20v3"

},
"STRIPE_DONATE_PUBLIC_KEY": {
"description": "Stripe donate public key (test key). Only needed for donate page testing."
},
"STRIPE_DONATE_SECRET_KEY": {
"description": "Stripe donate secret key (test key). Only needed for donate page testing."
}

},
"dockerComposeFile": "../../docker-compose.yml",
"service": "twfy",
"workspaceFolder": "/twfy",
Expand Down
30 changes: 30 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
{
"name": "theyworkforyou",
"secrets": {
"TWFY_VOTES_URL": {
"description": "URL to the TWFY Votes page"
},
"MAPIT_URL": {
"description": "URL to the MapIt API - defaults to mapit.mysociety.org"
},
"MAPIT_API_KEY": {
"description": "API key for the MapIt API - optional for small numbers of queries"
},
"DEMOCRACYCLUB_TOKEN": {
"description": "API key for the Democracy Club API - only for election postcode lookups."
},
"RECAPTCHA_SITE_KEY": {
"description": "Recaptcha site key. Can use v2 test keys from link.",
"documentationUrl": "https://developers.google.com/recaptcha/docs/faq#:~:text=hidden%3B%20%7D-,I%27d%20like%20to%20run%20automated%20tests%20with%20reCAPTCHA.%20What%20should%20I%20do%3F,-For%20reCAPTCHA%20v3"

},
"RECAPTCHA_SECRET": {
"description": "Recaptcha secret key. Can use v2 test keys from link.",
"documentationUrl": "https://developers.google.com/recaptcha/docs/faq#:~:text=hidden%3B%20%7D-,I%27d%20like%20to%20run%20automated%20tests%20with%20reCAPTCHA.%20What%20should%20I%20do%3F,-For%20reCAPTCHA%20v3"

},
"STRIPE_DONATE_PUBLIC_KEY": {
"description": "Stripe donate public key (test key). Only needed for donate page testing."
},
"STRIPE_DONATE_SECRET_KEY": {
"description": "Stripe donate secret key (test key). Only needed for donate page testing."
}

},
"dockerComposeFile": "../docker-compose.yml",
"service": "twfy",
"workspaceFolder": "/twfy",
Expand Down
7 changes: 7 additions & 0 deletions bin/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ sed -r \
-e 's!^(.*"OPTION_TWFY_DB_NAME", *)"[^"]*"!'"\\1'twfy'!" \
-e 's!^(.*"OPTION_TWFY_MEMCACHED_HOST", *)"[^"]*"!'"\\1'memcache'!" \
-e 's!^(.*"TWFY_VOTES_URL", *)"[^"]*"!'"\\1'$TWFY_VOTES_URL'!" \
-e 's!^(.*"OPTION_MAPIT_URL", *)"[^"]*"!'"\\1'$MAPIT_URL'!" \
-e 's!^(.*"OPTION_MAPIT_API_KEY", *)"[^"]*"!'"\\1'$MAPIT_API_KEY'!" \
-e 's!^(.*"OPTION_DEMOCRACYCLUB_TOKEN", *)"[^"]*"!'"\\1'$DEMOCRACYCLUB_TOKEN'!" \
-e 's!^(.*"OPTION_RECAPTCHA_SITE_KEY", *)"[^"]*"!'"\\1'$RECAPTCHA_SITE_KEY'!" \
-e 's!^(.*"OPTION_RECAPTCHA_SECRET", *)"[^"]*"!'"\\1'$RECAPTCHA_SECRET'!" \
-e 's!^(.*"STRIPE_DONATE_PUBLIC_KEY", *)"[^"]*"!'"\\1'$STRIPE_DONATE_PUBLIC_KEY'!" \
-e 's!^(.*"STRIPE_DONATE_SECRET_KEY", *)"[^"]*"!'"\\1'$STRIPE_DONATE_SECRET_KEY'!" \
-e 's!^(.*"BASEDIR", *)"[^"]*"!'"\\1'/twfy/www/docs'!" \
-e 's!^(.*"DOMAIN", *)"[^"]*"!'"\\1'localhost'!" \
-e 's!^(.*"COOKIEDOMAIN", *)"[^"]*"!'"\\1'localhost'!" \
Expand Down
2 changes: 2 additions & 0 deletions conf/general-example
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ define('OPTION_HEARFROMYOURMP_BASE_URL', '');
if (!defined('OPTION_MAPIT_URL')) {
define('OPTION_MAPIT_URL', '');
}

define('OPTION_MAPIT_API_KEY', '');
define('OPTION_DEMOCRACYCLUB_TOKEN', '');
define('OPTION_MAPIT_UPRN_LOOKUP', '');

Expand Down
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ services:
TWFY_TEST_DB_USER: twfy
TWFY_TEST_DB_PASS: password
TWFY_VOTES_URL: ${TWFY_VOTES_URL}
MAPIT_URL: ${MAPIT_URL:-https://mapit.mysociety.org/}
MAPIT_API_KEY: ${MAPIT_API_KEY:-}
DEMOCRACYCLUB_TOKEN: ${DEMOCRACYCLUB_TOKEN:-}
RECAPTCHA_SITE_KEY: ${RECAPTCHA_SITE_KEY:-}
RECAPTCHA_SECRET: ${RECAPTCHA_SECRET:-}
STRIPE_DONATE_PUBLIC_KEY: ${STRIPE_DONATE_PUBLIC_KEY:-}
STRIPE_DONATE_SECRET_KEY: ${STRIPE_DONATE_SECRET_KEY:-}
DEV_MODE: 'true'
WSL_IP:
ports:
Expand Down

0 comments on commit f3f8ed9

Please sign in to comment.