Skip to content

Commit 18bbc2c

Browse files
fix(amazonq): add distinctive identifier for cloud trail (aws#2059)
Co-authored-by: invictus <[email protected]>
1 parent 8390f66 commit 18bbc2c

File tree

1 file changed

+37
-0
lines changed
  • server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools

1 file changed

+37
-0
lines changed

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/executeBash.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,12 @@ export class ExecuteBash {
134134
private readonly workspace: Features['workspace']
135135
private readonly telemetry: Features['telemetry']
136136
private readonly credentialsProvider: Features['credentialsProvider']
137+
private readonly features: Pick<Features, 'logging' | 'workspace' | 'telemetry' | 'credentialsProvider'> &
138+
Partial<Features>
137139
constructor(
138140
features: Pick<Features, 'logging' | 'workspace' | 'telemetry' | 'credentialsProvider'> & Partial<Features>
139141
) {
142+
this.features = features
140143
this.logging = features.logging
141144
this.workspace = features.workspace
142145
this.telemetry = features.telemetry
@@ -507,9 +510,43 @@ export class ExecuteBash {
507510
}
508511
}
509512

513+
// Set up environment variables with AWS CLI identifier for CloudTrail auditability
514+
const env = { ...process.env }
515+
516+
// Add Q Developer IDE identifier for AWS CLI commands
517+
// Check if command contains 'aws ' anywhere (handles multi-command scenarios)
518+
if (params.command.includes('aws ')) {
519+
let extensionVersion = 'unknown'
520+
try {
521+
const clientInfo = this.features?.lsp?.getClientInitializeParams()?.clientInfo
522+
const initOptions = this.features?.lsp?.getClientInitializeParams()?.initializationOptions
523+
extensionVersion =
524+
initOptions?.aws?.clientInfo?.extension?.version || clientInfo?.version || 'unknown'
525+
} catch {
526+
extensionVersion = 'unknown'
527+
}
528+
const userAgentMetadata = `AmazonQ-For-IDE Version/${extensionVersion}`
529+
this.logging.info(
530+
`AWS command detected: ${params.command}, setting AWS_EXECUTION_ENV to: ${userAgentMetadata}`
531+
)
532+
533+
if (env.AWS_EXECUTION_ENV) {
534+
env.AWS_EXECUTION_ENV = env.AWS_EXECUTION_ENV.trim()
535+
? `${env.AWS_EXECUTION_ENV} ${userAgentMetadata}`
536+
: userAgentMetadata
537+
} else {
538+
env.AWS_EXECUTION_ENV = userAgentMetadata
539+
}
540+
541+
this.logging.info(`Final AWS_EXECUTION_ENV value: ${env.AWS_EXECUTION_ENV}`)
542+
} else {
543+
this.logging.debug(`Non-AWS command: ${params.command}`)
544+
}
545+
510546
const childProcessOptions: ChildProcessOptions = {
511547
spawnOptions: {
512548
cwd: params.cwd,
549+
env,
513550
stdio: ['pipe', 'pipe', 'pipe'],
514551
windowsVerbatimArguments: IS_WINDOWS_PLATFORM, // if true, then arguments are passed exactly as provided. no quoting or escaping is done.
515552
},

0 commit comments

Comments
 (0)