This repository has been archived by the owner on May 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
groups.go
74 lines (64 loc) · 1.85 KB
/
groups.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package identity
import (
"time"
"github.com/common-fate/common-fate/pkg/storage/keys"
"github.com/common-fate/common-fate/pkg/types"
"github.com/common-fate/ddb"
)
const INTERNAL = "internal"
type IDPGroup struct {
ID string
Name string
Description string
}
func (g IDPGroup) ToInternalGroup(source string) Group {
now := time.Now()
return Group{
ID: g.ID,
IdpID: g.ID,
Name: g.Name,
Description: g.Description,
Status: types.IdpStatusACTIVE,
CreatedAt: now,
UpdatedAt: now,
Source: source,
}
}
type Group struct {
// external id of the group
ID string `json:"id" dynamodbav:"id"`
IdpID string `json:"idpId" dynamodbav:"idpId"`
Name string `json:"name" dynamodbav:"name"`
Description string `json:"description" dynamodbav:"description"`
Status types.IdpStatus `json:"status" dynamodbav:"status"`
Users []string `json:"users" dynamodbav:"users"`
Source string `json:"source" dynamodbav:"source"`
// CreatedAt is a read-only field after the request has been created.
CreatedAt time.Time `json:"createdAt" dynamodbav:"createdAt"`
UpdatedAt time.Time `json:"updatedAt" dynamodbav:"updatedAt"`
}
func (g *Group) ToAPI() types.Group {
req := types.Group{
Name: g.Name,
Description: g.Description,
Id: g.ID,
MemberCount: len(g.Users),
Members: g.Users,
Source: g.Source,
}
if req.Members == nil {
req.Members = []string{}
}
return req
}
func (g *Group) DDBKeys() (ddb.Keys, error) {
keys := ddb.Keys{
PK: keys.Groups.PK1,
SK: keys.Groups.SK1(g.ID),
GSI1PK: keys.Groups.GSI1PK,
GSI1SK: keys.Groups.GSI1SK(string(g.Status), g.Name),
GSI2PK: keys.Groups.GSI2PK,
GSI2SK: keys.Groups.GSI2SK(g.Source, string(g.Status), g.Name),
}
return keys, nil
}