MCPcopy Index your code
hub / github.com/coder/coder / applyDefaultsToConfig

Function applyDefaultsToConfig

coderd/externalauth/externalauth.go:940–982  ·  view source on GitHub ↗

applyDefaultsToConfig applies defaults to the config entry.

(config *codersdk.ExternalAuthConfig)

Source from the content-addressed store, hash-verified

938
939// applyDefaultsToConfig applies defaults to the config entry.
940func applyDefaultsToConfig(config *codersdk.ExternalAuthConfig) {
941 configType := codersdk.EnhancedExternalAuthProvider(strings.ToLower(config.Type))
942 if configType == "bitbucket" {
943 // For backwards compatibility, we need to support the "bitbucket" string.
944 configType = codersdk.EnhancedExternalAuthProviderBitBucketCloud
945 defer func() {
946 // The config type determines the config ID (if unset). So change the legacy
947 // type to the correct new type after the defaults have been configured.
948 config.Type = string(codersdk.EnhancedExternalAuthProviderBitBucketCloud)
949 }()
950 }
951 // If static defaults exist, apply them.
952 if defaults, ok := staticDefaults[configType]; ok {
953 copyDefaultSettings(config, defaults)
954 return
955 }
956
957 // Dynamic defaults
958 switch configType {
959 case codersdk.EnhancedExternalAuthProviderGitHub:
960 copyDefaultSettings(config, gitHubDefaults(config))
961 return
962 case codersdk.EnhancedExternalAuthProviderGitLab:
963 copyDefaultSettings(config, gitlabDefaults(config))
964 return
965 case codersdk.EnhancedExternalAuthProviderBitBucketServer:
966 copyDefaultSettings(config, bitbucketServerDefaults(config))
967 return
968 case codersdk.EnhancedExternalAuthProviderJFrog:
969 copyDefaultSettings(config, jfrogArtifactoryDefaults(config))
970 return
971 case codersdk.EnhancedExternalAuthProviderGitea:
972 copyDefaultSettings(config, giteaDefaults(config))
973 return
974 case codersdk.EnhancedExternalAuthProviderAzureDevopsEntra:
975 copyDefaultSettings(config, azureDevopsEntraDefaults(config))
976 return
977 default:
978 // Global defaults are specified at the end of the `copyDefaultSettings` function.
979 copyDefaultSettings(config, codersdk.ExternalAuthConfig{})
980 return
981 }
982}
983
984func copyDefaultSettings(config *codersdk.ExternalAuthConfig, defaults codersdk.ExternalAuthConfig) {
985 if config.AuthURL == "" {

Callers 4

ConvertConfigFunction · 0.85
TestGitlabDefaultsFunction · 0.85
TestUntypedFunction · 0.85

Calls 8

copyDefaultSettingsFunction · 0.85
gitHubDefaultsFunction · 0.85
gitlabDefaultsFunction · 0.85
bitbucketServerDefaultsFunction · 0.85
jfrogArtifactoryDefaultsFunction · 0.85
giteaDefaultsFunction · 0.85
azureDevopsEntraDefaultsFunction · 0.85

Tested by 3

TestGitlabDefaultsFunction · 0.68
TestUntypedFunction · 0.68