Skip to content

Commit 93f6309

Browse files
authored
fix: use consistent env var naming for credential providers (#146)
Use computeDefaultCredentialEnvVarName (AGENTCORE_CREDENTIAL_ prefix) instead of accessing credential.envVars which no longer exists after the schema migration. This ensures the deploy command looks for the same env var name that was set when the credential was created.
1 parent 9ab5eab commit 93f6309

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

src/cli/operations/deploy/pre-deploy-identity.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { AgentCoreProjectSpec, Credential } from '../../../schema';
33
import { getCredentialProvider } from '../../aws';
44
import { isNoCredentialsError } from '../../errors';
55
import { apiKeyProviderExists, createApiKeyProvider, setTokenVaultKmsKey } from '../identity';
6+
import { computeDefaultCredentialEnvVarName } from '../identity/create-identity';
67
import { BedrockAgentCoreControlClient } from '@aws-sdk/client-bedrock-agentcore-control';
78
import { CreateKeyCommand, KMSClient } from '@aws-sdk/client-kms';
89

@@ -119,24 +120,12 @@ async function setupTokenVaultKms(
119120
}
120121
}
121122

122-
/**
123-
* Get the environment variable name for a credential.
124-
* Uses the first envVar in the credential's envVars array, or generates a default.
125-
*/
126-
function getCredentialEnvVarName(credential: Credential): string {
127-
if (credential.envVars && credential.envVars.length > 0 && credential.envVars[0]) {
128-
return credential.envVars[0].name;
129-
}
130-
// Default naming convention
131-
return `AGENTCORE_IDENTITY_${credential.name.toUpperCase().replace(/[^A-Z0-9]/g, '_')}`;
132-
}
133-
134123
async function setupApiKeyCredentialProvider(
135124
client: BedrockAgentCoreControlClient,
136125
credential: Credential,
137126
credentials: SecureCredentials
138127
): Promise<ApiKeyProviderSetupResult> {
139-
const envVarName = getCredentialEnvVarName(credential);
128+
const envVarName = computeDefaultCredentialEnvVarName(credential.name);
140129
const apiKey = credentials.get(envVarName);
141130

142131
if (!apiKey) {
@@ -200,7 +189,7 @@ export async function getMissingCredentials(
200189

201190
for (const credential of projectSpec.credentials) {
202191
if (credential.type === 'ApiKeyCredentialProvider') {
203-
const envVarName = getCredentialEnvVarName(credential);
192+
const envVarName = computeDefaultCredentialEnvVarName(credential.name);
204193
if (!envVars[envVarName]) {
205194
missing.push({
206195
providerName: credential.name,

0 commit comments

Comments
 (0)