@@ -6,13 +6,16 @@ import (
6
6
"github.com/aws/aws-sdk-go/aws"
7
7
"github.com/aws/aws-sdk-go/aws/session"
8
8
"github.com/aws/aws-sdk-go/service/dynamodb"
9
+ "github.com/rebuy-de/aws-nuke/pkg/types"
9
10
"github.com/sirupsen/logrus"
10
11
)
11
12
12
13
type DynamoDBTableItem struct {
13
- svc * dynamodb.DynamoDB
14
- id map [string ]* dynamodb.AttributeValue
15
- table * DynamoDBTable
14
+ svc * dynamodb.DynamoDB
15
+ id map [string ]* dynamodb.AttributeValue
16
+ table * DynamoDBTable
17
+ keyName string
18
+ keyValue string
16
19
}
17
20
18
21
func init () {
@@ -45,20 +48,13 @@ func ListDynamoDBItems(sess *session.Session) ([]Resource, error) {
45
48
return nil , descErr
46
49
}
47
50
48
- var params * dynamodb.ScanInput
49
-
50
- key := * descResp .Table .KeySchema [0 ].AttributeName
51
- // Don't use ProjectionExpression in case it is a reserved keyword,
52
- // because it creates errors otherwise.
53
- if strings .ToLower (key ) == "hash" || strings .ToLower (key ) == "path" {
54
- params = & dynamodb.ScanInput {
55
- TableName : & dynamoTable .id ,
56
- }
57
- } else {
58
- params = & dynamodb.ScanInput {
59
- TableName : & dynamoTable .id ,
60
- ProjectionExpression : aws .String (key ),
61
- }
51
+ keyName := descResp .Table .KeySchema [0 ].AttributeName
52
+ params := & dynamodb.ScanInput {
53
+ TableName : & dynamoTable .id ,
54
+ ProjectionExpression : aws .String ("#key" ),
55
+ ExpressionAttributeNames : map [string ]* string {
56
+ "#key" : keyName ,
57
+ },
62
58
}
63
59
64
60
scanResp , scanErr := svc .Scan (params )
@@ -67,10 +63,19 @@ func ListDynamoDBItems(sess *session.Session) ([]Resource, error) {
67
63
}
68
64
69
65
for _ , itemMap := range scanResp .Items {
66
+ var keyValue string
67
+
68
+ for _ , value := range itemMap {
69
+ value := strings .TrimSpace (value .String ())
70
+ keyValue = string ([]rune (value )[8 :(len ([]rune (value )) - 3 )])
71
+ }
72
+
70
73
resources = append (resources , & DynamoDBTableItem {
71
- svc : svc ,
72
- id : itemMap ,
73
- table : dynamoTable ,
74
+ svc : svc ,
75
+ id : itemMap ,
76
+ table : dynamoTable ,
77
+ keyName : aws .StringValue (keyName ),
78
+ keyValue : keyValue ,
74
79
})
75
80
}
76
81
}
@@ -92,14 +97,14 @@ func (i *DynamoDBTableItem) Remove() error {
92
97
return nil
93
98
}
94
99
95
- func (i * DynamoDBTableItem ) String () string {
96
- table := i .table .String ()
97
- var keyField string
98
-
99
- for _ , value := range i .id {
100
- value := strings .TrimSpace (value .String ())
101
- keyField = string ([]rune (value )[8 :(len ([]rune (value )) - 3 )])
102
- }
100
+ func (i * DynamoDBTableItem ) Properties () types.Properties {
101
+ properties := types .NewProperties ()
102
+ properties .Set ("Table" , i .table )
103
+ properties .Set ("KeyName" , i .keyName )
104
+ properties .Set ("KeyValue" , i .keyValue )
105
+ return properties
106
+ }
103
107
104
- return table + " -> " + keyField
108
+ func (i * DynamoDBTableItem ) String () string {
109
+ return i .table .String () + " -> " + i .keyValue
105
110
}
0 commit comments