/
get_access_token.go
37 lines (31 loc) · 1.07 KB
/
get_access_token.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/access"
"github.com/common-fate/common-fate/pkg/storage/keys"
"github.com/common-fate/ddb"
)
type GetAccessToken struct {
RequestID string
Result *access.AccessToken
}
func (g *GetAccessToken) BuildQuery() (*dynamodb.QueryInput, error) {
qi := &dynamodb.QueryInput{
Limit: aws.Int32(1),
KeyConditionExpression: aws.String("PK = :pk1 and SK = :sk1"),
ExpressionAttributeValues: map[string]types.AttributeValue{
":pk1": &types.AttributeValueMemberS{Value: keys.AccessToken.PK1},
":sk1": &types.AttributeValueMemberS{Value: keys.AccessToken.SK1(g.RequestID)},
},
}
return qi, nil
}
func (g *GetAccessToken) UnmarshalQueryOutput(out *dynamodb.QueryOutput) error {
if len(out.Items) != 1 {
return ddb.ErrNoItems
}
return attributevalue.UnmarshalMap(out.Items[0], &g.Result)
}