mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 14:51:44 +00:00
Add an alert banner to check for revoked licenses (#53294)
This commit is contained in:
parent
e7bc41aab4
commit
d56d855185
@ -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.
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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())
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user