debian-forge-composer/internal/target/target.go
Ygal Blum feb357e538 Support Generic S3 upload in Composer API
Use case
--------
If Endpoint is not set and Region is - upload to AWS S3
If both the Endpoint and Region are set - upload the Generic S3 via Weldr API
If neither the Endpoint and Region are set - upload the Generic S3 via Composer API (use configuration)

jobimpl-osbuild
---------------
Add configuration fields for Generic S3 upload
Support S3 upload requests coming from Weldr or Composer API to either AWS or Generic S3
Weldr API for Generic S3 requires that all connection parameters but the credentials be passed in the API call
Composer API for Generic S3 requires that all conneciton parameters are taken from the configuration
Adjust to the consolidation in Target and UploadOptions

Target and UploadOptions
------------------------
Add the fields that were specific to the Generic S3 structures to the AWS S3 one
Remove the structures for Generic S3 and always use the AWS S3 ones

Worker Main
-----------
Add Endpoint, Region, Bucket, CABundle and SkipSSLVerification to the configuration structure
Pass the values to the Server

Weldr API
---------
Keep the generic.s3 provider name to maintain the API, but unmarshel into awsS3UploadSettings

tests - api.sh
--------------
Allow the caller to specifiy either AWS or Generic S3 upload targets for specific image types
Implement the pieces required for testing upload to a Generic S3 service
In some cases generalize the AWS S3 functions for reuse

GitLab CI
---------
Add test case for api.sh tests with edge-commit and generic S3
2022-06-02 16:12:53 +03:00

92 lines
2.4 KiB
Go

package target
import (
"encoding/json"
"errors"
"time"
"github.com/google/uuid"
"github.com/osbuild/osbuild-composer/internal/common"
)
type Target struct {
Uuid uuid.UUID `json:"uuid"`
ImageName string `json:"image_name"` // Desired name of the image in the target environment
Name string `json:"name"` // Name of the specific target type
Created time.Time `json:"created"`
Status common.ImageBuildState `json:"status"`
Options TargetOptions `json:"options"` // Target type specific options
}
func newTarget(name string, options TargetOptions) *Target {
return &Target{
Uuid: uuid.New(),
Name: name,
Created: time.Now(),
Status: common.IBWaiting,
Options: options,
}
}
type TargetOptions interface {
isTargetOptions()
}
type rawTarget struct {
Uuid uuid.UUID `json:"uuid"`
ImageName string `json:"image_name"`
Name string `json:"name"`
Created time.Time `json:"created"`
Status common.ImageBuildState `json:"status"`
Options json.RawMessage `json:"options"`
}
func (target *Target) UnmarshalJSON(data []byte) error {
var rawTarget rawTarget
err := json.Unmarshal(data, &rawTarget)
if err != nil {
return err
}
options, err := UnmarshalTargetOptions(rawTarget.Name, rawTarget.Options)
if err != nil {
return err
}
target.Uuid = rawTarget.Uuid
target.ImageName = rawTarget.ImageName
target.Name = rawTarget.Name
target.Created = rawTarget.Created
target.Status = rawTarget.Status
target.Options = options
return nil
}
func UnmarshalTargetOptions(targetName string, rawOptions json.RawMessage) (TargetOptions, error) {
var options TargetOptions
switch targetName {
case "org.osbuild.azure":
options = new(AzureTargetOptions)
case "org.osbuild.aws":
options = new(AWSTargetOptions)
case "org.osbuild.aws.s3":
options = new(AWSS3TargetOptions)
case "org.osbuild.gcp":
options = new(GCPTargetOptions)
case "org.osbuild.azure.image":
options = new(AzureImageTargetOptions)
case "org.osbuild.local":
options = new(LocalTargetOptions)
case "org.osbuild.koji":
options = new(KojiTargetOptions)
case "org.osbuild.vmware":
options = new(VMWareTargetOptions)
case "org.osbuild.oci":
options = new(OCITargetOptions)
default:
return nil, errors.New("unexpected target name")
}
err := json.Unmarshal(rawOptions, options)
return options, err
}