Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion cli/cmd/download_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ type DownloadPackageCmd struct {
type DownloadPackageOpts struct {
GlobalOptions
Version string
Hash string
Filename string
}

func (c *DownloadPackageCmd) RunE(_ *cobra.Command, args []string) error {
fmt.Printf("Downloading package %s\n", c.Opts.Version)

p := portal.NewPortalClient()
build, err := p.GetBuild(portal.CodesphereProduct, c.Opts.Version)
build, err := p.GetBuild(portal.CodesphereProduct, c.Opts.Version, c.Opts.Hash)
if err != nil {
return fmt.Errorf("failed to get codesphere package: %w", err)
}
Expand Down Expand Up @@ -55,6 +56,7 @@ func AddDownloadPackageCmd(download *cobra.Command, opts GlobalOptions) {
FileWriter: util.NewFilesystemWriter(),
}
pkg.cmd.Flags().StringVarP(&pkg.Opts.Version, "version", "V", "", "Codesphere version to download")
pkg.cmd.Flags().StringVarP(&pkg.Opts.Hash, "hash", "H", "", "Codesphere version to download")
pkg.cmd.Flags().StringVarP(&pkg.Opts.Filename, "file", "f", "installer.tar.gz", "Specify artifact to download")
download.AddCommand(pkg.cmd)

Expand Down
Binary file modified cli/cmd/testdata/testcli.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion cli/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func AddUpdateCmd(rootCmd *cobra.Command) {
func (c *UpdateCmd) SelfUpdate(p portal.Portal) error {
currentVersion := semver.MustParse(c.Version.Version())

latest, err := p.GetBuild(portal.OmsProduct, "")
latest, err := p.GetBuild(portal.OmsProduct, "", "")
if err != nil {
return fmt.Errorf("failed to query OMS Portal for latest version: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var _ = Describe("Update", func() {
mockVersion.EXPECT().Arch().Return("fakearch")
mockVersion.EXPECT().Version().Return("0.0.0")
mockVersion.EXPECT().Os().Return("fakeos")
mockPortal.EXPECT().GetBuild(portal.OmsProduct, "").Return(latestBuild, nil)
mockPortal.EXPECT().GetBuild(portal.OmsProduct, "", "").Return(latestBuild, nil)
mockPortal.EXPECT().DownloadBuildArtifact(portal.OmsProduct, buildToDownload, mock.Anything).RunAndReturn(
func(product portal.Product, build portal.Build, file io.Writer) error {
embeddedFile, err := testdata.Open("testdata/testcli.tar.gz")
Expand All @@ -90,7 +90,7 @@ var _ = Describe("Update", func() {

It("Detects when current version is latest version", func() {
mockVersion.EXPECT().Version().Return(latestBuild.Version)
mockPortal.EXPECT().GetBuild(portal.OmsProduct, "").Return(latestBuild, nil)
mockPortal.EXPECT().GetBuild(portal.OmsProduct, "", "").Return(latestBuild, nil)
err := c.SelfUpdate(mockPortal)
Expect(err).NotTo(HaveOccurred())
})
Expand Down
17 changes: 10 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,28 @@ require (
github.com/onsi/gomega v1.37.0
github.com/spf13/cobra v1.9.1
github.com/stretchr/testify v1.10.0
golang.org/x/sync v0.14.0
golang.org/x/sync v0.16.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/stretchr/objx v0.5.2 // indirect
go.uber.org/automaxprocs v1.6.0 // indirect
golang.org/x/net v0.40.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/text v0.25.0 // indirect
golang.org/x/tools v0.31.0 // indirect
golang.org/x/net v0.43.0 // indirect
golang.org/x/sys v0.35.0 // indirect
golang.org/x/text v0.28.0 // indirect
golang.org/x/tools v0.36.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
44 changes: 26 additions & 18 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnweb
github.com/codesphere-cloud/cs-go v0.10.1 h1:QhiBKYkBlAeephPKfl0AY18MLGNdcY2uAjvncu7ezq8=
github.com/codesphere-cloud/cs-go v0.10.1/go.mod h1:lJENk49WB9ZIGeZdZdzERYlCxlpL1FNcN8oj/NjgUfw=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
Expand All @@ -19,8 +20,11 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jedib0t/go-pretty/v6 v6.6.7 h1:m+LbHpm0aIAPLzLbMfn8dc3Ht8MW7lsSO4MPItz/Uuo=
github.com/jedib0t/go-pretty/v6 v6.6.7/go.mod h1:YwC5CE4fJ1HFUDeivSV1r//AmANFHyqczZk+U6BDALU=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
Expand All @@ -29,13 +33,17 @@ github.com/onsi/ginkgo/v2 v2.23.4 h1:ktYTpKJAVZnDT4VjxSbiBenUjmlL/5QkBEocaWXiQus
github.com/onsi/ginkgo/v2 v2.23.4/go.mod h1:Bt66ApGPBFzHyR+JO10Zbt0Gsp4uWxu5mIOTusL46e8=
github.com/onsi/gomega v1.37.0 h1:CdEG8g0S133B4OswTDC/5XPSzE1OeP29QOioj2PID2Y=
github.com/onsi/gomega v1.37.0/go.mod h1:8D9+Txp43QWKhM24yyOBEdpkzN8FvJyAwecBgsU4KU0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
Expand All @@ -47,20 +55,20 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs=
go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwEFJ8r8=
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=
golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
golang.org/x/tools v0.31.0 h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU=
golang.org/x/tools v0.31.0/go.mod h1:naFTU+Cev749tSJRXJlna0T3WxKvb1kWEx15xA4SdmQ=
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
golang.org/x/tools v0.36.0 h1:kWS0uv/zsvHEle1LbV5LE8QujrxB3wfQyxHfhOk0Qkg=
golang.org/x/tools v0.36.0/go.mod h1:WBDiHKJK8YgLHlcQPYQzNCkUxUypCaa5ZegCVutKm+s=
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
10 changes: 6 additions & 4 deletions internal/portal/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

type Portal interface {
ListBuilds(product Product) (availablePackages Builds, err error)
GetBuild(product Product, version string) (Build, error)
GetBuild(product Product, version string, hash string) (Build, error)
DownloadBuildArtifact(product Product, build Build, file io.Writer) error
RegisterAPIKey(owner string, organization string, role string, expiresAt time.Time) error
RevokeAPIKey(key string) error
Expand Down Expand Up @@ -138,7 +138,7 @@ func (c *PortalClient) ListBuilds(product Product) (availablePackages Builds, er
return
}

func (c *PortalClient) GetBuild(product Product, version string) (Build, error) {
func (c *PortalClient) GetBuild(product Product, version string, hash string) (Build, error) {
packages, err := c.ListBuilds(product)
if err != nil {
return Build{}, fmt.Errorf("failed to list %s packages: %w", product, err)
Expand All @@ -149,14 +149,16 @@ func (c *PortalClient) GetBuild(product Product, version string) (Build, error)
}

if version == "" || version == "latest" {
// Builds are always ordered by date, newest build is latest version
return packages.Builds[len(packages.Builds)-1], nil
}

matchingPackages := []Build{}
for _, build := range packages.Builds {
if build.Version == version {
// Builds are always ordered by date, newest build is latest version
matchingPackages = append(matchingPackages, build)
if len(hash) == 0 || build.Hash == hash {
matchingPackages = append(matchingPackages, build)
}
}
}

Expand Down
70 changes: 68 additions & 2 deletions internal/portal/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,73 @@ var _ = Describe("PortalClient", func() {
Date: lastBuild,
Version: "1.42.1",
}
packages, err := client.GetBuild(portal.OmsProduct, "")
packages, err := client.GetBuild(portal.OmsProduct, "", "")
Expect(err).NotTo(HaveOccurred())
Expect(packages).To(Equal(expectedResult))
Expect(getUrl.String()).To(Equal("fake-portal.com/packages/oms"))
})
})

Context("When the build with version is included", func() {
BeforeEach(func() {
firstBuild, _ = time.Parse("2006-01-02", "2025-04-02")
lastBuild, _ = time.Parse("2006-01-02", "2025-05-01")

getPackagesResponse = portal.Builds{
Builds: []portal.Build{
{
Hash: "firstBuild",
Date: firstBuild,
Version: "1.42.0",
},
{
Hash: "lastBuild",
Date: lastBuild,
Version: "1.42.1",
},
},
}
})
It("returns the build", func() {
expectedResult := portal.Build{
Hash: "lastBuild",
Date: lastBuild,
Version: "1.42.1",
}
packages, err := client.GetBuild(portal.OmsProduct, "1.42.1", "")
Expect(err).NotTo(HaveOccurred())
Expect(packages).To(Equal(expectedResult))
Expect(getUrl.String()).To(Equal("fake-portal.com/packages/oms"))
})
})

Context("When the build with version and hash is included", func() {
BeforeEach(func() {
firstBuild, _ = time.Parse("2006-01-02", "2025-04-02")
lastBuild, _ = time.Parse("2006-01-02", "2025-05-01")

getPackagesResponse = portal.Builds{
Builds: []portal.Build{
{
Hash: "firstBuild",
Date: firstBuild,
Version: "1.42.0",
},
{
Hash: "lastBuild",
Date: lastBuild,
Version: "1.42.1",
},
},
}
})
It("returns the build", func() {
expectedResult := portal.Build{
Hash: "lastBuild",
Date: lastBuild,
Version: "1.42.1",
}
packages, err := client.GetBuild(portal.OmsProduct, "1.42.1", "lastBuild")
Expect(err).NotTo(HaveOccurred())
Expect(packages).To(Equal(expectedResult))
Expect(getUrl.String()).To(Equal("fake-portal.com/packages/oms"))
Expand All @@ -258,7 +324,7 @@ var _ = Describe("PortalClient", func() {
})
It("returns an error and an empty build", func() {
expectedResult := portal.Build{}
packages, err := client.GetBuild(portal.OmsProduct, "")
packages, err := client.GetBuild(portal.OmsProduct, "", "")
Expect(err).To(MatchError("no builds returned"))
Expect(packages).To(Equal(expectedResult))
Expect(getUrl.String()).To(Equal("fake-portal.com/packages/oms"))
Expand Down
27 changes: 14 additions & 13 deletions internal/portal/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion internal/portal/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type Artifact struct {
}

func (b *Build) GetBuildForDownload(filename string) (Build, error) {

for _, a := range b.Artifacts {
if a.Filename != filename {
continue
Expand Down
Binary file modified internal/util/testdata/testdata1.tar.gz
Binary file not shown.