Skip to content

Commit

Permalink
weldr/upload/gcp: make Object optional
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thozza authored and ondrejbudai committed Oct 11, 2022
1 parent dd36fce commit dc47667
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 7 additions & 3 deletions internal/weldr/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion test/cases/gcp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit dc47667

Please sign in to comment.