Skip to content

Commit

Permalink
Cleaner fallback methods
Browse files Browse the repository at this point in the history
  • Loading branch information
KONFeature committed May 29, 2024
1 parent 4c4d4c0 commit e51f696
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ponder.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const pollingConfig = {
} as const;

function getConfigOrEnv(key: string): string | undefined {
return process.env[key] ?? undefined;
return process.env[key] ?? process.env[`${key}_FALLBACK`] ?? undefined;
}

export default createConfig({
Expand Down
56 changes: 40 additions & 16 deletions sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,28 +125,52 @@ function IndexerStack({ stack }: StackContext) {
`Found container: ${containerName}: ${container.containerName}`
);

// Add all the secrets directly to the container environment
for (const secret of secrets) {
// Rebuild the SSM access pass to the secret
let ssmPath: string;
if (secret.name === "DATABASE_URL") {
ssmPath = "/indexer/sst/Secret/DATABASE_URL/value";
} else {
ssmPath = `/sst/frak-indexer/.fallback/Secret/${secret.name}/value`;
// Add a stage secret to the container
const addSecret = (secretName: string) => {
const ssmPath = `/indexer/sst/Secret/${secretName}/value`;
try {
const stringParameter =
StringParameter.fromSecureStringParameterAttributes(
stack,
`Secret${secretName}`,
{
parameterName: ssmPath,
}
);
container.addSecret(
secretName,
Secret.fromSsmParameter(stringParameter)
);
} catch {
console.error(`Failed to regular secret: ${secretName}`);
}
};

container.addSecret(
secret.name,
Secret.fromSsmParameter(
// Forced to used deprecated method here since addSecret doesn't support the new `SecretValue`
// Add a fallback secret to the container
const addFallbackSecret = (secretName: string) => {
const ssmPath = `/sst/frak-indexer/.fallback/Secret/${secretName}/value`;
try {
const stringParameter =
StringParameter.fromSecureStringParameterAttributes(
stack,
`Secret${secret.name}`,
`SecretFallback${secretName}`,
{
parameterName: ssmPath,
}
)
)
);
);
container.addSecret(
`${secretName}_FALLBACK`,
Secret.fromSsmParameter(stringParameter)
);
} catch {
console.error(`Failed to add fallback secret: ${secretName}`);
}
};

// Add all the secrets directly to the container environment
for (const secret of secrets) {
// Add the secrets
addSecret(secret.name);
addFallbackSecret(secret.name);
}
}

0 comments on commit e51f696

Please sign in to comment.