This repository has been archived by the owner on Jun 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 107
/
SsmConfigProvider.java
41 lines (34 loc) · 1.35 KB
/
SsmConfigProvider.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.amazonaws.serverless.apprepo.container.config;
import java.time.Duration;
import lombok.RequiredArgsConstructor;
import software.amazon.awssdk.services.ssm.model.ParameterNotFoundException;
import software.amazon.serverless.ssmcachingclient.SsmParameterCachingClient;
/**
* Provide config value from AWS SSM.
*/
@RequiredArgsConstructor
public class SsmConfigProvider implements ConfigProvider {
private static final Duration DEFAULT_PAGINATION_TOKEN_TTL = Duration.ofHours(1);
private static final String APPLICATIONS_TABLE_NAME_CONFIG_KEY = "ddb/Applications/TableName";
private static final String KMS_KEY_ID_CONFIG_KEY = "kms/pagination/KeyId";
private static final String PAGINATION_TOKEN_TTL_IN_SECONDS_CONFIG_KEY =
"configuration/pagination/TtlInSeconds";
private final SsmParameterCachingClient ssm;
@Override
public String getApplicationsTableName() {
return ssm.getAsString(APPLICATIONS_TABLE_NAME_CONFIG_KEY);
}
@Override
public String getKmsKeyId() {
return ssm.getAsString(KMS_KEY_ID_CONFIG_KEY);
}
@Override
public Duration getPaginationTokenTtl() {
try {
String ttlString = ssm.getAsString(PAGINATION_TOKEN_TTL_IN_SECONDS_CONFIG_KEY);
return Duration.ofSeconds(Long.parseLong(ttlString));
} catch (ParameterNotFoundException e) {
return DEFAULT_PAGINATION_TOKEN_TTL;
}
}
}