Skip to content

Commit 3eb3945

Browse files
Ryan Hallbjanice75
Ryan Hall
andauthored
[feat]: Add Auto-Accept EULA functionality to OM (#652)
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 <[email protected]> Co-authored-by: Janice Bailey <[email protected]>
1 parent 2101f22 commit 3eb3945

File tree

5 files changed

+103
-4
lines changed

5 files changed

+103
-4
lines changed

configtemplate/metadata/pivnet_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ var _ = Describe("Pivnet Client", func() {
1717
server.RouteToHandler("GET", "/api/v2/products/example-product/releases/1",
1818
ghttp.RespondWith(http.StatusOK, `{"id":1}`),
1919
)
20+
server.RouteToHandler("POST", "/api/v2/products/example-product/releases/1/pivnet_resource_eula_acceptance",
21+
ghttp.RespondWith(http.StatusOK, `{}`),
22+
)
2023
server.RouteToHandler("GET", "/api/v2/products/example-product/releases/1/file_groups",
2124
ghttp.RespondWith(http.StatusOK, `{}`),
2225
)

depstability/records/depnames-7.11.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ github.com/go-ole/go-ole
7373
github.com/go-playground/locales
7474
github.com/go-playground/universal-translator
7575
github.com/go-task/slim-sprig
76+
github.com/go-task/slim-sprig/v3
7677
github.com/gofrs/uuid
7778
github.com/golang-jwt/jwt/v4
7879
github.com/golang/glog

download_clients/fakes/pivnet_downloader_service.go

+75
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

download_clients/pivnet_client.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ package download_clients
22

33
import (
44
"fmt"
5-
"github.com/pivotal-cf/go-pivnet/v6/logshim"
6-
"github.com/pivotal-cf/pivnet-cli/v2/filter"
75
"io"
86
"log"
97
"os"
108
"path"
119
"strconv"
1210
"strings"
1311

12+
"github.com/pivotal-cf/go-pivnet/v6/logshim"
13+
"github.com/pivotal-cf/pivnet-cli/v2/filter"
14+
1415
"github.com/pivotal-cf/go-pivnet/v6"
1516
"github.com/pivotal-cf/go-pivnet/v6/download"
1617
pivnetlog "github.com/pivotal-cf/go-pivnet/v6/logger"
@@ -24,6 +25,7 @@ type PivnetDownloader interface {
2425
ProductFilesForRelease(productSlug string, releaseID int) ([]pivnet.ProductFile, error)
2526
DownloadProductFile(location *download.FileInfo, productSlug string, releaseID int, productFileID int, progressWriter io.Writer) error
2627
ReleaseDependencies(productSlug string, releaseID int) ([]pivnet.ReleaseDependency, error)
28+
AcceptEULA(productSlug string, releaseID int) error
2729
}
2830

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

100+
err = p.downloader.AcceptEULA(slug, release.ID)
101+
if err != nil {
102+
return nil, fmt.Errorf("could not accept EULA for download product file %s at version %s: %s", slug, version, err)
103+
}
104+
98105
// 2. Get filename from pivnet
99106
productFiles, err := p.downloader.ProductFilesForRelease(slug, release.ID)
100107
if err != nil {

download_clients/pivnet_client_test.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import (
44
"bytes"
55
"errors"
66
"fmt"
7-
"github.com/onsi/gomega/ghttp"
8-
pivnetlog "github.com/pivotal-cf/go-pivnet/v6/logger"
97
"io/ioutil"
108
"log"
119
"net/http"
1210
"time"
1311

12+
"github.com/onsi/gomega/ghttp"
13+
pivnetlog "github.com/pivotal-cf/go-pivnet/v6/logger"
14+
1415
. "github.com/onsi/ginkgo"
1516
. "github.com/onsi/gomega"
1617
"github.com/pivotal-cf/go-pivnet/v6"
@@ -57,6 +58,10 @@ var _ = Describe("Grabbing Metadata", func() {
5758
ghttp.VerifyRequest("GET", "/api/v2/products/pivnet-product/releases/24"),
5859
ghttp.RespondWith(http.StatusOK, `{"id":24}`),
5960
),
61+
ghttp.CombineHandlers(
62+
ghttp.VerifyRequest("POST", "/api/v2/products/pivnet-product/releases/24/pivnet_resource_eula_acceptance"),
63+
ghttp.RespondWith(http.StatusOK, ""),
64+
),
6065
ghttp.CombineHandlers(
6166
ghttp.VerifyRequest("GET", "/api/v2/products/pivnet-product/releases/24/product_files"),
6267
ghttp.RespondWith(http.StatusOK, fmt.Sprintf(`{
@@ -189,6 +194,14 @@ var _ = Describe("PivnetClient", func() {
189194
Expect(err).To(MatchError(ContainSubstring("could not fetch the release for someslug")))
190195
})
191196

197+
It("returns an error if it could not accept the EULA", func() {
198+
fakePivnetDownloader.AcceptEULAReturns(errors.New("some error"))
199+
200+
client := download_clients.NewPivnetClient(stdout, stderr, fakePivnetFactory, "", true, "")
201+
_, err := client.GetLatestProductFile("someslug", "1.0.0", "*.zip")
202+
Expect(err).To(MatchError(ContainSubstring("could not accept EULA")))
203+
})
204+
192205
It("returns an error if product files are not available for a slug", func() {
193206
fakePivnetDownloader.ReleaseForVersionReturns(createRelease("1.0.0"), nil)
194207
fakePivnetDownloader.ProductFilesForReleaseReturns([]pivnet.ProductFile{}, errors.New("some error"))

0 commit comments

Comments
 (0)