Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,33 @@ func defaultFuncOrganization(engine workflow.Engine, config configuration.Config
}
}

defaultOrgId, err := config.GetStringWithError(configuration.DEFAULT_ORGANIZATION)
if err != nil {
logger.Print("Failed to determine default value for \"ORGANIZATION\":", err)
}

return defaultOrgId, err
}
return callback
}

func defaultFuncDefaultOrganization(engine workflow.Engine, config configuration.Configuration, logger *zerolog.Logger, apiClientFactory func(url string, client *http.Client) api.ApiClient) configuration.DefaultValueFunction {
err := config.AddKeyDependency(configuration.DEFAULT_ORGANIZATION, configuration.API_URL)
if err != nil {
logger.Print("Failed to add dependency for ORGANIZATION:", err)
}

callback := func(_ configuration.Configuration, existingValue interface{}) (interface{}, error) {
// TODO - This function uses the outer (global) config and network access, so will not respect values set in the closures' (potentially cloned) configs.
existingString, ok := existingValue.(string)
if existingValue != nil && ok && len(existingString) > 0 {
return existingString, nil
}
Comment on lines +100 to +105
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious when do we invalidate ?
I think we should invalidate cache on token change and api endpoint


client := engine.GetNetworkAccess().GetHttpClient()
url := config.GetString(configuration.API_URL)
apiClient := apiClientFactory(url, client)

orgId, err := apiClient.GetDefaultOrgId()
if err != nil {
logger.Print("Failed to determine default value for \"ORGANIZATION\":", err)
Expand Down Expand Up @@ -294,6 +321,7 @@ func initConfiguration(engine workflow.Engine, config configuration.Configuratio

config.AddDefaultValue(configuration.ORGANIZATION, defaultFuncOrganization(engine, config, logger, apiClientFactory))
config.AddDefaultValue(configuration.ORGANIZATION_SLUG, defaultFuncOrganizationSlug(engine, config, logger, apiClientFactory))
config.AddDefaultValue(configuration.DEFAULT_ORGANIZATION, defaultFuncDefaultOrganization(engine, config, logger, apiClientFactory))

config.AddDefaultValue(configuration.FF_OAUTH_AUTH_FLOW_ENABLED, func(_ configuration.Configuration, existingValue any) (any, error) {
if existingValue == nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/configuration/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ const (
// Org related configuration
// ---------

ORGANIZATION string = "org" // ORGANIZATION (string) sets/returns the Organization ID
ORGANIZATION_SLUG string = "internal_org_slug" // ORGANIZATION_SLUG (string) returns the slug of the organization and correlates to the ORGANIZATION ID.
ORGANIZATION string = "org" // ORGANIZATION (string) sets/returns the Organization ID
ORGANIZATION_SLUG string = "internal_org_slug" // ORGANIZATION_SLUG (string) returns the slug of the organization and correlates to the ORGANIZATION ID.
DEFAULT_ORGANIZATION string = "default_org" // DEFAULT_ORGANIZATION (string) returns the default Organization ID, as specified for the user in the web UI.
Copy link
Contributor

@PeterSchafer PeterSchafer Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Is it really globally relevant to access this value? Otherwise if this is required for some sub functionality, I would recommend to register it close to the functionality. The reason I'm asking is that I'm worried users get confused between ORGANIZATION and DEFAULT_ORGANIZATION. So far DEFAULT_ORGANIZATION was not required by any extension or other GAF consumer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would also want it in LS so we can replace this awful code I wrote while under a time crunch: https://github.com/snyk/snyk-ls/blob/main/domain/ide/command/folder_handler.go#L166
I realised we only need to compare the org Id and now slug, so if I can just query the default org and compare OR have a function in GAF I can call to check if an org Id is the default org Id, then that would be great.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have a function in GAF I can call to check if an org Id is the default org Id

This sounds like great a small impact byproduct of the logic that is already available. So if we can reduce the amount of code we add and even reduce the possibility for incorrect usage, I would say it is a win for everyone.


// ---------
// URL configuration
Expand Down