From 3b725ea9ff760aadafd92acd305c68a82dd63df4 Mon Sep 17 00:00:00 2001 From: Michael Maurizi Date: Fri, 1 Mar 2019 15:40:41 -0500 Subject: [PATCH] Remove Google API keys from repository into shared secrets file --- Jenkinsfile | 5 +---- README.md | 10 ++++++++-- example/constants.ts.example | 1 + src/app/app.module.ts | 5 ++--- src/environments/environment.prod.ts | 1 - src/environments/environment.ts | 1 - 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8db28937..c38667f2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -29,10 +29,7 @@ node { stage('test') { wrap([$class: 'AnsiColorBuildWrapper']) { - writeFile file: 'src/app/constants.ts', text: """ - export const defaultCity = {\'id\': 7, \'properties\': {\'name\': \'Philadelphia\', \'admin\': \'PA\'}}; - export const apiHost = \'${env.API_HOST}\'; - export const defaultScenario = \'RCP85\';\n""" + sh "aws s3 cp 's3://${env.CC_SETTINGS_BUCKET}/angular/constants.ts' 'src/app/constants.ts'" sh './scripts/test --jenkins' diff --git a/README.md b/README.md index 94a4ad9c..4768816f 100644 --- a/README.md +++ b/README.md @@ -13,12 +13,18 @@ Alternatively, you can bring up the vagrant VM that has the dependencies install If your development host machine meets the requirements above, simply: - Clone this repo and run `yarn install` - - `cp example/constants.ts.example src/app/constants.ts` - - Edit `constants.ts` to set the API server name + - Copy the "Climate lab dev config" from LastPass to `src/app/constants.ts` (See below if you do not have access to this resource) - `yarn run serve` The site will then be available at [http://localhost:4200](http://localhost:4200) on your host machine. +#### Setting up constants.ts + +For users who don't have access to our internal configuration file, you can create your own with the following steps: + - Enable the "Maps JavaScript API" and "Places API" from the [Google API library](https://console.cloud.google.com/apis/library), then create a new [Google API key](https://console.cloud.google.com/apis/credentials/). You can restrict it to the "Maps JavaScript API" and "Places API" with referrers set to `http://localhost:4200/*` + - `cp example/constants.ts.example src/app/constants.ts` + - Edit `constants.ts` to set the API server name and Google API key + ### Setup via Vagrant VM _Recommended only if you don't have the requirements above installed on your host system and are unable to install. If you do, strongly consider instructions in #Setup instead._ diff --git a/example/constants.ts.example b/example/constants.ts.example index 2433645d..909d9c4e 100644 --- a/example/constants.ts.example +++ b/example/constants.ts.example @@ -4,3 +4,4 @@ */ export const apiHost = 'https://app.climate.azavea.com'; +export const googleApiKey = 'Add API key here'; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index be9f3671..6f64ad83 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -49,8 +49,7 @@ import { ImageExportService } from './services/image-export.service'; import { MapCellService } from './services/map-cell.service'; import { ProjectService } from './services/project.service'; -import { apiHost } from './constants'; -import { environment } from '../environments/environment'; +import { apiHost, googleApiKey } from './constants'; // Custom app providers const locationStrategyProvider = { @@ -60,7 +59,7 @@ const locationStrategyProvider = { // Google maps config const AGM_CONFIG = { - apiKey: environment.googleMapsApiKey, + apiKey: googleApiKey, libraries: ['places'] }; diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 43d8eb42..5173b59d 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,5 +1,4 @@ export const environment = { production: true, distance: 32000, - googleMapsApiKey: 'AIzaSyDbVOdIZAq4rBo94p947kCBo_KKPyqFf9I', }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 68f5d325..8f4c3e4b 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -6,5 +6,4 @@ export const environment = { production: false, distance: 32000, - googleMapsApiKey: 'AIzaSyCUvxTzvJ9kGEu2S7U641D7QGt5Xym0DjM', };