mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-12-02 10:09:02 +01:00
Community installs already stored 90 days of daily metric averages and 366 days of availability history, but the chart, availability and agent history reads refused anything past seven days, and lapsed paid installs had history past seven days purged 60 days after a downgrade. Locking users out of data on their own disk is the kind of limit that drew the loudest complaints before (the monitored-system cap, SSO), and it is not what people pay for: 12 of 88 covered paid installs read past seven days in the last 30 days. The history routes now serve every supported range on every plan, and storage retention alone decides how far back the answer goes. long_term_metrics moves into Community as a compatibility key with no upgrade reason. TierHistoryDays, max_history_days and the downgrade purge (DowngradeRetentionState, the metrics store commercial ceiling and the generated-report purge) are removed, so nothing deletes history or reports because a plan ended. The chart and drawer lock panels, the history plan link, the billing summary row and the plan copy that sold history go with them. Paying users lose nothing. The public pricing pages and licence server copy in pulse-pro change when the release carrying this ships.
303 lines
12 KiB
Go
303 lines
12 KiB
Go
package api
|
|
|
|
import (
|
|
"crypto/ed25519"
|
|
"net/http"
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
|
|
pkglicensing "github.com/rcourtman/pulse-go-rewrite/pkg/licensing"
|
|
)
|
|
|
|
// Sentinel errors for user-friendly activation error mapping.
|
|
var (
|
|
errMalformedLicenseSentinel = pkglicensing.ErrMalformedLicense
|
|
errInvalidLicenseSentinel = pkglicensing.ErrInvalidLicense
|
|
errSignatureInvalidSentinel = pkglicensing.ErrSignatureInvalid
|
|
errExpiredLicenseSentinel = pkglicensing.ErrExpiredLicense
|
|
errNoPublicKeySentinel = pkglicensing.ErrNoPublicKey
|
|
)
|
|
|
|
type licenseServerErrorModel = pkglicensing.LicenseServerError
|
|
|
|
type licenseService = pkglicensing.Service
|
|
type licenseModel = pkglicensing.License
|
|
type licenseStatus = pkglicensing.LicenseStatus
|
|
type licensePersistence = pkglicensing.Persistence
|
|
type licenseEvaluator = pkglicensing.Evaluator
|
|
type licenseFeatureServiceResolver = pkglicensing.FeatureServiceResolver
|
|
type licenseFeatureChecker = pkglicensing.FeatureChecker
|
|
type licenseFeaturesResponse = pkglicensing.LicenseFeaturesResponse
|
|
type activateLicenseRequestModel = pkglicensing.ActivateLicenseRequest
|
|
type activateLicenseResponseModel = pkglicensing.ActivateLicenseResponse
|
|
type activationStateModel = pkglicensing.ActivationState
|
|
type billingStoreModel = pkglicensing.BillingStore
|
|
type billingState = pkglicensing.BillingState
|
|
type subscriptionState = pkglicensing.SubscriptionState
|
|
type entitlementPayloadModel = pkglicensing.EntitlementPayload
|
|
type commercialPosturePayloadModel = pkglicensing.CommercialPosturePayload
|
|
type runtimeCapabilitiesPayloadModel = pkglicensing.RuntimeCapabilitiesPayload
|
|
type runtimeIdentityModel = pkglicensing.RuntimeIdentity
|
|
type limitStatusModel = pkglicensing.LimitStatus
|
|
type upgradeReasonModel = pkglicensing.UpgradeReason
|
|
type entitlementUsageSnapshotModel = pkglicensing.EntitlementUsageSnapshot
|
|
type legacyConnectionCountsModel = pkglicensing.LegacyConnectionCounts
|
|
type commercialMigrationStatusModel = pkglicensing.CommercialMigrationStatus
|
|
type purchaseReturnClaimsModel = pkglicensing.PurchaseReturnClaims
|
|
type entitlementLeaseClaimsModel = pkglicensing.EntitlementLeaseClaims
|
|
|
|
type licenseTier = pkglicensing.Tier
|
|
type checkoutPortalHandoffRequestModel = pkglicensing.CheckoutPortalHandoffRequest
|
|
type checkoutPortalHandoffResponseModel = pkglicensing.CheckoutPortalHandoffResponse
|
|
|
|
const (
|
|
featureMultiTenantKey = pkglicensing.FeatureMultiTenant
|
|
featureAgentProfilesValue = pkglicensing.FeatureAgentProfiles
|
|
featureAIPatrolValue = pkglicensing.FeatureAIPatrol
|
|
featureAIAutoFixValue = pkglicensing.FeatureAIAutoFix
|
|
featureAuditLoggingValue = pkglicensing.FeatureAuditLogging
|
|
featureRBACValue = pkglicensing.FeatureRBAC
|
|
featureAdvancedReportingValue = pkglicensing.FeatureAdvancedReporting
|
|
featureExternalProbeValue = pkglicensing.FeatureExternalProbe
|
|
featureWhiteLabelValue = pkglicensing.FeatureWhiteLabel
|
|
featureDemoFixturesValue = pkglicensing.FeatureDemoFixtures
|
|
maxUsersLicenseGateKey = pkglicensing.MaxUsersLicenseGateKey
|
|
subscriptionStateActiveValue = pkglicensing.SubStateActive
|
|
subscriptionStateExpiredValue = pkglicensing.SubStateExpired
|
|
subscriptionStateGraceValue = pkglicensing.SubStateGrace
|
|
subscriptionStateCanceledValue = pkglicensing.SubStateCanceled
|
|
subscriptionStateTrialValue = pkglicensing.SubStateTrial
|
|
activationKeyPrefixValue = pkglicensing.ActivationKeyPrefix
|
|
defaultLicenseServerURLValue = pkglicensing.DefaultLicenseServerURL
|
|
)
|
|
|
|
func newLicenseService() *licenseService {
|
|
return pkglicensing.NewService()
|
|
}
|
|
|
|
func hasMultiTenantLicense(service *licenseService) bool {
|
|
return service != nil && service.HasFeature(featureMultiTenantKey)
|
|
}
|
|
|
|
func upgradeURLForFeatureFromLicensing(feature string) string {
|
|
return pkglicensing.UpgradeURLForFeature(feature)
|
|
}
|
|
|
|
func isProviderHostedWorkspaceFromLicensing(orgID string) bool {
|
|
return pkglicensing.IsProviderHostedWorkspace(orgID)
|
|
}
|
|
|
|
// isProviderHostedRuntimeFromLicensing reports whether this runtime is a
|
|
// provider MSP client runtime, whichever organization a request names.
|
|
func isProviderHostedRuntimeFromLicensing() bool {
|
|
return strings.EqualFold(strings.TrimSpace(os.Getenv(pkglicensing.ProviderHostedRuntimeEnvVar)), "true")
|
|
}
|
|
|
|
func proTrialSignupURLFromLicensing(override string) string {
|
|
return pkglicensing.ResolveProTrialSignupURL(override)
|
|
}
|
|
|
|
func pulseAccountPortalURLFromLicensing(override string) string {
|
|
return pkglicensing.ResolvePulseAccountPortalURL(override)
|
|
}
|
|
|
|
func defaultBillingStateFromLicensing() *billingState {
|
|
return pkglicensing.DefaultBillingState()
|
|
}
|
|
|
|
func normalizeBillingStateFromLicensing(state *billingState) *billingState {
|
|
return pkglicensing.NormalizeBillingState(state)
|
|
}
|
|
|
|
func cloneCommercialMigrationStatusFromLicensing(state *commercialMigrationStatusModel) *commercialMigrationStatusModel {
|
|
return pkglicensing.CloneCommercialMigrationStatus(state)
|
|
}
|
|
|
|
func applyCommercialMigrationFailureTimingFromLicensing(
|
|
status, previous *commercialMigrationStatusModel,
|
|
now time.Time,
|
|
) *commercialMigrationStatusModel {
|
|
return pkglicensing.ApplyCommercialMigrationFailureTiming(status, previous, now)
|
|
}
|
|
|
|
func classifyLegacyExchangeErrorFromLicensing(err error) *commercialMigrationStatusModel {
|
|
return pkglicensing.ClassifyLegacyExchangeError(err)
|
|
}
|
|
|
|
func classifyPersistedLicenseLoadErrorFromLicensing(err error) *commercialMigrationStatusModel {
|
|
return pkglicensing.ClassifyPersistedLicenseLoadError(err)
|
|
}
|
|
|
|
const commercialMigrationStatePendingValue = pkglicensing.CommercialMigrationStatePending
|
|
|
|
func isValidBillingSubscriptionStateFromLicensing(state subscriptionState) bool {
|
|
return pkglicensing.IsValidBillingSubscriptionState(state)
|
|
}
|
|
|
|
func cloudCapabilitiesFromLicensing() []string {
|
|
return pkglicensing.DeriveCapabilitiesFromTier(pkglicensing.TierCloud, nil)
|
|
}
|
|
|
|
func defaultTrialDurationFromLicensing() time.Duration {
|
|
return pkglicensing.DefaultTrialDuration
|
|
}
|
|
|
|
func buildTrialBillingStateWithPlanFromLicensing(now time.Time, capabilities []string, planVersion string, duration time.Duration) *billingState {
|
|
return pkglicensing.BuildTrialBillingStateWithPlan(now, capabilities, planVersion, duration)
|
|
}
|
|
|
|
func newLicensePersistenceFromLicensing(configDir string) (*licensePersistence, error) {
|
|
return pkglicensing.NewPersistence(configDir)
|
|
}
|
|
|
|
func newLicenseServerClientFromLicensing(baseURL string) *pkglicensing.LicenseServerClient {
|
|
return pkglicensing.NewLicenseServerClient(baseURL)
|
|
}
|
|
|
|
func isLicenseValidationDevModeFromLicensing() bool {
|
|
return pkglicensing.IsLicenseValidationDevMode()
|
|
}
|
|
|
|
func isDemoModeFromLicensing() bool {
|
|
return pkglicensing.IsDemoMode()
|
|
}
|
|
|
|
func newLicenseEvaluatorForBillingStoreFromLicensing(store billingStoreModel, orgID string, cacheTTL time.Duration, expectedInstanceHost string) *licenseEvaluator {
|
|
return pkglicensing.NewEvaluator(
|
|
pkglicensing.NewDatabaseSource(store, orgID, cacheTTL).WithExpectedInstanceHost(expectedInstanceHost),
|
|
)
|
|
}
|
|
|
|
func maxUsersLimitFromLicensing(lic *licenseModel) int {
|
|
return pkglicensing.MaxUsersLimitFromLicense(lic)
|
|
}
|
|
|
|
func exceedsUserLimitFromLicensing(current, additions, limit int) bool {
|
|
return pkglicensing.ExceedsUserLimit(current, additions, limit)
|
|
}
|
|
|
|
func userLimitExceededMessageFromLicensing(current, limit int) string {
|
|
return pkglicensing.UserLimitExceededMessage(current, limit)
|
|
}
|
|
|
|
func mapStripeSubscriptionStatusToStateFromLicensing(status string) subscriptionState {
|
|
return pkglicensing.MapStripeSubscriptionStatusToState(status)
|
|
}
|
|
|
|
func shouldGrantPaidCapabilitiesFromLicensing(state subscriptionState) bool {
|
|
return pkglicensing.ShouldGrantPaidCapabilities(state)
|
|
}
|
|
|
|
func deriveStripePlanVersionFromLicensing(metadata map[string]string, priceID string) string {
|
|
return pkglicensing.DeriveStripePlanVersion(metadata, priceID)
|
|
}
|
|
|
|
func buildEntitlementPayloadFromLicensing(status *licenseStatus, subscriptionState string) entitlementPayloadModel {
|
|
return pkglicensing.BuildEntitlementPayload(status, subscriptionState)
|
|
}
|
|
|
|
func buildFeatureMapFromLicensing(service *licenseService) map[string]bool {
|
|
return pkglicensing.BuildFeatureMap(service, nil)
|
|
}
|
|
|
|
func buildEntitlementPayloadWithUsageFromLicensing(
|
|
status *licenseStatus,
|
|
subscriptionState string,
|
|
usage entitlementUsageSnapshotModel,
|
|
trialEndsAtUnix *int64,
|
|
) entitlementPayloadModel {
|
|
return pkglicensing.BuildEntitlementPayloadWithUsage(status, subscriptionState, usage, trialEndsAtUnix)
|
|
}
|
|
|
|
func buildRuntimeCapabilitiesPayloadWithUsageFromLicensing(
|
|
status *licenseStatus,
|
|
subscriptionState string,
|
|
usage entitlementUsageSnapshotModel,
|
|
) runtimeCapabilitiesPayloadModel {
|
|
return pkglicensing.BuildRuntimeCapabilitiesPayloadWithUsage(status, subscriptionState, usage)
|
|
}
|
|
|
|
func communityRuntimeIdentityFromLicensing() runtimeIdentityModel {
|
|
return pkglicensing.CommunityRuntimeIdentity()
|
|
}
|
|
|
|
func proRuntimeIdentityFromLicensing() runtimeIdentityModel {
|
|
return pkglicensing.ProRuntimeIdentity()
|
|
}
|
|
|
|
func normalizeRuntimeIdentityFromLicensing(identity runtimeIdentityModel) runtimeIdentityModel {
|
|
return pkglicensing.NormalizeRuntimeIdentity(identity)
|
|
}
|
|
|
|
func cloneRuntimeIdentityFromLicensing(identity runtimeIdentityModel) *runtimeIdentityModel {
|
|
return pkglicensing.CloneRuntimeIdentity(identity)
|
|
}
|
|
|
|
func filterCapabilitiesForRuntimeIdentityFromLicensing(
|
|
capabilities []string,
|
|
identity runtimeIdentityModel,
|
|
) ([]string, []pkglicensing.RuntimeCapabilityBlock) {
|
|
return pkglicensing.FilterCapabilitiesForRuntimeIdentity(capabilities, identity)
|
|
}
|
|
|
|
func buildCommercialPosturePayloadWithUsageFromLicensing(
|
|
status *licenseStatus,
|
|
subscriptionState string,
|
|
usage entitlementUsageSnapshotModel,
|
|
trialEndsAtUnix *int64,
|
|
) commercialPosturePayloadModel {
|
|
return pkglicensing.BuildCommercialPosturePayloadWithUsage(
|
|
status,
|
|
subscriptionState,
|
|
usage,
|
|
trialEndsAtUnix,
|
|
)
|
|
}
|
|
|
|
func commercialPosturePayloadFromEntitlementPayloadFromLicensing(
|
|
payload entitlementPayloadModel,
|
|
) commercialPosturePayloadModel {
|
|
return pkglicensing.CommercialPosturePayloadFromEntitlementPayload(payload)
|
|
}
|
|
|
|
func limitStateFromLicensing(current, limit int64) string {
|
|
return pkglicensing.LimitState(current, limit)
|
|
}
|
|
|
|
func trialActivationPublicKeyFromLicensing() (ed25519.PublicKey, error) {
|
|
return pkglicensing.HostedEntitlementPublicKey()
|
|
}
|
|
|
|
func signPurchaseReturnTokenFromLicensing(signingKey []byte, claims purchaseReturnClaimsModel) (string, error) {
|
|
return pkglicensing.SignPurchaseReturnToken(signingKey, claims)
|
|
}
|
|
|
|
func verifyPurchaseReturnTokenFromLicensing(token string, signingKey []byte, expectedInstanceHost string, now time.Time) (*purchaseReturnClaimsModel, error) {
|
|
return pkglicensing.VerifyPurchaseReturnToken(token, signingKey, expectedInstanceHost, now)
|
|
}
|
|
|
|
func verifyEntitlementLeaseTokenFromLicensing(token string, key ed25519.PublicKey, expectedInstanceHost string, now time.Time) (*entitlementLeaseClaimsModel, error) {
|
|
return pkglicensing.VerifyEntitlementLeaseToken(token, key, expectedInstanceHost, now)
|
|
}
|
|
|
|
func parseEntitlementLeaseTokenFromLicensing(token string, key ed25519.PublicKey, expectedInstanceHost string) (*entitlementLeaseClaimsModel, error) {
|
|
return pkglicensing.ParseEntitlementLeaseToken(token, key, expectedInstanceHost)
|
|
}
|
|
|
|
func writePaymentRequiredFromLicensing(w http.ResponseWriter, payload map[string]interface{}) {
|
|
pkglicensing.WritePaymentRequired(w, payload)
|
|
}
|
|
|
|
func writeLicenseRequiredFromLicensing(w http.ResponseWriter, feature, message string) {
|
|
pkglicensing.WriteLicenseRequired(w, feature, message, pkglicensing.UpgradeURLForFeature)
|
|
}
|
|
|
|
// licenseTierFreeValue is the canonical free-tier constant for use outside the bridge.
|
|
const licenseTierFreeValue = pkglicensing.TierFree
|
|
|
|
// overflowDaysRemainingFromLicensing returns the number of days remaining in the overflow window.
|
|
func overflowDaysRemainingFromLicensing(tier licenseTier, overflowGrantedAt *int64, now time.Time) int {
|
|
return pkglicensing.OverflowDaysRemaining(tier, overflowGrantedAt, now)
|
|
}
|