- Notifications
You must be signed in to change notification settings - Fork929
chore: support multi-org group sync with runtime configuration#14578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
99c97c2
bfddeb6
f2857c6
791a059
4326e9d
6d3ed2e
0803619
596e7b4
b9476ac
ee8e4e4
d5ff0f7
86c0f6f
2f03e18
ec8092d
d63727d
2a1769c
640e86e
c544a29
476be45
164aeac
986498d
290cfa5
c563b10
d2c247f
12685bd
bf0d4ed
f95128e
88b0ad9
6491f6a
bd23288
a390ec4
a0a1c53
a86ba83
0df7f28
7a802a9
611f1e3
7f28a53
41994d2
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package coderdtest | ||
import "github.com/google/uuid" | ||
type DeterministicUUIDGenerator struct { | ||
Named map[string]uuid.UUID | ||
} | ||
func NewDeterministicUUIDGenerator() *DeterministicUUIDGenerator { | ||
return &DeterministicUUIDGenerator{ | ||
Named: make(map[string]uuid.UUID), | ||
} | ||
} | ||
func (d *DeterministicUUIDGenerator) ID(name string) uuid.UUID { | ||
if v, ok := d.Named[name]; ok { | ||
return v | ||
} | ||
d.Named[name] = uuid.New() | ||
return d.Named[name] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2,6 +2,7 @@ package idpsync | ||
import ( | ||
"context" | ||
"encoding/json" | ||
"regexp" | ||
"github.com/golang-jwt/jwt/v4" | ||
@@ -12,6 +13,7 @@ import ( | ||
"github.com/coder/coder/v2/coderd/database" | ||
"github.com/coder/coder/v2/coderd/database/db2sdk" | ||
"github.com/coder/coder/v2/coderd/database/dbauthz" | ||
"github.com/coder/coder/v2/coderd/runtimeconfig" | ||
"github.com/coder/coder/v2/coderd/util/slice" | ||
) | ||
@@ -32,7 +34,6 @@ func (s AGPLIDPSync) ParseGroupClaims(_ context.Context, _ jwt.MapClaims) (Group | ||
}, nil | ||
} | ||
func (s AGPLIDPSync) SyncGroups(ctx context.Context, db database.Store, user database.User, params GroupParams) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Enterprise license code just handles the I put the actual | ||
// Nothing happens if sync is not enabled | ||
if !params.SyncEnabled { | ||
@@ -43,6 +44,8 @@ func (s AGPLIDPSync) SyncGroups(ctx context.Context, db database.Store, user dat | ||
ctx = dbauthz.AsSystemRestricted(ctx) | ||
db.InTx(func(tx database.Store) error { | ||
manager := runtimeconfig.NewStoreManager(tx) | ||
userGroups, err := tx.GetGroups(ctx, database.GetGroupsParams{ | ||
HasMemberID: user.ID, | ||
}) | ||
@@ -60,12 +63,12 @@ func (s AGPLIDPSync) SyncGroups(ctx context.Context, db database.Store, user dat | ||
// For each org, we need to fetch the sync settings | ||
orgSettings := make(map[uuid.UUID]GroupSyncSettings) | ||
for orgID := range userOrgs { | ||
orgResolver :=manager.Scoped(orgID.String()) | ||
settings, err := s.SyncSettings.Group.Resolve(ctx, orgResolver) | ||
if err != nil { | ||
return xerrors.Errorf("resolve group sync settings: %w", err) | ||
} | ||
orgSettings[orgID] =*settings | ||
} | ||
// collect all diffs to do 1 sql update for all orgs | ||
@@ -177,6 +180,20 @@ type GroupSyncSettings struct { | ||
AutoCreateMissingGroups bool `json:"auto_create_missing_groups"` | ||
} | ||
func (s *GroupSyncSettings) Set(v string) error { | ||
return json.Unmarshal([]byte(v), s) | ||
} | ||
func (s *GroupSyncSettings) String() string { | ||
v, err := json.Marshal(s) | ||
if err != nil { | ||
return "decode failed: " + err.Error() | ||
} | ||
return string(v) | ||
} | ||
func (s *GroupSyncSettings) Type() string { | ||
return "GroupSyncSettings" | ||
} | ||
type ExpectedGroup struct { | ||
GroupID *uuid.UUID | ||
GroupName *string | ||
Uh oh!
There was an error while loading.Please reload this page.