Skip to content

Commit

Permalink
[DR-3128] Convert config classes to records (#1487)
Browse files Browse the repository at this point in the history
* Change DuosConfiguration to record

* Change EcmConfiguration to record

* Change OauthConfiguration to record

* Change PolicyServiceConfiguration to record

* Change RawlsConfiguration to record

* Change ResourceBufferServiceConfiguration to record

* Change SamConfiguration to record

* Change SentryConfiguration to record

* Change TerraConfiguration to record

* Change UserMetricsConfiguration to record

* Spotbugs fixes

* Fix annotations

* Add ConstructorBinding annotation

* Change MigrateConfiguration to record

* Convert BigQueryConfiguration to record

* Convert GcsConfiguration to record

* Convert AzureResourceConfiguration to record

* Change GoogleResourceConfiguration to record

* Fix SamConfiguration comment

* Update src/main/java/bio/terra/app/configuration/PolicyServiceConfiguration.java

Co-authored-by: Phil Shapiro <[email protected]>

* Fix AzureResourceConfiguration

---------

Co-authored-by: Phil Shapiro <[email protected]>
  • Loading branch information
samanehsan and pshapiro4broad authored Aug 3, 2023
1 parent 66c278f commit 3198570
Show file tree
Hide file tree
Showing 70 changed files with 265 additions and 790 deletions.
6 changes: 5 additions & 1 deletion src/main/java/bio/terra/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@ConfigurationPropertiesScan("bio.terra")
@SpringBootApplication(
exclude = {DataSourceAutoConfiguration.class},
scanBasePackages = {"bio.terra"})
public class Main implements CommandLineRunner {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,10 @@ public NamedParameterJdbcTemplate synapseJdbcTemplate(
AzureResourceConfiguration azureResourceConfiguration) {

SQLServerDataSource ds = new SQLServerDataSource();
ds.setServerName(azureResourceConfiguration.getSynapse().getWorkspaceName());
ds.setUser(azureResourceConfiguration.getSynapse().getSqlAdminUser());
ds.setPassword(azureResourceConfiguration.getSynapse().getSqlAdminPassword());
ds.setDatabaseName(azureResourceConfiguration.getSynapse().getDatabaseName());
ds.setServerName(azureResourceConfiguration.synapse().workspaceName());
ds.setUser(azureResourceConfiguration.synapse().sqlAdminUser());
ds.setPassword(azureResourceConfiguration.synapse().sqlAdminPassword());
ds.setDatabaseName(azureResourceConfiguration.synapse().databaseName());

return new NamedParameterJdbcTemplate(ds);
}
Expand Down
17 changes: 3 additions & 14 deletions src/main/java/bio/terra/app/configuration/DuosConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
package bio.terra.app.configuration;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.boot.context.properties.ConstructorBinding;

@Configuration
@ConfigurationProperties(prefix = "duos")
public class DuosConfiguration {

private String basePath;

public String getBasePath() {
return basePath;
}

public void setBasePath(String basePath) {
this.basePath = basePath;
}
}
@ConstructorBinding
public record DuosConfiguration(String basePath) {}
28 changes: 3 additions & 25 deletions src/main/java/bio/terra/app/configuration/EcmConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,8 @@
package bio.terra.app.configuration;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.boot.context.properties.ConstructorBinding;

@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "ecm")
public class EcmConfiguration {

private String basePath;
private String rasIssuer;

public String getBasePath() {
return basePath;
}

public void setBasePath(String basePath) {
this.basePath = basePath;
}

public String getRasIssuer() {
return rasIssuer;
}

public void setRasIssuer(String rasIssuer) {
this.rasIssuer = rasIssuer;
}
}
@ConstructorBinding
public record EcmConfiguration(String basePath, String rasIssuer) {}
47 changes: 4 additions & 43 deletions src/main/java/bio/terra/app/configuration/OauthConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,48 +1,9 @@
package bio.terra.app.configuration;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.boot.context.properties.ConstructorBinding;

@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "oauth")
public class OauthConfiguration {

private String schemeName;
private String loginEndpoint;
private String clientId;
private String clientSecret;

public String getSchemeName() {
return schemeName;
}

public void setSchemeName(String schemeName) {
this.schemeName = schemeName;
}

public String getLoginEndpoint() {
return loginEndpoint;
}

public void setLoginEndpoint(String loginEndpoint) {
this.loginEndpoint = loginEndpoint;
}

public String getClientId() {
return clientId;
}

public void setClientId(String clientId) {
this.clientId = clientId;
}

public String getClientSecret() {
return clientSecret;
}

public void setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
}
}
@ConstructorBinding
public record OauthConfiguration(
String schemeName, String loginEndpoint, String clientId, String clientSecret) {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,21 @@

import com.google.auth.oauth2.AccessToken;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.auth.oauth2.ServiceAccountCredentials;
import java.io.IOException;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.boot.context.properties.ConstructorBinding;

/** Configuration for managing connection to Terra Policy Service. * */
@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "tps")
public class PolicyServiceConfiguration {

private boolean enabled;
private String basePath;
@ConstructorBinding
public record PolicyServiceConfiguration(boolean enabled, String basePath) {

private static final List<String> POLICY_SCOPES = List.of("openid", "email", "profile");

public boolean getEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public String getBasePath() {
return basePath;
}

public void setBasePath(String basePath) {
this.basePath = basePath;
}

public String getAccessToken() throws IOException {
GoogleCredentials credentials =
ServiceAccountCredentials.getApplicationDefault().createScoped(POLICY_SCOPES);
GoogleCredentials.getApplicationDefault().createScoped(POLICY_SCOPES);
AccessToken token = credentials.refreshAccessToken();
return token.getTokenValue();
}
Expand Down
19 changes: 3 additions & 16 deletions src/main/java/bio/terra/app/configuration/RawlsConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
package bio.terra.app.configuration;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.boot.context.properties.ConstructorBinding;

@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "rawls")
public class RawlsConfiguration {

private String basePath;

public String getBasePath() {
return basePath;
}

public void setBasePath(String basePath) {
this.basePath = basePath;
}
}
@ConstructorBinding
public record RawlsConfiguration(String basePath) {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,17 @@
import java.io.IOException;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.boot.context.properties.ConstructorBinding;

/** Configuration for managing connection to Buffer Service. * */
@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "rbs")
public class ResourceBufferServiceConfiguration {

private boolean enabled;
private String instanceUrl;
private String poolId;
private String clientCredentialFilePath;
@ConstructorBinding
public record ResourceBufferServiceConfiguration(
boolean enabled, String instanceUrl, String poolId, String clientCredentialFilePath) {

// I think we'd want to re-use our app scopes.
private static final List<String> BUFFER_SCOPES = List.of("openid", "email", "profile");

public boolean getEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public String getInstanceUrl() {
return instanceUrl;
}

public void setInstanceUrl(String instanceUrl) {
this.instanceUrl = instanceUrl;
}

public String getPoolId() {
return poolId;
}

public void setPoolId(String poolId) {
this.poolId = poolId;
}

public String getClientCredentialFilePath() {
return clientCredentialFilePath;
}

public void setClientCredentialFilePath(String clientCredentialFilePath) {
this.clientCredentialFilePath = clientCredentialFilePath;
}

// TODO - not sure if this is actually how we want to do this, just copying wsm's implementation
// for now
public String getAccessToken() throws IOException {
Expand Down
99 changes: 22 additions & 77 deletions src/main/java/bio/terra/app/configuration/SamConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,81 +1,26 @@
package bio.terra.app.configuration;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties
import org.springframework.boot.context.properties.ConstructorBinding;

/*
* SAM Retry notes:
* We frequently experience socket timeouts with SAM, so we have implemented retry. The
* configuration controls work like this. operationTimeoutSeconds is the maximum amount of time we
* allow for the SAM operation, including the SAM operations and our retry sleep time. This is the
* upper bound on how long the entire operation will take.
*
* The retry strategy is exponential backoff. The error wait starts at retryInitialWaitSeconds,
* and doubles up to retryMaximumWaitSeconds. The retry stays at retryMaximumWaitSeconds until we
* reach the operationTimeoutSeconds limit. Well, depending on the numbers you choose, we might hit
* operationTimeoutSeconds before we reach retryMaximumSeconds.
*/
@ConfigurationProperties(prefix = "sam")
public class SamConfiguration {
private String basePath;
private String stewardsGroupEmail;
private String adminsGroupEmail;
private int retryInitialWaitSeconds;
private int retryMaximumWaitSeconds;
private int operationTimeoutSeconds;

public String getBasePath() {
return basePath;
}

public void setBasePath(String basePath) {
this.basePath = basePath;
}

public String getStewardsGroupEmail() {
return stewardsGroupEmail;
}

public void setStewardsGroupEmail(String stewardsGroupEmail) {
this.stewardsGroupEmail = stewardsGroupEmail;
}

public String getAdminsGroupEmail() {
return adminsGroupEmail;
}

public void setAdminsGroupEmail(String adminsGroupEmail) {
this.adminsGroupEmail = adminsGroupEmail;
}

// SAM Retry notes:
// We frequently experience socket timeouts with SAM, so we have implemented retry. The
// configuration controls
// work like this. operationTimeoutSeconds is the maximum amount of time we allow for the SAM
// operation,
// including the SAM operations and our retry sleep time. This is the upper bound on how long the
// entire
// operation will take.
//
// The retry strategy is exponential backoff. The error wait starts at retryInitialWaitSeconds,
// and doubles
// up to retryMaximumWaitSeconds. The retry stays at retryMaximumWaitSeconds until we reach the
// operationTimeoutSeconds limit. Well, depending on the numbers you choose, we might hit
// operationTimeoutSeconds
// before we reach retryMaximumSeconds.

public int getRetryInitialWaitSeconds() {
return retryInitialWaitSeconds;
}

public void setRetryInitialWaitSeconds(int retryInitialWaitSeconds) {
this.retryInitialWaitSeconds = retryInitialWaitSeconds;
}

public int getRetryMaximumWaitSeconds() {
return retryMaximumWaitSeconds;
}

public void setRetryMaximumWaitSeconds(int retryMaximumWaitSeconds) {
this.retryMaximumWaitSeconds = retryMaximumWaitSeconds;
}

public int getOperationTimeoutSeconds() {
return operationTimeoutSeconds;
}

public void setOperationTimeoutSeconds(int operationTimeoutSeconds) {
this.operationTimeoutSeconds = operationTimeoutSeconds;
}
}
@ConstructorBinding
public record SamConfiguration(
String basePath,
String stewardsGroupEmail,
String adminsGroupEmail,
int retryInitialWaitSeconds,
int retryMaximumWaitSeconds,
int operationTimeoutSeconds) {}
Loading

0 comments on commit 3198570

Please sign in to comment.