Sponsor: remove Creem license key activation (#31824)

This commit is contained in:
Michael Geers 2026-07-15 16:45:57 +02:00 • committed by GitHub
parent 75cb289a61
commit 8b243c2a25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 104 additions and 534 deletions

View file

@ -35,9 +35,9 @@ import (
)
var (
mu sync.RWMutex
Subject, Token, ActivationKey string
ExpiresAt time.Time
mu sync.RWMutex
Subject, Token string
ExpiresAt time.Time
)
func machineID() string {
@ -58,35 +58,6 @@ func IsAuthorizedForApi() bool {
return IsAuthorized() && Subject != unavailable && Token != ""
}
// ActivateSponsorship activates a license key with email and returns the JWT token
func ActivateSponsorship(licenseKey, email string) (string, error) {
conn, err := cloud.Connection()
if err != nil {
return "", fmt.Errorf("connection failed: %w", err)
}
client := pb.NewAuthClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
res, err := client.Activate(ctx, &pb.ActivateRequest{
Key: licenseKey,
Email: email,
MachineId: machineID(),
})
if err != nil {
return "", fmt.Errorf("activation failed: %w", err)
}
if res.Error != "" {
return "", fmt.Errorf("%s", res.Error)
}
return res.Token, nil
}
// check and set sponsorship token
func ConfigureSponsorship(token string) error {
mu.Lock()
@ -130,10 +101,9 @@ func ConfigureSponsorship(token string) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
res, err := client.IsAuthorized(ctx, &pb.AuthRequest{Token: token})
res, err := client.IsAuthorized(ctx, &pb.AuthRequest{Token: token, MachineId: machineID()})
if err == nil && res.Authorized {
Subject = res.Subject
ActivationKey = res.ActivationKey
ExpiresAt = res.ExpiresAt.AsTime()
}
@ -161,20 +131,11 @@ func redactToken(token string) string {
return token[:6] + "......." + token[len(token)-6:]
}
// redactKey returns a redacted version of the activation key showing only the first segment
func redactKey(key string) string {
if idx := strings.Index(key, "-"); idx > 0 {
return key[:idx] + "-XXXXX-XXXXX-XXXXX-XXXXX"
}
return ""
}
type Status struct {
Name string `json:"name"`
ExpiresAt time.Time `json:"expiresAt,omitempty"`
ExpiresSoon bool `json:"expiresSoon,omitempty"`
Token string `json:"token,omitempty"`
ActivationKey string `json:"activationKey,omitempty"`
Name string `json:"name"`
ExpiresAt time.Time `json:"expiresAt,omitempty"`
ExpiresSoon bool `json:"expiresSoon,omitempty"`
Token string `json:"token,omitempty"`
}
// RedactedStatus returns the sponsorship status
@ -188,10 +149,9 @@ func RedactedStatus() Status {
}
return Status{
Name: Subject,
ExpiresAt: ExpiresAt,
ExpiresSoon: expiresSoon,
Token: redactToken(Token),
ActivationKey: redactKey(ActivationKey),
Name: Subject,
ExpiresAt: ExpiresAt,
ExpiresSoon: expiresSoon,
Token: redactToken(Token),
}
}