@@ -2,6 +2,7 @@ package idpsync
2
2
3
3
import (
4
4
"context"
5
+ "encoding/json"
5
6
"regexp"
6
7
7
8
"github.com/golang-jwt/jwt/v4"
@@ -12,6 +13,7 @@ import (
12
13
"github.com/coder/coder/v2/coderd/database"
13
14
"github.com/coder/coder/v2/coderd/database/db2sdk"
14
15
"github.com/coder/coder/v2/coderd/database/dbauthz"
16
+ "github.com/coder/coder/v2/coderd/runtimeconfig"
15
17
"github.com/coder/coder/v2/coderd/util/slice"
16
18
)
17
19
@@ -32,7 +34,6 @@ func (s AGPLIDPSync) ParseGroupClaims(_ context.Context, _ jwt.MapClaims) (Group
32
34
}, nil
33
35
}
34
36
35
- // TODO: Group allowlist behavior should probably happen at this step.
36
37
func (s AGPLIDPSync ) SyncGroups (ctx context.Context , db database.Store , user database.User , params GroupParams ) error {
37
38
// Nothing happens if sync is not enabled
38
39
if ! params .SyncEnabled {
@@ -43,6 +44,8 @@ func (s AGPLIDPSync) SyncGroups(ctx context.Context, db database.Store, user dat
43
44
ctx = dbauthz .AsSystemRestricted (ctx )
44
45
45
46
db .InTx (func (tx database.Store ) error {
47
+ manager := runtimeconfig .NewStoreManager (tx )
48
+
46
49
userGroups , err := tx .GetGroups (ctx , database.GetGroupsParams {
47
50
HasMemberID : user .ID ,
48
51
})
@@ -60,12 +63,12 @@ func (s AGPLIDPSync) SyncGroups(ctx context.Context, db database.Store, user dat
60
63
// For each org, we need to fetch the sync settings
61
64
orgSettings := make (map [uuid.UUID ]GroupSyncSettings )
62
65
for orgID := range userOrgs {
63
- orgResolver := s . Manager .Scoped (orgID .String ())
66
+ orgResolver := manager .Scoped (orgID .String ())
64
67
settings , err := s .SyncSettings .Group .Resolve (ctx , orgResolver )
65
68
if err != nil {
66
69
return xerrors .Errorf ("resolve group sync settings: %w" , err )
67
70
}
68
- orgSettings [orgID ] = settings . Value
71
+ orgSettings [orgID ] = * settings
69
72
}
70
73
71
74
// collect all diffs to do 1 sql update for all orgs
@@ -177,6 +180,20 @@ type GroupSyncSettings struct {
177
180
AutoCreateMissingGroups bool `json:"auto_create_missing_groups"`
178
181
}
179
182
183
+ func (s * GroupSyncSettings ) Set (v string ) error {
184
+ return json .Unmarshal ([]byte (v ), s )
185
+ }
186
+ func (s * GroupSyncSettings ) String () string {
187
+ v , err := json .Marshal (s )
188
+ if err != nil {
189
+ return "decode failed: " + err .Error ()
190
+ }
191
+ return string (v )
192
+ }
193
+ func (s * GroupSyncSettings ) Type () string {
194
+ return "GroupSyncSettings"
195
+ }
196
+
180
197
type ExpectedGroup struct {
181
198
GroupID * uuid.UUID
182
199
GroupName * string
0 commit comments