Skip to content

Commit

Permalink
adding env and client ids into the SourceConfigOptions struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed Jan 16, 2024
1 parent 11f1135 commit 606081b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions catalog/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestCatalog_GetEndpoints_HaveKnownPlatformType_Production(t *testing.T) {
})

for _, endpointId := range endpointPlatformTypes {
_, err := definitions.GetSourceDefinition(pkg.FastenLighthouseEnvProduction, map[pkg.PlatformType]string{}, definitions.GetSourceConfigOptions{EndpointId: endpointId})
_, err := definitions.GetSourceDefinition(definitions.GetSourceConfigOptions{EndpointId: endpointId, Env: pkg.FastenLighthouseEnvProduction})
require.NoError(t, err)
}

Expand Down Expand Up @@ -131,7 +131,7 @@ func TestCatalog_GetEndpoints_HaveKnownPlatformType_Sandbox(t *testing.T) {
})

for _, endpointId := range endpointPlatformTypes {
_, err := definitions.GetSourceDefinition(pkg.FastenLighthouseEnvSandbox, map[pkg.PlatformType]string{}, definitions.GetSourceConfigOptions{EndpointId: endpointId})
_, err := definitions.GetSourceDefinition(definitions.GetSourceConfigOptions{EndpointId: endpointId, Env: pkg.FastenLighthouseEnvSandbox})
require.NoError(t, err)
}

Expand Down
3 changes: 2 additions & 1 deletion clients/internal/dynamic_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ type dynamicSourceClient struct {
func GetDynamicSourceClient(env pkg.FastenLighthouseEnvType, ctx context.Context, globalLogger logrus.FieldLogger, sourceCreds models.SourceCredential, testHttpClient ...*http.Client) (models.SourceClient, error) {

//get the endpoint definition
endpointDefinition, err := definitions.GetSourceDefinition(env, map[pkg.PlatformType]string{}, definitions.GetSourceConfigOptions{
endpointDefinition, err := definitions.GetSourceDefinition(definitions.GetSourceConfigOptions{
EndpointId: sourceCreds.GetEndpointId(),
Env: env,
})
if err != nil {
return nil, err
Expand Down
24 changes: 16 additions & 8 deletions definitions/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,24 @@ import (
var platformFs embed.FS

type GetSourceConfigOptions struct {
//One of the following is required: PlatformType or EndpointId
PlatformType pkg.PlatformType
EndpointId string

EndpointId string
//Optional - filter's the endpoint id by the environment (sandbox, prod).
Env pkg.FastenLighthouseEnvType
//Optional - sets the Client ID for the SourceConfig
ClientIdLookup map[pkg.PlatformType]string
}

func GetSourceDefinition(
env pkg.FastenLighthouseEnvType,
clientIdLookup map[pkg.PlatformType]string,
options GetSourceConfigOptions,
) (*models.LighthouseSourceDefinition, error) {

if len(options.PlatformType) > 0 {
//only manual and fasten can be retrieved directly, all other Endpoint configs are retrieved via the catalog (endpointId -> platformType -> platformDefinition)
if options.PlatformType == pkg.PlatformTypeManual || options.PlatformType == pkg.PlatformTypeFasten {
platformDefinition, err := getPlatformDefinition(options.PlatformType, env, clientIdLookup)
platformDefinition, err := getPlatformDefinition(options.PlatformType)
if err != nil {
return nil, fmt.Errorf("error retrieving platform definition (%s): %w", options.PlatformType, err)
}
Expand All @@ -43,7 +46,12 @@ func GetSourceDefinition(
return nil, fmt.Errorf("unsupported platform type: %s", options.PlatformType)
}
} else if len(options.EndpointId) > 0 {
endpointLookup, err := catalog.GetEndpoints(&modelsCatalog.CatalogQueryOptions{Id: options.EndpointId, LighthouseEnvType: env})
queryOpts := &modelsCatalog.CatalogQueryOptions{Id: options.EndpointId}
if len(options.Env) > 0 {
queryOpts.LighthouseEnvType = options.Env
}

endpointLookup, err := catalog.GetEndpoints(queryOpts)
if err != nil {
return nil, fmt.Errorf("error retrieving endpoint (%s): %w", options.EndpointId, err)
}
Expand All @@ -56,13 +64,13 @@ func GetSourceDefinition(
//this is the platform that we need to use as the base class.
platformType := endpoint.GetPlatformType()

platformDefinition, err := getPlatformDefinition(platformType, env, clientIdLookup)
platformDefinition, err := getPlatformDefinition(platformType)
if err != nil {
return nil, fmt.Errorf("error retrieving platform definition (%s): %w", platformType, err)
}
//TODO: merge endpoint data into platform definition

platformDefinition.Populate(&endpoint, env, clientIdLookup)
platformDefinition.Populate(&endpoint, options.Env, options.ClientIdLookup)

return platformDefinition, err
} else {
Expand All @@ -71,7 +79,7 @@ func GetSourceDefinition(

}

func getPlatformDefinition(platformType pkg.PlatformType, env pkg.FastenLighthouseEnvType, clientIdLookup map[pkg.PlatformType]string) (*models.LighthouseSourceDefinition, error) {
func getPlatformDefinition(platformType pkg.PlatformType) (*models.LighthouseSourceDefinition, error) {

if platformType == pkg.PlatformTypeManual {
return &models.LighthouseSourceDefinition{PatientAccessEndpoint: &modelsCatalog.PatientAccessEndpoint{PlatformType: string(pkg.PlatformTypeManual)}}, nil
Expand Down
2 changes: 1 addition & 1 deletion definitions/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestGetPlatformDefinition(t *testing.T) {

//test
for _, platformType := range platformTypes {
_, err := getPlatformDefinition(platformType, pkg.FastenLighthouseEnvSandbox, map[pkg.PlatformType]string{})
_, err := getPlatformDefinition(platformType)
//assert
require.NoError(t, err)

Expand Down

0 comments on commit 606081b

Please sign in to comment.