mirror of https://github.com/docker/cli.git
Bump licensing library
Removes the billing profile flow which is now handled on the back-end. Signed-off-by: Daniel Hiltgen <daniel.hiltgen@docker.com>
This commit is contained in:
parent
8a424333f9
commit
8e565d0399
|
@ -22,7 +22,7 @@ github.com/docker/go-events 9461782956ad83b30282bf90e31fa6a70c255ba9
|
||||||
github.com/docker/go-metrics d466d4f6fd960e01820085bd7e1a24426ee7ef18
|
github.com/docker/go-metrics d466d4f6fd960e01820085bd7e1a24426ee7ef18
|
||||||
github.com/docker/go-units 47565b4f722fb6ceae66b95f853feed578a4a51c # v0.3.3
|
github.com/docker/go-units 47565b4f722fb6ceae66b95f853feed578a4a51c # v0.3.3
|
||||||
github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a
|
github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a
|
||||||
github.com/docker/licensing f2eae57157a06681b024f1690923d03e414179a0
|
github.com/docker/licensing 1c117a1720cb413dd6a101d36a6c567b1ccb90fe
|
||||||
github.com/docker/swarmkit cfa742c8abe6f8e922f6e4e920153c408e7d9c3b
|
github.com/docker/swarmkit cfa742c8abe6f8e922f6e4e920153c408e7d9c3b
|
||||||
github.com/flynn-archive/go-shlex 3f9db97f856818214da2e1057f8ad84803971cff
|
github.com/flynn-archive/go-shlex 3f9db97f856818214da2e1057f8ad84803971cff
|
||||||
github.com/ghodss/yaml 0ca9ea5df5451ffdf184b4428c902747c2c11cd7 # v1.0.0
|
github.com/ghodss/yaml 0ca9ea5df5451ffdf184b4428c902747c2c11cd7 # v1.0.0
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -28,7 +28,7 @@ type Client interface {
|
||||||
GetHubUserOrgs(ctx context.Context, authToken string) (orgs []model.Org, err error)
|
GetHubUserOrgs(ctx context.Context, authToken string) (orgs []model.Org, err error)
|
||||||
GetHubUserByName(ctx context.Context, username string) (user *model.User, 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)
|
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)
|
ListSubscriptions(ctx context.Context, authToken, dockerID string) (response []*model.Subscription, err error)
|
||||||
ListSubscriptionsDetails(ctx context.Context, authToken, dockerID string) (response []*model.SubscriptionDetail, 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)
|
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
|
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)
|
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{
|
sub, err := c.createSubscription(ctx, &model.SubscriptionCreationRequest{
|
||||||
Name: "Docker Enterprise Free Trial",
|
Name: "Docker Enterprise Free Trial",
|
||||||
DockerID: dockerID,
|
DockerID: dockerID,
|
||||||
|
@ -116,8 +94,7 @@ func (c *client) GenerateNewTrialSubscription(ctx context.Context, authToken, do
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.Wrap(err, errors.Fields{
|
return "", errors.Wrap(err, errors.Fields{
|
||||||
"dockerID": dockerID,
|
"docker_id": dockerID,
|
||||||
"email": email,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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})
|
subs, err := c.listSubscriptions(ctx, map[string]string{"docker_id": dockerID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, errors.Fields{
|
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})
|
subs, err := c.listSubscriptionsDetails(ctx, map[string]string{"docker_id": dockerID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, errors.Fields{
|
return nil, errors.Wrap(err, errors.Fields{
|
||||||
"dockerID": dockerID,
|
"docker_id": dockerID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -21,10 +21,6 @@ type User struct {
|
||||||
Company string `json:"company,omitempty"`
|
Company string `json:"company,omitempty"`
|
||||||
ProfileURL string `json:"profile_url,omitempty"`
|
ProfileURL string `json:"profile_url,omitempty"`
|
||||||
GravatarURL string `json:"gravatar_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
|
// Org details a Docker organization
|
||||||
|
|
Loading…
Reference in New Issue