Do not read AWS credentials from container-data
@@ -11,19 +11,26 @@ import com.yahoo.slime.Slime;
import com.yahoo.slime.SlimeUtils;
import java.io.IOException;
+import java.io.UncheckedIOException;
import java.nio.file.Files;
+import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.concurrent.atomic.AtomicReference;
public class VespaAwsCredentialsProvider implements AWSCredentialsProvider {
- private static final String DEFAULT_CREDENTIALS_PATH = "/opt/vespa/var/container-data/opt/vespa/conf/vespa/credentials.json";
+ private static final String DEFAULT_CREDENTIALS_PATH = "/opt/vespa/var/vespa/aws/credentials.json";
+ // TODO (freva): Remove when host-admin writes to the new path above
+ private static final String DEFAULT_CREDENTIALS_PATH_OLD = "/opt/vespa/var/container-data/opt/vespa/conf/vespa/credentials.json";
private final AtomicReference<AWSCredentials> credentials = new AtomicReference<>();
private final Path credentialsPath;
+ private final Path credentialsPathOld;
+
public VespaAwsCredentialsProvider() {
this.credentialsPath = Path.of(DEFAULT_CREDENTIALS_PATH);
+ this.credentialsPathOld = Path.of(DEFAULT_CREDENTIALS_PATH_OLD);
refresh();
}
@@ -43,14 +50,19 @@ public class VespaAwsCredentialsProvider implements AWSCredentialsProvider {
private AWSSessionCredentials readCredentials() {
try {
- Slime slime = SlimeUtils.jsonToSlime(Files.readAllBytes(credentialsPath));
+ Slime slime;
+ try {
+ slime = SlimeUtils.jsonToSlime(Files.readAllBytes(credentialsPath));
+ } catch (NoSuchFileException ignored) {
+ slime = SlimeUtils.jsonToSlime(Files.readAllBytes(credentialsPathOld));
+ }
Cursor cursor = slime.get();
String accessKey = cursor.field("awsAccessKey").asString();
String secretKey = cursor.field("awsSecretKey").asString();
String sessionToken = cursor.field("sessionToken").asString();
return new BasicSessionCredentials(accessKey, secretKey, sessionToken);
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new UncheckedIOException(e);
}
}
}
