From f074e41a89ab102237b01f08c0c380bf9d27a5a9 Mon Sep 17 00:00:00 2001 From: victory Date: Sat, 12 Jun 2021 00:54:06 +0100 Subject: [PATCH] feat: added full list of environement credentials --- .github/workflows/ci.yml | 2 +- README.md | 73 +++++++++++++++++++++++++++---- netlify/functions/subscription.js | 2 +- 3 files changed, 67 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a600f1..590d1ed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,7 +63,7 @@ jobs: - name: Run the semantic-release run: npx semantic-release env: - GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Code Coverage Report diff --git a/README.md b/README.md index 432dd07..4a39cb1 100644 --- a/README.md +++ b/README.md @@ -9,26 +9,83 @@ The image below shows the architecture of these serverless functions in connecti ## Running Locally -The serverless functions within this project are managed using [netlify-dev](https://www.netlify.com/products/dev/). Start the functions emulator from the `netlify` directory using `yarn netlify-dev` to listen for requests to any of created functions on port `5050`. +The serverless functions within this project are managed using [netlify-dev](https://www.netlify.com/products/dev/). +Start the function emulator using `yarn netlify-dev` command to handle any HTTP request made to any of the created functions on port `5050`. -Credentials within this project are managed using environment variables and [GitHub Secrets](https://docs.github.com/en/actions/reference/encrypted-secrets). To run the functions here locally using the `netlify dev` command, create a `.env` file in the root directory with the following values; +Service credentials used within the serverless functions in this project are loaded as environment variables using [dotenv](https://www.npmjs.com/package/dotenv). +Before executing the `netlify dev` command, create a `.env` file in the root directory with the following values to store the needed credentials; + +**Note:** It is recommended to test the Stripe integration in a test mode using [Test API Keys ](https://stripe.com/docs/keys#test-live-modes) from Stripe. ``` # Access key from Stripe to access your Stripe resources STRIPE_KEY=STRIPE_KEY -# The product ID which users are subscribed to. -EMAIL_PRODUCT_ID=STRIPE_KEY +# The ID of the email price product used in billing subscribers. +EMAIL_PRODUCT_PRICE_ID=EMAIL_PRODUCT_PRICE_ID + +# Your Auth0 Domain +AUTHO_DOMAIN=AUTHO_DOMAIN + +# Auth0 Management Application Client ID +MGT_CLIENT_ID=MGT_CLIENT_ID + +# Auth0 Management Application Client Secret +MGT_CLIENT_SECRET=MGT_CLIENT_SECRET + +# Email SMTP host +SMTP_HOST=SMTP_HOST + +# Email SMTP Password +SMTP_PASSWORD=SMTP_PASSWORD + +# Email Sender Address +SMTP_SENDER=SMTP_SENDER + +# Email SMTP Username +SMTP_USERNAME=SMTP_USERNAME ``` ## CI / CD Pipeline +All serverless function endpoints within this Cloud API all tested using [Postman Tests](https://www.postman.com/automated-testing/). The API documentation explaining the endpoints can be found in the GitHub pages for this repository [here](https://ambianic.github.io/ambianic-subscriptions.github.io/). An exported file of the postman collection in json format is available at `./tests/postman/ambianic-functions-collection.postman_collection.json`. -The three currently available serverless function endpoints are all tested using [Postman Tests](https://www.postman.com/automated-testing/). The API documentation explaining the endpoints can be found in the GitHub pages for this repository [here](https://ambianic.github.io/ambianic-subscriptions.github.io/). An exported file of the postman collection in json format is available at `./tests/postman/ambianic-functions-collection.postman_collection.json`. - -Continuous integration for this project is managed using [GitHub Actions](https://github.com/features/actions), driven using the steps in the `.github/workflows/ci.yaml` file. The following sensitive credentials used within the CI jobs are managed using [Github Secrets](https://docs.github.com/en/actions/reference/encrypted-secrets); +Continuous integration for this project is managed using [GitHub Actions](https://github.com/features/actions), driven using the steps in the `.github/workflows/ci.yaml` file. +The following sensitive credentials are used within the CI jobs are stored using [Github Secrets](https://docs.github.com/en/actions/reference/encrypted-secrets) and are retrieved and used within each workflow build; -- STRIPE_KEY - GITHUB_TOKEN - NPM_TOKEN - REPOSITORY_ACCESS_TOKEN + +## Cloud Deployment +All serverless functions within this project were designed to be deployed and executed as [Netlify Functions](https://www.netlify.com/products/functions/). +The following environment variables used within the serverless functions, and should be added in your application's [Build Environment Variables](https://docs.netlify.com/configure-builds/environment-variables/) when the project is deployed to [Netlify](https://www.netlify.com). + +``` +# Access key from Stripe to access your Stripe resources +STRIPE_KEY=STRIPE_KEY + +# The ID of the email price product used in billing subscribers. +EMAIL_PRODUCT_PRICE_ID=EMAIL_PRODUCT_PRICE_ID + +# Your Auth0 Domain +AUTHO_DOMAIN=AUTHO_DOMAIN + +# Auth0 Management Application Client ID +MGT_CLIENT_ID=MGT_CLIENT_ID + +# Auth0 Management Application Client Secret +MGT_CLIENT_SECRET=MGT_CLIENT_SECRET + +# Email SMTP host +SMTP_HOST=SMTP_HOST + +# Email SMTP Password +SMTP_PASSWORD=SMTP_PASSWORD + +# Email Sender Address +SMTP_SENDER=SMTP_SENDER + +# Email SMTP Username +SMTP_USERNAME=SMTP_USERNAME +``` \ No newline at end of file diff --git a/netlify/functions/subscription.js b/netlify/functions/subscription.js index 6e78885..9130d0b 100644 --- a/netlify/functions/subscription.js +++ b/netlify/functions/subscription.js @@ -64,7 +64,7 @@ exports.handler = async ( customer: customerID, items: [ { - price: process.env.EMAIL_PRODUCT_ID, + price: process.env.EMAIL_PRODUCT_PRICE_ID, }, ], })