/
get_rule_current.go
37 lines (32 loc) · 1.12 KB
/
get_rule_current.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package storage
import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
"github.com/common-fate/common-fate/pkg/rule"
"github.com/common-fate/common-fate/pkg/storage/keys"
"github.com/common-fate/ddb"
)
type GetAccessRuleCurrent struct {
ID string
Result *rule.AccessRule
}
func (g *GetAccessRuleCurrent) BuildQuery() (*dynamodb.QueryInput, error) {
qi := &dynamodb.QueryInput{
Limit: aws.Int32(1),
KeyConditionExpression: aws.String("GSI2PK = :pk AND GSI2SK = :sk"),
IndexName: &keys.IndexNames.GSI2,
ExpressionAttributeValues: map[string]types.AttributeValue{
":pk": &types.AttributeValueMemberS{Value: keys.AccessRule.GSI2PK},
":sk": &types.AttributeValueMemberS{Value: keys.AccessRule.GSI2SK(g.ID)},
},
}
return qi, nil
}
func (g *GetAccessRuleCurrent) UnmarshalQueryOutput(out *dynamodb.QueryOutput) error {
if len(out.Items) != 1 {
return ddb.ErrNoItems
}
return attributevalue.UnmarshalMap(out.Items[0], &g.Result)
}