Skip to content

Commit

Permalink
pull updates with app license from DB, not from app archive
Browse files Browse the repository at this point in the history
if the app archive fails to update, then the license may be out of date there
  • Loading branch information
laverya committed Aug 14, 2020
1 parent 615cbbe commit 186c8bd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
3 changes: 2 additions & 1 deletion kotsadm/pkg/license/license.go
Expand Up @@ -115,6 +115,7 @@ func createNewVersion(a *app.App, archiveDir string, registrySettings *registryt
return nil
}

// Gets the license as it was at a given app sequence
func GetCurrentLicenseString(a *app.App) (string, error) {
archiveDir, err := version.GetAppVersionArchive(a.ID, a.CurrentSequence)
if err != nil {
Expand All @@ -129,7 +130,7 @@ func GetCurrentLicenseString(a *app.App) (string, error) {
return string(kotsLicense), nil
}

// GetLicense gets the license for an application with the given app id
// GetLicense gets the current (latest) license for an application with the given app id
func Get(appID string) (*kotsv1beta1.License, error) {
db := persistence.MustGetPGSession()
query := `select kots_license from app_version where app_id = $1 order by sequence desc limit 1`
Expand Down
8 changes: 6 additions & 2 deletions kotsadm/pkg/updatechecker/updatechecker.go
Expand Up @@ -3,7 +3,6 @@ package updatechecker
import (
"fmt"
"os"
"path/filepath"
"sync"
"time"

Expand Down Expand Up @@ -186,8 +185,13 @@ func CheckForUpdates(appID string, deploy bool) (int64, error) {
return 0, errors.Wrap(err, "failed to load kotskinds from path")
}

latestLicense, err := license.Get(a.ID)
if err != nil {
return 0, errors.Wrap(err, "failed to get latest license")
}

getUpdatesOptions := kotspull.GetUpdatesOptions{
LicenseFile: filepath.Join(archiveDir, "upstream", "userdata", "license.yaml"),
License: latestLicense,
CurrentCursor: kotsKinds.Installation.Spec.UpdateCursor,
CurrentChannel: kotsKinds.Installation.Spec.ChannelName,
Silent: false,
Expand Down
8 changes: 7 additions & 1 deletion kotsadm/pkg/upstream/upstream.go
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/pkg/errors"
"github.com/replicatedhq/kots/kotsadm/pkg/app"
"github.com/replicatedhq/kots/kotsadm/pkg/kotsutil"
"github.com/replicatedhq/kots/kotsadm/pkg/license"
"github.com/replicatedhq/kots/kotsadm/pkg/logger"
"github.com/replicatedhq/kots/kotsadm/pkg/preflight"
"github.com/replicatedhq/kots/kotsadm/pkg/registry"
Expand Down Expand Up @@ -82,8 +83,13 @@ func DownloadUpdate(appID string, archiveDir string, toCursor string) (sequence
return 0, errors.Wrap(err, "failed to get new app sequence")
}

latestLicense, err := license.Get(a.ID)
if err != nil {
return 0, errors.Wrap(err, "failed to get latest license")
}

pullOptions := kotspull.PullOptions{
LicenseFile: filepath.Join(archiveDir, "upstream", "userdata", "license.yaml"),
LicenseObj: latestLicense,
Namespace: appNamespace,
ConfigFile: filepath.Join(archiveDir, "upstream", "userdata", "config.yaml"),
InstallationFile: filepath.Join(archiveDir, "upstream", "userdata", "installation.yaml"),
Expand Down
18 changes: 4 additions & 14 deletions pkg/pull/peek.go
Expand Up @@ -2,6 +2,7 @@ package pull

import (
"github.com/pkg/errors"
kotsv1beta1 "github.com/replicatedhq/kots/kotskinds/apis/kots/v1beta1"
"github.com/replicatedhq/kots/pkg/logger"
"github.com/replicatedhq/kots/pkg/upstream"
)
Expand All @@ -10,7 +11,7 @@ type GetUpdatesOptions struct {
HelmRepoURI string
Namespace string
LocalPath string
LicenseFile string
License *kotsv1beta1.License
CurrentCursor string
CurrentChannel string
Silent bool
Expand All @@ -33,19 +34,8 @@ func GetUpdates(upstreamURI string, getUpdatesOptions GetUpdatesOptions) ([]upst
fetchOptions.CurrentCursor = getUpdatesOptions.CurrentCursor
fetchOptions.CurrentChannel = getUpdatesOptions.CurrentChannel

if getUpdatesOptions.LicenseFile != "" {
license, err := ParseLicenseFromFile(getUpdatesOptions.LicenseFile)
if err != nil {
if errors.Cause(err) == ErrSignatureInvalid {
return nil, ErrSignatureInvalid
}
if errors.Cause(err) == ErrSignatureMissing {
return nil, ErrSignatureMissing
}
return nil, errors.Wrap(err, "failed to parse license from file")
}

fetchOptions.License = license
if getUpdatesOptions.License != nil {
fetchOptions.License = getUpdatesOptions.License
}

log.ActionWithSpinner("Listing releases")
Expand Down
5 changes: 4 additions & 1 deletion pkg/pull/pull.go
Expand Up @@ -31,6 +31,7 @@ type PullOptions struct {
Namespace string
Downstreams []string
LocalPath string
LicenseObj *kotsv1beta1.License
LicenseFile string
InstallationFile string
AirgapRoot string
Expand Down Expand Up @@ -117,7 +118,9 @@ func Pull(upstreamURI string, pullOptions PullOptions) (string, error) {
return "", errors.Wrap(err, "failed to find config files in local path")
}

if pullOptions.LicenseFile != "" {
if pullOptions.LicenseObj != nil {
fetchOptions.License = pullOptions.LicenseObj
} else if pullOptions.LicenseFile != "" {
license, err := ParseLicenseFromFile(pullOptions.LicenseFile)
if err != nil {
if errors.Cause(err) == ErrSignatureInvalid {
Expand Down

0 comments on commit 186c8bd

Please sign in to comment.