Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions licensing/verify_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ const (
)

var (
airGappedFn = func() bool { return settings.Global().AirGapped }
verifiedAtFn = func() string { return strings.TrimSpace(settings.Global().LastLicenseVerifiedAt) }
// Peek only — never settings.Global() here. Load → honorMachinePolicy →
// AllowsMachinePolicy → commercialClaims → CommercialTrustOK would recurse.
airGappedFn = func() bool { return settings.PeekAirGapped() }
verifiedAtFn = func() string { return settings.PeekLastLicenseVerifiedAt() }
verifyAttemptAtFn = func() string {
return strings.TrimSpace(settings.Global().LastLicenseVerifyAttemptAt)
return settings.PeekLastLicenseVerifyAttemptAt()
}
putSettingFn = settings.Put
nowFn = time.Now
Expand Down
7 changes: 6 additions & 1 deletion malwaredb/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ func LicenseHeader() string {
if env := strings.TrimSpace(os.Getenv("NVM_LICENSE")); env != "" {
return strings.TrimPrefix(env, "Bearer ")
}
access := strings.TrimSpace(settings.Global().AccessToken)
// Prefer a peeked token first so malware-refresh does not force Load when
// the caller already seeded settings. Fall back to Global for cold start.
access := settings.PeekAccessToken()
if access == "" {
access = strings.TrimSpace(settings.Global().AccessToken)
}
access = strings.TrimPrefix(access, "Bearer ")
if access != "" {
return access
Expand Down
26 changes: 26 additions & 0 deletions settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ func seedLicensingFromMachineHives() {
globalSettings.AirGapped = v != 0
}
}
if raw, ok := values["LastLicenseVerifiedAt"]; ok && strings.TrimSpace(globalSettings.LastLicenseVerifiedAt) == "" {
if normalized, ok := normalizeRegistryStringValue(raw); ok {
globalSettings.LastLicenseVerifiedAt = normalized
}
}
if raw, ok := values["LastLicenseVerifyAttemptAt"]; ok && strings.TrimSpace(globalSettings.LastLicenseVerifyAttemptAt) == "" {
if normalized, ok := normalizeRegistryStringValue(raw); ok {
globalSettings.LastLicenseVerifyAttemptAt = normalized
}
}
}
}

Expand Down Expand Up @@ -587,6 +597,22 @@ func PeekAccessToken() string {
return strings.TrimSpace(globalSettings.AccessToken)
}

// PeekAirGapped returns the in-memory AirGapped flag without triggering Load.
// CommercialTrustOK must not call Global() from honorMachinePolicy mid-Load.
func PeekAirGapped() bool {
return globalSettings.AirGapped
}

// PeekLastLicenseVerifiedAt returns the in-memory verify stamp without Load.
func PeekLastLicenseVerifiedAt() string {
return strings.TrimSpace(globalSettings.LastLicenseVerifiedAt)
}

// PeekLastLicenseVerifyAttemptAt returns the in-memory attempt stamp without Load.
func PeekLastLicenseVerifyAttemptAt() string {
return strings.TrimSpace(globalSettings.LastLicenseVerifyAttemptAt)
}

// expandEnvVars expands Windows-style %VAR% environment variable references in path.
var winEnvVar = regexp.MustCompile(`%([^%]+)%`)

Expand Down
Loading