Make EnableLegacyExtensions a non-pointer (#43653)

This simplifies the code a little, and removes one potentially dangerous pointer destructure in jscontext.go.
This commit is contained in:
Erik Seliger 2022-10-31 17:35:49 +01:00 committed by GitHub
parent 69def480a8
commit d08215bbae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 9 additions and 19 deletions

View File

@ -190,7 +190,6 @@ func canUpdateSiteConfiguration() bool {
return os.Getenv("SITE_CONFIG_FILE") == "" || siteConfigAllowEdits
}
func (r *siteResolver) EnableLegacyExtensions(ctx context.Context) bool {
c := conf.Get()
return *c.ExperimentalFeatures.EnableLegacyExtensions
func (r *siteResolver) EnableLegacyExtensions() bool {
return conf.ExperimentalFeatures().EnableLegacyExtensions
}

View File

@ -247,7 +247,7 @@ func NewJSContextFromRequest(req *http.Request, db database.DB) JSContext {
ExperimentalFeatures: conf.ExperimentalFeatures(),
EnableLegacyExtensions: *conf.ExperimentalFeatures().EnableLegacyExtensions,
EnableLegacyExtensions: conf.ExperimentalFeatures().EnableLegacyExtensions,
LicenseInfo: licenseInfo,
}

View File

@ -5,8 +5,7 @@ import (
)
func ShouldRedirectLegacyExtensionEndpoints() bool {
cfg := conf.Get()
if cfg.ExperimentalFeatures != nil && cfg.ExperimentalFeatures.EnableLegacyExtensions != nil && *cfg.ExperimentalFeatures.EnableLegacyExtensions == true {
if conf.ExperimentalFeatures().EnableLegacyExtensions {
return false
}
return true

View File

@ -68,10 +68,9 @@ func TestLegacyExtensionsRedirectsWithExtensionsEnabled(t *testing.T) {
}
func enableLegacyExtensions() {
enableLegacyExtensionsVar := true
conf.Mock(&conf.Unified{SiteConfiguration: schema.SiteConfiguration{
ExperimentalFeatures: &schema.ExperimentalFeatures{
EnableLegacyExtensions: &enableLegacyExtensionsVar,
EnableLegacyExtensions: true,
},
}})
}

View File

@ -226,10 +226,9 @@ func strptrptr(s string) **string {
}
func enableLegacyExtensions() {
enableLegacyExtensionsVar := true
conf.Mock(&conf.Unified{SiteConfiguration: schema.SiteConfiguration{
ExperimentalFeatures: &schema.ExperimentalFeatures{
EnableLegacyExtensions: &enableLegacyExtensionsVar,
EnableLegacyExtensions: true,
},
}})
}

View File

@ -84,8 +84,7 @@ func ExtensionRegistryListAllowedExtensions() map[string]bool {
}
func ExtensionRegistryWriteEnabled() error {
cfg := conf.Get()
if cfg.ExperimentalFeatures == nil || cfg.ExperimentalFeatures.EnableLegacyExtensions == nil || *cfg.ExperimentalFeatures.EnableLegacyExtensions == false {
if !conf.ExperimentalFeatures().EnableLegacyExtensions {
return errors.Errorf("Extensions are disabled. See https://docs.sourcegraph.com/extensions/deprecation")
}

View File

@ -20,10 +20,6 @@ func parseConfigData(data string, cfg any) error {
if v.ExperimentalFeatures == nil {
v.ExperimentalFeatures = &schema.ExperimentalFeatures{}
}
if v.ExperimentalFeatures.EnableLegacyExtensions == nil {
v.ExperimentalFeatures.EnableLegacyExtensions = func() *bool { b := false; return &b }()
}
}
return nil
}

View File

@ -620,7 +620,7 @@ type ExperimentalFeatures struct {
// EnableGithubInternalRepoVisibility description: Enable support for visilibity of internal Github repositories
EnableGithubInternalRepoVisibility bool `json:"enableGithubInternalRepoVisibility,omitempty"`
// EnableLegacyExtensions description: Enable the extension registry and the use of extensions (doesn't affect code intel and git extras).
EnableLegacyExtensions *bool `json:"enableLegacyExtensions,omitempty"`
EnableLegacyExtensions bool `json:"enableLegacyExtensions,omitempty"`
// EnablePermissionsWebhooks description: Enables webhook consumers to sync permissions from external services faster than the defaults schedule
EnablePermissionsWebhooks bool `json:"enablePermissionsWebhooks,omitempty"`
// EnablePostSignupFlow description: Enables post sign-up user flow to add code hosts and sync code

View File

@ -545,8 +545,7 @@
"enableLegacyExtensions": {
"description": "Enable the extension registry and the use of extensions (doesn't affect code intel and git extras).",
"type": "boolean",
"default": false,
"!go": { "pointer": true }
"default": false
},
"insightsAlternateLoadingStrategy": {
"description": "Use an in-memory strategy of loading Code Insights. Should only be used for benchmarking on large instances, not for customer use currently.",