From f73bd83419447db7c0d8f987a6144831c6e8d999 Mon Sep 17 00:00:00 2001 From: Daniel Hiltgen Date: Thu, 18 Oct 2018 14:44:05 -0700 Subject: [PATCH 1/2] Bump licensing library Removes the billing profile flow which is now handled on the back-end. Signed-off-by: Daniel Hiltgen (cherry picked from commit 8e565d03995c582b607c2e903824684060dd8fb0) Signed-off-by: Sebastiaan van Stijn --- vendor.conf | 2 +- .../github.com/docker/licensing/accounts.go | 32 ---------- vendor/github.com/docker/licensing/client.go | 33 ++-------- .../docker/licensing/model/accounts.go | 61 ------------------- .../docker/licensing/model/users.go | 4 -- 5 files changed, 6 insertions(+), 126 deletions(-) delete mode 100644 vendor/github.com/docker/licensing/accounts.go delete mode 100644 vendor/github.com/docker/licensing/model/accounts.go diff --git a/vendor.conf b/vendor.conf index 9a6d2aba98..73e1fe0bad 100755 --- a/vendor.conf +++ b/vendor.conf @@ -24,7 +24,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 f2eae57157a06681b024f1690923d03e414179a0 +github.com/docker/licensing 1c117a1720cb413dd6a101d36a6c567b1ccb90fe github.com/docker/swarmkit 8af8c420f491f006ab1730e08d446a795b1667d7 github.com/flynn-archive/go-shlex 3f9db97f856818214da2e1057f8ad84803971cff github.com/ghodss/yaml 0ca9ea5df5451ffdf184b4428c902747c2c11cd7 # v1.0.0 diff --git a/vendor/github.com/docker/licensing/accounts.go b/vendor/github.com/docker/licensing/accounts.go deleted file mode 100644 index 312faff143..0000000000 --- a/vendor/github.com/docker/licensing/accounts.go +++ /dev/null @@ -1,32 +0,0 @@ -package licensing - -import ( - "context" - - "github.com/docker/licensing/lib/go-clientlib" - "github.com/docker/licensing/model" -) - -func (c *client) createAccount(ctx context.Context, dockerID string, request *model.AccountCreationRequest) (*model.Account, error) { - url := c.baseURI - url.Path += "/api/billing/v4/accounts/" + dockerID - - response := new(model.Account) - if _, _, err := c.doReq(ctx, "PUT", &url, clientlib.SendJSON(request), clientlib.RecvJSON(response)); err != nil { - return nil, err - } - - return response, nil -} - -func (c *client) getAccount(ctx context.Context, dockerID string) (*model.Account, error) { - url := c.baseURI - url.Path += "/api/billing/v4/accounts/" + dockerID - - response := new(model.Account) - if _, _, err := c.doReq(ctx, "GET", &url, clientlib.RecvJSON(response)); err != nil { - return nil, err - } - - return response, nil -} diff --git a/vendor/github.com/docker/licensing/client.go b/vendor/github.com/docker/licensing/client.go index 62a2cd524d..1ad0d87fbd 100644 --- a/vendor/github.com/docker/licensing/client.go +++ b/vendor/github.com/docker/licensing/client.go @@ -28,7 +28,7 @@ type Client interface { GetHubUserOrgs(ctx context.Context, authToken string) (orgs []model.Org, err error) GetHubUserByName(ctx context.Context, username string) (user *model.User, err error) VerifyLicense(ctx context.Context, license model.IssuedLicense) (res *model.CheckResponse, err error) - GenerateNewTrialSubscription(ctx context.Context, authToken, dockerID, email string) (subscriptionID string, err error) + GenerateNewTrialSubscription(ctx context.Context, authToken, dockerID string) (subscriptionID string, err error) ListSubscriptions(ctx context.Context, authToken, dockerID string) (response []*model.Subscription, err error) ListSubscriptionsDetails(ctx context.Context, authToken, dockerID string) (response []*model.SubscriptionDetail, err error) DownloadLicenseFromHub(ctx context.Context, authToken, subscriptionID string) (license *model.IssuedLicense, err error) @@ -80,31 +80,9 @@ func (c *client) VerifyLicense(ctx context.Context, license model.IssuedLicense) return res, nil } -func (c *client) GenerateNewTrialSubscription(ctx context.Context, authToken, dockerID, email string) (string, error) { +func (c *client) GenerateNewTrialSubscription(ctx context.Context, authToken, dockerID string) (string, error) { ctx = jwt.NewContext(ctx, authToken) - if _, err := c.getAccount(ctx, dockerID); err != nil { - code, ok := errors.HTTPStatus(err) - // create billing account if one is not found - if ok && code == http.StatusNotFound { - _, err = c.createAccount(ctx, dockerID, &model.AccountCreationRequest{ - Profile: model.Profile{ - Email: email, - }, - }) - if err != nil { - return "", errors.Wrap(err, errors.Fields{ - "dockerID": dockerID, - "email": email, - }) - } - } else { - return "", errors.Wrap(err, errors.Fields{ - "dockerID": dockerID, - }) - } - } - sub, err := c.createSubscription(ctx, &model.SubscriptionCreationRequest{ Name: "Docker Enterprise Free Trial", DockerID: dockerID, @@ -116,8 +94,7 @@ func (c *client) GenerateNewTrialSubscription(ctx context.Context, authToken, do }) if err != nil { return "", errors.Wrap(err, errors.Fields{ - "dockerID": dockerID, - "email": email, + "docker_id": dockerID, }) } @@ -131,7 +108,7 @@ func (c *client) ListSubscriptions(ctx context.Context, authToken, dockerID stri subs, err := c.listSubscriptions(ctx, map[string]string{"docker_id": dockerID}) if err != nil { return nil, errors.Wrap(err, errors.Fields{ - "dockerID": dockerID, + "docker_id": dockerID, }) } @@ -155,7 +132,7 @@ func (c *client) ListSubscriptionsDetails(ctx context.Context, authToken, docker subs, err := c.listSubscriptionsDetails(ctx, map[string]string{"docker_id": dockerID}) if err != nil { return nil, errors.Wrap(err, errors.Fields{ - "dockerID": dockerID, + "docker_id": dockerID, }) } diff --git a/vendor/github.com/docker/licensing/model/accounts.go b/vendor/github.com/docker/licensing/model/accounts.go deleted file mode 100644 index a646ecd9fb..0000000000 --- a/vendor/github.com/docker/licensing/model/accounts.go +++ /dev/null @@ -1,61 +0,0 @@ -package model - -import ( - "github.com/docker/licensing/lib/go-validation" -) - -// Profile represents an Account profile -type Profile struct { - Email string `json:"email"` - FirstName string `json:"first_name"` - LastName string `json:"last_name"` - - Addresses []*Address `json:"addresses,omitempty"` - CompanyName string `json:"company_name,omitempty"` - PhonePrimary string `json:"phone_primary,omitempty"` - JobFunction string `json:"job_function,omitempty"` - VatID string `json:"vat_id,omitempty"` -} - -// Address represents a Profile address -type Address struct { - AddressLine1 string `json:"address_line_1,omitempty"` - AddressLine2 string `json:"address_line_2,omitempty"` - AddressLine3 string `json:"address_line_3,omitempty"` - City string `json:"city,omitempty"` - Province string `json:"province,omitempty"` - Country string `json:"country,omitempty"` - Postcode string `json:"post_code,omitempty"` - PrimaryAddress bool `json:"primary_address,omitempty"` -} - -// Account represents a billing profile -type Account struct { - DockerID string `json:"docker_id"` - - Profile Profile `json:"profile"` -} - -// AccountCreationRequest represents an Account creation request -type AccountCreationRequest struct { - Profile Profile `json:"profile"` -} - -// Validate returns true if the account request is valid, false otherwise. -// If invalid, one or more validation Errors will be returned. -func (a *AccountCreationRequest) Validate() (bool, validation.Errors) { - profile := a.Profile - - var errs validation.Errors - - if validation.IsEmpty(profile.Email) { - errs = append(errs, validation.InvalidEmpty("email")) - } - - if !validation.IsEmpty(profile.Email) && !validation.IsEmail(profile.Email) { - errs = append(errs, validation.InvalidEmail("email", profile.Email)) - } - - valid := len(errs) == 0 - return valid, errs -} diff --git a/vendor/github.com/docker/licensing/model/users.go b/vendor/github.com/docker/licensing/model/users.go index c61389da14..24da8c2793 100644 --- a/vendor/github.com/docker/licensing/model/users.go +++ b/vendor/github.com/docker/licensing/model/users.go @@ -21,10 +21,6 @@ type User struct { Company string `json:"company,omitempty"` ProfileURL string `json:"profile_url,omitempty"` GravatarURL string `json:"gravatar_url,omitempty"` - - Email string `json:"email"` - Primary bool `json:"primary"` - Verified bool `json:"verified"` } // Org details a Docker organization From b9f1d30fa7d880188bd80a8a2d5946480c8ffec8 Mon Sep 17 00:00:00 2001 From: Daniel Hiltgen Date: Thu, 18 Oct 2018 14:45:27 -0700 Subject: [PATCH 2/2] Remove e-mail from trial flow Signed-off-by: Daniel Hiltgen (cherry picked from commit 0ff9e5cd10718af0649c6977fb043f6849802c63) Signed-off-by: Sebastiaan van Stijn --- cli/command/engine/activate_test.go | 2 +- internal/licenseutils/client_test.go | 6 +++--- internal/licenseutils/utils.go | 2 +- internal/licenseutils/utils_test.go | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cli/command/engine/activate_test.go b/cli/command/engine/activate_test.go index a740d18041..9eff3b8cf0 100644 --- a/cli/command/engine/activate_test.go +++ b/cli/command/engine/activate_test.go @@ -92,7 +92,7 @@ func (c mockLicenseClient) GetHubUserByName(ctx context.Context, username string func (c mockLicenseClient) VerifyLicense(ctx context.Context, license model.IssuedLicense) (res *model.CheckResponse, err error) { return nil, fmt.Errorf("not implemented") } -func (c mockLicenseClient) GenerateNewTrialSubscription(ctx context.Context, authToken, dockerID, email string) (subscriptionID string, err error) { +func (c mockLicenseClient) GenerateNewTrialSubscription(ctx context.Context, authToken, dockerID string) (subscriptionID string, err error) { return "", fmt.Errorf("not implemented") } func (c mockLicenseClient) ListSubscriptions(ctx context.Context, authToken, dockerID string) (response []*model.Subscription, err error) { diff --git a/internal/licenseutils/client_test.go b/internal/licenseutils/client_test.go index 40bb37f2de..b0b202ebb1 100644 --- a/internal/licenseutils/client_test.go +++ b/internal/licenseutils/client_test.go @@ -13,7 +13,7 @@ type ( getHubUserOrgsFunc func(ctx context.Context, authToken string) (orgs []model.Org, err error) getHubUserByNameFunc func(ctx context.Context, username string) (user *model.User, err error) verifyLicenseFunc func(ctx context.Context, license model.IssuedLicense) (res *model.CheckResponse, err error) - generateNewTrialSubscriptionFunc func(ctx context.Context, authToken, dockerID, email string) (subscriptionID string, err error) + generateNewTrialSubscriptionFunc func(ctx context.Context, authToken, dockerID string) (subscriptionID string, err error) listSubscriptionsFunc func(ctx context.Context, authToken, dockerID string) (response []*model.Subscription, err error) listSubscriptionsDetailsFunc func(ctx context.Context, authToken, dockerID string) (response []*model.SubscriptionDetail, err error) downloadLicenseFromHubFunc func(ctx context.Context, authToken, subscriptionID string) (license *model.IssuedLicense, err error) @@ -52,9 +52,9 @@ func (c *fakeLicensingClient) VerifyLicense(ctx context.Context, license model.I return nil, nil } -func (c *fakeLicensingClient) GenerateNewTrialSubscription(ctx context.Context, authToken, dockerID, email string) (subscriptionID string, err error) { +func (c *fakeLicensingClient) GenerateNewTrialSubscription(ctx context.Context, authToken, dockerID string) (subscriptionID string, err error) { if c.generateNewTrialSubscriptionFunc != nil { - return c.generateNewTrialSubscriptionFunc(ctx, authToken, dockerID, email) + return c.generateNewTrialSubscriptionFunc(ctx, authToken, dockerID) } return "", nil } diff --git a/internal/licenseutils/utils.go b/internal/licenseutils/utils.go index a6809d17ed..d9503dc652 100644 --- a/internal/licenseutils/utils.go +++ b/internal/licenseutils/utils.go @@ -134,7 +134,7 @@ func (u HubUser) GetAvailableLicenses(ctx context.Context) ([]LicenseDisplay, er // GenerateTrialLicense will generate a new trial license for the specified user or org func (u HubUser) GenerateTrialLicense(ctx context.Context, targetID string) (*model.IssuedLicense, error) { - subID, err := u.Client.GenerateNewTrialSubscription(ctx, u.token, targetID, u.User.Email) + subID, err := u.Client.GenerateNewTrialSubscription(ctx, u.token, targetID) if err != nil { return nil, err } diff --git a/internal/licenseutils/utils_test.go b/internal/licenseutils/utils_test.go index 1033640de2..68b67239fe 100644 --- a/internal/licenseutils/utils_test.go +++ b/internal/licenseutils/utils_test.go @@ -147,7 +147,7 @@ func TestGenerateTrialFail(t *testing.T) { ctx := context.Background() user := HubUser{ Client: &fakeLicensingClient{ - generateNewTrialSubscriptionFunc: func(ctx context.Context, authToken, dockerID, email string) (subscriptionID string, err error) { + generateNewTrialSubscriptionFunc: func(ctx context.Context, authToken, dockerID string) (subscriptionID string, err error) { return "", fmt.Errorf("generate trial failure") }, }, @@ -161,7 +161,7 @@ func TestGenerateTrialHappy(t *testing.T) { ctx := context.Background() user := HubUser{ Client: &fakeLicensingClient{ - generateNewTrialSubscriptionFunc: func(ctx context.Context, authToken, dockerID, email string) (subscriptionID string, err error) { + generateNewTrialSubscriptionFunc: func(ctx context.Context, authToken, dockerID string) (subscriptionID string, err error) { return "subid", nil }, },