-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get latest license on app install (#280)
* Get latest license on app install
- Loading branch information
Showing
7 changed files
with
59 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
package k8sdoc | ||
|
||
import () | ||
|
||
type Doc struct { | ||
APIVersion string `yaml:"apiVersion"` | ||
Kind string `yaml:"kind"` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
package types | ||
|
||
import ( | ||
"k8s.io/api/core/v1" | ||
) | ||
|
||
type DeployOptions struct { | ||
Namespace string | ||
Kubeconfig string | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package license | ||
|
||
import ( | ||
"encoding/base64" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
|
||
"github.com/pkg/errors" | ||
kotsv1beta1 "github.com/replicatedhq/kots/kotskinds/apis/kots/v1beta1" | ||
"github.com/replicatedhq/kots/kotskinds/client/kotsclientset/scheme" | ||
"github.com/replicatedhq/kots/pkg/version" | ||
) | ||
|
||
func GetLatestLicense(license *kotsv1beta1.License) (*kotsv1beta1.License, error) { | ||
url := fmt.Sprintf("%s/license/%s", license.Spec.Endpoint, license.Spec.AppSlug) | ||
|
||
req, err := http.NewRequest("GET", url, nil) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to call newrequest") | ||
} | ||
req.Header.Add("User-Agent", fmt.Sprintf("KOTS/%s", version.Version())) | ||
req.Header.Set("Authorization", fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", license.Spec.LicenseID, license.Spec.LicenseID))))) | ||
|
||
resp, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to execute get request") | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode >= 400 { | ||
return nil, errors.Wrap(err, "unexpected result from get request") | ||
} | ||
|
||
body, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to load response") | ||
} | ||
|
||
decode := scheme.Codecs.UniversalDeserializer().Decode | ||
obj, _, err := decode(body, nil, nil) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to decode latest license data") | ||
} | ||
latestLicense := obj.(*kotsv1beta1.License) | ||
|
||
return latestLicense, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters