|
| 1 | +package com.softwareag.controlplane.agent.aws.configuration; |
| 2 | + |
| 3 | +import com.softwareag.controlplane.agentaws.auth.AWSCredentialsProvider; |
| 4 | +import com.softwareag.controlplane.agentaws.heartbeat.manager.impl.HeartbeatManagerImpl; |
| 5 | +import com.softwareag.controlplane.agentaws.assets.manager.impl.AssetsManagerImpl; |
| 6 | +import com.softwareag.controlplane.agentaws.metrics.manager.impl.MetricsManagerImpl; |
| 7 | +import org.springframework.beans.factory.annotation.Autowired; |
| 8 | +import org.springframework.context.annotation.Bean; |
| 9 | +import org.springframework.context.annotation.Configuration; |
| 10 | +import software.amazon.awssdk.regions.Region; |
| 11 | +import software.amazon.awssdk.services.sts.StsClient; |
| 12 | + |
| 13 | +/** |
| 14 | + * Configuration class responsible for managing AWS agent specific beans and configurations. |
| 15 | + */ |
| 16 | +@Configuration |
| 17 | +public class AWSAgentConfigManager { |
| 18 | + |
| 19 | + @Autowired |
| 20 | + private AWSProperties awsProperties; |
| 21 | + |
| 22 | + /** |
| 23 | + * Creates and provides an instance of HeartbeatManagerImpl, configured with AWS credentials and region. |
| 24 | + * |
| 25 | + * @return The configured HeartbeatManagerImpl instance. |
| 26 | + */ |
| 27 | + @Bean |
| 28 | + public HeartbeatManagerImpl heartbeatManager() { |
| 29 | + return HeartbeatManagerImpl.getInstance(awsProperties.getRegion()); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Creates and provides an instance of MetricsManagerImpl, configured with AWS credentials, region, stage, and metrics preferences. |
| 34 | + * |
| 35 | + * @return The configured MetricsManagerImpl instance. |
| 36 | + */ |
| 37 | + @Bean |
| 38 | + public MetricsManagerImpl metricsManager() { |
| 39 | + return MetricsManagerImpl.getInstance(awsProperties.getRegion(), awsProperties.getStage(), awsProperties.getMetricsByDataOrStatistics()); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Creates and provides an instance of AssetsManagerImpl, configured with AWS credentials and region. |
| 44 | + * |
| 45 | + * @return The configured AssetsManagerImpl instance. |
| 46 | + */ |
| 47 | + @Bean |
| 48 | + public AssetsManagerImpl assetsManager() { |
| 49 | + return AssetsManagerImpl.getInstance(awsProperties.getRegion()); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Creates and configures an AWS Security Token Service (STS) client for accessing AWS resources. |
| 54 | + * |
| 55 | + * @return The configured STS client. |
| 56 | + */ |
| 57 | + @Bean |
| 58 | + public StsClient stsClient() { |
| 59 | + return StsClient.builder() |
| 60 | + .region(Region.of(awsProperties.getRegion())) |
| 61 | + .credentialsProvider(AWSCredentialsProvider.getCredentialsProvider()) |
| 62 | + .build(); |
| 63 | + } |
| 64 | +} |
0 commit comments