Skip to content

Commit

Permalink
Remove CF secret parsing. Not needed for new BEIS PaaS
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbarnett91 committed Nov 24, 2023
1 parent 8b3c7e5 commit 0aca458
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 25 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ dependencies {
implementation 'org.jsoup:jsoup:1.16.2'
implementation 'com.google.guava:guava:32.1.3-jre'
implementation 'io.nayuki:qrcodegen:1.6.0'
implementation 'io.pivotal.cfenv:java-cfenv:2.4.2'
implementation 'org.yaml:snakeyaml:2.2' // shade older 1.33 provided by Spring Boot 3.1 to fix CVEs. Can be removed when going to Spring Boot 3.2
implementation 'org.slf4j:slf4j-api:2.0.7'

Expand Down
27 changes: 3 additions & 24 deletions src/main/java/uk/gov/beis/els/service/AnalyticsService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package uk.gov.beis.els.service;

import com.google.common.base.Strings;
import io.pivotal.cfenv.core.CfEnv;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -33,10 +32,11 @@ public class AnalyticsService {

public AnalyticsService(@Value("${app.enable_google_analytics}") boolean analyticsEnabled,
@Value("${app.analytics_connection_timeout_ms}") int connectionTimeoutMs,
@Value("${app.analytics_measurement_id}") String measurementId) {
@Value("${app.analytics_measurement_id}") String measurementId,
@Value("${app.analytics_api_secret}") String apiSecret) {
this.analyticsEnabled = analyticsEnabled;
this.connectionTimeoutMs = connectionTimeoutMs;
this.apiSecret = parseGaApiSecret();
this.apiSecret = apiSecret;
this.measurementId = measurementId;
}

Expand Down Expand Up @@ -84,25 +84,4 @@ public void sendGoogleAnalyticsEvent(String jsClientId, GoogleAnalyticsEventCate

}

// Handle secrets set via GovUk PaaS. Can be removed once migrated to BEIS AWS platform
// See https://docs.cloudfoundry.org/devguide/deploy-apps/environment-variable.html#VCAP-SERVICES and
// https://docs.cloudfoundry.org/devguide/services/user-provided.html
private String parseGaApiSecret() {
if (System.getenv("VCAP_SERVICES") == null) {
// Allow running locally when PaaS vars don't exist
LOGGER.warn("No Gov PaaS VCAP_SERVICES env var found, unable to extract GA api secret. Falling back to LOCAL_DEV_ANALYTICS_API_SECRET");
String localSecretValue = System.getenv("LOCAL_DEV_ANALYTICS_API_SECRET");
return (localSecretValue == null)? "not-set" : localSecretValue;
}
try {
CfEnv cfEnv = new CfEnv();
return cfEnv
.findServiceByName("ga-credentials")
.getCredentials()
.getString("api_key");
} catch (Exception e) {
throw new RuntimeException("Failed to parse Gov PaaS VCAP_SERVICES env var");
}
}

}
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ app.home_page_url=${HOME_PAGE_URL:/}
app.enable_google_analytics=${ENABLE_GOOGLE_ANALYTICS:false}
# Ensure measurement ID matches in cookieControl.js
app.analytics_measurement_id=${GOOGLE_ANALYTICS_MEASUREMENT_ID:not-set}
app.analytics_api_secret=${GOOGLE_ANALYTICS_API_SECRET:not-set}
app.analytics_connection_timeout_ms=${ANALYTICS_CONN_TIMEOUT_MS:1000}
app.valid_referer_domain=${VALID_REFERER_DOMAIN:http://localhost}

Expand Down

0 comments on commit 0aca458

Please sign in to comment.