Skip to content

Commit 27e3b82

Browse files
Use subnet package in pkg for license validation (#3156)
1 parent 239b317 commit 27e3b82

File tree

3 files changed

+15
-47
lines changed

3 files changed

+15
-47
lines changed

api/admin_subnet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ func GetSubnetInfoResponse(session *models.Principal, params subnetApi.SubnetInf
356356
return nil, ErrorWithContext(ctx, ErrSubnetLicenseNotFound)
357357
}
358358

359-
licenseInfo, err := subnet.ParseLicense(client, seededLicense)
359+
licenseInfo, err := getLicenseInfo(*client.Client, seededLicense)
360360
if err != nil {
361361
return nil, ErrorWithContext(ctx, err)
362362
}

api/license.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
package api
1818

1919
import (
20+
"net/http"
2021
"os"
2122

22-
"github.com/minio/console/pkg/subnet"
23+
"github.com/minio/pkg/v2/licverifier"
24+
"github.com/minio/pkg/v2/subnet"
2325
)
2426

2527
type SubnetPlan int
@@ -43,8 +45,18 @@ func (sp SubnetPlan) String() string {
4345

4446
var InstanceLicensePlan = PlanAGPL
4547

48+
func getLicenseInfo(client http.Client, license string) (*licverifier.LicenseInfo, error) {
49+
lv := subnet.LicenseValidator{
50+
Client: client,
51+
ExpiryGracePeriod: 0,
52+
}
53+
lv.Init(getConsoleDevMode())
54+
return lv.ParseLicense(license)
55+
}
56+
4657
func fetchLicensePlan() {
47-
licenseInfo, err := subnet.ParseLicense(GetConsoleHTTPClient("", "127.0.0.1"), os.Getenv(EnvSubnetLicense))
58+
client := GetConsoleHTTPClient("", "127.0.0.1")
59+
licenseInfo, err := getLicenseInfo(*client, os.Getenv(EnvSubnetLicense))
4860
if err != nil {
4961
return
5062
}

pkg/subnet/subnet.go

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,11 @@
1818
package subnet
1919

2020
import (
21-
"bytes"
2221
"encoding/json"
2322
"errors"
24-
"fmt"
2523

2624
"github.com/minio/console/pkg/http"
2725

28-
"github.com/minio/pkg/v2/licverifier"
29-
3026
"github.com/minio/console/models"
3127
"github.com/minio/madmin-go/v3"
3228
mc "github.com/minio/mc/cmd"
@@ -124,46 +120,6 @@ func Register(client http.ClientI, admInfo madmin.InfoMessage, apiKey, token, ac
124120
return nil, errors.New("subnet api key not found")
125121
}
126122

127-
const publicKey = "/downloads/license-pubkey.pem"
128-
129-
// downloadSubnetPublicKey will download the current subnet public key.
130-
func downloadSubnetPublicKey(client http.ClientI) (string, error) {
131-
// Get the public key directly from Subnet
132-
url := fmt.Sprintf("%s%s", subnetBaseURL(), publicKey)
133-
resp, err := client.Get(url)
134-
if err != nil {
135-
return "", err
136-
}
137-
defer resp.Body.Close()
138-
buf := new(bytes.Buffer)
139-
_, err = buf.ReadFrom(resp.Body)
140-
if err != nil {
141-
return "", err
142-
}
143-
return buf.String(), err
144-
}
145-
146-
// ParseLicense parses the license with the bundle public key and return it's information
147-
func ParseLicense(client http.ClientI, license string) (*licverifier.LicenseInfo, error) {
148-
var publicKeys []string
149-
150-
subnetPubKey, err := downloadSubnetPublicKey(client)
151-
if err != nil {
152-
// there was an issue getting the subnet public key
153-
// use hardcoded public keys instead
154-
publicKeys = OfflinePublicKeys
155-
} else {
156-
publicKeys = append(publicKeys, subnetPubKey)
157-
}
158-
159-
licenseInfo, err := GetLicenseInfoFromJWT(license, publicKeys)
160-
if err != nil {
161-
return nil, err
162-
}
163-
164-
return licenseInfo, nil
165-
}
166-
167123
func GetAPIKey(client http.ClientI, token string) (string, error) {
168124
resp, err := subnetGetReq(client, subnetAPIKeyURL(), subnetAuthHeaders(token))
169125
if err != nil {

0 commit comments

Comments
 (0)