mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
Moves the configuration from environment to database backed, to allow configuring organization sync at runtime.
41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package enidpsync
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/golang-jwt/jwt/v4"
|
|
|
|
"github.com/coder/coder/v2/coderd/database"
|
|
"github.com/coder/coder/v2/coderd/idpsync"
|
|
"github.com/coder/coder/v2/codersdk"
|
|
)
|
|
|
|
func (e EnterpriseIDPSync) OrganizationSyncEntitled() bool {
|
|
return e.entitlements.Enabled(codersdk.FeatureMultipleOrganizations)
|
|
}
|
|
|
|
func (e EnterpriseIDPSync) OrganizationSyncEnabled(ctx context.Context, db database.Store) bool {
|
|
if !e.OrganizationSyncEntitled() {
|
|
return false
|
|
}
|
|
|
|
settings, err := e.OrganizationSyncSettings(ctx, db)
|
|
if err == nil && settings.Field != "" {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (e EnterpriseIDPSync) ParseOrganizationClaims(ctx context.Context, mergedClaims jwt.MapClaims) (idpsync.OrganizationParams, *idpsync.HTTPError) {
|
|
if !e.OrganizationSyncEntitled() {
|
|
// Default to agpl if multi-org is not enabled
|
|
return e.AGPLIDPSync.ParseOrganizationClaims(ctx, mergedClaims)
|
|
}
|
|
|
|
return idpsync.OrganizationParams{
|
|
// Return true if entitled
|
|
SyncEntitled: true,
|
|
MergedClaims: mergedClaims,
|
|
}, nil
|
|
}
|