-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[18.09] Expose licensing details before loading #1387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| License: Quantity: 1 Nodes Expiration date: 2018-03-18 Expired! You will no longer receive updates. Please renew at https://docker.com/licensing |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package licenseutils | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
@@ -35,18 +36,22 @@ func (u HubUser) GetOrgByID(orgID string) (model.Org, error) { | |
| return model.Org{}, fmt.Errorf("org %s not found", orgID) | ||
| } | ||
|
|
||
| // Login to the license server and return a client that can be used to look up and download license files or generate new trial licenses | ||
| func Login(ctx context.Context, authConfig *types.AuthConfig) (HubUser, error) { | ||
| func getClient() (licensing.Client, error) { | ||
| baseURI, err := url.Parse(licensingDefaultBaseURI) | ||
| if err != nil { | ||
| return HubUser{}, err | ||
| return nil, err | ||
| } | ||
|
|
||
| lclient, err := licensing.New(&licensing.Config{ | ||
| return licensing.New(&licensing.Config{ | ||
| BaseURI: *baseURI, | ||
| HTTPClient: &http.Client{}, | ||
| PublicKeys: licensingPublicKeys, | ||
| }) | ||
| } | ||
|
|
||
| // Login to the license server and return a client that can be used to look up and download license files or generate new trial licenses | ||
| func Login(ctx context.Context, authConfig *types.AuthConfig) (HubUser, error) { | ||
| lclient, err := getClient() | ||
| if err != nil { | ||
| return HubUser{}, err | ||
| } | ||
|
|
@@ -143,20 +148,25 @@ func (u HubUser) GetIssuedLicense(ctx context.Context, ID string) (*model.Issued | |
|
|
||
| // LoadLocalIssuedLicense will load a local license file | ||
| func LoadLocalIssuedLicense(ctx context.Context, filename string) (*model.IssuedLicense, error) { | ||
| baseURI, err := url.Parse(licensingDefaultBaseURI) | ||
| lclient, err := getClient() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return doLoadLocalIssuedLicense(ctx, filename, lclient) | ||
| } | ||
|
|
||
| // GetLicenseSummary summarizes the license for the user | ||
| func GetLicenseSummary(ctx context.Context, license model.IssuedLicense) (string, error) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see a lot of code duplication between |
||
| lclient, err := getClient() | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| lclient, err := licensing.New(&licensing.Config{ | ||
| BaseURI: *baseURI, | ||
| HTTPClient: &http.Client{}, | ||
| PublicKeys: licensingPublicKeys, | ||
| }) | ||
| cr, err := lclient.VerifyLicense(ctx, license) | ||
| if err != nil { | ||
| return nil, err | ||
| return "", err | ||
| } | ||
| return doLoadLocalIssuedLicense(ctx, filename, lclient) | ||
| return lclient.SummarizeLicense(cr, license.KeyID).String(), nil | ||
| } | ||
|
|
||
| func doLoadLocalIssuedLicense(ctx context.Context, filename string, lclient licensing.Client) (*model.IssuedLicense, error) { | ||
|
|
@@ -165,6 +175,9 @@ func doLoadLocalIssuedLicense(ctx context.Context, filename string, lclient lice | |
| if err != nil { | ||
| return nil, err | ||
| } | ||
| // The file may contain a leading BOM, which will choke the | ||
| // json deserializer. | ||
| data = bytes.TrimPrefix(data, []byte("\xef\xbb\xbf")) | ||
|
|
||
| err = json.Unmarshal(data, &license) | ||
| if err != nil { | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Use
fmt.Fprintlninstead