Allow build-time redefining activation URL for selfhosted licenses

This commit is contained in:
Taras Kushnir
2025-11-11 09:56:35 +02:00
parent a016ef1a2b
commit 3eb08538df
2 changed files with 11 additions and 3 deletions

View File

@@ -2,9 +2,11 @@ services:
server:
build:
args:
GO_LDFLAGS: '-s -w -X github.com/PrivateCaptcha/PrivateCaptcha/pkg/maintenance.LicenseURL=http://host.docker.internal:8181/selfhosted/activation'
EXTRA_BUILD_FLAGS: '-tags enterprise'
migration:
build:
args:
GO_LDFLAGS: '-s -w -X github.com/PrivateCaptcha/PrivateCaptcha/pkg/maintenance.LicenseURL=http://host.docker.internal:8181/selfhosted/activation'
EXTRA_BUILD_FLAGS: '-tags enterprise'

View File

@@ -36,7 +36,7 @@ const (
var (
// NOTE: for testing, replace with host.docker.internal domain
licenseURL = fmt.Sprintf("https://api.privatecaptcha.com/%s/%s", common.SelfHostedEndpoint, common.ActivationEndpoint)
LicenseURL string
errLicenseRequest = errors.New("license request error")
errLicenseServer = errors.New("license server error")
errEnterpriseConfigError = errors.New("enterprise config error")
@@ -44,6 +44,12 @@ var (
errNoMacAddress = errors.New("mac address not found")
)
func init() {
if LicenseURL == "" {
LicenseURL = fmt.Sprintf("https://api.privatecaptcha.com/%s/%s", common.SelfHostedEndpoint, common.ActivationEndpoint)
}
}
func NewCheckLicenseJob(store db.Implementor, config common.ConfigStore, version string, quitFunc func(ctx context.Context)) (common.PeriodicJob, error) {
keys, err := license.ActivationKeys()
if err != nil {
@@ -54,14 +60,14 @@ func NewCheckLicenseJob(store db.Implementor, config common.ConfigStore, version
return nil, errNoEnterpriseKeys
}
if len(licenseURL) == 0 {
if len(LicenseURL) == 0 {
return nil, errEnterpriseConfigError
}
return &checkLicenseJob{
store: store,
keys: keys,
url: licenseURL,
url: LicenseURL,
licenseKey: config.Get(common.EnterpriseLicenseKeyKey),
adminEmail: config.Get(common.AdminEmailKey),
quitFunc: quitFunc,