Skip to content

Commit

Permalink
[lambda][flare] Get resource tags (#955)
Browse files Browse the repository at this point in the history
Get resource tags and save in `tags.json`
  • Loading branch information
nhulston authored Jul 7, 2023
1 parent d2087ee commit fe12f41
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 13 deletions.
67 changes: 67 additions & 0 deletions src/commands/lambda/__tests__/__snapshots__/flare.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ exports[`lambda flare AWS Lambda configuration prints config when running as a d
FunctionName: 'some-function'
}
🏷 Getting Resource Tags...
[!] No resource tags were found.
💾 Saving files...
• Saved function config to mock-folder/.datadog-ci/function_config.json
Expand Down Expand Up @@ -64,6 +67,9 @@ exports[`lambda flare AWS credentials continues when getAWSCredentials() returns
FunctionName: 'some-function'
}
🏷 Getting Resource Tags...
[!] No resource tags were found.
💾 Saving files...
• Saved function config to mock-folder/.datadog-ci/function_config.json
Expand Down Expand Up @@ -96,6 +102,9 @@ exports[`lambda flare AWS credentials requests AWS credentials when none are fou
FunctionName: 'some-function'
}
🏷 Getting Resource Tags...
[!] No resource tags were found.
💾 Saving files...
• Saved function config to mock-folder/.datadog-ci/function_config.json
Expand Down Expand Up @@ -148,6 +157,13 @@ exports[`lambda flare getAllLogs throws an error when unable to get log events 1

exports[`lambda flare getAllLogs throws an error when unable to get log streams 1`] = `[Error: Unable to get log streams: Error getting log streams]`;

exports[`lambda flare getTags should return the tags when they exist 1`] = `
Object {
"Key1": "Value1",
"Key2": "Value2",
}
`;

exports[`lambda flare gets CloudWatch Logs does not get logs when --with-logs is not included 1`] = `
"
🐶 Generating Lambda flare to send your configuration to Datadog...
Expand All @@ -170,6 +186,9 @@ exports[`lambda flare gets CloudWatch Logs does not get logs when --with-logs is
FunctionName: 'some-function'
}
🏷 Getting Resource Tags...
[!] No resource tags were found.
💾 Saving files...
• Saved function config to mock-folder/.datadog-ci/function_config.json
Expand Down Expand Up @@ -202,6 +221,9 @@ exports[`lambda flare gets CloudWatch Logs gets logs, saves, and sends correctly
FunctionName: 'some-function'
}
🏷 Getting Resource Tags...
[!] No resource tags were found.
☁️ Getting CloudWatch logs...
✅ Found log streams:
Expand Down Expand Up @@ -244,6 +266,9 @@ exports[`lambda flare gets CloudWatch Logs prints error when getLogEvents throws
FunctionName: 'some-function'
}
🏷 Getting Resource Tags...
[!] No resource tags were found.
☁️ Getting CloudWatch logs...
[Error] Unable to get log events for stream Stream1: MOCK ERROR: Unable to get log events
"
Expand Down Expand Up @@ -271,6 +296,9 @@ exports[`lambda flare gets CloudWatch Logs prints error when getLogStreamNames t
FunctionName: 'some-function'
}
🏷 Getting Resource Tags...
[!] No resource tags were found.
☁️ Getting CloudWatch logs...
[Error] Unable to get log streams: MOCK ERROR: Unable to get log stream names
"
Expand Down Expand Up @@ -298,6 +326,9 @@ exports[`lambda flare gets CloudWatch Logs warns and skips getting logs when get
FunctionName: 'some-function'
}
🏷 Getting Resource Tags...
[!] No resource tags were found.
☁️ Getting CloudWatch logs...
[!] No CloudWatch log streams were found. Logs will not be retrieved or sent.
Expand Down Expand Up @@ -333,6 +364,9 @@ exports[`lambda flare gets CloudWatch Logs warns and skips log when getLogEvents
FunctionName: 'some-function'
}
🏷 Getting Resource Tags...
[!] No resource tags were found.
☁️ Getting CloudWatch logs...
✅ Found log streams:
Expand Down Expand Up @@ -398,6 +432,9 @@ exports[`lambda flare prompts for confirmation before sending does not send when
FunctionName: 'some-function'
}
🏷 Getting Resource Tags...
[!] No resource tags were found.
💾 Saving files...
• Saved function config to mock-folder/.datadog-ci/function_config.json
Expand Down Expand Up @@ -428,6 +465,9 @@ exports[`lambda flare prompts for confirmation before sending sends when user an
FunctionName: 'some-function'
}
🏷 Getting Resource Tags...
[!] No resource tags were found.
💾 Saving files...
• Saved function config to mock-folder/.datadog-ci/function_config.json
Expand Down Expand Up @@ -460,6 +500,9 @@ exports[`lambda flare send to Datadog does not send request to Datadog when a dr
FunctionName: 'some-function'
}
🏷 Getting Resource Tags...
[!] No resource tags were found.
💾 Saving files...
• Saved function config to mock-folder/.datadog-ci/function_config.json
Expand Down Expand Up @@ -491,6 +534,9 @@ exports[`lambda flare send to Datadog successfully adds zip file to FormData 1`]
FunctionName: 'some-function'
}
🏷 Getting Resource Tags...
[!] No resource tags were found.
💾 Saving files...
• Saved function config to mock-folder/.datadog-ci/function_config.json
Expand Down Expand Up @@ -523,6 +569,9 @@ exports[`lambda flare send to Datadog successfully sends request to Datadog 1`]
FunctionName: 'some-function'
}
🏷 Getting Resource Tags...
[!] No resource tags were found.
💾 Saving files...
• Saved function config to mock-folder/.datadog-ci/function_config.json
Expand Down Expand Up @@ -555,6 +604,9 @@ exports[`lambda flare validates required flags extracts region from function nam
FunctionName: 'some-function'
}
🏷 Getting Resource Tags...
[!] No resource tags were found.
💾 Saving files...
• Saved function config to mock-folder/.datadog-ci/function_config.json
Expand Down Expand Up @@ -622,6 +674,9 @@ exports[`lambda flare validates required flags runs successfully with all requir
FunctionName: 'some-function'
}
🏷 Getting Resource Tags...
[!] No resource tags were found.
💾 Saving files...
• Saved function config to mock-folder/.datadog-ci/function_config.json
Expand Down Expand Up @@ -654,6 +709,9 @@ exports[`lambda flare validates required flags uses API key ENV variable and run
FunctionName: 'some-function'
}
🏷 Getting Resource Tags...
[!] No resource tags were found.
💾 Saving files...
• Saved function config to mock-folder/.datadog-ci/function_config.json
Expand Down Expand Up @@ -686,6 +744,9 @@ exports[`lambda flare validates required flags uses API key ENV variable and run
FunctionName: 'some-function'
}
🏷 Getting Resource Tags...
[!] No resource tags were found.
💾 Saving files...
• Saved function config to mock-folder/.datadog-ci/function_config.json
Expand Down Expand Up @@ -714,6 +775,9 @@ exports[`lambda flare validates required flags uses API key ENV variable and run
FunctionName: 'some-function'
}
🏷 Getting Resource Tags...
[!] No resource tags were found.
💾 Saving files...
• Saved function config to mock-folder/.datadog-ci/function_config.json
Expand Down Expand Up @@ -746,6 +810,9 @@ exports[`lambda flare validates required flags uses region ENV variable when no
FunctionName: 'some-function'
}
🏷 Getting Resource Tags...
[!] No resource tags were found.
💾 Saving files...
• Saved function config to mock-folder/.datadog-ci/function_config.json
Expand Down
10 changes: 10 additions & 0 deletions src/commands/lambda/__tests__/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import {
ListTagsCommand,
ListTagsResponse,
GetLayerVersionCommandInput,
ServiceInputTypes,
ServiceOutputTypes,
ListTagsCommandOutput,
} from '@aws-sdk/client-lambda'
import {AwsStub} from 'aws-sdk-client-mock'
import {Cli, Command} from 'clipanion/lib/advanced'
Expand Down Expand Up @@ -195,6 +198,13 @@ export const mockCloudWatchLogEvents = (
cloudWatchLogsClientMock.on(GetLogEventsCommand).resolves({events})
}

export const mockResourceTags = (
lambdaClientMock: AwsStub<ServiceInputTypes, ServiceOutputTypes>,
output: ListTagsCommandOutput
) => {
lambdaClientMock.on(ListTagsCommand).resolves(output)
}

export const mockAwsAccount = '123456789012'
export const mockAwsAccessKeyId = 'M0CKAWS4CC3SSK3Y1DSL'
export const mockAwsSecretAccessKey = 'M0CKAWSs3cR3T4cC3SSK3YS3rv3rL3SSD4tad0g0'
Expand Down
Loading

0 comments on commit fe12f41

Please sign in to comment.