mirror of https://github.com/docker/cli.git
Vendor bump of licensing lib
Signed-off-by: Daniel Hiltgen <daniel.hiltgen@docker.com>
(cherry picked from commit 41910b6d68
)
Signed-off-by: Daniel Hiltgen <daniel.hiltgen@docker.com>
This commit is contained in:
parent
d486baebfc
commit
9cd6d5333d
|
@ -22,7 +22,7 @@ github.com/docker/go-events 9461782956ad83b30282bf90e31fa6a70c255ba9
|
|||
github.com/docker/go-metrics d466d4f6fd960e01820085bd7e1a24426ee7ef18
|
||||
github.com/docker/go-units 47565b4f722fb6ceae66b95f853feed578a4a51c # v0.3.3
|
||||
github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a
|
||||
github.com/docker/licensing 5c4c7b4
|
||||
github.com/docker/licensing f2eae57157a06681b024f1690923d03e414179a0
|
||||
github.com/docker/swarmkit 9f271c2963d18a7c60d2c4001fb418ca4037df19
|
||||
github.com/flynn-archive/go-shlex 3f9db97f856818214da2e1057f8ad84803971cff
|
||||
github.com/ghodss/yaml 0ca9ea5df5451ffdf184b4428c902747c2c11cd7 # v1.0.0
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package licensing
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
|
@ -34,6 +35,7 @@ type Client interface {
|
|||
ParseLicense(license []byte) (parsedLicense *model.IssuedLicense, err error)
|
||||
StoreLicense(ctx context.Context, dclnt WrappedDockerClient, licenses *model.IssuedLicense, localRootDir string) error
|
||||
LoadLocalLicense(ctx context.Context, dclnt WrappedDockerClient) (*model.Subscription, error)
|
||||
SummarizeLicense(res *model.CheckResponse, keyID string) *model.Subscription
|
||||
}
|
||||
|
||||
func (c *client) LoginViaAuth(ctx context.Context, username, password string) (string, error) {
|
||||
|
@ -185,6 +187,10 @@ func (c *client) DownloadLicenseFromHub(ctx context.Context, authToken, subscrip
|
|||
|
||||
func (c *client) ParseLicense(license []byte) (*model.IssuedLicense, error) {
|
||||
parsedLicense := &model.IssuedLicense{}
|
||||
// The file may contain a leading BOM, which will choke the
|
||||
// json deserializer.
|
||||
license = bytes.Trim(license, "\xef\xbb\xbf")
|
||||
|
||||
if err := json.Unmarshal(license, &parsedLicense); err != nil {
|
||||
return nil, errors.WithMessage(err, "failed to parse license")
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ type Subscription struct {
|
|||
}
|
||||
|
||||
func (s *Subscription) String() string {
|
||||
storeURL := "https://store.docker.com"
|
||||
storeURL := "https://docker.com/licensing"
|
||||
|
||||
var nameMsg, expirationMsg, statusMsg string
|
||||
switch s.State {
|
||||
|
|
|
@ -87,18 +87,23 @@ func (c *client) LoadLocalLicense(ctx context.Context, clnt WrappedDockerClient)
|
|||
licenseData, err = readLicenseFromHost(ctx, info.DockerRootDir)
|
||||
} else {
|
||||
// Load the latest license index
|
||||
latestVersion, err := getLatestNamedConfig(clnt, licenseNamePrefix)
|
||||
var latestVersion int
|
||||
latestVersion, err = getLatestNamedConfig(clnt, licenseNamePrefix)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "not a swarm manager.") {
|
||||
return nil, ErrWorkerNode
|
||||
}
|
||||
return nil, fmt.Errorf("unable to get latest license version: %s", err)
|
||||
}
|
||||
if latestVersion >= 0 {
|
||||
cfg, _, err := clnt.ConfigInspectWithRaw(ctx, fmt.Sprintf("%s-%d", licenseNamePrefix, latestVersion))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to load license from swarm config: %s", err)
|
||||
}
|
||||
licenseData = cfg.Spec.Data
|
||||
} else {
|
||||
licenseData, err = readLicenseFromHost(ctx, info.DockerRootDir)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
|
@ -115,6 +120,10 @@ func (c *client) LoadLocalLicense(ctx context.Context, clnt WrappedDockerClient)
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return checkResponseToSubscription(checkResponse, parsedLicense.KeyID), nil
|
||||
}
|
||||
|
||||
func checkResponseToSubscription(checkResponse *model.CheckResponse, keyID string) *model.Subscription {
|
||||
|
||||
// TODO - this translation still needs some work
|
||||
// Primary missing piece is how to distinguish from basic, vs std/advanced
|
||||
|
@ -144,7 +153,7 @@ func (c *client) LoadLocalLicense(ctx context.Context, clnt WrappedDockerClient)
|
|||
// Translate the legacy structure into the new Subscription fields
|
||||
return &model.Subscription{
|
||||
// Name
|
||||
ID: parsedLicense.KeyID, // This is not actually the same, but is unique
|
||||
ID: keyID, // This is not actually the same, but is unique
|
||||
// DockerID
|
||||
ProductID: productID,
|
||||
ProductRatePlan: ratePlan,
|
||||
|
@ -159,7 +168,11 @@ func (c *client) LoadLocalLicense(ctx context.Context, clnt WrappedDockerClient)
|
|||
Value: checkResponse.MaxEngines,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *client) SummarizeLicense(checkResponse *model.CheckResponse, keyID string) *model.Subscription {
|
||||
return checkResponseToSubscription(checkResponse, keyID)
|
||||
}
|
||||
|
||||
// getLatestNamedConfig looks for versioned instances of configs with the
|
||||
|
|
Loading…
Reference in New Issue