Skip to content

Commit

Permalink
Merge pull request #3078 from redpanda-data/license-package
Browse files Browse the repository at this point in the history
Add public license package
  • Loading branch information
Jeffail authored Dec 13, 2024
2 parents 0fbfee2 + 882edec commit a495eb0
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.

## 4.44.0 - TBD

### Added

- Go API: New `public/license` package added to allow custom programmatic instantiations of Redpanda Connect to run enterprise license components. (@Jeffail)

### Fixed

- `gcp_bigquery` output with parquet format no longer returns errors incorrectly. (@rockwotj)
Expand Down
28 changes: 28 additions & 0 deletions internal/license/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,34 @@ func InjectTestService(res *service.Resources) {
setSharedService(res, s)
}

// 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 {
s := &Service{
logger: res.Logger(),
loadedLicense: &atomic.Pointer[RedpandaLicense]{},
}

license, err := s.validateLicense(licenseBytes)
if err != nil {
return fmt.Errorf("failed to validate license: %w", err)
}

if err := license.CheckExpiry(); err != nil {
return err
}

s.logger.With(
"license_org", license.Organization,
"license_type", typeDisplayName(license.Type),
"expires_at", time.Unix(license.Expiry, 0).Format(time.RFC3339),
).Debug("Successfully loaded Redpanda license")

s.loadedLicense.Store(&license)
return nil
}

func (s *Service) readAndValidateLicense() (RedpandaLicense, error) {
licenseBytes, err := s.readLicense()
if err != nil {
Expand Down
42 changes: 42 additions & 0 deletions public/license/license.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2024 Redpanda Data, Inc.
//
// Licensed as a Redpanda Enterprise file under the Redpanda Community
// License (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// https://github.com/redpanda-data/connect/blob/main/licenses/rcl.md

package license

import (
"github.com/redpanda-data/benthos/v4/public/service"

"github.com/redpanda-data/connect/v4/internal/license"
)

// LocateLicenseOptBuilder represents options specified for a license locator.
type LocateLicenseOptBuilder struct {
c license.Config
}

// LocateLicenseOptFunc defines an option to pass through the LocateLicense
// function call in order to customize its behavior.
type LocateLicenseOptFunc func(*LocateLicenseOptBuilder)

// LocateLicense attempts to locate a Redpanda Enteprise license from the
// environment and, if successful, enriches the provided resources with
// information of this license that enterprise components may reference.
func LocateLicense(res *service.Resources, opts ...LocateLicenseOptFunc) {
optBuilder := LocateLicenseOptBuilder{}
for _, o := range opts {
o(&optBuilder)
}
license.RegisterService(res, optBuilder.c)
}

// StoreCustomLicenseBytes 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 StoreCustomLicenseBytes(res *service.Resources, licenseBytes []byte) error {
return license.InjectCustomLicenseBytes(res, licenseBytes)
}

0 comments on commit a495eb0

Please sign in to comment.