From 41910b6d68e3ccb79d322188e516e0ef3ccf1304 Mon Sep 17 00:00:00 2001 From: Daniel Hiltgen Date: Mon, 10 Sep 2018 14:31:56 -0700 Subject: [PATCH] Vendor bump of licensing lib Signed-off-by: Daniel Hiltgen --- vendor.conf | 2 +- vendor/github.com/docker/licensing/client.go | 6 +++++ .../docker/licensing/model/subscriptions.go | 2 +- vendor/github.com/docker/licensing/storage.go | 27 ++++++++++++++----- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/vendor.conf b/vendor.conf index 7a84ad4fdd..91932df6cc 100755 --- a/vendor.conf +++ b/vendor.conf @@ -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 cfa742c8abe6f8e922f6e4e920153c408e7d9c3b github.com/flynn-archive/go-shlex 3f9db97f856818214da2e1057f8ad84803971cff github.com/ghodss/yaml 0ca9ea5df5451ffdf184b4428c902747c2c11cd7 # v1.0.0 diff --git a/vendor/github.com/docker/licensing/client.go b/vendor/github.com/docker/licensing/client.go index 8cf9d888a8..62a2cd524d 100644 --- a/vendor/github.com/docker/licensing/client.go +++ b/vendor/github.com/docker/licensing/client.go @@ -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") } diff --git a/vendor/github.com/docker/licensing/model/subscriptions.go b/vendor/github.com/docker/licensing/model/subscriptions.go index 7e5f883368..95dadb8d48 100644 --- a/vendor/github.com/docker/licensing/model/subscriptions.go +++ b/vendor/github.com/docker/licensing/model/subscriptions.go @@ -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 { diff --git a/vendor/github.com/docker/licensing/storage.go b/vendor/github.com/docker/licensing/storage.go index d4fe01c379..0358fad521 100644 --- a/vendor/github.com/docker/licensing/storage.go +++ b/vendor/github.com/docker/licensing/storage.go @@ -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) } - 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) + 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) } - licenseData = cfg.Spec.Data } 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