From dc476671e4f10e9bfcd1eead5f307491ad1dbc35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Tue, 27 Sep 2022 09:14:08 +0200 Subject: [PATCH] weldr/upload/gcp: make `Object` optional Previously, it was expected from the user to provide the Object name when uploading image to GCP. The object name does not matter much, because the object is deleted once image import finishes. Make the specification of the object name optional and generate it if not provided. Adjust the GCP Weldr test case to not provide the Object name when uploading the image. The user can still provide the Object name if needed. --- internal/weldr/upload.go | 10 +++++++--- test/cases/gcp.sh | 1 - 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/weldr/upload.go b/internal/weldr/upload.go index 04ab1626a..2e905085d 100644 --- a/internal/weldr/upload.go +++ b/internal/weldr/upload.go @@ -65,7 +65,7 @@ func (azureUploadSettings) isUploadSettings() {} type gcpUploadSettings struct { Region string `json:"region"` Bucket string `json:"bucket"` - Object string `json:"object"` + Object string `json:"object,omitempty"` // base64 encoded GCP credentials JSON file Credentials string `json:"credentials,omitempty"` @@ -300,9 +300,13 @@ func uploadRequestToTarget(u uploadRequest, imageType distro.ImageType) *target. } } - // The uploaded image object name must have 'tar.gz' suffix to be imported + // Providing the Object name is optional. If it is provided, we must + // ensure that it has a '.tar.gz' suffix to be successfully imported. + // If it is not provided, we will generate a random name. objectName := options.Object - if !strings.HasSuffix(objectName, ".tar.gz") { + if objectName == "" { + objectName = fmt.Sprintf("composer-api-%s.tar.gz", uuid.New().String()) + } else if !strings.HasSuffix(objectName, ".tar.gz") { objectName = objectName + ".tar.gz" logrus.Infof("[GCP] object name must end with '.tar.gz', using %q as the object name", objectName) } diff --git a/test/cases/gcp.sh b/test/cases/gcp.sh index ecf03d55f..457aace8e 100755 --- a/test/cases/gcp.sh +++ b/test/cases/gcp.sh @@ -201,7 +201,6 @@ provider = "gcp" [settings] bucket = "${GCP_BUCKET}" region = "${GCP_REGION}" -object = "${GCP_IMAGE_NAME}" credentials = "$(base64 -w 0 "${GOOGLE_APPLICATION_CREDENTIALS}")" EOF