Add an alert banner to check for revoked licenses (#53294)

This commit is contained in:
Petri-Johan Last 2023-06-12 15:17:49 +02:00 committed by GitHub
parent e7bc41aab4
commit d56d855185
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 8 deletions

View File

@ -79,6 +79,17 @@ func Init(
return errors.Wrap(err, "Failed to createe sub-repo client")
}
graphqlbackend.AlertFuncs = append(graphqlbackend.AlertFuncs, func(args graphqlbackend.AlertFuncArgs) []*graphqlbackend.Alert {
if licensing.IsLicenseValid() {
return nil
}
return []*graphqlbackend.Alert{{
TypeValue: graphqlbackend.AlertTypeError,
MessageValue: "To continue using Sourcegraph, a site admin must renew the Sourcegraph license (or downgrade to only using Sourcegraph Free features). Update the license key in the [**site configuration**](/site-admin/configuration).",
}}
})
// Warn about usage of authz providers that are not enabled by the license.
graphqlbackend.AlertFuncs = append(graphqlbackend.AlertFuncs, func(args graphqlbackend.AlertFuncArgs) []*graphqlbackend.Alert {
// Only site admins can act on this alert, so only show it to site admins.

View File

@ -141,6 +141,11 @@ func Check(feature Feature) error {
if err != nil {
return errors.WithMessage(err, fmt.Sprintf("checking feature %q activation", feature))
}
if !IsLicenseValid() {
return errors.New("Sourcegraph license is no longer valid")
}
return feature.Check(info)
}

View File

@ -98,7 +98,7 @@ func GetConfiguredProductLicenseInfo() (*Info, error) {
return info, err
}
func isLicenseValid() bool {
func IsLicenseValid() bool {
val := store.Get(licenseValidityStoreKey)
if val.IsNil() {
return true
@ -141,10 +141,6 @@ func GetConfiguredProductLicenseInfoWithSignature() (*Info, string, error) {
return nil, "", err
}
if !isLicenseValid() {
return nil, "", errors.New("license is not valid")
}
lastKeyText = keyText
lastInfo = info
lastSignature = signature

View File

@ -24,18 +24,18 @@ func TestIsLicenseValid(t *testing.T) {
t.Run("unset key returns true", func(t *testing.T) {
cleanupStore(t, store)
require.True(t, isLicenseValid())
require.True(t, IsLicenseValid())
})
t.Run("set false key returns false", func(t *testing.T) {
cleanupStore(t, store)
require.NoError(t, store.Set(licenseValidityStoreKey, false))
require.False(t, isLicenseValid())
require.False(t, IsLicenseValid())
})
t.Run("set true key returns true", func(t *testing.T) {
cleanupStore(t, store)
require.NoError(t, store.Set(licenseValidityStoreKey, true))
require.True(t, isLicenseValid())
require.True(t, IsLicenseValid())
})
}