CreateLicense signs a new license JWT from business params. Only available when private key is configured (SaaS mode). Handles JWT plumbing (issuer, audience, kid) internally.
(params *LicenseParams)
| 425 | // Only available when private key is configured (SaaS mode). |
| 426 | // Handles JWT plumbing (issuer, audience, kid) internally. |
| 427 | func (s *LicenseService) CreateLicense(params *LicenseParams) (string, error) { |
| 428 | if s.config.PrivateKey == nil { |
| 429 | return "", errors.New("license signing not available: private key not configured") |
| 430 | } |
| 431 | |
| 432 | c := newLicenseClaims(params) |
| 433 | c.Issuer = s.config.Issuer |
| 434 | c.Audience = jwt.ClaimStrings{s.config.Audience} |
| 435 | c.IssuedAt = jwt.NewNumericDate(time.Now()) |
| 436 | c.Subject = params.WorkspaceID |
| 437 | if !params.ExpiresAt.IsZero() { |
| 438 | c.ExpiresAt = jwt.NewNumericDate(params.ExpiresAt) |
| 439 | } |
| 440 | |
| 441 | token := jwt.NewWithClaims(jwt.SigningMethodRS256, c) |
| 442 | token.Header["kid"] = s.config.Version |
| 443 | return token.SignedString(s.config.PrivateKey) |
| 444 | } |
| 445 | |
| 446 | // InvalidateCache removes the cached subscription for a workspace, |
| 447 | // forcing the next LoadSubscription call to reload from the database. |
no test coverage detected