cloudapi: Add support for GCP as upload target
Add support for GCP as an upload target to the internal API. Extend the cloudapi to allow GCP as an upload target in the compose request. Regenerate the cloudapi go code. Added GCP-specific upload result component in the API definition, similar to AWS. It is not yet used, but it will be once returning a target-specific result from worker is supported. Add support for GCP upload target to the worker job implementation. Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
parent
ff95059748
commit
94d399f010
7 changed files with 251 additions and 36 deletions
|
|
@ -204,9 +204,47 @@ func (server *Server) Compose(w http.ResponseWriter, r *http.Request) {
|
|||
t.ImageName = key
|
||||
}
|
||||
|
||||
targets = append(targets, t)
|
||||
} else if uploadRequest.Type == "gcp" {
|
||||
var gcpUploadOptions GCPUploadRequestOptions
|
||||
jsonUploadOptions, err := json.Marshal(uploadRequest.Options)
|
||||
if err != nil {
|
||||
http.Error(w, "Unable to marshal gcp upload request", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal(jsonUploadOptions, &gcpUploadOptions)
|
||||
if err != nil {
|
||||
http.Error(w, "Unable to unmarshal gcp upload request", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
var share []string
|
||||
if gcpUploadOptions.ShareWithAccounts != nil {
|
||||
share = *gcpUploadOptions.ShareWithAccounts
|
||||
}
|
||||
var region string
|
||||
if gcpUploadOptions.Region != nil {
|
||||
region = *gcpUploadOptions.Region
|
||||
}
|
||||
object := fmt.Sprintf("composer-api-%s", uuid.New().String())
|
||||
t := target.NewGCPTarget(&target.GCPTargetOptions{
|
||||
Filename: imageType.Filename(),
|
||||
Region: region,
|
||||
Os: "", // not exposed in cloudapi for now
|
||||
Bucket: gcpUploadOptions.Bucket,
|
||||
Object: object,
|
||||
ShareWithAccounts: share,
|
||||
})
|
||||
// Import will fail if an image with this name already exists
|
||||
if gcpUploadOptions.ImageName != nil {
|
||||
t.ImageName = *gcpUploadOptions.ImageName
|
||||
} else {
|
||||
t.ImageName = object
|
||||
}
|
||||
|
||||
targets = append(targets, t)
|
||||
} else {
|
||||
http.Error(w, "Unknown upload request type, only aws is supported", http.StatusBadRequest)
|
||||
http.Error(w, "Unknown upload request type, only 'aws' and 'gcp' is supported", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue