Skip to content

Commit

Permalink
[feat]: Add Auto-Accept EULA functionality to OM (#652)
Browse files Browse the repository at this point in the history
feat: Adds Auto-Accept EULA functionality when Downloading products.

Because of the great migration from TanzuNet to RMT, not all EULA data will potentially transfer, so this version of OM added the `AcceptEula` pivnet_client functionality to the `PivnetDownloader` interface. This allows the Pivnet client to Auto-Accept the EULA for the product it downloads, while also allowing the mock to be generated for accurate testing.


Co-authored-by: Ryan Hall <hallr@vmware.com>
Co-authored-by: Janice Bailey <bjanice@vmware.com>
  • Loading branch information
rhall-pivotal and bjanice75 committed Jun 17, 2024
1 parent 2101f22 commit 3eb3945
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 4 deletions.
3 changes: 3 additions & 0 deletions configtemplate/metadata/pivnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ var _ = Describe("Pivnet Client", func() {
server.RouteToHandler("GET", "/api/v2/products/example-product/releases/1",
ghttp.RespondWith(http.StatusOK, `{"id":1}`),
)
server.RouteToHandler("POST", "/api/v2/products/example-product/releases/1/pivnet_resource_eula_acceptance",
ghttp.RespondWith(http.StatusOK, `{}`),
)
server.RouteToHandler("GET", "/api/v2/products/example-product/releases/1/file_groups",
ghttp.RespondWith(http.StatusOK, `{}`),
)
Expand Down
1 change: 1 addition & 0 deletions depstability/records/depnames-7.11.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ github.com/go-ole/go-ole
github.com/go-playground/locales
github.com/go-playground/universal-translator
github.com/go-task/slim-sprig
github.com/go-task/slim-sprig/v3
github.com/gofrs/uuid
github.com/golang-jwt/jwt/v4
github.com/golang/glog
Expand Down
75 changes: 75 additions & 0 deletions download_clients/fakes/pivnet_downloader_service.go

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

11 changes: 9 additions & 2 deletions download_clients/pivnet_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package download_clients

import (
"fmt"
"github.com/pivotal-cf/go-pivnet/v6/logshim"
"github.com/pivotal-cf/pivnet-cli/v2/filter"
"io"
"log"
"os"
"path"
"strconv"
"strings"

"github.com/pivotal-cf/go-pivnet/v6/logshim"
"github.com/pivotal-cf/pivnet-cli/v2/filter"

"github.com/pivotal-cf/go-pivnet/v6"
"github.com/pivotal-cf/go-pivnet/v6/download"
pivnetlog "github.com/pivotal-cf/go-pivnet/v6/logger"
Expand All @@ -24,6 +25,7 @@ type PivnetDownloader interface {
ProductFilesForRelease(productSlug string, releaseID int) ([]pivnet.ProductFile, error)
DownloadProductFile(location *download.FileInfo, productSlug string, releaseID int, productFileID int, progressWriter io.Writer) error
ReleaseDependencies(productSlug string, releaseID int) ([]pivnet.ReleaseDependency, error)
AcceptEULA(productSlug string, releaseID int) error
}

type PivnetFactory func(ts pivnet.AccessTokenService, config pivnet.ClientConfig, logger pivnetlog.Logger) PivnetDownloader
Expand Down Expand Up @@ -95,6 +97,11 @@ func (p *pivnetClient) GetLatestProductFile(slug, version, glob string) (FileArt
return nil, fmt.Errorf("could not fetch the release for %s %s: %s", slug, version, err)
}

err = p.downloader.AcceptEULA(slug, release.ID)
if err != nil {
return nil, fmt.Errorf("could not accept EULA for download product file %s at version %s: %s", slug, version, err)
}

// 2. Get filename from pivnet
productFiles, err := p.downloader.ProductFilesForRelease(slug, release.ID)
if err != nil {
Expand Down
17 changes: 15 additions & 2 deletions download_clients/pivnet_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"bytes"
"errors"
"fmt"
"github.com/onsi/gomega/ghttp"
pivnetlog "github.com/pivotal-cf/go-pivnet/v6/logger"
"io/ioutil"
"log"
"net/http"
"time"

"github.com/onsi/gomega/ghttp"
pivnetlog "github.com/pivotal-cf/go-pivnet/v6/logger"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/pivotal-cf/go-pivnet/v6"
Expand Down Expand Up @@ -57,6 +58,10 @@ var _ = Describe("Grabbing Metadata", func() {
ghttp.VerifyRequest("GET", "/api/v2/products/pivnet-product/releases/24"),
ghttp.RespondWith(http.StatusOK, `{"id":24}`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/api/v2/products/pivnet-product/releases/24/pivnet_resource_eula_acceptance"),
ghttp.RespondWith(http.StatusOK, ""),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/api/v2/products/pivnet-product/releases/24/product_files"),
ghttp.RespondWith(http.StatusOK, fmt.Sprintf(`{
Expand Down Expand Up @@ -189,6 +194,14 @@ var _ = Describe("PivnetClient", func() {
Expect(err).To(MatchError(ContainSubstring("could not fetch the release for someslug")))
})

It("returns an error if it could not accept the EULA", func() {
fakePivnetDownloader.AcceptEULAReturns(errors.New("some error"))

client := download_clients.NewPivnetClient(stdout, stderr, fakePivnetFactory, "", true, "")
_, err := client.GetLatestProductFile("someslug", "1.0.0", "*.zip")
Expect(err).To(MatchError(ContainSubstring("could not accept EULA")))
})

It("returns an error if product files are not available for a slug", func() {
fakePivnetDownloader.ReleaseForVersionReturns(createRelease("1.0.0"), nil)
fakePivnetDownloader.ProductFilesForReleaseReturns([]pivnet.ProductFile{}, errors.New("some error"))
Expand Down

0 comments on commit 3eb3945

Please sign in to comment.