Skip to content
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

Allow getting versions for any package. #2935

Merged
merged 2 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions cmd/updater/versionCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,26 @@ import (
var (
destFile string
versionBucket string
packageName string
specificVersion uint64
semanticOutput bool
)

// DefaultPackageName is the package we'll use by default.
const DefaultPackageName = "node"

func init() {
versionCmd.AddCommand(checkCmd)
versionCmd.AddCommand(getCmd)

checkCmd.Flags().StringVarP(&versionBucket, "bucket", "b", "", "S3 bucket containing updates.")
checkCmd.Flags().BoolVarP(&semanticOutput, "semantic", "s", false, "Human readable semantic version output.")
checkCmd.Flags().StringVarP(&packageName, "package", "p", DefaultPackageName, "Get version of specific package.")
checkCmd.Flags().StringVarP(&versionBucket, "bucket", "b", "", "S3 bucket containing updates.")

getCmd.Flags().StringVarP(&destFile, "outputFile", "o", "", "Path for downloaded file (required).")
getCmd.Flags().StringVarP(&versionBucket, "bucket", "b", "", "S3 bucket containing updates.")
getCmd.Flags().Uint64VarP(&specificVersion, "version", "v", 0, "Specific version to download.")
getCmd.Flags().StringVarP(&packageName, "package", "p", DefaultPackageName, "Get version of specific package.")
getCmd.Flags().StringVarP(&versionBucket, "bucket", "b", "", "S3 bucket containing updates.")
getCmd.MarkFlagRequired("outputFile")
}

Expand All @@ -67,7 +73,7 @@ var checkCmd = &cobra.Command{
if err != nil {
exitErrorf("Error creating s3 session %s\n", err.Error())
} else {
version, _, err := s3Session.GetLatestUpdateVersion(channel)
version, _, err := s3Session.GetPackageVersion(channel, packageName, 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like you could deprecate GetLatestUpdateVersion with this change.

if err != nil {
exitErrorf("Error getting latest version from s3 %s\n", err.Error())
}
Expand Down Expand Up @@ -102,7 +108,7 @@ var getCmd = &cobra.Command{
if err != nil {
exitErrorf("Error creating s3 session %s\n", err.Error())
} else {
version, name, err := s3Session.GetUpdateVersion(channel, specificVersion)
version, name, err := s3Session.GetPackageVersion(channel, packageName, specificVersion)
winder marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
exitErrorf("Error getting latest version from s3 %s\n", err.Error())
}
Expand Down
11 changes: 0 additions & 11 deletions util/s3/s3Helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@ func makeS3Session(credentials *credentials.Credentials, bucket string) (helper
return
}

// GetLatestUpdateVersion returns the latest version details for the 'node' package
func (helper *Helper) GetLatestUpdateVersion(channel string) (maxVersion uint64, maxVersionName string, err error) {
return helper.GetUpdateVersion(channel, 0)
}

// GetLatestPackageVersion returns the latest version details for a given package name (eg node, install, tools)
func (helper *Helper) GetLatestPackageVersion(channel string, packageName string) (maxVersion uint64, maxVersionName string, err error) {
return helper.GetPackageVersion(channel, packageName, 0)
Expand All @@ -214,12 +209,6 @@ func (helper *Helper) GetLatestPackageFilesVersion(channel string, packagePrefix
return helper.GetPackageFilesVersion(channel, packagePrefix, 0)
}

// GetUpdateVersion ensures the specified version is present and returns the name of the file, if found
// Or if specificVersion == 0, returns the name of the file with the max version
func (helper *Helper) GetUpdateVersion(channel string, specificVersion uint64) (maxVersion uint64, maxVersionName string, err error) {
return helper.GetPackageVersion(channel, "node", specificVersion)
}

// DownloadFile downloads the specified file to the provided Writer
func (helper *Helper) DownloadFile(name string, writer io.WriterAt) error {
downloader := s3manager.NewDownloader(helper.session)
Expand Down