1+ import { generateUniqueId } from '@cloudgraph/sdk'
2+
13import upperFirst from 'lodash/upperFirst'
24import { RawAwsRdsDbInstance } from './data'
3- import {
4- AwsRdsDbInstance ,
5+ import {
6+ AwsRdsDbInstance , AwsRdsDbInstanceGroupOption , AwsRdsDbInstanceParameterGroup , AwsRdsDbInstanceSnapshot ,
57} from '../../types/generated'
6- import { formatTagsFromMap } from '../../utils/format'
8+ import { convertAwsTagsToTagMap , formatTagsFromMap } from '../../utils/format'
9+ import { AwsTag } from '../../types'
710
811export default ( {
912 service,
1013 account,
1114 region
12- } :
13- {
14- service : RawAwsRdsDbInstance
15- account : string
16- region : string
17- } ) : AwsRdsDbInstance => {
15+ } :
16+ {
17+ service : RawAwsRdsDbInstance
18+ account : string
19+ region : string
20+ } ) : AwsRdsDbInstance => {
1821 const {
1922 DBInstanceArn : arn ,
2023 DBInstanceIdentifier : dBInstanceIdentifier ,
@@ -42,19 +45,96 @@ export default ({
4245 Endpoint : endpoint ,
4346 LicenseModel : licenseModel ,
4447 Tags = { } ,
48+ Snapshots = [ ]
4549 } = service
4650
4751 const subnetGroup = service . DBSubnetGroup ?. DBSubnetGroupName || ''
4852
49- const parameterGroup = service . DBParameterGroups . map (
50- ( { DBParameterGroupName, ParameterApplyStatus } ) =>
51- `${ DBParameterGroupName } (${ ParameterApplyStatus } )`
52- ) . join ( ' | ' )
53+ const parameterGroups : AwsRdsDbInstanceParameterGroup [ ] = service . DBParameterGroups . map (
54+ ( parameter ) => {
55+ const { DBParameterGroupName, ParameterApplyStatus } = parameter
56+ return ( {
57+ id : generateUniqueId ( {
58+ arn,
59+ ...parameter
60+ } ) ,
61+ description : `${ DBParameterGroupName } (${ ParameterApplyStatus } )` ,
62+ name : DBParameterGroupName ,
63+ status : ParameterApplyStatus
64+ } )
65+ }
66+ )
67+
68+ const optionsGroups : AwsRdsDbInstanceGroupOption [ ] = service . OptionGroupMemberships . map (
69+ ( option ) => {
70+ const { OptionGroupName, Status } = option
71+ return ( {
72+ id : generateUniqueId ( {
73+ arn,
74+ ...option
75+ } ) ,
76+ description : `${ OptionGroupName } (${ upperFirst ( Status ) } )` ,
77+ groupName : OptionGroupName ,
78+ status : Status
79+ } )
80+ }
81+
82+ )
83+
84+ const snapshots : AwsRdsDbInstanceSnapshot [ ] = Snapshots . map (
85+ ( snapshot ) => {
86+ const tags = convertAwsTagsToTagMap ( snapshot . TagList as AwsTag [ ] )
87+ return ( {
88+ id : generateUniqueId ( {
89+ arn,
90+ ...snapshot
91+ } ) ,
92+ dBSnapshotIdentifier : snapshot . DBSnapshotIdentifier ,
93+ dBInstanceIdentifier : snapshot . DBInstanceIdentifier ,
94+ snapshotCreateTime : snapshot . SnapshotCreateTime ?. toISOString ( ) ,
95+ engine : snapshot . Engine ,
96+ allocatedStorage : snapshot . AllocatedStorage ,
97+ status : snapshot . Status ,
98+ port : snapshot . Port ,
99+ availabilityZone : snapshot . AvailabilityZone ,
100+ vpcId : snapshot . VpcId ,
101+ instanceCreateTime : snapshot . InstanceCreateTime ?. toISOString ( ) ,
102+ masterUsername : snapshot . MasterUsername ,
103+ engineVersion : snapshot . EngineVersion ,
104+ licenseModel : snapshot . LicenseModel ,
105+ snapshotType : snapshot . SnapshotType ,
106+ iops : snapshot . Iops ,
107+ optionGroupName : snapshot . OptionGroupName ,
108+ percentProgress : snapshot . PercentProgress ,
109+ sourceRegion : snapshot . SourceRegion ,
110+ sourceDBSnapshotIdentifier : snapshot . SourceDBSnapshotIdentifier ,
111+ storageType : snapshot . StorageType ,
112+ tdeCredentialArn : snapshot . TdeCredentialArn ,
113+ encrypted : snapshot . Encrypted ,
114+ kmsKeyId : snapshot . KmsKeyId ,
115+ dBSnapshotArn : snapshot . DBSnapshotArn ,
116+ timezone : snapshot . Timezone ,
117+ iAMDatabaseAuthenticationEnabled : snapshot . IAMDatabaseAuthenticationEnabled ,
118+ processorFeatures : snapshot . ProcessorFeatures ?. map ( p => ( {
119+ id : generateUniqueId ( {
120+ arn,
121+ ...p
122+ } ) ,
123+ name : p . Name ,
124+ value : p . Value
125+ } ) ) ,
126+ dbiResourceId : snapshot . DbiResourceId ,
127+ tagList : snapshot . TagList ,
128+ originalSnapshotCreateTime : snapshot . OriginalSnapshotCreateTime ?. toISOString ( ) ,
129+ snapshotDatabaseTime : snapshot . SnapshotDatabaseTime ?. toISOString ( ) ,
130+ snapshotTarget : snapshot . SnapshotTarget ,
131+ storageThroughput : snapshot . StorageThroughput ,
132+ tags : formatTagsFromMap ( tags )
133+ } )
134+ }
135+ )
136+
53137
54- const optionsGroups = service . OptionGroupMemberships . map (
55- ( { OptionGroupName, Status } ) =>
56- `${ OptionGroupName } (${ upperFirst ( Status ) } )`
57- ) . join ( ' | ' )
58138
59139 return {
60140 id : arn ,
@@ -77,7 +157,7 @@ export default ({
77157 autoMinorVersionUpgrade,
78158 iamDbAuthenticationEnabled,
79159 optionsGroups,
80- parameterGroup ,
160+ parameterGroups ,
81161 storageType,
82162 instanceClass,
83163 allocatedStorage,
@@ -91,6 +171,7 @@ export default ({
91171 kmsKey,
92172 encrypted,
93173 licenseModel,
174+ snapshots,
94175 tags : formatTagsFromMap ( Tags ) ,
95176 }
96177}
0 commit comments