Skip to content

Commit

Permalink
Merge pull request #11 from vmware-labs/drivers-tools
Browse files Browse the repository at this point in the history
Add drivers_tools, custom_isos and addons
  • Loading branch information
laidbackware authored Dec 8, 2023
2 parents 9fbc1fd + 7502995 commit 8b27de8
Show file tree
Hide file tree
Showing 27 changed files with 246 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19.3
go-version: 1.21.4

- name: Checkout Code
uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions api/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"github.com/vmware-labs/vmware-customer-connect-sdk/sdk"
)

func FetchDownloadPayload(slug, subProduct, version, fileName, username, password string, acceptEula bool) (data []sdk.DownloadPayload, err error) {
func FetchDownloadPayload(slug, subProduct, version, fileName, username, password, dlgType string, acceptEula bool) (data []sdk.DownloadPayload, err error) {
if err = EnsureLogin(username, password); err != nil {
return
}

data, err = authenticatedClient.GenerateDownloadPayload(slug, subProduct, version, fileName, acceptEula)
data, err = authenticatedClient.GenerateDownloadPayload(slug, subProduct, version, fileName, dlgType, acceptEula)
if err != nil {
return
}
Expand Down
14 changes: 7 additions & 7 deletions api/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func TestFetchDownloadLinkVersionGlob(t *testing.T) {
var downloadPayload []sdk.DownloadPayload
downloadPayload, err = FetchDownloadPayload("vmware_tools", "vmtools", "11.*", "VMware-Tools-darwin-*.tar.gz", testing_user, testing_pass, true)
downloadPayload, err = FetchDownloadPayload("vmware_tools", "vmtools", "11.*", "VMware-Tools-darwin-*.tar.gz", testing_user, testing_pass, "PRODUCT_BINARY", true)
require.Nil(t, err)
require.NotEmpty(t, downloadPayload)
assert.NotEmpty(t, downloadPayload[0].DlgType, "Expected response not to be empty")
Expand All @@ -29,7 +29,7 @@ func TestFetchDownloadLinkVersionGlob(t *testing.T) {

func TestFetchDownloadPayloadVersionGlobMultiple(t *testing.T) {
var downloadPayload []sdk.DownloadPayload
downloadPayload, err = FetchDownloadPayload("vmware_tools", "vmtools", "11.*", "VMware-Tools-*", testing_user, testing_pass, true)
downloadPayload, err = FetchDownloadPayload("vmware_tools", "vmtools", "11.*", "VMware-Tools-*", testing_user, testing_pass, "PRODUCT_BINARY", true)
require.Nil(t, err)
require.NotEmpty(t, downloadPayload)
assert.NotEmpty(t, downloadPayload[0].DlgType, "Expected response not to be empty")
Expand All @@ -38,35 +38,35 @@ func TestFetchDownloadPayloadVersionGlobMultiple(t *testing.T) {

func TestFetchDownloadLinkInvalidVersion(t *testing.T) {
var downloadPayload []sdk.DownloadPayload
downloadPayload, err = FetchDownloadPayload("vmware_tools", "vmtools", "666", "VMware-Tools-darwin-*.tar.gz", testing_user, testing_pass, true)
downloadPayload, err = FetchDownloadPayload("vmware_tools", "vmtools", "666", "VMware-Tools-darwin-*.tar.gz", testing_user, testing_pass, "PRODUCT_BINARY", true)
assert.ErrorIs(t, err, sdk.ErrorInvalidVersion)
assert.Empty(t, downloadPayload, "Expected response to be empty")
}

func TestFetchDownloadLinkNeedEula(t *testing.T) {
var downloadPayload []sdk.DownloadPayload
downloadPayload, err = FetchDownloadPayload("vmware_tools", "vmtools", "11.1.0", "VMware-Tools-darwin-*.tar.gz", testing_user, testing_pass, false)
downloadPayload, err = FetchDownloadPayload("vmware_tools", "vmtools", "11.1.0", "VMware-Tools-darwin-*.tar.gz", testing_user, testing_pass, "PRODUCT_BINARY", false)
assert.ErrorIs(t, err, sdk.ErrorEulaUnaccepted)
assert.Empty(t, downloadPayload, "Expected response to be empty")
}

func TestFetchDownloadLinkNotEntitled(t *testing.T) {
var downloadPayload []sdk.DownloadPayload
downloadPayload, err = FetchDownloadPayload("vmware_nsx_t_data_center", "nsx-t", "3.2.3.1", "nsx-unified-appliance-secondary-*.qcow2", testing_user, testing_pass, true)
downloadPayload, err = FetchDownloadPayload("vmware_nsx_t_data_center", "nsx-t", "3.2.3.1", "nsx-unified-appliance-secondary-*.qcow2", testing_user, testing_pass, "PRODUCT_BINARY", true)
assert.ErrorIs(t, err, sdk.ErrorNotEntitled)
assert.Empty(t, downloadPayload, "Expected response to be empty")
}

func TestGenerateDownloadInvalidVersionGlob(t *testing.T) {
var downloadPayload []sdk.DownloadPayload
downloadPayload, err = FetchDownloadPayload("vmware_tools", "vmtools", "666.*", "VMware-Tools-darwin-*.tar.gz", testing_user, testing_pass, true)
downloadPayload, err = FetchDownloadPayload("vmware_tools", "vmtools", "666.*", "VMware-Tools-darwin-*.tar.gz", testing_user, testing_pass, "PRODUCT_BINARY", true)
assert.ErrorIs(t, err, sdk.ErrorNoMatchingVersions)
assert.Empty(t, downloadPayload, "Expected response to be empty")
}

func TestGenerateDownloadDoubleVersion(t *testing.T) {
var downloadPayload []sdk.DownloadPayload
downloadPayload, err = FetchDownloadPayload("vmware_tools", "vmtools", "*.*", "VMware-Tools-darwin-*.tar.gz", testing_user, testing_pass, true)
downloadPayload, err = FetchDownloadPayload("vmware_tools", "vmtools", "*.*", "VMware-Tools-darwin-*.tar.gz", testing_user, testing_pass, "PRODUCT_BINARY", true)
assert.ErrorIs(t, err, sdk.ErrorMultipleVersionGlob)
assert.Empty(t, downloadPayload, "Expected response to be empty")
}
4 changes: 2 additions & 2 deletions api/eula.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
)


func GetEula(slug, subProduct, version, username, password string) (data string, err error) {
func GetEula(slug, subProduct, version, username, password, dlgType string) (data string, err error) {
var productID string
var apiVersions sdk.APIVersions
productID, apiVersions, err = basicClient.GetDlgProduct(slug, subProduct, version)
productID, apiVersions, err = basicClient.GetDlgProduct(slug, subProduct, version, dlgType)
if err != nil {
return
}
Expand Down
8 changes: 4 additions & 4 deletions api/eula_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ import (
)

func TestGetEula(t *testing.T) {
eulaUrl, err := GetEula("vmware_tools", "vmtools", "11.1.1", testing_user, testing_pass)
eulaUrl, err := GetEula("vmware_tools", "vmtools", "11.1.1", testing_user, testing_pass, "PRODUCT_BINARY")
assert.Nil(t, err)
assert.NotEmpty(t, eulaUrl)
}

func TestGetEulaInvalidSlug(t *testing.T) {
eulaUrl, err := GetEula("tools", "vmtools", "", testing_user, testing_pass)
eulaUrl, err := GetEula("tools", "vmtools", "", testing_user, testing_pass, "PRODUCT_BINARY")
assert.ErrorIs(t, err, sdk.ErrorInvalidSlug)
assert.Empty(t, eulaUrl)
}

func TestGetEulaInvalidSubProduct(t *testing.T) {
eulaUrl, err := GetEula("vmware_tools", "tools", "", testing_user, testing_pass)
eulaUrl, err := GetEula("vmware_tools", "tools", "", testing_user, testing_pass, "PRODUCT_BINARY")
assert.ErrorIs(t, err, sdk.ErrorInvalidSubProduct)
assert.Empty(t, eulaUrl)
}

func TestGetEulaInvalidVersion(t *testing.T) {
eulaUrl, err := GetEula("vmware_tools", "vmtools", "666", testing_user, testing_pass)
eulaUrl, err := GetEula("vmware_tools", "vmtools", "666", testing_user, testing_pass, "PRODUCT_BINARY")
assert.ErrorIs(t, err, sdk.ErrorInvalidVersion)
assert.Empty(t, eulaUrl)
}
8 changes: 4 additions & 4 deletions api/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ type Availability struct {
EligibleToDownload bool
}

func ListFiles(slug, subProduct, version, username, password string) (dlgDetails sdk.DlgDetails, apiVersions sdk.APIVersions, err error) {
func ListFiles(slug, subProduct, version, username, password, dlgType string) (dlgDetails sdk.DlgDetails, apiVersions sdk.APIVersions, err error) {
if err = EnsureLogin(username, password); err != nil {
return
}

var productID string
productID, apiVersions, err = authenticatedClient.GetDlgProduct(slug, subProduct, version)
productID, apiVersions, err = authenticatedClient.GetDlgProduct(slug, subProduct, version, dlgType)
if err != nil {
return
}
Expand All @@ -35,8 +35,8 @@ func ListFiles(slug, subProduct, version, username, password string) (dlgDetails
return
}

func ListFilesArray(slug, subProduct, version, username, password string) (data [][]string, availability Availability, apiVersions sdk.APIVersions, err error) {
dlgDetails, apiVersions, err := ListFiles(slug, subProduct, version, username, password)
func ListFilesArray(slug, subProduct, version, username, password, dlgType string) (data [][]string, availability Availability, apiVersions sdk.APIVersions, err error) {
dlgDetails, apiVersions, err := ListFiles(slug, subProduct, version, username, password, dlgType)
if err != nil {
return
}
Expand Down
10 changes: 5 additions & 5 deletions api/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,33 @@ var testing_user = mustEnv("VCC_USER")
var testing_pass = mustEnv("VCC_PASS")

func TestGetFiles(t *testing.T) {
files, availability, apiVersions, err := ListFilesArray("vmware_tools", "vmtools", "11.1.1", testing_user, testing_pass)
files, availability, apiVersions, err := ListFilesArray("vmware_tools", "vmtools", "11.1.1", testing_user, testing_pass, "PRODUCT_BINARY")
assert.Nil(t, err)
assert.Greater(t, len(files), 5, "Expected response to contain at least 5 items")
assert.Equal(t, apiVersions.MinorVersion, "11.1.1")
assert.True(t, availability.EligibleToDownload)
}

func TestGetFilesInvalidSlug(t *testing.T) {
files, _, _, err := ListFilesArray("tools", "vmtools", "", testing_user, testing_pass)
files, _, _, err := ListFilesArray("tools", "vmtools", "", testing_user, testing_pass, "PRODUCT_BINARY")
assert.ErrorIs(t, err, sdk.ErrorInvalidSlug)
assert.Empty(t, files, "Expected response to be empty")
}

func TestGetFilesInvalidSubProduct(t *testing.T) {
files, _, _, err := ListFilesArray("vmware_tools", "tools", "", testing_user, testing_pass)
files, _, _, err := ListFilesArray("vmware_tools", "tools", "", testing_user, testing_pass, "PRODUCT_BINARY")
assert.ErrorIs(t, err, sdk.ErrorInvalidSubProduct)
assert.Empty(t, files, "Expected response to be empty")
}

func TestGetFilesInvalidVersion(t *testing.T) {
files, _, _, err := ListFilesArray("vmware_tools", "vmtools", "666", testing_user, testing_pass)
files, _, _, err := ListFilesArray("vmware_tools", "vmtools", "666", testing_user, testing_pass, "PRODUCT_BINARY")
assert.ErrorIs(t, err, sdk.ErrorInvalidVersion)
assert.Empty(t, files, "Expected response to be empty")
}

func TestGetFilesNotEntitled(t *testing.T) {
files, availability, apiVersions, err := ListFilesArray("vmware_nsx_t_data_center", "nsx-t", "3.2.3.1", testing_user, testing_pass)
files, availability, apiVersions, err := ListFilesArray("vmware_nsx_t_data_center", "nsx-t", "3.2.3.1", testing_user, testing_pass, "PRODUCT_BINARY")
assert.Nil(t, err)
assert.Greater(t, len(files), 5, "Expected response to contain at least 5 items")
assert.Equal(t, apiVersions.MinorVersion, "3.2.3.1")
Expand Down
19 changes: 19 additions & 0 deletions api/major_versions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2022 VMware, Inc.
// SPDX-License-Identifier: Apache 2.0

package api

import (
"fmt"
"strings"
)

func GetMajorVersionsString(slug string) (majorVersionString string, err error) {
var majorVersionSlice []string
majorVersionSlice, err = basicClient.GetMajorVersionsSlice(slug)
if err != nil {
return
}
majorVersionString = fmt.Sprintf("'%s'", strings.Join(majorVersionSlice,"', '"))
return
}
19 changes: 19 additions & 0 deletions api/major_versions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2022 VMware, Inc.
// SPDX-License-Identifier: Apache 2.0

package api

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
// "github.com/vmware-labs/vmware-customer-connect-sdk/sdk"
)

func TestGetGetMajorVersionsString(t *testing.T) {
var majorVersions string
majorVersions, err := GetMajorVersionsString("vmware_vsphere")
require.Nil(t, err)
assert.Contains(t, majorVersions, "8_0")
}
9 changes: 3 additions & 6 deletions api/subproducts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
package api

import (
// "fmt"
// "os"

"github.com/vmware-labs/vmware-customer-connect-sdk/sdk"
)

func ListSubProducts(slug string) (data [][]string, err error) {
func ListSubProducts(slug, dlgType, majorVersion string) (data [][]string, err error) {
var subProducts []sdk.SubProductDetails
subProducts, err = basicClient.GetSubProductsSlice(slug)
subProducts, err = basicClient.GetSubProductsSlice(slug, dlgType, majorVersion)
if err != nil {
return
}
Expand All @@ -22,4 +19,4 @@ func ListSubProducts(slug string) (data [][]string, err error) {
}

return
}
}
14 changes: 11 additions & 3 deletions api/subproducts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ import (

func TestGetSubProducts(t *testing.T) {
var products [][]string
products, err := ListSubProducts("vmware_tools")
products, err := ListSubProducts("vmware_tools", "PRODUCT_BINARY", "")
require.Nil(t, err)
assert.NotEmpty(t, products)
}

func TestGetSubProductsDriversMajorVersion(t *testing.T) {
var products [][]string
products, err := ListSubProducts("vmware_vsphere", "DRIVERS_TOOLS", "8_0")
require.Nil(t, err)
assert.NotEmpty(t, products)
assert.LessOrEqual(t, len(products), 400)
}

func TestGetSubProductsInvalidSlug(t *testing.T) {
versions, err := ListVersions("tools", "vmtools")
products, err := ListSubProducts("tools", "PRODUCT_BINARY", "")
assert.ErrorIs(t, err, sdk.ErrorInvalidSlug)
assert.Empty(t, versions, "Expected response to be empty")
assert.Empty(t, products, "Expected response to be empty")
}
4 changes: 2 additions & 2 deletions api/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"strings"
)

func ListVersions(slug, subProduct string) (data string, err error) {
versionArray, err := basicClient.GetVersionSlice(slug, subProduct)
func ListVersions(slug, subProduct, dlgType string) (data string, err error) {
versionArray, err := basicClient.GetVersionSlice(slug, subProduct, dlgType)
if err != nil {
return
}
Expand Down
6 changes: 3 additions & 3 deletions api/versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ import (
)

func TestGetVersions(t *testing.T) {
versions, err := ListVersions("vmware_tools", "vmtools")
versions, err := ListVersions("vmware_tools", "vmtools", "PRODUCT_BINARY")
require.Nil(t, err)
assert.Greater(t, len(versions), 10, "Expected response to contain at least 10 items")
}

func TestGetVersionsInvalidSlug(t *testing.T) {
versions, err := ListVersions("tools", "vmtools")
versions, err := ListVersions("tools", "vmtools", "PRODUCT_BINARY")
assert.ErrorIs(t, err, sdk.ErrorInvalidSlug)
assert.Empty(t, versions, "Expected response to be empty")
}

func TestGetVersionsInvalidSubProduct(t *testing.T) {
versions, err := ListVersions("vmware_tools", "tools")
versions, err := ListVersions("vmware_tools", "tools", "PRODUCT_BINARY")
assert.ErrorIs(t, err, sdk.ErrorInvalidSubProduct)
assert.Empty(t, versions, "Expected response to be empty")
}
3 changes: 3 additions & 0 deletions cmd/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const (
getVersions = ` # List of available versions of sub-products vmtools of vmware_tools
vcc get versions -p vmware_tools -s vmtools`

getMajorVersions = ` # List of available major versions of product vmware_tools
vcc get versions -p vmware_tools`

getFiles = ` # List of available files of version 11.3.0 of vmware_tools
vcc get files -p vmware_tools -s vmtools -v 11.3.0`

Expand Down
12 changes: 7 additions & 5 deletions cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
)

var (
manifestFile string
fileName string
acceptEula bool
outputDir string
fileName string
forceDownload bool
outputDir string
manifestFile string
)

// downloadCmd represents the download command
Expand All @@ -36,6 +36,7 @@ Either VCC_USER and VCC_PASS environment variable must be set
or the --user and --pass flags should be added`,
Example: downloadUsage,
Run: func(cmd *cobra.Command, args []string) {
dlgType = validateDlgType(dlgType)
validateCredentials(cmd)
validateOutputDir()
manifestWorkflow := validateDownloadFlags(cmd)
Expand All @@ -45,7 +46,7 @@ or the --user and --pass flags should be added`,
downloadFromManifest()
} else {
fmt.Println("Collecting download payload")
downloadPayloads, err := api.FetchDownloadPayload(slug, subProduct, version, fileName, username, password, acceptEula)
downloadPayloads, err := api.FetchDownloadPayload(slug, subProduct, version, fileName, username, password, dlgType, acceptEula)
handleErrors(err)
downloadFiles(downloadPayloads)
}
Expand All @@ -71,7 +72,7 @@ func downloadFromManifest() {
fmt.Printf("Collecting download payload for [%s] [%s] [%s] [%s]\n", manifestSpec.Slug, manifestSpec.SubProduct,
manifestSpec.Version, glob)
downloadPayloads, err := api.FetchDownloadPayload(manifestSpec.Slug, manifestSpec.SubProduct, manifestSpec.Version,
glob, username, password, acceptEula)
glob, username, password, dlgType, acceptEula)
handleErrors(err)
allPayloads = append(allPayloads, downloadPayloads)
}
Expand Down Expand Up @@ -138,4 +139,5 @@ func init() {
downloadCmd.Flags().StringVarP(&outputDir, "output", "o", "", "Directory to download files to")
downloadCmd.Flags().BoolVarP(&acceptEula, "accepteula", "a", false, "Filename string")
downloadCmd.Flags().BoolVarP(&forceDownload, "forcedownload", "d", false, "(optional) Force a file to be re-downloaded even if it already exists")
downloadCmd.Flags().StringVarP(&dlgType, "type", "t", "product_binary", "(optional) Download type. One of: (product_binary, drivers_tools, custom_iso, addons). Default: product_binary")
}
4 changes: 3 additions & 1 deletion cmd/eula.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ Either VCC_USER and VCC_PASS environment variable must be set
or the --user and --pass flags should be added`,
Example: getFiles,
Run: func(cmd *cobra.Command, args []string) {
dlgType = validateDlgType(dlgType)
validateCredentials(cmd)
eula, err := api.GetEula(slug, subProduct, version, username, password)
eula, err := api.GetEula(slug, subProduct, version, username, password, dlgType)
handleErrors(err)
fmt.Printf("Open the URL in your browser: %s\n", eula)
},
Expand All @@ -36,4 +37,5 @@ func init() {
eulaCmd.MarkFlagRequired("product")
eulaCmd.MarkFlagRequired("sub-product")
eulaCmd.MarkFlagRequired("version")
eulaCmd.Flags().StringVarP(&dlgType, "type", "t", "product_binary", "(optional) Download type. One of: (product_binary, drivers_tools, custom_iso, addons). Default: product_binary")
}
Loading

0 comments on commit 8b27de8

Please sign in to comment.