|
|
|
@ -21,6 +21,7 @@ import ( |
|
|
|
|
"crypto/ecdsa" |
|
|
|
|
"errors" |
|
|
|
|
"fmt" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
"github.com/dgrijalva/jwt-go" |
|
|
|
|
) |
|
|
|
@ -37,12 +38,14 @@ type LicenseInfo struct { |
|
|
|
|
AccountID int64 // Subnet account id
|
|
|
|
|
StorageCapacity int64 // Storage capacity used in TB
|
|
|
|
|
ServiceType string // Subnet service type
|
|
|
|
|
ExpiresAt time.Time // Time of license expiry
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// license key JSON field names
|
|
|
|
|
const ( |
|
|
|
|
accountID = "accountId" |
|
|
|
|
sub = "sub" |
|
|
|
|
expiresAt = "exp" |
|
|
|
|
teamName = "teamName" |
|
|
|
|
capacity = "capacity" |
|
|
|
|
serviceType = "serviceType" |
|
|
|
@ -71,6 +74,11 @@ func toLicenseInfo(claims jwt.MapClaims) (LicenseInfo, error) { |
|
|
|
|
if !ok { |
|
|
|
|
return LicenseInfo{}, errors.New("Invalid email in claims") |
|
|
|
|
} |
|
|
|
|
expiryTS, ok := claims[expiresAt].(float64) |
|
|
|
|
if !ok { |
|
|
|
|
return LicenseInfo{}, errors.New("Invalid time of expiry in claims") |
|
|
|
|
} |
|
|
|
|
expiresAt := time.Unix(int64(expiryTS), 0) |
|
|
|
|
tName, ok := claims[teamName].(string) |
|
|
|
|
if !ok { |
|
|
|
|
return LicenseInfo{}, errors.New("Invalid team name in claims") |
|
|
|
@ -89,6 +97,7 @@ func toLicenseInfo(claims jwt.MapClaims) (LicenseInfo, error) { |
|
|
|
|
AccountID: int64(accID), |
|
|
|
|
StorageCapacity: int64(storageCap), |
|
|
|
|
ServiceType: sType, |
|
|
|
|
ExpiresAt: expiresAt, |
|
|
|
|
}, nil |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|