Merge pull request #1473 from thaJeztah/master_bump_licensing_lib

[master] Bump licensing library
This commit is contained in:
Sebastiaan van Stijn 2019-01-08 00:41:07 +01:00 committed by GitHub
commit 7d9f2affc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 13 additions and 133 deletions

View File

@ -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) {

View File

@ -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
}

View File

@ -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
}

View File

@ -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
},
},

View File

@ -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

View File

@ -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
}

View File

@ -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,
})
}

View File

@ -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
}

View File

@ -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