| 1 | import type { Alarm } from "./Alarm.ts"; |
| 2 | import type { AlarmMuteRule } from "./AlarmMuteRule.ts"; |
| 3 | import type { CompositeAlarm } from "./CompositeAlarm.ts"; |
| 4 | import type { Dashboard } from "./Dashboard.ts"; |
| 5 | import type { InsightRule } from "./InsightRule.ts"; |
| 6 | import type { MetricStream } from "./MetricStream.ts"; |
| 7 | import { sortByLogicalId } from "./common.ts"; |
| 8 | |
| 9 | export type AlarmResource = Alarm | CompositeAlarm; |
| 10 | |
| 11 | export type InsightRuleResource = InsightRule; |
| 12 | |
| 13 | export type TaggableResource = |
| 14 | | AlarmResource |
| 15 | | Dashboard |
| 16 | | MetricStream |
| 17 | | InsightRule |
| 18 | | AlarmMuteRule; |
| 19 | |
| 20 | export const sortAlarmResources = ( |
| 21 | alarms: [AlarmResource, ...AlarmResource[]], |
| 22 | ) => sortByLogicalId(alarms) as [AlarmResource, ...AlarmResource[]]; |
| 23 | |
| 24 | export const sortInsightRuleResources = ( |
| 25 | rules: [InsightRuleResource, ...InsightRuleResource[]], |
| 26 | ) => sortByLogicalId(rules) as [InsightRuleResource, ...InsightRuleResource[]]; |
| 27 | |
| 28 | export const getTaggableResourceArn = (resource: TaggableResource) => { |
| 29 | switch (resource.Type) { |
| 30 | case "AWS.CloudWatch.Alarm": |
| 31 | case "AWS.CloudWatch.CompositeAlarm": |
| 32 | return resource.alarmArn; |
| 33 | case "AWS.CloudWatch.Dashboard": |
| 34 | return resource.dashboardArn; |
| 35 | case "AWS.CloudWatch.MetricStream": |
| 36 | return resource.metricStreamArn; |
| 37 | case "AWS.CloudWatch.InsightRule": |
| 38 | return resource.ruleArn; |
| 39 | case "AWS.CloudWatch.AlarmMuteRule": |
| 40 | return resource.alarmMuteRuleArn; |
| 41 | } |
| 42 | }; |