diff --git a/build.gradle b/build.gradle index 5b9ee059..b9082138 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/src/main/java/uk/gov/beis/els/service/AnalyticsService.java b/src/main/java/uk/gov/beis/els/service/AnalyticsService.java index 346d09f9..777f3b19 100644 --- a/src/main/java/uk/gov/beis/els/service/AnalyticsService.java +++ b/src/main/java/uk/gov/beis/els/service/AnalyticsService.java @@ -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; @@ -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; } @@ -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"); - } - } - } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 101669ff..ae76edda 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -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}