Skip to content

Commit

Permalink
convert clientId to a lookup, not a map.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed Dec 25, 2024
1 parent 94d5cca commit 2905dfa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions definitions/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type SourceDefinitionOptions struct {
//Optional - filter's the endpoint id by the environment (sandbox, prod).
Env pkg.FastenLighthouseEnvType
//Optional - sets the Client ID for the SourceConfig
ClientIdLookupFn func(pkg.PlatformType, string, pkg.FastenLighthouseEnvType) map[pkg.PlatformType]string
ClientIdLookupFn func(pkg.PlatformType, string, pkg.FastenLighthouseEnvType) string

//Optional - post-Populate hook can be used to further customize the SourceDefinition
PostPopulateFn func(*models.LighthouseSourceDefinition)
Expand All @@ -51,15 +51,20 @@ func WithEnv(env pkg.FastenLighthouseEnvType) func(*SourceDefinitionOptions) {
}
}

// deprecated
func WithClientIdLookup(lookup map[pkg.PlatformType]string) func(*SourceDefinitionOptions) {
return func(o *SourceDefinitionOptions) {
o.ClientIdLookupFn = func(pkg.PlatformType, string, pkg.FastenLighthouseEnvType) map[pkg.PlatformType]string {
return lookup
o.ClientIdLookupFn = func(platformType pkg.PlatformType, endpointId string, envType pkg.FastenLighthouseEnvType) string {
if clientId, ok := lookup[platformType]; ok {
return clientId
} else {
return "" //noop
}
}
}
}

func WithClientIdLookupFn(lookup func(pkg.PlatformType, string, pkg.FastenLighthouseEnvType) map[pkg.PlatformType]string) func(*SourceDefinitionOptions) {
func WithClientIdLookupFn(lookup func(pkg.PlatformType, string, pkg.FastenLighthouseEnvType) string) func(*SourceDefinitionOptions) {
return func(o *SourceDefinitionOptions) {
o.ClientIdLookupFn = lookup
}
Expand All @@ -77,8 +82,8 @@ func GetSourceDefinition(
) (*models.LighthouseSourceDefinition, error) {

options := &SourceDefinitionOptions{
ClientIdLookupFn: func(pkg.PlatformType, string, pkg.FastenLighthouseEnvType) map[pkg.PlatformType]string {
return nil //noop
ClientIdLookupFn: func(pkg.PlatformType, string, pkg.FastenLighthouseEnvType) string {
return "" //noop
},
PostPopulateFn: func(definition *models.LighthouseSourceDefinition) {
return //noop
Expand Down
4 changes: 2 additions & 2 deletions definitions/models/lighthouse_endpoint_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type LighthouseSourceDefinition struct {
func (def *LighthouseSourceDefinition) Populate(
endpoint *catalog.PatientAccessEndpoint,
env pkg.FastenLighthouseEnvType,
clientIdLookup map[pkg.PlatformType]string,
clientId string, //should be populated via the ClientIdLookupFn
) {

//must be done first
Expand Down Expand Up @@ -116,7 +116,7 @@ func (def *LighthouseSourceDefinition) Populate(
//Common defaults. All customizations should be above this line
def.Issuer = def.Url
// retrieve client-id, if available
if clientId, clientIdOk := clientIdLookup[def.PlatformType]; clientIdOk {
if clientId != "" {
def.ClientId = clientId
}
def.RedirectUri = pkg.GetCallbackEndpoint(string(def.PlatformType))
Expand Down

0 comments on commit 2905dfa

Please sign in to comment.