debian-forge-composer/internal/target/target.go
Ygal Blum bee14bf392 OSBuild - add support for generic S3 services
jobimpl-osbuild
---------------
Add GenericS3Creds to struct
Add method to create AWS with Endpoint for Generic S3 (with its own credentials file)
Move uploading to S3 and result handling to a separate method (along with the special VMDK handling)
adjust the AWS S3 case to the new method
Implement a new case for uploading to a generic S3 service

awscloud
--------
Add wrapper methods for endpoint support
Set the endpoint to the AWS session
Set s3ForcePathStyle to true if endpoint was set

Target
------
Define a new target type for the GenericS3Target and Options
Handle unmarshaling of the target options and result for the Generic S3

Weldr
-----
Add support for only uploading to AWS S3
Define new structures for AWS S3 and Generic S3 (based on AWS S3)
Handle unmarshaling of the providers settings' upload settings

main
----
Add a section in the main config for the Generic S3 service for credentials
If provided pass the credentials file name to the osbuild job implementation

Upload Utility
--------------
Add upload-generic-s3 utility

Makefile
------
Do not fail if the bin directory already exists

Tests
-----
Add test cases for both AWS and a generic S3 server
Add a generic s3_test.sh file for both test cases and add it to the tests RPM spec
Adjust the libvirt test case script to support already created images
GitLabCI - Extend the libvirt test case to include the two new tests
2022-04-07 15:01:01 +02:00

94 lines
2.5 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)
case "org.osbuild.generic.s3":
options = new(GenericS3TargetOptions)
default:
return nil, errors.New("unexpected target name")
}
err := json.Unmarshal(rawOptions, options)
return options, err
}