Skip to content

Commit

Permalink
Add set service to licensing injection
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffail committed Dec 16, 2024
1 parent 91688b9 commit d3d9c02
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion internal/license/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ func InjectTestService(res *service.Resources) {
// InjectCustomLicenseBytes attempts to parse a Redpanda Enterprise license
// from a slice of bytes and, if successful, stores it within the provided
// resources pointer for enterprise components to reference.
func InjectCustomLicenseBytes(res *service.Resources, licenseBytes []byte) error {
func InjectCustomLicenseBytes(res *service.Resources, conf Config, licenseBytes []byte) error {
s := &Service{
logger: res.Logger(),
loadedLicense: &atomic.Pointer[RedpandaLicense]{},
conf: conf,
}

license, err := s.validateLicense(licenseBytes)
Expand All @@ -128,6 +129,7 @@ func InjectCustomLicenseBytes(res *service.Resources, licenseBytes []byte) error
).Debug("Successfully loaded Redpanda license")

s.loadedLicense.Store(&license)
setSharedService(res, s)
return nil
}

Expand Down
18 changes: 18 additions & 0 deletions internal/license/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,21 @@ func TestLicenseEnterpriseNoLicense(t *testing.T) {

assert.False(t, loaded.AllowsEnterpriseFeatures())
}

func TestInjectedLicense(t *testing.T) {
key, lic := createLicense(t, RedpandaLicense{
Version: 1,
Type: 1,
Expiry: time.Now().Add(time.Hour).Unix(),
})

res := service.MockResources()
require.NoError(t, InjectCustomLicenseBytes(res, Config{
customPublicKeyPem: key,
}, []byte(lic)))

loaded, err := LoadFromResources(res)
require.NoError(t, err)

assert.True(t, loaded.AllowsEnterpriseFeatures())
}
2 changes: 1 addition & 1 deletion public/license/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ func LocateLicense(res *service.Resources, opts ...LocateLicenseOptFunc) {
// from a slice of bytes and, if successful, stores it within the provided
// resources pointer for enterprise components to reference.
func StoreCustomLicenseBytes(res *service.Resources, licenseBytes []byte) error {
return license.InjectCustomLicenseBytes(res, licenseBytes)
return license.InjectCustomLicenseBytes(res, license.Config{}, licenseBytes)
}

0 comments on commit d3d9c02

Please sign in to comment.