From 3198570b711a39510684a03b0cd685756d839b6b Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Thu, 3 Aug 2023 14:30:00 -0400 Subject: [PATCH] [DR-3128] Convert config classes to records (#1487) * 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 * Fix AzureResourceConfiguration --------- Co-authored-by: Phil Shapiro --- src/main/java/bio/terra/Main.java | 6 +- .../ApplicationConfiguration.java | 8 +- .../app/configuration/DuosConfiguration.java | 17 +- .../app/configuration/EcmConfiguration.java | 28 +-- .../app/configuration/OauthConfiguration.java | 47 +--- .../PolicyServiceConfiguration.java | 30 +-- .../app/configuration/RawlsConfiguration.java | 19 +- .../ResourceBufferServiceConfiguration.java | 46 +--- .../app/configuration/SamConfiguration.java | 99 ++------- .../configuration/SentryConfiguration.java | 27 +-- .../app/configuration/TerraConfiguration.java | 18 +- .../UserMetricsConfiguration.java | 60 +----- .../UnauthenticatedApiController.java | 8 +- .../bio/terra/app/usermetrics/BardClient.java | 7 +- .../usermetrics/UserMetricsInterceptor.java | 7 +- .../service/auth/iam/sam/SamApiService.java | 2 +- .../terra/service/auth/iam/sam/SamIam.java | 6 +- .../terra/service/auth/ras/EcmService.java | 4 +- .../service/auth/ras/OidcApiService.java | 2 +- .../configuration/ConfigurationService.java | 10 +- .../bio/terra/service/duos/DuosClient.java | 4 +- .../terra/service/filedata/DrsService.java | 2 +- .../filedata/azure/AzureSynapsePdao.java | 26 +-- .../azure/blobstore/AzureBlobStorePdao.java | 4 +- .../google/bq/BigQueryConfiguration.java | 17 +- .../filedata/google/gcs/GcsConfiguration.java | 44 +--- .../google/gcs/GcsProjectFactory.java | 4 +- .../service/policy/PolicyApiService.java | 2 +- .../terra/service/policy/PolicyService.java | 8 +- .../profile/azure/AzureAuthzService.java | 2 +- .../bio/terra/service/rawls/RawlsClient.java | 3 +- .../bio/terra/service/rawls/RawlsService.java | 2 +- .../resourcemanagement/BufferService.java | 14 +- .../resourcemanagement/ResourceService.java | 2 +- .../AzureApplicationDeploymentService.java | 2 +- .../azure/AzureAuthService.java | 4 +- .../azure/AzureMonitoringService.java | 36 ++-- .../azure/AzureResourceConfiguration.java | 202 +++--------------- .../google/GoogleProjectService.java | 6 +- .../google/GoogleResourceConfiguration.java | 57 +---- .../google/GoogleResourceDao.java | 4 +- .../google/GoogleResourceManagerService.java | 2 +- .../bio/terra/service/upgrade/Migrate.java | 9 +- .../service/upgrade/MigrateConfiguration.java | 27 +-- .../UnauthenticatedApiControllerTest.java | 6 +- .../terra/app/usermetrics/BardClientTest.java | 2 +- .../UserMetricsInterceptorTest.java | 10 +- .../java/bio/terra/common/SynapseUtils.java | 2 +- .../integration/AzureIntegrationTest.java | 4 +- .../bio/terra/integration/SamFixtures.java | 6 +- .../service/auth/iam/sam/SamIamTest.java | 16 +- .../auth/iam/sam/SamRetryIntegrationTest.java | 2 +- .../configuration/ConfigServiceTest.java | 6 +- .../SecureMonitoringIntegrationTest.java | 4 +- .../terra/service/duos/DuosClientTest.java | 2 +- .../service/filedata/DrsServiceTest.java | 2 +- .../azure/AzureIngestFileConnectedTest.java | 8 +- .../blobstore/AzureBlobStorePdaoTest.java | 4 +- .../util/BlobContainerClientFactoryTest.java | 4 +- .../azure/util/BlobContainerCopierTest.java | 4 +- .../filedata/azure/util/BlobCrlTest.java | 4 +- .../azure/util/SasUrlFactoriesTest.java | 4 +- .../google/firestore/BatchOperationTest.java | 5 +- .../service/policy/PolicyServiceTest.java | 6 +- .../profile/azure/AzureAuthzServiceTest.java | 4 +- .../terra/service/rawls/RawlsServiceTest.java | 2 +- .../BufferServiceConnectedTest.java | 2 +- ...AzureApplicationDeploymentServiceTest.java | 2 +- .../azure/AzureMonitoringServiceTest.java | 4 +- .../azure/AzureResourceConfigurationTest.java | 6 +- 70 files changed, 265 insertions(+), 790 deletions(-) diff --git a/src/main/java/bio/terra/Main.java b/src/main/java/bio/terra/Main.java index a3e9d6f38d..f7d1eae885 100644 --- a/src/main/java/bio/terra/Main.java +++ b/src/main/java/bio/terra/Main.java @@ -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 diff --git a/src/main/java/bio/terra/app/configuration/ApplicationConfiguration.java b/src/main/java/bio/terra/app/configuration/ApplicationConfiguration.java index 7af6c2bf11..1c596b6981 100644 --- a/src/main/java/bio/terra/app/configuration/ApplicationConfiguration.java +++ b/src/main/java/bio/terra/app/configuration/ApplicationConfiguration.java @@ -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); } diff --git a/src/main/java/bio/terra/app/configuration/DuosConfiguration.java b/src/main/java/bio/terra/app/configuration/DuosConfiguration.java index 03943b3b22..52d639d571 100644 --- a/src/main/java/bio/terra/app/configuration/DuosConfiguration.java +++ b/src/main/java/bio/terra/app/configuration/DuosConfiguration.java @@ -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) {} diff --git a/src/main/java/bio/terra/app/configuration/EcmConfiguration.java b/src/main/java/bio/terra/app/configuration/EcmConfiguration.java index cd8845b0a0..3b09561926 100644 --- a/src/main/java/bio/terra/app/configuration/EcmConfiguration.java +++ b/src/main/java/bio/terra/app/configuration/EcmConfiguration.java @@ -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) {} diff --git a/src/main/java/bio/terra/app/configuration/OauthConfiguration.java b/src/main/java/bio/terra/app/configuration/OauthConfiguration.java index 34a5ec38b3..83c5e861ad 100644 --- a/src/main/java/bio/terra/app/configuration/OauthConfiguration.java +++ b/src/main/java/bio/terra/app/configuration/OauthConfiguration.java @@ -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) {} diff --git a/src/main/java/bio/terra/app/configuration/PolicyServiceConfiguration.java b/src/main/java/bio/terra/app/configuration/PolicyServiceConfiguration.java index c4ca0d86e2..82647e22a8 100644 --- a/src/main/java/bio/terra/app/configuration/PolicyServiceConfiguration.java +++ b/src/main/java/bio/terra/app/configuration/PolicyServiceConfiguration.java @@ -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 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(); } diff --git a/src/main/java/bio/terra/app/configuration/RawlsConfiguration.java b/src/main/java/bio/terra/app/configuration/RawlsConfiguration.java index f0c586165b..33f31f9e2d 100644 --- a/src/main/java/bio/terra/app/configuration/RawlsConfiguration.java +++ b/src/main/java/bio/terra/app/configuration/RawlsConfiguration.java @@ -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) {} diff --git a/src/main/java/bio/terra/app/configuration/ResourceBufferServiceConfiguration.java b/src/main/java/bio/terra/app/configuration/ResourceBufferServiceConfiguration.java index 47402ce691..59febd4151 100644 --- a/src/main/java/bio/terra/app/configuration/ResourceBufferServiceConfiguration.java +++ b/src/main/java/bio/terra/app/configuration/ResourceBufferServiceConfiguration.java @@ -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 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 { diff --git a/src/main/java/bio/terra/app/configuration/SamConfiguration.java b/src/main/java/bio/terra/app/configuration/SamConfiguration.java index b692066702..48cdfdd3f9 100644 --- a/src/main/java/bio/terra/app/configuration/SamConfiguration.java +++ b/src/main/java/bio/terra/app/configuration/SamConfiguration.java @@ -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) {} diff --git a/src/main/java/bio/terra/app/configuration/SentryConfiguration.java b/src/main/java/bio/terra/app/configuration/SentryConfiguration.java index 4532f45328..04aa09f415 100644 --- a/src/main/java/bio/terra/app/configuration/SentryConfiguration.java +++ b/src/main/java/bio/terra/app/configuration/SentryConfiguration.java @@ -12,15 +12,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.servlet.NoHandlerFoundException; -@Configuration -@EnableConfigurationProperties @ConfigurationProperties(prefix = "sentry") -public class SentryConfiguration { +@ConstructorBinding +public record SentryConfiguration(String dsn, String environment) { private static final Logger logger = LoggerFactory.getLogger(SentryConfiguration.class); private static final String DEFAULT_UNDEFINED_ENVIRONMENT = "undefined"; private static final List> FILTERED = @@ -34,25 +32,6 @@ public class SentryConfiguration { NoHandlerFoundException.class, ForbiddenException.class); - private String dsn; - private String environment; - - public String getDsn() { - return dsn; - } - - public void setDsn(String dsn) { - this.dsn = dsn; - } - - public String getEnvironment() { - return environment; - } - - public void setEnvironment(String environment) { - this.environment = environment; - } - @PostConstruct private void postConstruct() { logger.info("Initializing Sentry"); diff --git a/src/main/java/bio/terra/app/configuration/TerraConfiguration.java b/src/main/java/bio/terra/app/configuration/TerraConfiguration.java index 522d019c9b..d01997c6ad 100644 --- a/src/main/java/bio/terra/app/configuration/TerraConfiguration.java +++ b/src/main/java/bio/terra/app/configuration/TerraConfiguration.java @@ -1,20 +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 = "terra") -public class TerraConfiguration { - private String basePath; - - public String getBasePath() { - return basePath; - } - - public void setBasePath(String basePath) { - this.basePath = basePath; - } -} +@ConstructorBinding +public record TerraConfiguration(String basePath) {} diff --git a/src/main/java/bio/terra/app/configuration/UserMetricsConfiguration.java b/src/main/java/bio/terra/app/configuration/UserMetricsConfiguration.java index 2f94dd5339..d3b64889ba 100644 --- a/src/main/java/bio/terra/app/configuration/UserMetricsConfiguration.java +++ b/src/main/java/bio/terra/app/configuration/UserMetricsConfiguration.java @@ -6,61 +6,17 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.context.properties.ConstructorBinding; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -@Configuration -@EnableConfigurationProperties @ConfigurationProperties(prefix = "usermetrics") -public class UserMetricsConfiguration { - - private String appId; - private String bardBasePath; - private Integer metricsReportingPoolSize; - - private Integer syncRefreshIntervalSeconds; - private List ignorePaths; - - public String getAppId() { - return appId; - } - - public void setAppId(String appId) { - this.appId = appId; - } - - public String getBardBasePath() { - return bardBasePath; - } - - public void setBardBasePath(String bardBasePath) { - this.bardBasePath = bardBasePath; - } - - public Integer getMetricsReportingPoolSize() { - return metricsReportingPoolSize; - } - - public Integer getSyncRefreshIntervalSeconds() { - return syncRefreshIntervalSeconds; - } - - public void setMetricsReportingPoolSize(Integer metricsReportingPoolSize) { - this.metricsReportingPoolSize = metricsReportingPoolSize; - } - - public void setSyncRefreshIntervalSeconds(Integer syncRefreshIntervalSeconds) { - this.syncRefreshIntervalSeconds = syncRefreshIntervalSeconds; - } - - public List getIgnorePaths() { - return ignorePaths; - } - - public void setIgnorePaths(List ignorePaths) { - this.ignorePaths = ignorePaths; - } +@ConstructorBinding +public record UserMetricsConfiguration( + String appId, + String bardBasePath, + Integer metricsReportingPoolSize, + Integer syncRefreshIntervalSeconds, + List ignorePaths) { @Bean("metricsReportingThreadpool") public ExecutorService metricsPerformanceThreadpool() { diff --git a/src/main/java/bio/terra/app/controller/UnauthenticatedApiController.java b/src/main/java/bio/terra/app/controller/UnauthenticatedApiController.java index 771ed6c0d9..35e74ee950 100644 --- a/src/main/java/bio/terra/app/controller/UnauthenticatedApiController.java +++ b/src/main/java/bio/terra/app/controller/UnauthenticatedApiController.java @@ -81,13 +81,13 @@ public ResponseEntity serviceStatus() { public ResponseEntity retrieveRepositoryConfig() { RepositoryConfigurationModel configurationModel = new RepositoryConfigurationModel() - .clientId(oauthConfig.getClientId()) + .clientId(oauthConfig.clientId()) .oidcClientId(openIDConnectConfiguration.getClientId()) .activeProfiles(Arrays.asList(env.getActiveProfiles())) .semVer(semVer) .gitHash(gitHash) - .terraUrl(terraConfiguration.getBasePath()) - .samUrl(samConfiguration.getBasePath()) + .terraUrl(terraConfiguration.basePath()) + .samUrl(samConfiguration.basePath()) .authorityEndpoint(openIDConnectConfiguration.getAuthorityEndpoint()); return new ResponseEntity<>(configurationModel, HttpStatus.OK); @@ -114,7 +114,7 @@ public String index() { @RequestMapping(value = "/swagger-ui.html") public String getSwaggerUI(Model model) { - model.addAttribute("oauthClientId", oauthConfig.getClientId()); + model.addAttribute("oauthClientId", oauthConfig.clientId()); model.addAttribute("oidcClientId", openIDConnectConfiguration.getClientId()); return "index"; } diff --git a/src/main/java/bio/terra/app/usermetrics/BardClient.java b/src/main/java/bio/terra/app/usermetrics/BardClient.java index 7af4491c80..792b637084 100644 --- a/src/main/java/bio/terra/app/usermetrics/BardClient.java +++ b/src/main/java/bio/terra/app/usermetrics/BardClient.java @@ -49,8 +49,7 @@ public BardClient(UserMetricsConfiguration metricsConfig, RestTemplate restTempl int ttl = Objects.requireNonNullElse( - metricsConfig.getSyncRefreshIntervalSeconds(), - DEFAULT_BEARER_TOKEN_CACHE_TIMEOUT_SECONDS); + metricsConfig.syncRefreshIntervalSeconds(), DEFAULT_BEARER_TOKEN_CACHE_TIMEOUT_SECONDS); this.bearerCache = Collections.synchronizedMap(new PassiveExpiringMap<>(ttl, TimeUnit.SECONDS)); this.metricsConfig = metricsConfig; @@ -116,11 +115,11 @@ boolean syncProfile(AuthenticatedUserRequest userReq) { @VisibleForTesting String getApiUrl() { - return metricsConfig.getBardBasePath() + API_PATH; + return metricsConfig.bardBasePath() + API_PATH; } @VisibleForTesting String getSyncPathUrl() { - return metricsConfig.getBardBasePath() + SYNC_PATH; + return metricsConfig.bardBasePath() + SYNC_PATH; } } diff --git a/src/main/java/bio/terra/app/usermetrics/UserMetricsInterceptor.java b/src/main/java/bio/terra/app/usermetrics/UserMetricsInterceptor.java index c7834c1879..34d9ac2397 100644 --- a/src/main/java/bio/terra/app/usermetrics/UserMetricsInterceptor.java +++ b/src/main/java/bio/terra/app/usermetrics/UserMetricsInterceptor.java @@ -58,7 +58,7 @@ public void afterCompletion( } // Don't log metrics if bard isn't configured or the path is part of the ignore-list - if (StringUtils.isEmpty(metricsConfig.getBardBasePath()) || ignoreEventForPath(path)) { + if (StringUtils.isEmpty(metricsConfig.bardBasePath()) || ignoreEventForPath(path)) { return; } @@ -78,13 +78,12 @@ public void afterCompletion( new BardEvent( API_EVENT_NAME, bardEventProperties, - metricsConfig.getAppId(), + metricsConfig.appId(), applicationConfiguration.getDnsName()))); } /** Should we actually ignore sending a tracking event for this path */ private boolean ignoreEventForPath(String path) { - return metricsConfig.getIgnorePaths().stream() - .anyMatch(p -> FilenameUtils.wildcardMatch(path, p)); + return metricsConfig.ignorePaths().stream().anyMatch(p -> FilenameUtils.wildcardMatch(path, p)); } } diff --git a/src/main/java/bio/terra/service/auth/iam/sam/SamApiService.java b/src/main/java/bio/terra/service/auth/iam/sam/SamApiService.java index cf9c4b82a9..e2fec86072 100644 --- a/src/main/java/bio/terra/service/auth/iam/sam/SamApiService.java +++ b/src/main/java/bio/terra/service/auth/iam/sam/SamApiService.java @@ -58,7 +58,7 @@ private ApiClient createUnauthApiClient() { return new ApiClient() .setHttpClient(sharedHttpClient) .setUserAgent("OpenAPI-Generator/1.0.0 java") // only logs an error in sam - .setBasePath(samConfig.getBasePath()); + .setBasePath(samConfig.basePath()); } private ApiClient createApiClient(String accessToken) { diff --git a/src/main/java/bio/terra/service/auth/iam/sam/SamIam.java b/src/main/java/bio/terra/service/auth/iam/sam/SamIam.java index cfa7bb418c..bd4744e3be 100644 --- a/src/main/java/bio/terra/service/auth/iam/sam/SamIam.java +++ b/src/main/java/bio/terra/service/auth/iam/sam/SamIam.java @@ -217,7 +217,7 @@ CreateResourceRequestV2 createDatasetResourceRequest( req.putPoliciesItem( IamRole.ADMIN.toString(), - createAccessPolicyOneV2(IamRole.ADMIN, samConfig.getAdminsGroupEmail())); + createAccessPolicyOneV2(IamRole.ADMIN, samConfig.adminsGroupEmail())); List stewards = new ArrayList<>(); stewards.add(userStatusInfo.getUserEmail()); @@ -285,7 +285,7 @@ CreateResourceRequestV2 createSnapshotResourceRequest( req.putPoliciesItem( IamRole.ADMIN.toString(), - createAccessPolicyOneV2(IamRole.ADMIN, samConfig.getAdminsGroupEmail())); + createAccessPolicyOneV2(IamRole.ADMIN, samConfig.adminsGroupEmail())); List stewards = new ArrayList<>(); stewards.add(userStatusInfo.getUserEmail()); @@ -345,7 +345,7 @@ private void createProfileResourceInnerV2(AuthenticatedUserRequest userReq, Stri req.setResourceId(profileId); req.putPoliciesItem( IamRole.ADMIN.toString(), - createAccessPolicyOneV2(IamRole.ADMIN, samConfig.getAdminsGroupEmail())); + createAccessPolicyOneV2(IamRole.ADMIN, samConfig.adminsGroupEmail())); req.putPoliciesItem( IamRole.OWNER.toString(), createAccessPolicyOneV2(IamRole.OWNER, userStatusInfo.getUserEmail())); diff --git a/src/main/java/bio/terra/service/auth/ras/EcmService.java b/src/main/java/bio/terra/service/auth/ras/EcmService.java index 840d6f6ca1..af8ad26dd4 100644 --- a/src/main/java/bio/terra/service/auth/ras/EcmService.java +++ b/src/main/java/bio/terra/service/auth/ras/EcmService.java @@ -56,13 +56,13 @@ public EcmService( public PassportApi getPassportApi() { var client = new ApiClient(restTemplate); - client.setBasePath(ecmConfiguration.getBasePath()); + client.setBasePath(ecmConfiguration.basePath()); return new PassportApi(client); } public void addRasIssuerAndType(RASv1Dot1VisaCriterion criterion) { - criterion.issuer(ecmConfiguration.getRasIssuer()).type(RAS_CRITERIA_TYPE); + criterion.issuer(ecmConfiguration.rasIssuer()).type(RAS_CRITERIA_TYPE); } public ValidatePassportResult validatePassport(ValidatePassportRequest validatePassportRequest) { diff --git a/src/main/java/bio/terra/service/auth/ras/OidcApiService.java b/src/main/java/bio/terra/service/auth/ras/OidcApiService.java index 3450b24ed6..07e6bf2442 100644 --- a/src/main/java/bio/terra/service/auth/ras/OidcApiService.java +++ b/src/main/java/bio/terra/service/auth/ras/OidcApiService.java @@ -21,7 +21,7 @@ public OidcApiService(EcmConfiguration ecmConfiguration, RestTemplate restTempla public OidcApi getOidcApi(AuthenticatedUserRequest userReq) { var client = new ApiClient(restTemplate); - client.setBasePath(ecmConfiguration.getBasePath()); + client.setBasePath(ecmConfiguration.basePath()); client.setAccessToken(userReq.getToken()); return new OidcApi(client); diff --git a/src/main/java/bio/terra/service/configuration/ConfigurationService.java b/src/main/java/bio/terra/service/configuration/ConfigurationService.java index f7aab55126..9da3810665 100644 --- a/src/main/java/bio/terra/service/configuration/ConfigurationService.java +++ b/src/main/java/bio/terra/service/configuration/ConfigurationService.java @@ -202,9 +202,9 @@ private void checkDuplicate(ConfigEnum configEnum) { // Setup the configuration. This is done once during construction. private void setConfiguration() { // -- Parameters -- - addParameter(SAM_RETRY_INITIAL_WAIT_SECONDS, samConfiguration.getRetryInitialWaitSeconds()); - addParameter(SAM_RETRY_MAXIMUM_WAIT_SECONDS, samConfiguration.getRetryMaximumWaitSeconds()); - addParameter(SAM_OPERATION_TIMEOUT_SECONDS, samConfiguration.getOperationTimeoutSeconds()); + addParameter(SAM_RETRY_INITIAL_WAIT_SECONDS, samConfiguration.retryInitialWaitSeconds()); + addParameter(SAM_RETRY_MAXIMUM_WAIT_SECONDS, samConfiguration.retryMaximumWaitSeconds()); + addParameter(SAM_OPERATION_TIMEOUT_SECONDS, samConfiguration.operationTimeoutSeconds()); addParameter(LOAD_BULK_ARRAY_FILES_MAX, appConfiguration.getMaxBulkFileLoadArray()); addParameter(LOAD_CONCURRENT_FILES, appConfiguration.getLoadConcurrentFiles()); addParameter(LOAD_CONCURRENT_INGESTS, appConfiguration.getLoadConcurrentIngests()); @@ -219,8 +219,8 @@ private void setConfiguration() { addParameter(DRS_LOOKUP_MAX, appConfiguration.getMaxDrsLookups()); addParameter(AUTH_CACHE_TIMEOUT_SECONDS, appConfiguration.getAuthCacheTimeoutSeconds()); addParameter( - ALLOW_REUSE_EXISTING_BUCKETS, googleResourceConfiguration.getAllowReuseExistingBuckets()); - addParameter(FIRESTORE_RETRIES, googleResourceConfiguration.getFirestoreRetries()); + ALLOW_REUSE_EXISTING_BUCKETS, googleResourceConfiguration.allowReuseExistingBuckets()); + addParameter(FIRESTORE_RETRIES, googleResourceConfiguration.firestoreRetries()); // -- Faults -- addFaultSimple(CREATE_ASSET_FAULT); diff --git a/src/main/java/bio/terra/service/duos/DuosClient.java b/src/main/java/bio/terra/service/duos/DuosClient.java index 89dbc8f167..f4e9750494 100644 --- a/src/main/java/bio/terra/service/duos/DuosClient.java +++ b/src/main/java/bio/terra/service/duos/DuosClient.java @@ -51,7 +51,7 @@ private HttpHeaders getHttpHeaders() { @VisibleForTesting String getStatusUrl() { - return String.format("%s/status", duosConfiguration.getBasePath()); + return String.format("%s/status", duosConfiguration.basePath()); } /** @@ -67,7 +67,7 @@ public SystemStatus status() { @VisibleForTesting String getDatasetUrl(String duosId) { - return String.format("%s/api/tdr/%s", duosConfiguration.getBasePath(), duosId); + return String.format("%s/api/tdr/%s", duosConfiguration.basePath(), duosId); } /** diff --git a/src/main/java/bio/terra/service/filedata/DrsService.java b/src/main/java/bio/terra/service/filedata/DrsService.java index e1c93394c2..5946f83915 100644 --- a/src/main/java/bio/terra/service/filedata/DrsService.java +++ b/src/main/java/bio/terra/service/filedata/DrsService.java @@ -203,7 +203,7 @@ private DRSAuthorizations buildDRSAuth(boolean passportAuthorizationAvailable) { DRSAuthorizations auths = new DRSAuthorizations(); if (passportAuthorizationAvailable) { auths.addSupportedTypesItem(DRSAuthorizations.SupportedTypesEnum.PASSPORTAUTH); - auths.addPassportAuthIssuersItem(ecmConfiguration.getRasIssuer()); + auths.addPassportAuthIssuersItem(ecmConfiguration.rasIssuer()); } auths.addSupportedTypesItem(DRSAuthorizations.SupportedTypesEnum.BEARERAUTH); return auths; diff --git a/src/main/java/bio/terra/service/filedata/azure/AzureSynapsePdao.java b/src/main/java/bio/terra/service/filedata/azure/AzureSynapsePdao.java index 2e4ff5ecef..0ce5f4b206 100644 --- a/src/main/java/bio/terra/service/filedata/azure/AzureSynapsePdao.java +++ b/src/main/java/bio/terra/service/filedata/azure/AzureSynapsePdao.java @@ -381,13 +381,13 @@ public AzureSynapsePdao( @PostConstruct private void initializeDb() { // If this configuration wasn't set, skip initialization - if (azureResourceConfiguration.getSynapse() == null) { + if (azureResourceConfiguration.synapse() == null) { return; } - boolean initialize = azureResourceConfiguration.getSynapse().isInitialize(); - String dbName = azureResourceConfiguration.getSynapse().getDatabaseName(); - String encryptionKey = azureResourceConfiguration.getSynapse().getEncryptionKey(); - String parquetFormatName = azureResourceConfiguration.getSynapse().getParquetFileFormatName(); + boolean initialize = azureResourceConfiguration.synapse().initialize(); + String dbName = azureResourceConfiguration.synapse().databaseName(); + String encryptionKey = azureResourceConfiguration.synapse().encryptionKey(); + String parquetFormatName = azureResourceConfiguration.synapse().parquetFileFormatName(); if (initialize) { logger.info("Initializing Synapse database {}", dbName); @@ -545,7 +545,7 @@ public int createScratchParquetFiles( sqlCreateTableTemplate.add("destinationParquetFile", scratchParquetFile); sqlCreateTableTemplate.add("destinationDataSourceName", scratchDataSourceName); sqlCreateTableTemplate.add( - "fileFormat", azureResourceConfiguration.getSynapse().getParquetFileFormatName()); + "fileFormat", azureResourceConfiguration.synapse().parquetFileFormatName()); sqlCreateTableTemplate.add("ingestFileName", ingestFileName); sqlCreateTableTemplate.add("controlFileDataSourceName", controlFileDataSourceName); sqlCreateTableTemplate.add("columns", datasetTable.getSynapseColumns()); @@ -585,7 +585,7 @@ public long createFinalParquetFiles( sqlCreateFinalParquetFilesTemplate.add("destinationParquetFile", destinationParquetFile); sqlCreateFinalParquetFilesTemplate.add("destinationDataSourceName", destinationDataSourceName); sqlCreateFinalParquetFilesTemplate.add( - "fileFormat", azureResourceConfiguration.getSynapse().getParquetFileFormatName()); + "fileFormat", azureResourceConfiguration.synapse().parquetFileFormatName()); sqlCreateFinalParquetFilesTemplate.add("scratchTableName", scratchTableName); String columns = @@ -655,7 +655,7 @@ public void createSnapshotRowIdsParquetFile( .add("tableName", rowIdTableName) .add("destinationParquetFile", rowIdParquetFile) .add("destinationDataSourceName", snapshotDataSourceName) - .add("fileFormat", azureResourceConfiguration.getSynapse().getParquetFileFormatName()) + .add("fileFormat", azureResourceConfiguration.synapse().parquetFileFormatName()) .add("selectStatements", sqlMergeTablesTemplate.render()); executeSynapseQuery(sqlCreateRowIdTable.render()); } @@ -1101,7 +1101,7 @@ private ST generateSnapshotParquetCreateQuery( .add("tableName", snapshotTableName) .add("destinationParquetFile", snapshotParquetFileName) .add("destinationDataSourceName", snapshotDataSourceName) - .add("fileFormat", azureResourceConfiguration.getSynapse().getParquetFileFormatName()) + .add("fileFormat", azureResourceConfiguration.synapse().parquetFileFormatName()) .add("ingestFileName", datasetParquetFileName) .add("ingestFileDataSourceName", datasetDataSourceName) .add("drsLocator", drsLocator) @@ -1330,14 +1330,14 @@ public int executeCountQuery(String query) throws SQLException { @VisibleForTesting public SQLServerDataSource getDatasource() { - return getDatasource(azureResourceConfiguration.getSynapse().getDatabaseName()); + return getDatasource(azureResourceConfiguration.synapse().databaseName()); } private SQLServerDataSource getDatasource(String databaseName) { SQLServerDataSource ds = new SQLServerDataSource(); - ds.setServerName(azureResourceConfiguration.getSynapse().getWorkspaceName()); - ds.setUser(azureResourceConfiguration.getSynapse().getSqlAdminUser()); - ds.setPassword(azureResourceConfiguration.getSynapse().getSqlAdminPassword()); + ds.setServerName(azureResourceConfiguration.synapse().workspaceName()); + ds.setUser(azureResourceConfiguration.synapse().sqlAdminUser()); + ds.setPassword(azureResourceConfiguration.synapse().sqlAdminPassword()); ds.setDatabaseName(databaseName); return ds; } diff --git a/src/main/java/bio/terra/service/filedata/azure/blobstore/AzureBlobStorePdao.java b/src/main/java/bio/terra/service/filedata/azure/blobstore/AzureBlobStorePdao.java index 32401186ac..b584939d30 100644 --- a/src/main/java/bio/terra/service/filedata/azure/blobstore/AzureBlobStorePdao.java +++ b/src/main/java/bio/terra/service/filedata/azure/blobstore/AzureBlobStorePdao.java @@ -112,8 +112,8 @@ public AzureBlobStorePdao( private RequestRetryOptions getRetryOptions() { return new RequestRetryOptions( RetryPolicyType.EXPONENTIAL, - this.resourceConfiguration.getMaxRetries(), - this.resourceConfiguration.getRetryTimeoutSeconds(), + this.resourceConfiguration.maxRetries(), + this.resourceConfiguration.retryTimeoutSeconds(), null, null, null); diff --git a/src/main/java/bio/terra/service/filedata/google/bq/BigQueryConfiguration.java b/src/main/java/bio/terra/service/filedata/google/bq/BigQueryConfiguration.java index 6fe6fbd360..bbd3128948 100644 --- a/src/main/java/bio/terra/service/filedata/google/bq/BigQueryConfiguration.java +++ b/src/main/java/bio/terra/service/filedata/google/bq/BigQueryConfiguration.java @@ -2,35 +2,24 @@ import java.util.Optional; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; +import org.springframework.boot.context.properties.ConstructorBinding; import org.springframework.context.annotation.Profile; /** Configuration for interacting with BigQuery. */ -@Configuration +@ConstructorBinding @Profile("google") @ConfigurationProperties(prefix = "datarepo.bq") -public class BigQueryConfiguration { +public record BigQueryConfiguration(Integer rateLimitRetries, Integer rateLimitRetryWaitMs) { private static final int DEFAULT_MAX_NUM_UPDATE_LIMIT_INDUCED_RETRIES = 3; private static final int DEFAULT_RETRY_WAIT_MS = 500; - private Integer rateLimitRetries; - private Integer rateLimitRetryWaitMs; - public int getRateLimitRetries() { return Optional.ofNullable(rateLimitRetries) .orElse(DEFAULT_MAX_NUM_UPDATE_LIMIT_INDUCED_RETRIES); } - public void setRateLimitRetries(Integer rateLimitRetries) { - this.rateLimitRetries = rateLimitRetries; - } - public int getRateLimitRetryWaitMs() { return Optional.ofNullable(rateLimitRetryWaitMs).orElse(DEFAULT_RETRY_WAIT_MS); } - - public void setRateLimitRetryWaitMs(Integer rateLimitRetryWaitMs) { - this.rateLimitRetryWaitMs = rateLimitRetryWaitMs; - } } diff --git a/src/main/java/bio/terra/service/filedata/google/gcs/GcsConfiguration.java b/src/main/java/bio/terra/service/filedata/google/gcs/GcsConfiguration.java index 186bb2e008..9325950eda 100644 --- a/src/main/java/bio/terra/service/filedata/google/gcs/GcsConfiguration.java +++ b/src/main/java/bio/terra/service/filedata/google/gcs/GcsConfiguration.java @@ -1,7 +1,7 @@ package bio.terra.service.filedata.google.gcs; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; +import org.springframework.boot.context.properties.ConstructorBinding; import org.springframework.context.annotation.Profile; /** @@ -9,44 +9,8 @@ * That way, implementation specifics can be separated from the interface. We'll see if it works out * that way. */ -@Configuration +@ConstructorBinding @Profile("google") @ConfigurationProperties(prefix = "datarepo.gcs") -public class GcsConfiguration { - private String bucket; - private String region; - private int connectTimeoutSeconds; - private int readTimeoutSeconds; - - public String getBucket() { - return bucket; - } - - public void setBucket(String bucket) { - this.bucket = bucket; - } - - public String getRegion() { - return region; - } - - public void setRegion(String region) { - this.region = region; - } - - public int getConnectTimeoutSeconds() { - return connectTimeoutSeconds; - } - - public void setConnectTimeoutSeconds(int connectTimeoutSeconds) { - this.connectTimeoutSeconds = connectTimeoutSeconds; - } - - public int getReadTimeoutSeconds() { - return readTimeoutSeconds; - } - - public void setReadTimeoutSeconds(int readTimeoutSeconds) { - this.readTimeoutSeconds = readTimeoutSeconds; - } -} +public record GcsConfiguration( + String bucket, String region, int connectTimeoutSeconds, int readTimeoutSeconds) {} diff --git a/src/main/java/bio/terra/service/filedata/google/gcs/GcsProjectFactory.java b/src/main/java/bio/terra/service/filedata/google/gcs/GcsProjectFactory.java index 386d5cf8a1..f1225a1c06 100644 --- a/src/main/java/bio/terra/service/filedata/google/gcs/GcsProjectFactory.java +++ b/src/main/java/bio/terra/service/filedata/google/gcs/GcsProjectFactory.java @@ -69,8 +69,8 @@ public GcsProject get(String projectId, boolean asMainServiceAccount) { p -> new GcsProject( p, - gcsConfiguration.getConnectTimeoutSeconds(), - gcsConfiguration.getReadTimeoutSeconds())); + gcsConfiguration.connectTimeoutSeconds(), + gcsConfiguration.readTimeoutSeconds())); } private GoogleProjectResource retrieveProjectResource(String projectId) { diff --git a/src/main/java/bio/terra/service/policy/PolicyApiService.java b/src/main/java/bio/terra/service/policy/PolicyApiService.java index 34e92123b3..b7b22de288 100644 --- a/src/main/java/bio/terra/service/policy/PolicyApiService.java +++ b/src/main/java/bio/terra/service/policy/PolicyApiService.java @@ -25,7 +25,7 @@ public PolicyApiService(PolicyServiceConfiguration policyServiceConfiguration) { private ApiClient getApiClient() { return new ApiClient() .setHttpClient(sharedHttpClient) - .setBasePath(policyServiceConfiguration.getBasePath()); + .setBasePath(policyServiceConfiguration.basePath()); } private ApiClient getApiClient(String accessToken) { diff --git a/src/main/java/bio/terra/service/policy/PolicyService.java b/src/main/java/bio/terra/service/policy/PolicyService.java index d7b1a5455a..3e66061c00 100644 --- a/src/main/java/bio/terra/service/policy/PolicyService.java +++ b/src/main/java/bio/terra/service/policy/PolicyService.java @@ -50,7 +50,7 @@ public void createSnapshotPao(UUID snapshotId, @Nullable TpsPolicyInputs policyI public void createPao( UUID resourceId, TpsObjectType resourceType, @Nullable TpsPolicyInputs policyInputs) { - if (!policyServiceConfiguration.getEnabled()) { + if (!policyServiceConfiguration.enabled()) { logger.info("Terra Policy Service is not enabled."); return; } @@ -74,7 +74,7 @@ public void createPao( * the PolicyServiceNotFoundException exception. */ public void deletePaoIfExists(UUID resourceId) { - if (!policyServiceConfiguration.getEnabled()) { + if (!policyServiceConfiguration.enabled()) { logger.info("Terra Policy Service is not enabled."); return; } @@ -119,14 +119,14 @@ public RepositoryStatusModelSystems status() { publicApi.getStatus(); return new RepositoryStatusModelSystems() .ok(true) - .critical(policyServiceConfiguration.getEnabled()) + .critical(policyServiceConfiguration.enabled()) .message("Terra Policy Service status ok"); } catch (Exception ex) { String errorMsg = "Terra Policy Service status check failed"; logger.error(errorMsg, ex); return new RepositoryStatusModelSystems() .ok(false) - .critical(policyServiceConfiguration.getEnabled()) + .critical(policyServiceConfiguration.enabled()) .message(errorMsg + ": " + ExceptionUtils.formatException(ex)); } } diff --git a/src/main/java/bio/terra/service/profile/azure/AzureAuthzService.java b/src/main/java/bio/terra/service/profile/azure/AzureAuthzService.java index 1c28ff38f4..a2011430e4 100644 --- a/src/main/java/bio/terra/service/profile/azure/AzureAuthzService.java +++ b/src/main/java/bio/terra/service/profile/azure/AzureAuthzService.java @@ -38,7 +38,7 @@ public boolean canAccess( GenericResource applicationDeployment = client .genericResources() - .getById(applicationResourceId, resourceConfiguration.getApiVersion()); + .getById(applicationResourceId, resourceConfiguration.apiVersion()); return ((Map>>) applicationDeployment.properties()) .get("parameters") diff --git a/src/main/java/bio/terra/service/rawls/RawlsClient.java b/src/main/java/bio/terra/service/rawls/RawlsClient.java index 69c80d7da4..04506ee1c4 100644 --- a/src/main/java/bio/terra/service/rawls/RawlsClient.java +++ b/src/main/java/bio/terra/service/rawls/RawlsClient.java @@ -40,8 +40,7 @@ public WorkspaceResponse getWorkspace(UUID workspaceId, AuthenticatedUserRequest try { ResponseEntity workspaceCall = restTemplate.exchange( - String.format( - "%s/api/workspaces/id/%s", rawlsConfiguration.getBasePath(), workspaceId), + String.format("%s/api/workspaces/id/%s", rawlsConfiguration.basePath(), workspaceId), HttpMethod.GET, new HttpEntity<>(headers), WorkspaceResponse.class); diff --git a/src/main/java/bio/terra/service/rawls/RawlsService.java b/src/main/java/bio/terra/service/rawls/RawlsService.java index e610da860a..4bf3a63db1 100644 --- a/src/main/java/bio/terra/service/rawls/RawlsService.java +++ b/src/main/java/bio/terra/service/rawls/RawlsService.java @@ -85,6 +85,6 @@ String getWorkspaceLink(WorkspaceResponse workspaceResponse) { return null; } return "%s/#workspaces/%s/%s" - .formatted(terraConfiguration.getBasePath(), workspace.getNamespace(), workspace.getName()); + .formatted(terraConfiguration.basePath(), workspace.getNamespace(), workspace.getName()); } } diff --git a/src/main/java/bio/terra/service/resourcemanagement/BufferService.java b/src/main/java/bio/terra/service/resourcemanagement/BufferService.java index 2966eb23e8..1796199157 100644 --- a/src/main/java/bio/terra/service/resourcemanagement/BufferService.java +++ b/src/main/java/bio/terra/service/resourcemanagement/BufferService.java @@ -55,7 +55,7 @@ public BufferService( private ApiClient createUnauthApiClient() { return new ApiClient() .setHttpClient(sharedHttpClient) - .setBasePath(bufferServiceConfiguration.getInstanceUrl()); + .setBasePath(bufferServiceConfiguration.instanceUrl()); } private ApiClient createApiClient(String accessToken) { @@ -81,11 +81,11 @@ public ResourceInfo handoutResource(boolean enableSecureMonitoring) { try { BufferApi bufferApi = bufferApi(); ResourceInfo info = - bufferApi.handoutResource(requestBody, bufferServiceConfiguration.getPoolId()); + bufferApi.handoutResource(requestBody, bufferServiceConfiguration.poolId()); logger.info( "Retrieved resource from pool {} on Buffer Service instance {}", - bufferServiceConfiguration.getPoolId(), - bufferServiceConfiguration.getInstanceUrl()); + bufferServiceConfiguration.poolId(), + bufferServiceConfiguration.instanceUrl()); if (enableSecureMonitoring) { var projectId = info.getCloudResourceUid().getGoogleProjectUid().getProjectId(); @@ -117,7 +117,7 @@ private void refolderProjectToSecureFolder(String projectId) var project = cloudResourceManager.projects().get(projectId).execute(); ResourceId resourceId = - new ResourceId().setType(GCS_FOLDER_TYPE).setId(googleConfig.getSecureFolderResourceId()); + new ResourceId().setType(GCS_FOLDER_TYPE).setId(googleConfig.secureFolderResourceId()); project.setParent(resourceId); @@ -136,12 +136,12 @@ public RepositoryStatusModelSystems status() { Map subsystemStatusMap = status.getSystems(); return new RepositoryStatusModelSystems() .ok(status.isOk()) - .critical(bufferServiceConfiguration.getEnabled()) + .critical(bufferServiceConfiguration.enabled()) .message(subsystemStatusMap.toString()); } catch (ApiException e) { return new RepositoryStatusModelSystems() .ok(false) - .critical(bufferServiceConfiguration.getEnabled()) + .critical(bufferServiceConfiguration.enabled()) .message(e.getResponseBody()); } } diff --git a/src/main/java/bio/terra/service/resourcemanagement/ResourceService.java b/src/main/java/bio/terra/service/resourcemanagement/ResourceService.java index 17060eb679..cc839879d3 100644 --- a/src/main/java/bio/terra/service/resourcemanagement/ResourceService.java +++ b/src/main/java/bio/terra/service/resourcemanagement/ResourceService.java @@ -648,7 +648,7 @@ private void modifyRoles( private Map> getStewardPolicy() { // get steward emails and add to policy - String stewardsGroupEmail = formatEmailForPolicy(samConfiguration.getStewardsGroupEmail()); + String stewardsGroupEmail = formatEmailForPolicy(samConfiguration.stewardsGroupEmail()); Map> policyMap = new HashMap<>(); policyMap.put(BQ_JOB_USER_ROLE, Collections.singletonList(stewardsGroupEmail)); return Collections.unmodifiableMap(policyMap); diff --git a/src/main/java/bio/terra/service/resourcemanagement/azure/AzureApplicationDeploymentService.java b/src/main/java/bio/terra/service/resourcemanagement/azure/AzureApplicationDeploymentService.java index 5326f5ac95..33e0eab67e 100644 --- a/src/main/java/bio/terra/service/resourcemanagement/azure/AzureApplicationDeploymentService.java +++ b/src/main/java/bio/terra/service/resourcemanagement/azure/AzureApplicationDeploymentService.java @@ -117,7 +117,7 @@ public GenericResource retrieveApplicationDeployment(BillingProfileModel billing MetadataDataAccessUtils.getApplicationDeploymentId(billingProfile); return client .genericResources() - .getById(applicationResourceId, resourceConfiguration.getApiVersion()); + .getById(applicationResourceId, resourceConfiguration.apiVersion()); } /** diff --git a/src/main/java/bio/terra/service/resourcemanagement/azure/AzureAuthService.java b/src/main/java/bio/terra/service/resourcemanagement/azure/AzureAuthService.java index 285556c90a..6441b056f9 100644 --- a/src/main/java/bio/terra/service/resourcemanagement/azure/AzureAuthService.java +++ b/src/main/java/bio/terra/service/resourcemanagement/azure/AzureAuthService.java @@ -37,8 +37,8 @@ public class AzureAuthService { @Autowired public AzureAuthService(AzureResourceConfiguration configuration) { this.configuration = configuration; - var maxRetries = configuration.getMaxRetries(); - var retryTimeoutSeconds = configuration.getRetryTimeoutSeconds(); + var maxRetries = configuration.maxRetries(); + var retryTimeoutSeconds = configuration.retryTimeoutSeconds(); retryOptions = new RequestRetryOptions( RetryPolicyType.EXPONENTIAL, maxRetries, retryTimeoutSeconds, null, null, null); diff --git a/src/main/java/bio/terra/service/resourcemanagement/azure/AzureMonitoringService.java b/src/main/java/bio/terra/service/resourcemanagement/azure/AzureMonitoringService.java index aff3368c79..2f5ec9ee70 100644 --- a/src/main/java/bio/terra/service/resourcemanagement/azure/AzureMonitoringService.java +++ b/src/main/java/bio/terra/service/resourcemanagement/azure/AzureMonitoringService.java @@ -75,7 +75,7 @@ public Workspace getLogAnalyticsWorkspace( BillingProfileModel profileModel, AzureStorageAccountResource storageAccount) { LogAnalyticsManager client = resourceConfiguration.getLogAnalyticsManagerClient( - resourceConfiguration.getCredentials().getHomeTenantId(), + resourceConfiguration.credentials().getHomeTenantId(), profileModel.getSubscriptionId()); try { Workspace byResourceGroup = @@ -107,7 +107,7 @@ public String createLogAnalyticsWorkspace( BillingProfileModel profileModel, AzureStorageAccountResource storageAccount) { LogAnalyticsManager client = resourceConfiguration.getLogAnalyticsManagerClient( - resourceConfiguration.getCredentials().getHomeTenantId(), + resourceConfiguration.credentials().getHomeTenantId(), profileModel.getSubscriptionId()); logger.info( @@ -135,7 +135,7 @@ public String createLogAnalyticsWorkspace( public void deleteLogAnalyticsWorkspace(BillingProfileModel profileModel, String id) { LogAnalyticsManager client = resourceConfiguration.getLogAnalyticsManagerClient( - resourceConfiguration.getCredentials().getHomeTenantId(), + resourceConfiguration.credentials().getHomeTenantId(), profileModel.getSubscriptionId()); logger.info("Deleting Log Analytics Workspace {}", id); @@ -236,7 +236,7 @@ public DataExport getDataExportRule( LogAnalyticsManager client = resourceConfiguration.getLogAnalyticsManagerClient( - resourceConfiguration.getCredentials().getHomeTenantId(), + resourceConfiguration.credentials().getHomeTenantId(), profileModel.getSubscriptionId()); try { @@ -275,7 +275,7 @@ public String createDataExportRule( String resourceId = resourceConfiguration - .getMonitoring() + .monitoring() .getLogCollectionConfigsAsMap() .get(storageAccount.getRegion()); if (resourceId == null) { @@ -285,7 +285,7 @@ public String createDataExportRule( } LogAnalyticsManager client = resourceConfiguration.getLogAnalyticsManagerClient( - resourceConfiguration.getCredentials().getHomeTenantId(), + resourceConfiguration.credentials().getHomeTenantId(), profileModel.getSubscriptionId()); logger.info( @@ -313,7 +313,7 @@ public String createDataExportRule( public void deleteDataExportRule(BillingProfileModel profileModel, String id) { LogAnalyticsManager client = resourceConfiguration.getLogAnalyticsManagerClient( - resourceConfiguration.getCredentials().getHomeTenantId(), + resourceConfiguration.credentials().getHomeTenantId(), profileModel.getSubscriptionId()); logger.info("Deleting Log Analytics Workspace data export rule {}", id); @@ -333,7 +333,7 @@ public SentinelOnboardingState getSentinel( BillingProfileModel profileModel, AzureStorageAccountResource storageAccount) { SecurityInsightsManager client = resourceConfiguration.getSecurityInsightsManagerClient( - resourceConfiguration.getCredentials().getHomeTenantId(), + resourceConfiguration.credentials().getHomeTenantId(), profileModel.getSubscriptionId()); try { @@ -367,7 +367,7 @@ public String createSentinel( BillingProfileModel profileModel, AzureStorageAccountResource storageAccount) { SecurityInsightsManager client = resourceConfiguration.getSecurityInsightsManagerClient( - resourceConfiguration.getCredentials().getHomeTenantId(), + resourceConfiguration.credentials().getHomeTenantId(), profileModel.getSubscriptionId()); logger.info( @@ -398,7 +398,7 @@ public void deleteSentinel(BillingProfileModel profileModel, String id) { SecurityInsightsManager client = resourceConfiguration.getSecurityInsightsManagerClient( - resourceConfiguration.getCredentials().getHomeTenantId(), + resourceConfiguration.credentials().getHomeTenantId(), profileModel.getSubscriptionId()); logger.info("Deleting Sentinel instance {}", id); @@ -418,7 +418,7 @@ public AlertRule getSentinelRuleUnauthorizedAccess( BillingProfileModel profileModel, AzureStorageAccountResource storageAccount) { SecurityInsightsManager client = resourceConfiguration.getSecurityInsightsManagerClient( - resourceConfiguration.getCredentials().getHomeTenantId(), + resourceConfiguration.credentials().getHomeTenantId(), profileModel.getSubscriptionId()); try { AlertRule alertRule = @@ -454,7 +454,7 @@ public String createSentinelRuleUnauthorizedAccess( BillingProfileModel profileModel, AzureStorageAccountResource storageAccount) { SecurityInsightsManager client = resourceConfiguration.getSecurityInsightsManagerClient( - resourceConfiguration.getCredentials().getHomeTenantId(), + resourceConfiguration.credentials().getHomeTenantId(), profileModel.getSubscriptionId()); // Note: this is copied from the rule defined in the Terra landing zone service @@ -503,7 +503,7 @@ public void deleteSentinelRuleUnauthorizedAccess( BillingProfileModel profileModel, AzureStorageAccountResource storageAccount) { SecurityInsightsManager client = resourceConfiguration.getSecurityInsightsManagerClient( - resourceConfiguration.getCredentials().getHomeTenantId(), + resourceConfiguration.credentials().getHomeTenantId(), profileModel.getSubscriptionId()); logger.info( @@ -529,7 +529,7 @@ public AutomationRule getNotificationRule( BillingProfileModel profileModel, AzureStorageAccountResource storageAccount) { SecurityInsightsManager client = resourceConfiguration.getSecurityInsightsManagerClient( - resourceConfiguration.getCredentials().getHomeTenantId(), + resourceConfiguration.credentials().getHomeTenantId(), profileModel.getSubscriptionId()); try { AutomationRule automationRule = @@ -566,7 +566,7 @@ public String createNotificationRule( BillingProfileModel profileModel, AzureStorageAccountResource storageAccount) { SecurityInsightsManager client = resourceConfiguration.getSecurityInsightsManagerClient( - resourceConfiguration.getCredentials().getHomeTenantId(), + resourceConfiguration.credentials().getHomeTenantId(), profileModel.getSubscriptionId()); logger.info( "Creating new Sentinel alert rule for Sentinel instance monitoring Storage Account {}", @@ -583,8 +583,8 @@ public String createNotificationRule( .withActionConfiguration( new PlaybookActionProperties() .withLogicAppResourceId( - resourceConfiguration.getMonitoring().getNotificationApplicationId()) - .withTenantId(resourceConfiguration.getCredentials().getHomeTenantId())); + resourceConfiguration.monitoring().notificationApplicationId()) + .withTenantId(resourceConfiguration.credentials().getHomeTenantId())); return client .automationRules() .define(SLACK_ALERT_RULE_NAME) @@ -608,7 +608,7 @@ public String createNotificationRule( public void deleteNotificationRule(BillingProfileModel profileModel, String id) { SecurityInsightsManager client = resourceConfiguration.getSecurityInsightsManagerClient( - resourceConfiguration.getCredentials().getHomeTenantId(), + resourceConfiguration.credentials().getHomeTenantId(), profileModel.getSubscriptionId()); logger.info("Deleting Sentinel alert rule {}", id); diff --git a/src/main/java/bio/terra/service/resourcemanagement/azure/AzureResourceConfiguration.java b/src/main/java/bio/terra/service/resourcemanagement/azure/AzureResourceConfiguration.java index b18ba34b77..d2e7ce3230 100644 --- a/src/main/java/bio/terra/service/resourcemanagement/azure/AzureResourceConfiguration.java +++ b/src/main/java/bio/terra/service/resourcemanagement/azure/AzureResourceConfiguration.java @@ -13,68 +13,20 @@ import java.util.UUID; import java.util.stream.Collectors; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.ConstructorBinding; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Configuration; /** Configuration for working with Azure resources */ -@Configuration +@ConstructorBinding @EnableConfigurationProperties @ConfigurationProperties(prefix = "azure") -public class AzureResourceConfiguration { - private Credentials credentials; - private Synapse synapse; - private int maxRetries; - private int retryTimeoutSeconds; - private String apiVersion; - private Monitoring monitoring; - - public Credentials getCredentials() { - return credentials; - } - - public void setCredentials(Credentials credentials) { - this.credentials = credentials; - } - - public Synapse getSynapse() { - return synapse; - } - - public void setSynapse(Synapse synapse) { - this.synapse = synapse; - } - - public int getMaxRetries() { - return maxRetries; - } - - public void setMaxRetries(int maxRetries) { - this.maxRetries = maxRetries; - } - - public int getRetryTimeoutSeconds() { - return retryTimeoutSeconds; - } - - public void setRetryTimeoutSeconds(int retryTimeoutSeconds) { - this.retryTimeoutSeconds = retryTimeoutSeconds; - } - - public String getApiVersion() { - return apiVersion; - } - - public void setApiVersion(String apiVersion) { - this.apiVersion = apiVersion; - } - - public Monitoring getMonitoring() { - return monitoring; - } - - public void setMonitoring(Monitoring monitoring) { - this.monitoring = monitoring; - } +public record AzureResourceConfiguration( + Credentials credentials, + Synapse synapse, + int maxRetries, + int retryTimeoutSeconds, + String apiVersion, + Monitoring monitoring) { /** * Given a user tenant Id, return Azure credentials @@ -84,8 +36,8 @@ public void setMonitoring(Monitoring monitoring) { */ public TokenCredential getAppToken(final UUID tenantId) { return new ClientSecretCredentialBuilder() - .clientId(credentials.applicationId.toString()) - .clientSecret(credentials.secret) + .clientId(credentials.getApplicationId().toString()) + .clientSecret(credentials.getSecret()) .tenantId(tenantId.toString()) .build(); } @@ -196,102 +148,28 @@ public void setHomeTenantId(UUID homeTenantId) { } } - public static class Synapse { - - private String workspaceName; - private String sqlAdminUser; - private String sqlAdminPassword; - private String databaseName; - private String parquetFileFormatName; - private String encryptionKey; - private boolean initialize; - - public String getWorkspaceName() { - return workspaceName; - } - - public void setWorkspaceName(String workspaceName) { - this.workspaceName = workspaceName; - } - - public String getSqlAdminUser() { - return sqlAdminUser; - } - - public void setSqlAdminUser(String sqlAdminUser) { - this.sqlAdminUser = sqlAdminUser; - } - - public String getSqlAdminPassword() { - return sqlAdminPassword; - } - - public void setSqlAdminPassword(String sqlAdminPassword) { - this.sqlAdminPassword = sqlAdminPassword; - } - - public String getDatabaseName() { - return databaseName; - } - - public void setDatabaseName(String databaseName) { - this.databaseName = databaseName; - } - - public String getParquetFileFormatName() { - return parquetFileFormatName; - } - - public void setParquetFileFormatName(String parquetFileFormatName) { - this.parquetFileFormatName = parquetFileFormatName; - } - - public String getEncryptionKey() { - return encryptionKey; - } - - public void setEncryptionKey(String encryptionKey) { - this.encryptionKey = encryptionKey; - } - - public boolean isInitialize() { - return initialize; - } - - public void setInitialize(boolean initialize) { - this.initialize = initialize; - } - } + public record Synapse( + String workspaceName, + String sqlAdminUser, + String sqlAdminPassword, + String databaseName, + String parquetFileFormatName, + String encryptionKey, + boolean initialize) {} /** Track the monitoring-related configuration */ - public static class Monitoring { - // The resource ID of the Azure Logic app that handles sending Slack notifications - private String notificationApplicationId; - // The list of regional storage accounts to send long term logs to - private List logCollectionConfigs; - - public String getNotificationApplicationId() { - return notificationApplicationId; - } - - public void setNotificationApplicationId(String notificationApplicationId) { - this.notificationApplicationId = notificationApplicationId; - } - - public List getLogCollectionConfigs() { - return logCollectionConfigs; - } - - public void setLogCollectionConfigs(List logCollectionConfigs) { - this.logCollectionConfigs = logCollectionConfigs; - } + public record Monitoring( + // The resource ID of the Azure Logic app that handles sending Slack notifications + String notificationApplicationId, + // The list of regional storage accounts to send long term logs to + List logCollectionConfigs) { public Map getLogCollectionConfigsAsMap() { return logCollectionConfigs.stream() .collect( Collectors.toMap( - LogCollectionConfig::getRegion, - LogCollectionConfig::getTargetStorageAccountResourceId)); + LogCollectionConfig::region, + LogCollectionConfig::targetStorageAccountResourceId)); } } @@ -300,31 +178,5 @@ public Map getLogCollectionConfigsAsMap() { * in the same region as the Log Analytics workspace which is why there may be several of these * objects in the service configuration */ - public static class LogCollectionConfig { - - private AzureRegion region; - private String targetStorageAccountResourceId; - - public AzureRegion getRegion() { - return region; - } - - public void setRegion(String region) { - AzureRegion azureRegion = AzureRegion.fromValue(region); - if (azureRegion == null) { - throw new IllegalArgumentException( - String.format( - "Invalid region '%s' specified in azure.monitoring.logCollectionConfigs", region)); - } - this.region = azureRegion; - } - - public String getTargetStorageAccountResourceId() { - return targetStorageAccountResourceId; - } - - public void setTargetStorageAccountResourceId(String targetStorageAccountResourceId) { - this.targetStorageAccountResourceId = targetStorageAccountResourceId; - } - } + public record LogCollectionConfig(AzureRegion region, String targetStorageAccountResourceId) {} } diff --git a/src/main/java/bio/terra/service/resourcemanagement/google/GoogleProjectService.java b/src/main/java/bio/terra/service/resourcemanagement/google/GoogleProjectService.java index 8ff33b6029..a0a17e13f0 100644 --- a/src/main/java/bio/terra/service/resourcemanagement/google/GoogleProjectService.java +++ b/src/main/java/bio/terra/service/resourcemanagement/google/GoogleProjectService.java @@ -301,7 +301,7 @@ void enableServices(GoogleProjectResource projectResource, GoogleRegion region) .map(GoogleApiServiceusageV1Service::getName) .collect(Collectors.toList()); } - long timeout = resourceConfiguration.getProjectCreateTimeoutSeconds(); + long timeout = resourceConfiguration.projectCreateTimeoutSeconds(); if (actualServiceNames.containsAll(requiredServices)) { logger.info("project already has the right resources enabled, skipping"); @@ -389,7 +389,7 @@ private Appengine appengine() throws GeneralSecurityException, IOException { } return new Appengine.Builder(httpTransport, jsonFactory, credential) - .setApplicationName(resourceConfiguration.getApplicationName()) + .setApplicationName(resourceConfiguration.applicationName()) .build(); } @@ -536,7 +536,7 @@ private ServiceUsage serviceUsage() throws IOException, GeneralSecurityException } return new ServiceUsage.Builder(httpTransport, jsonFactory, credential) - .setApplicationName(resourceConfiguration.getApplicationName()) + .setApplicationName(resourceConfiguration.applicationName()) .build(); } diff --git a/src/main/java/bio/terra/service/resourcemanagement/google/GoogleResourceConfiguration.java b/src/main/java/bio/terra/service/resourcemanagement/google/GoogleResourceConfiguration.java index c2fd43f62b..824c247b76 100644 --- a/src/main/java/bio/terra/service/resourcemanagement/google/GoogleResourceConfiguration.java +++ b/src/main/java/bio/terra/service/resourcemanagement/google/GoogleResourceConfiguration.java @@ -1,56 +1,15 @@ package bio.terra.service.resourcemanagement.google; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.ConstructorBinding; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Configuration; -@Configuration +@ConstructorBinding @EnableConfigurationProperties @ConfigurationProperties(prefix = "google") -public class GoogleResourceConfiguration { - private String applicationName; - private long projectCreateTimeoutSeconds; - private int firestoreRetries; - private boolean allowReuseExistingBuckets; - private String secureFolderResourceId; - - public String getApplicationName() { - return applicationName; - } - - public void setApplicationName(String applicationName) { - this.applicationName = applicationName; - } - - public long getProjectCreateTimeoutSeconds() { - return projectCreateTimeoutSeconds; - } - - public void setProjectCreateTimeoutSeconds(long projectCreateTimeoutSeconds) { - this.projectCreateTimeoutSeconds = projectCreateTimeoutSeconds; - } - - public boolean getAllowReuseExistingBuckets() { - return allowReuseExistingBuckets; - } - - public void setAllowReuseExistingBuckets(boolean allowReuseExistingBuckets) { - this.allowReuseExistingBuckets = allowReuseExistingBuckets; - } - - public int getFirestoreRetries() { - return firestoreRetries; - } - - public void setFirestoreRetries(int firestoreRetries) { - this.firestoreRetries = firestoreRetries; - } - - public String getSecureFolderResourceId() { - return secureFolderResourceId; - } - - public void setSecureFolderResourceId(String secureFolderResourceId) { - this.secureFolderResourceId = secureFolderResourceId; - } -} +public record GoogleResourceConfiguration( + String applicationName, + long projectCreateTimeoutSeconds, + int firestoreRetries, + boolean allowReuseExistingBuckets, + String secureFolderResourceId) {} diff --git a/src/main/java/bio/terra/service/resourcemanagement/google/GoogleResourceDao.java b/src/main/java/bio/terra/service/resourcemanagement/google/GoogleResourceDao.java index 931d255c28..893bb331f8 100644 --- a/src/main/java/bio/terra/service/resourcemanagement/google/GoogleResourceDao.java +++ b/src/main/java/bio/terra/service/resourcemanagement/google/GoogleResourceDao.java @@ -111,7 +111,7 @@ public GoogleResourceDao( @Qualifier("tdrServiceAccountEmail") String tdrServiceAccountEmail) throws SQLException { this.jdbcTemplate = jdbcTemplate; - this.defaultRegion = GoogleRegion.fromValue(gcsConfiguration.getRegion()); + this.defaultRegion = GoogleRegion.fromValue(gcsConfiguration.region()); this.googleResourceConfiguration = googleResourceConfiguration; this.tdrServiceAccountEmail = tdrServiceAccountEmail; } @@ -500,7 +500,7 @@ private GoogleBucketResource retrieveBucketBy(String sql, MapSqlParameterSource if (bucketResources.size() > 1) { // TODO This is only here because of the dev case. It should be removed when we start using // RBS in dev. - if (googleResourceConfiguration.getAllowReuseExistingBuckets()) { + if (googleResourceConfiguration.allowReuseExistingBuckets()) { return bucketResources.get(0).region(defaultRegion); } throw new CorruptMetadataException( diff --git a/src/main/java/bio/terra/service/resourcemanagement/google/GoogleResourceManagerService.java b/src/main/java/bio/terra/service/resourcemanagement/google/GoogleResourceManagerService.java index 1c79c55fa5..16d5c5a123 100644 --- a/src/main/java/bio/terra/service/resourcemanagement/google/GoogleResourceManagerService.java +++ b/src/main/java/bio/terra/service/resourcemanagement/google/GoogleResourceManagerService.java @@ -63,7 +63,7 @@ public CloudResourceManager cloudResourceManager() throws IOException, GeneralSe } return new CloudResourceManager.Builder(httpTransport, jsonFactory, credential) - .setApplicationName(resourceConfiguration.getApplicationName()) + .setApplicationName(resourceConfiguration.applicationName()) .build(); } diff --git a/src/main/java/bio/terra/service/upgrade/Migrate.java b/src/main/java/bio/terra/service/upgrade/Migrate.java index b1b8d0bb41..8776d200cc 100644 --- a/src/main/java/bio/terra/service/upgrade/Migrate.java +++ b/src/main/java/bio/terra/service/upgrade/Migrate.java @@ -55,21 +55,20 @@ public void migrateDatabase() { changesetFile, new ClassLoaderResourceAccessor(), new JdbcConnection(connection)); logger.info( - String.format("dropAllOnStart is set to %s", migrateConfiguration.getDropAllOnStart())); + String.format("dropAllOnStart is set to %s", migrateConfiguration.dropAllOnStart())); boolean allowDropAllOnStart = Arrays.stream(env.getActiveProfiles()) .anyMatch(env -> env.contains("dev") || env.contains("test") || env.contains("int")); logger.info(String.format("Allow dropAllOnStart is set to %s", allowDropAllOnStart)); - if (allowDropAllOnStart && migrateConfiguration.getDropAllOnStart()) { + if (allowDropAllOnStart && migrateConfiguration.dropAllOnStart()) { logger.info("Dropping all db objects in the default schema"); liquibase .dropAll(); // drops everything in the default schema. The migrate schema should be OK } logger.info( - String.format( - "updateAllOnStart is set to %s", migrateConfiguration.getUpdateAllOnStart())); - if (migrateConfiguration.getUpdateAllOnStart()) { + String.format("updateAllOnStart is set to %s", migrateConfiguration.updateAllOnStart())); + if (migrateConfiguration.updateAllOnStart()) { liquibase.update(new Contexts()); // Run all migrations - no context filtering } } catch (LiquibaseException | SQLException ex) { diff --git a/src/main/java/bio/terra/service/upgrade/MigrateConfiguration.java b/src/main/java/bio/terra/service/upgrade/MigrateConfiguration.java index 4f5ce19686..1f2e913a9d 100644 --- a/src/main/java/bio/terra/service/upgrade/MigrateConfiguration.java +++ b/src/main/java/bio/terra/service/upgrade/MigrateConfiguration.java @@ -1,34 +1,13 @@ package bio.terra.service.upgrade; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.stereotype.Component; +import org.springframework.boot.context.properties.ConstructorBinding; /** * Provides methods for upgrading the data repository metadata and stairway databases. See Liquibase * Migration Notes */ -@Component -@EnableConfigurationProperties @ConfigurationProperties(prefix = "db.migrate") -public class MigrateConfiguration { - private boolean dropAllOnStart; - private boolean updateAllOnStart; - - public boolean getDropAllOnStart() { - return dropAllOnStart; - } - - public void setDropAllOnStart(boolean dropAllOnStart) { - this.dropAllOnStart = dropAllOnStart; - } - - public boolean getUpdateAllOnStart() { - return updateAllOnStart; - } - - public void setUpdateAllOnStart(boolean updateAllOnStart) { - this.updateAllOnStart = updateAllOnStart; - } -} +@ConstructorBinding +public record MigrateConfiguration(boolean dropAllOnStart, boolean updateAllOnStart) {} diff --git a/src/test/java/bio/terra/app/controller/UnauthenticatedApiControllerTest.java b/src/test/java/bio/terra/app/controller/UnauthenticatedApiControllerTest.java index 6ff75e1301..e170e3f8a6 100644 --- a/src/test/java/bio/terra/app/controller/UnauthenticatedApiControllerTest.java +++ b/src/test/java/bio/terra/app/controller/UnauthenticatedApiControllerTest.java @@ -59,10 +59,10 @@ void testRetrieveRepositoryConfig() throws Exception { String samUrl = "sam.base.url"; String oidcAuthorityEndpoint = "/oidc/authority/endpoint"; - when(oauthConfig.getClientId()).thenReturn(oauthClientId); + when(oauthConfig.clientId()).thenReturn(oauthClientId); when(openIDConnectConfiguration.getClientId()).thenReturn(oidcClientId); - when(terraConfiguration.getBasePath()).thenReturn(terraUrl); - when(samConfiguration.getBasePath()).thenReturn(samUrl); + when(terraConfiguration.basePath()).thenReturn(terraUrl); + when(samConfiguration.basePath()).thenReturn(samUrl); when(openIDConnectConfiguration.getAuthorityEndpoint()).thenReturn(oidcAuthorityEndpoint); mvc.perform(get("/configuration")) diff --git a/src/test/java/bio/terra/app/usermetrics/BardClientTest.java b/src/test/java/bio/terra/app/usermetrics/BardClientTest.java index 0db0840498..6f260b6a9b 100644 --- a/src/test/java/bio/terra/app/usermetrics/BardClientTest.java +++ b/src/test/java/bio/terra/app/usermetrics/BardClientTest.java @@ -38,7 +38,7 @@ public class BardClientTest { @BeforeEach void setup() { - when(userMetricsConfiguration.getSyncRefreshIntervalSeconds()).thenReturn(1000); + when(userMetricsConfiguration.syncRefreshIntervalSeconds()).thenReturn(1000); bardClient = new BardClient(userMetricsConfiguration, restTemplate); diff --git a/src/test/java/bio/terra/app/usermetrics/UserMetricsInterceptorTest.java b/src/test/java/bio/terra/app/usermetrics/UserMetricsInterceptorTest.java index 7f9e6dde28..1b0e590978 100644 --- a/src/test/java/bio/terra/app/usermetrics/UserMetricsInterceptorTest.java +++ b/src/test/java/bio/terra/app/usermetrics/UserMetricsInterceptorTest.java @@ -68,9 +68,9 @@ public class UserMetricsInterceptorTest { @BeforeEach void setUp() { - when(metricsConfig.getIgnorePaths()).thenReturn(List.of()); - when(metricsConfig.getAppId()).thenReturn(APP_ID); - when(metricsConfig.getBardBasePath()).thenReturn(BARD_BASE_PATH); + when(metricsConfig.ignorePaths()).thenReturn(List.of()); + when(metricsConfig.appId()).thenReturn(APP_ID); + when(metricsConfig.bardBasePath()).thenReturn(BARD_BASE_PATH); when(applicationConfiguration.getDnsName()).thenReturn(DNS_NAME); @@ -150,7 +150,7 @@ void testSendEventWithBillingProfileId() throws Exception { @Test void testSendEventNotFiredWithNoBardBasePath() throws Exception { - when(metricsConfig.getBardBasePath()).thenReturn(null); + when(metricsConfig.bardBasePath()).thenReturn(null); runAndWait(); @@ -170,7 +170,7 @@ void testSendEventNotFiredWithNoToken() throws Exception { @ParameterizedTest @ValueSource(strings = {REQUEST_URI, "/foo/*"}) void testSendEventNotFiredWithIgnoredUrl(String ignorePath) throws Exception { - when(metricsConfig.getIgnorePaths()).thenReturn(List.of(ignorePath)); + when(metricsConfig.ignorePaths()).thenReturn(List.of(ignorePath)); mockRequestAuth(request); runAndWait(); diff --git a/src/test/java/bio/terra/common/SynapseUtils.java b/src/test/java/bio/terra/common/SynapseUtils.java index a160636c92..26ddce82d1 100644 --- a/src/test/java/bio/terra/common/SynapseUtils.java +++ b/src/test/java/bio/terra/common/SynapseUtils.java @@ -129,7 +129,7 @@ public void synapseTestSetup() throws SQLException { client = azureResourceConfiguration.getClient( - azureResourceConfiguration.getCredentials().getHomeTenantId(), + azureResourceConfiguration.credentials().getHomeTenantId(), billingProfile.getSubscriptionId()); applicationResource = diff --git a/src/test/java/bio/terra/integration/AzureIntegrationTest.java b/src/test/java/bio/terra/integration/AzureIntegrationTest.java index 1315cffbcc..e7fc093a3f 100644 --- a/src/test/java/bio/terra/integration/AzureIntegrationTest.java +++ b/src/test/java/bio/terra/integration/AzureIntegrationTest.java @@ -159,8 +159,8 @@ public void setup() throws Exception { retryOptions = new RequestRetryOptions( RetryPolicyType.EXPONENTIAL, - azureResourceConfiguration.getMaxRetries(), - azureResourceConfiguration.getRetryTimeoutSeconds(), + azureResourceConfiguration.maxRetries(), + azureResourceConfiguration.retryTimeoutSeconds(), null, null, null); diff --git a/src/test/java/bio/terra/integration/SamFixtures.java b/src/test/java/bio/terra/integration/SamFixtures.java index 511e9fc6f5..bf062501f3 100644 --- a/src/test/java/bio/terra/integration/SamFixtures.java +++ b/src/test/java/bio/terra/integration/SamFixtures.java @@ -40,7 +40,7 @@ public SamFixtures() { } public void deleteServiceAccountFromTerra(TestConfiguration.User user, String serviceAccount) { - logger.info("Deleting user {} from Sam {}", serviceAccount, samConfig.getBasePath()); + logger.info("Deleting user {} from Sam {}", serviceAccount, samConfig.basePath()); try { // Get the user ID to delete HttpHeaders authedHeader = getHeaders(user); @@ -63,7 +63,7 @@ public void deleteServiceAccountFromTerra(TestConfiguration.User user, String se // Delete the user String userDeletionUrl = "%s/api/admin/v1/user/%s" - .formatted(samConfig.getBasePath(), userStatus.getUserInfo().getUserSubjectId()); + .formatted(samConfig.basePath(), userStatus.getUserInfo().getUserSubjectId()); try { restTemplate.exchange( userDeletionUrl, HttpMethod.DELETE, new HttpEntity<>(null, authedHeader), Void.class); @@ -86,7 +86,7 @@ private ApiClient getApiClient(String accessToken) { ApiClient apiClient = new ApiClient(); apiClient.setAccessToken(accessToken); apiClient.setUserAgent("OpenAPI-Generator/1.0.0 java"); // only logs an error in sam - return apiClient.setBasePath(samConfig.getBasePath()); + return apiClient.setBasePath(samConfig.basePath()); } private HttpHeaders getHeaders(TestConfiguration.User user) { diff --git a/src/test/java/bio/terra/service/auth/iam/sam/SamIamTest.java b/src/test/java/bio/terra/service/auth/iam/sam/SamIamTest.java index f605d3afef..4745e2448c 100644 --- a/src/test/java/bio/terra/service/auth/iam/sam/SamIamTest.java +++ b/src/test/java/bio/terra/service/auth/iam/sam/SamIamTest.java @@ -75,19 +75,27 @@ public class SamIamTest { @Mock private UsersApi samUsersApi; private SamIam samIam; - private final SamConfiguration samConfig = new SamConfiguration(); private static final String ADMIN_EMAIL = "samAdminGroupEmail@a.com"; + private final SamConfiguration samConfig = + new SamConfiguration( + "https://sam.dsde-dev.broadinstitute.org", + "samStewardsGroupEmail@a.com", + ADMIN_EMAIL, + 10, + 30, + 60); private static final AuthenticatedUserRequest TEST_USER = AuthenticationFixtures.randomUserRequest(); @BeforeEach void setUp() throws Exception { - samConfig.setAdminsGroupEmail(ADMIN_EMAIL); + GoogleResourceConfiguration resourceConfiguration = + new GoogleResourceConfiguration("jade-data-repo", 600, 4, false, "123456"); samIam = new SamIam( samConfig, new ConfigurationService( - samConfig, null, new GoogleResourceConfiguration(), new ApplicationConfiguration()), + samConfig, null, resourceConfiguration, new ApplicationConfiguration()), samApiService); } @@ -539,7 +547,7 @@ void testCreateProfile() throws InterruptedException, ApiException { req.putPoliciesItem( IamRole.ADMIN.toString(), new AccessPolicyMembershipV2() - .memberEmails(List.of(samConfig.getAdminsGroupEmail())) + .memberEmails(List.of(samConfig.adminsGroupEmail())) .roles(List.of(IamRole.ADMIN.toString()))); req.putPoliciesItem( IamRole.OWNER.toString(), diff --git a/src/test/java/bio/terra/service/auth/iam/sam/SamRetryIntegrationTest.java b/src/test/java/bio/terra/service/auth/iam/sam/SamRetryIntegrationTest.java index 9fe75a37cd..2f89bb1e0e 100644 --- a/src/test/java/bio/terra/service/auth/iam/sam/SamRetryIntegrationTest.java +++ b/src/test/java/bio/terra/service/auth/iam/sam/SamRetryIntegrationTest.java @@ -57,7 +57,7 @@ private ApiClient getApiClient(String accessToken) { ApiClient apiClient = new ApiClient(); apiClient.setAccessToken(accessToken); apiClient.setUserAgent("OpenAPI-Generator/1.0.0 java"); // only logs an error in sam - return apiClient.setBasePath(samConfig.getBasePath()); + return apiClient.setBasePath(samConfig.basePath()); } @Before diff --git a/src/test/java/bio/terra/service/configuration/ConfigServiceTest.java b/src/test/java/bio/terra/service/configuration/ConfigServiceTest.java index 76e495b64b..f5a582cf05 100644 --- a/src/test/java/bio/terra/service/configuration/ConfigServiceTest.java +++ b/src/test/java/bio/terra/service/configuration/ConfigServiceTest.java @@ -53,9 +53,9 @@ public void configBasicTest() throws Exception { configService.reset(); final int delta = 10; - int retryInitialWaitSeconds = samConfiguration.getRetryInitialWaitSeconds(); - int retryMaximumWaitSeconds = samConfiguration.getRetryMaximumWaitSeconds(); - int operationTimeoutSeconds = samConfiguration.getOperationTimeoutSeconds(); + int retryInitialWaitSeconds = samConfiguration.retryInitialWaitSeconds(); + int retryMaximumWaitSeconds = samConfiguration.retryMaximumWaitSeconds(); + int operationTimeoutSeconds = samConfiguration.operationTimeoutSeconds(); // Retrieve all config and make sure initialization worked List configModelList = configService.getConfigList().getItems(); diff --git a/src/test/java/bio/terra/service/dataset/SecureMonitoringIntegrationTest.java b/src/test/java/bio/terra/service/dataset/SecureMonitoringIntegrationTest.java index 0ed5244f4e..8f0c9d560d 100644 --- a/src/test/java/bio/terra/service/dataset/SecureMonitoringIntegrationTest.java +++ b/src/test/java/bio/terra/service/dataset/SecureMonitoringIntegrationTest.java @@ -108,7 +108,7 @@ public void testDatasetWithSecureMonitoring() throws Exception { assertThat( "The parent of the dataset project is in the 'secure' folder", datasetParent.getId(), - equalTo(googleResourceConfiguration.getSecureFolderResourceId())); + equalTo(googleResourceConfiguration.secureFolderResourceId())); String datasetName = dataset.getName(); SnapshotRequestModel requestModel = @@ -161,7 +161,7 @@ public void testDatasetWithSecureMonitoring() throws Exception { assertThat( "The parent of the snapshot project is in the 'secure' folder", snapshotParent.getId(), - equalTo(googleResourceConfiguration.getSecureFolderResourceId())); + equalTo(googleResourceConfiguration.secureFolderResourceId())); } private DatasetSummaryModel datasetWithSecureMonitoring(boolean secureMonitoringEnabled) diff --git a/src/test/java/bio/terra/service/duos/DuosClientTest.java b/src/test/java/bio/terra/service/duos/DuosClientTest.java index 402b4184f7..50e2523af5 100644 --- a/src/test/java/bio/terra/service/duos/DuosClientTest.java +++ b/src/test/java/bio/terra/service/duos/DuosClientTest.java @@ -60,7 +60,7 @@ public void setup() { when(googleCredentialsService.getApplicationDefaultAccessToken(DuosClient.SCOPES)) .thenReturn(TDR_SA_TOKEN); - when(duosConfiguration.getBasePath()).thenReturn(BASE_PATH); + when(duosConfiguration.basePath()).thenReturn(BASE_PATH); duosClient = new DuosClient(duosConfiguration, restTemplate, googleCredentialsService); } diff --git a/src/test/java/bio/terra/service/filedata/DrsServiceTest.java b/src/test/java/bio/terra/service/filedata/DrsServiceTest.java index e3fdb4caa6..686c3dfd1a 100644 --- a/src/test/java/bio/terra/service/filedata/DrsServiceTest.java +++ b/src/test/java/bio/terra/service/filedata/DrsServiceTest.java @@ -237,7 +237,7 @@ void before() throws Exception { drsPassportRequestModel = new DRSPassportRequestModel().addPassportsItem("longPassportToken").expand(false); - when(ecmConfiguration.getRasIssuer()).thenReturn(RAS_ISSUER); + when(ecmConfiguration.rasIssuer()).thenReturn(RAS_ISSUER); } @Test diff --git a/src/test/java/bio/terra/service/filedata/azure/AzureIngestFileConnectedTest.java b/src/test/java/bio/terra/service/filedata/azure/AzureIngestFileConnectedTest.java index 3825811f7b..d61a332160 100644 --- a/src/test/java/bio/terra/service/filedata/azure/AzureIngestFileConnectedTest.java +++ b/src/test/java/bio/terra/service/filedata/azure/AzureIngestFileConnectedTest.java @@ -55,6 +55,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; @@ -86,7 +87,7 @@ public class AzureIngestFileConnectedTest { private FileLoadModel fileLoadModel; private TableServiceClient tableServiceClient; - @Autowired private AzureResourceConfiguration azureResourceConfiguration; + @SpyBean private AzureResourceConfiguration azureResourceConfiguration; @Autowired AzureSynapsePdao azureSynapsePdao; @Autowired ConnectedOperations connectedOperations; @Autowired private ConnectedTestConfiguration testConfig; @@ -107,8 +108,8 @@ public void setup() throws Exception { UUID storageAccountId = UUID.randomUUID(); datasetId = UUID.randomUUID(); - homeTenantId = azureResourceConfiguration.getCredentials().getHomeTenantId(); - azureResourceConfiguration.getCredentials().setHomeTenantId(testConfig.getTargetTenantId()); + AzureResourceConfiguration.Credentials credentials = azureResourceConfiguration.credentials(); + credentials.setHomeTenantId(testConfig.getTargetTenantId()); billingProfile = new BillingProfileModel() @@ -177,7 +178,6 @@ public void cleanup() throws Exception { } catch (Exception ex) { logger.error("Unable to clean up metadata for fileId {}", fileId, ex); } - azureResourceConfiguration.getCredentials().setHomeTenantId(homeTenantId); connectedOperations.teardown(); } diff --git a/src/test/java/bio/terra/service/filedata/azure/blobstore/AzureBlobStorePdaoTest.java b/src/test/java/bio/terra/service/filedata/azure/blobstore/AzureBlobStorePdaoTest.java index e11153315a..4c123f32ac 100644 --- a/src/test/java/bio/terra/service/filedata/azure/blobstore/AzureBlobStorePdaoTest.java +++ b/src/test/java/bio/terra/service/filedata/azure/blobstore/AzureBlobStorePdaoTest.java @@ -142,8 +142,8 @@ public void setUp() { dataset = new Dataset().id(DATASET_ID); when(profileDao.getBillingProfileById(PROFILE_ID)).thenReturn(BILLING_PROFILE); when(resourceConfiguration.getAppToken(TENANT_ID)).thenReturn(targetCredential); - when(resourceConfiguration.getMaxRetries()).thenReturn(3); - when(resourceConfiguration.getRetryTimeoutSeconds()).thenReturn(60); + when(resourceConfiguration.maxRetries()).thenReturn(3); + when(resourceConfiguration.retryTimeoutSeconds()).thenReturn(60); when(azureResourceDao.retrieveStorageAccountById(RESOURCE_ID)) .thenReturn(AZURE_STORAGE_ACCOUNT_RESOURCE); targetBlobContainerFactory = mock(BlobContainerClientFactory.class); diff --git a/src/test/java/bio/terra/service/filedata/azure/util/BlobContainerClientFactoryTest.java b/src/test/java/bio/terra/service/filedata/azure/util/BlobContainerClientFactoryTest.java index 3db480dfeb..bbe6a7a0f4 100644 --- a/src/test/java/bio/terra/service/filedata/azure/util/BlobContainerClientFactoryTest.java +++ b/src/test/java/bio/terra/service/filedata/azure/util/BlobContainerClientFactoryTest.java @@ -58,8 +58,8 @@ public void setUp() { retryOptions = new RequestRetryOptions( RetryPolicyType.EXPONENTIAL, - azureResourceConfiguration.getMaxRetries(), - azureResourceConfiguration.getRetryTimeoutSeconds(), + azureResourceConfiguration.maxRetries(), + azureResourceConfiguration.retryTimeoutSeconds(), null, null, null); diff --git a/src/test/java/bio/terra/service/filedata/azure/util/BlobContainerCopierTest.java b/src/test/java/bio/terra/service/filedata/azure/util/BlobContainerCopierTest.java index 229e918091..38730dce9f 100644 --- a/src/test/java/bio/terra/service/filedata/azure/util/BlobContainerCopierTest.java +++ b/src/test/java/bio/terra/service/filedata/azure/util/BlobContainerCopierTest.java @@ -64,8 +64,8 @@ public void setUp() { retryOptions = new RequestRetryOptions( RetryPolicyType.EXPONENTIAL, - azureResourceConfiguration.getMaxRetries(), - azureResourceConfiguration.getRetryTimeoutSeconds(), + azureResourceConfiguration.maxRetries(), + azureResourceConfiguration.retryTimeoutSeconds(), null, null, null); diff --git a/src/test/java/bio/terra/service/filedata/azure/util/BlobCrlTest.java b/src/test/java/bio/terra/service/filedata/azure/util/BlobCrlTest.java index 86aa9fcc6b..4274c7bd1a 100644 --- a/src/test/java/bio/terra/service/filedata/azure/util/BlobCrlTest.java +++ b/src/test/java/bio/terra/service/filedata/azure/util/BlobCrlTest.java @@ -58,8 +58,8 @@ public void setUp() throws Exception { RequestRetryOptions retryOptions = new RequestRetryOptions( RetryPolicyType.EXPONENTIAL, - azureResourceConfiguration.getMaxRetries(), - azureResourceConfiguration.getRetryTimeoutSeconds(), + azureResourceConfiguration.maxRetries(), + azureResourceConfiguration.retryTimeoutSeconds(), null, null, null); diff --git a/src/test/java/bio/terra/service/filedata/azure/util/SasUrlFactoriesTest.java b/src/test/java/bio/terra/service/filedata/azure/util/SasUrlFactoriesTest.java index ed96bf27d9..9afd324756 100644 --- a/src/test/java/bio/terra/service/filedata/azure/util/SasUrlFactoriesTest.java +++ b/src/test/java/bio/terra/service/filedata/azure/util/SasUrlFactoriesTest.java @@ -56,8 +56,8 @@ public void setUp() { RequestRetryOptions retryOptions = new RequestRetryOptions( RetryPolicyType.EXPONENTIAL, - azureResourceConfiguration.getMaxRetries(), - azureResourceConfiguration.getRetryTimeoutSeconds(), + azureResourceConfiguration.maxRetries(), + azureResourceConfiguration.retryTimeoutSeconds(), null, null, null); diff --git a/src/test/java/bio/terra/service/filedata/google/firestore/BatchOperationTest.java b/src/test/java/bio/terra/service/filedata/google/firestore/BatchOperationTest.java index de1b116145..651427372a 100644 --- a/src/test/java/bio/terra/service/filedata/google/firestore/BatchOperationTest.java +++ b/src/test/java/bio/terra/service/filedata/google/firestore/BatchOperationTest.java @@ -37,8 +37,9 @@ public class BatchOperationTest { @Before public void setup() { - GoogleResourceConfiguration resourceConfiguration = new GoogleResourceConfiguration(); - resourceConfiguration.setFirestoreRetries(4); + // Use fewer firestoreRetries for testing + GoogleResourceConfiguration resourceConfiguration = + new GoogleResourceConfiguration("jade-data-repo", 600, 4, false, "123456"); ConfigurationService configurationService = new ConfigurationService( samConfiguration, gcsConfiguration, resourceConfiguration, appConfiguration); diff --git a/src/test/java/bio/terra/service/policy/PolicyServiceTest.java b/src/test/java/bio/terra/service/policy/PolicyServiceTest.java index e8fd7ff415..db61256c61 100644 --- a/src/test/java/bio/terra/service/policy/PolicyServiceTest.java +++ b/src/test/java/bio/terra/service/policy/PolicyServiceTest.java @@ -58,7 +58,7 @@ public void setup() throws Exception { } private void mockPolicyServiceConfiguration() { - when(policyServiceConfiguration.getEnabled()).thenReturn(true); + when(policyServiceConfiguration.enabled()).thenReturn(true); } private void mockPolicyApi() { @@ -163,7 +163,7 @@ void testStatusOk() { mockUnauthPolicyApi(); RepositoryStatusModelSystems status = policyService.status(); assertTrue(status.isOk()); - assertThat(status.isCritical(), equalTo(policyServiceConfiguration.getEnabled())); + assertThat(status.isCritical(), equalTo(policyServiceConfiguration.enabled())); assertThat(status.getMessage(), containsString("Terra Policy Service status ok")); } @@ -175,7 +175,7 @@ void testStatusNotOk() throws Exception { doThrow(exception).when(tpsUnauthApi).getStatus(); RepositoryStatusModelSystems status = policyService.status(); assertFalse(status.isOk()); - assertThat(status.isCritical(), equalTo(policyServiceConfiguration.getEnabled())); + assertThat(status.isCritical(), equalTo(policyServiceConfiguration.enabled())); assertThat(status.getMessage(), containsString(exception.getMessage())); } } diff --git a/src/test/java/bio/terra/service/profile/azure/AzureAuthzServiceTest.java b/src/test/java/bio/terra/service/profile/azure/AzureAuthzServiceTest.java index 2b3e7faed0..deef431072 100644 --- a/src/test/java/bio/terra/service/profile/azure/AzureAuthzServiceTest.java +++ b/src/test/java/bio/terra/service/profile/azure/AzureAuthzServiceTest.java @@ -49,7 +49,7 @@ public void setUp() throws Exception { .thenReturn(Map.of("parameters", Map.of(AUTH_PARAM_KEY, Map.of("value", USER_EMAIL)))); when(resourceManager.genericResources()).thenReturn(genericResources); when(resourceConfiguration.getClient(SUBSCRIPTION_ID)).thenReturn(resourceManager); - when(genericResources.getById(RESOURCE_ID, resourceConfiguration.getApiVersion())) + when(genericResources.getById(RESOURCE_ID, resourceConfiguration.apiVersion())) .thenReturn(genericResource); azureAuthzService = new AzureAuthzService(resourceConfiguration); } @@ -86,7 +86,7 @@ public void testValidateUserDoesNotHaveAccess() { @Test public void testValidateResourceNotFound() { - when(genericResources.getById(RESOURCE_ID, resourceConfiguration.getApiVersion())) + when(genericResources.getById(RESOURCE_ID, resourceConfiguration.apiVersion())) .thenThrow(ResourceManagerException.class); assertThat( diff --git a/src/test/java/bio/terra/service/rawls/RawlsServiceTest.java b/src/test/java/bio/terra/service/rawls/RawlsServiceTest.java index 3b19d7b93c..17e2f04bf2 100644 --- a/src/test/java/bio/terra/service/rawls/RawlsServiceTest.java +++ b/src/test/java/bio/terra/service/rawls/RawlsServiceTest.java @@ -64,7 +64,7 @@ public class RawlsServiceTest { public void setUp() throws Exception { rawlsService = new RawlsService(terraConfiguration, rawlsClient); - when(terraConfiguration.getBasePath()).thenReturn(BASE_PATH); + when(terraConfiguration.basePath()).thenReturn(BASE_PATH); when(rawlsClient.getWorkspace(accessibleWorkspaceId, TEST_USER)) .thenReturn(accessibleWorkspaceResponse); diff --git a/src/test/java/bio/terra/service/resourcemanagement/BufferServiceConnectedTest.java b/src/test/java/bio/terra/service/resourcemanagement/BufferServiceConnectedTest.java index 07cfe8c73d..614e56a7ce 100644 --- a/src/test/java/bio/terra/service/resourcemanagement/BufferServiceConnectedTest.java +++ b/src/test/java/bio/terra/service/resourcemanagement/BufferServiceConnectedTest.java @@ -162,7 +162,7 @@ public void testProjectRefoldering() throws Exception { assertThat( "Sensitive project was moved to the correct folder", sensitiveParent.getId(), - equalTo(googleResourceConfiguration.getSecureFolderResourceId())); + equalTo(googleResourceConfiguration.secureFolderResourceId())); } private SnapshotModel getTestSnapshot(UUID id) throws Exception { diff --git a/src/test/java/bio/terra/service/resourcemanagement/azure/AzureApplicationDeploymentServiceTest.java b/src/test/java/bio/terra/service/resourcemanagement/azure/AzureApplicationDeploymentServiceTest.java index 89de6eddb4..4d29bae790 100644 --- a/src/test/java/bio/terra/service/resourcemanagement/azure/AzureApplicationDeploymentServiceTest.java +++ b/src/test/java/bio/terra/service/resourcemanagement/azure/AzureApplicationDeploymentServiceTest.java @@ -68,7 +68,7 @@ public void testGetOrRegisterApplicationDeployment() { STORAGE_PREFIX_KEY, Map.of(PARAMETER_VALUE_KEY, "tdr"), STORAGE_TYPE_KEY, Map.of(PARAMETER_VALUE_KEY, "Standard_LRS")))); String appResourceId = MetadataDataAccessUtils.getApplicationDeploymentId(billingProfileModel); - when(genericResources.getById(appResourceId, resourceConfiguration.getApiVersion())) + when(genericResources.getById(appResourceId, resourceConfiguration.apiVersion())) .thenReturn(genericResource); when(client.genericResources()).thenReturn(genericResources); when(resourceDao.retrieveApplicationDeploymentByName( diff --git a/src/test/java/bio/terra/service/resourcemanagement/azure/AzureMonitoringServiceTest.java b/src/test/java/bio/terra/service/resourcemanagement/azure/AzureMonitoringServiceTest.java index 2f045595ab..f4b78c6c9d 100644 --- a/src/test/java/bio/terra/service/resourcemanagement/azure/AzureMonitoringServiceTest.java +++ b/src/test/java/bio/terra/service/resourcemanagement/azure/AzureMonitoringServiceTest.java @@ -256,7 +256,7 @@ void testNotificationRuleNotFound() { private void mockLogAnalyticsClient() { Credentials credentials = new Credentials(); credentials.setHomeTenantId(HOME_TENANT_ID); - when(resourceConfiguration.getCredentials()).thenReturn(credentials); + when(resourceConfiguration.credentials()).thenReturn(credentials); when(resourceConfiguration.getLogAnalyticsManagerClient(HOME_TENANT_ID, SUBSCRIPTION_ID)) .thenReturn(logAnalyticsManager); @@ -265,7 +265,7 @@ private void mockLogAnalyticsClient() { private void mockSecurityInsightsClient() { Credentials credentials = new Credentials(); credentials.setHomeTenantId(HOME_TENANT_ID); - when(resourceConfiguration.getCredentials()).thenReturn(credentials); + when(resourceConfiguration.credentials()).thenReturn(credentials); when(resourceConfiguration.getSecurityInsightsManagerClient(HOME_TENANT_ID, SUBSCRIPTION_ID)) .thenReturn(securityInsightsManager); diff --git a/src/test/java/bio/terra/service/resourcemanagement/azure/AzureResourceConfigurationTest.java b/src/test/java/bio/terra/service/resourcemanagement/azure/AzureResourceConfigurationTest.java index 53cb1ea0d9..30009e5306 100644 --- a/src/test/java/bio/terra/service/resourcemanagement/azure/AzureResourceConfigurationTest.java +++ b/src/test/java/bio/terra/service/resourcemanagement/azure/AzureResourceConfigurationTest.java @@ -171,7 +171,7 @@ public void testAbilityToDeployApplication() { () -> { AzureResourceManager clientFromHome = azureResourceConfiguration.getClient( - azureResourceConfiguration.getCredentials().getHomeTenantId(), + azureResourceConfiguration.credentials().getHomeTenantId(), profileModel.getSubscriptionId()); clientFromHome @@ -235,7 +235,7 @@ public void testAbilityToDeployApplication() { // user's subscription AzureResourceManager clientFromHome = azureResourceConfiguration.getClient( - azureResourceConfiguration.getCredentials().getHomeTenantId(), + azureResourceConfiguration.credentials().getHomeTenantId(), profileModel.getSubscriptionId()); try { @@ -372,7 +372,7 @@ private ManagedApplicationDeployment createManagedApplication( ((Map>>) client .genericResources() - .getById(resourceReference.id(), azureResourceConfiguration.getApiVersion()) + .getById(resourceReference.id(), azureResourceConfiguration.apiVersion()) .properties()) .get("outputs");