target: use constants for target names, instead of string literals
This commit is contained in:
parent
f6fa5ccca1
commit
c63bfe6d83
16 changed files with 95 additions and 72 deletions
|
|
@ -549,27 +549,27 @@ func (h *apiHandlers) getComposeStatusImpl(ctx echo.Context, id string) error {
|
|||
var uploadOptions interface{}
|
||||
|
||||
switch tr.Name {
|
||||
case "org.osbuild.aws":
|
||||
case target.TargetNameAWS:
|
||||
uploadType = UploadTypesAws
|
||||
awsOptions := tr.Options.(*target.AWSTargetResultOptions)
|
||||
uploadOptions = AWSEC2UploadStatus{
|
||||
Ami: awsOptions.Ami,
|
||||
Region: awsOptions.Region,
|
||||
}
|
||||
case "org.osbuild.aws.s3":
|
||||
case target.TargetNameAWSS3:
|
||||
uploadType = UploadTypesAwsS3
|
||||
awsOptions := tr.Options.(*target.AWSS3TargetResultOptions)
|
||||
uploadOptions = AWSS3UploadStatus{
|
||||
Url: awsOptions.URL,
|
||||
}
|
||||
case "org.osbuild.gcp":
|
||||
case target.TargetNameGCP:
|
||||
uploadType = UploadTypesGcp
|
||||
gcpOptions := tr.Options.(*target.GCPTargetResultOptions)
|
||||
uploadOptions = GCPUploadStatus{
|
||||
ImageName: gcpOptions.ImageName,
|
||||
ProjectId: gcpOptions.ProjectID,
|
||||
}
|
||||
case "org.osbuild.azure.image":
|
||||
case target.TargetNameAzureImage:
|
||||
uploadType = UploadTypesAzure
|
||||
gcpOptions := tr.Options.(*target.AzureImageTargetResultOptions)
|
||||
uploadOptions = AzureUploadStatus{
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ func FixtureBase() *Store {
|
|||
|
||||
var localTarget = &target.Target{
|
||||
Uuid: uuid.MustParse("20000000-0000-0000-0000-000000000000"),
|
||||
Name: "org.osbuild.local",
|
||||
Name: target.TargetNameLocal,
|
||||
ImageName: "localimage",
|
||||
Created: date,
|
||||
Status: common.IBWaiting,
|
||||
|
|
@ -37,7 +37,7 @@ func FixtureBase() *Store {
|
|||
|
||||
var awsTarget = &target.Target{
|
||||
Uuid: uuid.MustParse("10000000-0000-0000-0000-000000000000"),
|
||||
Name: "org.osbuild.aws",
|
||||
Name: target.TargetNameAWS,
|
||||
ImageName: "awsimage",
|
||||
Created: date,
|
||||
Status: common.IBWaiting,
|
||||
|
|
@ -163,7 +163,7 @@ func FixtureFinished() *Store {
|
|||
|
||||
var localTarget = &target.Target{
|
||||
Uuid: uuid.MustParse("20000000-0000-0000-0000-000000000000"),
|
||||
Name: "org.osbuild.local",
|
||||
Name: target.TargetNameLocal,
|
||||
ImageName: "localimage",
|
||||
Created: date,
|
||||
Status: common.IBWaiting,
|
||||
|
|
@ -172,7 +172,7 @@ func FixtureFinished() *Store {
|
|||
|
||||
var awsTarget = &target.Target{
|
||||
Uuid: uuid.MustParse("10000000-0000-0000-0000-000000000000"),
|
||||
Name: "org.osbuild.aws",
|
||||
Name: target.TargetNameAWS,
|
||||
ImageName: "awsimage",
|
||||
Created: date,
|
||||
Status: common.IBWaiting,
|
||||
|
|
|
|||
|
|
@ -1016,7 +1016,7 @@ func Test_newComposeV0(t *testing.T) {
|
|||
{
|
||||
Uuid: uuid.MustParse("f53b49c0-d321-447e-8ab8-6e827891e3f0"),
|
||||
ImageName: "",
|
||||
Name: "org.osbuild.local",
|
||||
Name: target.TargetNameLocal,
|
||||
Created: MustParseTime("2020-08-12T09:21:44.427717205-07:00"),
|
||||
Status: common.IBWaiting,
|
||||
Options: target.LocalTargetOptions{
|
||||
|
|
@ -1045,7 +1045,7 @@ func Test_newComposeV0(t *testing.T) {
|
|||
{
|
||||
Uuid: uuid.MustParse("f53b49c0-d321-447e-8ab8-6e827891e3f0"),
|
||||
ImageName: "",
|
||||
Name: "org.osbuild.local",
|
||||
Name: target.TargetNameLocal,
|
||||
Created: MustParseTime("2020-08-12T09:21:44.427717205-07:00"),
|
||||
Status: common.IBWaiting,
|
||||
Options: target.LocalTargetOptions{
|
||||
|
|
@ -1118,7 +1118,7 @@ func Test_newComposeFromV0(t *testing.T) {
|
|||
{
|
||||
Uuid: uuid.MustParse("f53b49c0-d321-447e-8ab8-6e827891e3f0"),
|
||||
ImageName: "",
|
||||
Name: "org.osbuild.local",
|
||||
Name: target.TargetNameLocal,
|
||||
Created: MustParseTime("2020-08-12T09:21:44.427717205-07:00"),
|
||||
Status: common.IBWaiting,
|
||||
Options: target.LocalTargetOptions{
|
||||
|
|
@ -1147,7 +1147,7 @@ func Test_newComposeFromV0(t *testing.T) {
|
|||
{
|
||||
Uuid: uuid.MustParse("f53b49c0-d321-447e-8ab8-6e827891e3f0"),
|
||||
ImageName: "",
|
||||
Name: "org.osbuild.local",
|
||||
Name: target.TargetNameLocal,
|
||||
Created: MustParseTime("2020-08-12T09:21:44.427717205-07:00"),
|
||||
Status: common.IBWaiting,
|
||||
Options: target.LocalTargetOptions{
|
||||
|
|
@ -1213,7 +1213,7 @@ func Test_newComposesV0(t *testing.T) {
|
|||
{
|
||||
Uuid: uuid.MustParse("f53b49c0-d321-447e-8ab8-6e827891e3f0"),
|
||||
ImageName: "",
|
||||
Name: "org.osbuild.local",
|
||||
Name: target.TargetNameLocal,
|
||||
Created: MustParseTime("2020-08-12T09:21:44.427717205-07:00"),
|
||||
Status: common.IBWaiting,
|
||||
Options: target.LocalTargetOptions{
|
||||
|
|
@ -1241,7 +1241,7 @@ func Test_newComposesV0(t *testing.T) {
|
|||
{
|
||||
Uuid: uuid.MustParse("14c454d0-26f3-4a56-8ceb-a5673aaba686"),
|
||||
ImageName: "",
|
||||
Name: "org.osbuild.local",
|
||||
Name: target.TargetNameLocal,
|
||||
Created: MustParseTime("2020-08-12T09:21:44.427717205-07:00"),
|
||||
Status: common.IBWaiting,
|
||||
Options: target.LocalTargetOptions{
|
||||
|
|
@ -1272,7 +1272,7 @@ func Test_newComposesV0(t *testing.T) {
|
|||
{
|
||||
Uuid: uuid.MustParse("f53b49c0-d321-447e-8ab8-6e827891e3f0"),
|
||||
ImageName: "",
|
||||
Name: "org.osbuild.local",
|
||||
Name: target.TargetNameLocal,
|
||||
Created: MustParseTime("2020-08-12T09:21:44.427717205-07:00"),
|
||||
Status: common.IBWaiting,
|
||||
Options: target.LocalTargetOptions{
|
||||
|
|
@ -1303,7 +1303,7 @@ func Test_newComposesV0(t *testing.T) {
|
|||
{
|
||||
Uuid: uuid.MustParse("14c454d0-26f3-4a56-8ceb-a5673aaba686"),
|
||||
ImageName: "",
|
||||
Name: "org.osbuild.local",
|
||||
Name: target.TargetNameLocal,
|
||||
Created: MustParseTime("2020-08-12T09:21:44.427717205-07:00"),
|
||||
Status: common.IBWaiting,
|
||||
Options: target.LocalTargetOptions{
|
||||
|
|
@ -1375,7 +1375,7 @@ func Test_newComposesFromV0(t *testing.T) {
|
|||
{
|
||||
Uuid: uuid.MustParse("f53b49c0-d321-447e-8ab8-6e827891e3f0"),
|
||||
ImageName: "",
|
||||
Name: "org.osbuild.local",
|
||||
Name: target.TargetNameLocal,
|
||||
Created: MustParseTime("2020-08-12T09:21:44.427717205-07:00"),
|
||||
Status: common.IBWaiting,
|
||||
Options: target.LocalTargetOptions{
|
||||
|
|
@ -1405,7 +1405,7 @@ func Test_newComposesFromV0(t *testing.T) {
|
|||
{
|
||||
Uuid: uuid.MustParse("14c454d0-26f3-4a56-8ceb-a5673aaba686"),
|
||||
ImageName: "",
|
||||
Name: "org.osbuild.local",
|
||||
Name: target.TargetNameLocal,
|
||||
Created: MustParseTime("2020-08-12T09:21:44.427717205-07:00"),
|
||||
Status: common.IBWaiting,
|
||||
Options: target.LocalTargetOptions{
|
||||
|
|
@ -1436,7 +1436,7 @@ func Test_newComposesFromV0(t *testing.T) {
|
|||
{
|
||||
Uuid: uuid.MustParse("f53b49c0-d321-447e-8ab8-6e827891e3f0"),
|
||||
ImageName: "",
|
||||
Name: "org.osbuild.local",
|
||||
Name: target.TargetNameLocal,
|
||||
Created: MustParseTime("2020-08-12T09:21:44.427717205-07:00"),
|
||||
Status: common.IBWaiting,
|
||||
Options: target.LocalTargetOptions{
|
||||
|
|
@ -1465,7 +1465,7 @@ func Test_newComposesFromV0(t *testing.T) {
|
|||
{
|
||||
Uuid: uuid.MustParse("14c454d0-26f3-4a56-8ceb-a5673aaba686"),
|
||||
ImageName: "",
|
||||
Name: "org.osbuild.local",
|
||||
Name: target.TargetNameLocal,
|
||||
Created: MustParseTime("2020-08-12T09:21:44.427717205-07:00"),
|
||||
Status: common.IBWaiting,
|
||||
Options: target.LocalTargetOptions{
|
||||
|
|
@ -1527,7 +1527,7 @@ func Test_newImageBuildFromV0(t *testing.T) {
|
|||
{
|
||||
Uuid: uuid.MustParse("f53b49c0-d321-447e-8ab8-6e827891e3f0"),
|
||||
ImageName: "",
|
||||
Name: "org.osbuild.local",
|
||||
Name: target.TargetNameLocal,
|
||||
Created: MustParseTime("2020-08-12T09:21:44.427717205-07:00"),
|
||||
Status: common.IBWaiting,
|
||||
Options: target.LocalTargetOptions{
|
||||
|
|
@ -1552,7 +1552,7 @@ func Test_newImageBuildFromV0(t *testing.T) {
|
|||
{
|
||||
Uuid: uuid.MustParse("f53b49c0-d321-447e-8ab8-6e827891e3f0"),
|
||||
ImageName: "",
|
||||
Name: "org.osbuild.local",
|
||||
Name: target.TargetNameLocal,
|
||||
Created: MustParseTime("2020-08-12T09:21:44.427717205-07:00"),
|
||||
Status: common.IBWaiting,
|
||||
Options: target.LocalTargetOptions{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
package target
|
||||
|
||||
const (
|
||||
TargetNameAWS TargetName = "org.osbuild.aws"
|
||||
TargetNameAWSS3 TargetName = "org.osbuild.aws.s3"
|
||||
)
|
||||
|
||||
type AWSTargetOptions struct {
|
||||
Filename string `json:"filename"`
|
||||
Region string `json:"region"`
|
||||
|
|
@ -14,7 +19,7 @@ type AWSTargetOptions struct {
|
|||
func (AWSTargetOptions) isTargetOptions() {}
|
||||
|
||||
func NewAWSTarget(options *AWSTargetOptions) *Target {
|
||||
return newTarget("org.osbuild.aws", options)
|
||||
return newTarget(TargetNameAWS, options)
|
||||
}
|
||||
|
||||
type AWSTargetResultOptions struct {
|
||||
|
|
@ -25,7 +30,7 @@ type AWSTargetResultOptions struct {
|
|||
func (AWSTargetResultOptions) isTargetResultOptions() {}
|
||||
|
||||
func NewAWSTargetResult(options *AWSTargetResultOptions) *TargetResult {
|
||||
return newTargetResult("org.osbuild.aws", options)
|
||||
return newTargetResult(TargetNameAWS, options)
|
||||
}
|
||||
|
||||
type AWSS3TargetOptions struct {
|
||||
|
|
@ -44,7 +49,7 @@ type AWSS3TargetOptions struct {
|
|||
func (AWSS3TargetOptions) isTargetOptions() {}
|
||||
|
||||
func NewAWSS3Target(options *AWSS3TargetOptions) *Target {
|
||||
return newTarget("org.osbuild.aws.s3", options)
|
||||
return newTarget(TargetNameAWSS3, options)
|
||||
}
|
||||
|
||||
type AWSS3TargetResultOptions struct {
|
||||
|
|
@ -54,5 +59,5 @@ type AWSS3TargetResultOptions struct {
|
|||
func (AWSS3TargetResultOptions) isTargetResultOptions() {}
|
||||
|
||||
func NewAWSS3TargetResult(options *AWSS3TargetResultOptions) *TargetResult {
|
||||
return newTargetResult("org.osbuild.aws.s3", options)
|
||||
return newTargetResult(TargetNameAWSS3, options)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package target
|
||||
|
||||
const TargetNameAzureImage TargetName = "org.osbuild.azure.image"
|
||||
|
||||
type AzureImageTargetOptions struct {
|
||||
Filename string `json:"filename"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
|
|
@ -29,7 +31,7 @@ func (AzureImageTargetOptions) isTargetOptions() {}
|
|||
// If you need to just upload a PageBlob into Azure Storage, see the
|
||||
// org.osbuild.azure target.
|
||||
func NewAzureImageTarget(options *AzureImageTargetOptions) *Target {
|
||||
return newTarget("org.osbuild.azure.image", options)
|
||||
return newTarget(TargetNameAzureImage, options)
|
||||
}
|
||||
|
||||
type AzureImageTargetResultOptions struct {
|
||||
|
|
@ -39,5 +41,5 @@ type AzureImageTargetResultOptions struct {
|
|||
func (AzureImageTargetResultOptions) isTargetResultOptions() {}
|
||||
|
||||
func NewAzureImageTargetResult(options *AzureImageTargetResultOptions) *TargetResult {
|
||||
return newTargetResult("org.osbuild.azure.image", options)
|
||||
return newTargetResult(TargetNameAzureImage, options)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package target
|
||||
|
||||
const TargetNameAzure TargetName = "org.osbuild.azure"
|
||||
|
||||
type AzureTargetOptions struct {
|
||||
Filename string `json:"filename"`
|
||||
StorageAccount string `json:"storageAccount"`
|
||||
|
|
@ -20,5 +22,5 @@ func (AzureTargetOptions) isTargetOptions() {}
|
|||
// If you need to upload an Azure Image instead, see the
|
||||
// org.osbuild.azure.image target.
|
||||
func NewAzureTarget(options *AzureTargetOptions) *Target {
|
||||
return newTarget("org.osbuild.azure", options)
|
||||
return newTarget(TargetNameAzure, options)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package target
|
||||
|
||||
const TargetNameContainer TargetName = "org.osbuild.container"
|
||||
|
||||
type ContainerTargetOptions struct {
|
||||
Filename string `json:"filename"`
|
||||
Reference string `json:"reference"`
|
||||
|
|
@ -13,5 +15,5 @@ type ContainerTargetOptions struct {
|
|||
func (ContainerTargetOptions) isTargetOptions() {}
|
||||
|
||||
func NewContainerTarget(options *ContainerTargetOptions) *Target {
|
||||
return newTarget("org.osbuild.container", options)
|
||||
return newTarget(TargetNameContainer, options)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package target
|
||||
|
||||
const TargetNameGCP TargetName = "org.osbuild.gcp"
|
||||
|
||||
type GCPTargetOptions struct {
|
||||
Filename string `json:"filename"`
|
||||
Region string `json:"region"`
|
||||
|
|
@ -17,7 +19,7 @@ type GCPTargetOptions struct {
|
|||
func (GCPTargetOptions) isTargetOptions() {}
|
||||
|
||||
func NewGCPTarget(options *GCPTargetOptions) *Target {
|
||||
return newTarget("org.osbuild.gcp", options)
|
||||
return newTarget(TargetNameGCP, options)
|
||||
}
|
||||
|
||||
type GCPTargetResultOptions struct {
|
||||
|
|
@ -28,5 +30,5 @@ type GCPTargetResultOptions struct {
|
|||
func (GCPTargetResultOptions) isTargetResultOptions() {}
|
||||
|
||||
func NewGCPTargetResult(options *GCPTargetResultOptions) *TargetResult {
|
||||
return newTargetResult("org.osbuild.gcp", options)
|
||||
return newTargetResult(TargetNameGCP, options)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package target
|
||||
|
||||
const TargetNameKoji TargetName = "org.osbuild.koji"
|
||||
|
||||
type KojiTargetOptions struct {
|
||||
// Filename of the image as produced by osbuild for a given export
|
||||
Filename string `json:"filename"`
|
||||
|
|
@ -10,7 +12,7 @@ type KojiTargetOptions struct {
|
|||
func (KojiTargetOptions) isTargetOptions() {}
|
||||
|
||||
func NewKojiTarget(options *KojiTargetOptions) *Target {
|
||||
return newTarget("org.osbuild.koji", options)
|
||||
return newTarget(TargetNameKoji, options)
|
||||
}
|
||||
|
||||
type KojiTargetResultOptions struct {
|
||||
|
|
@ -21,5 +23,5 @@ type KojiTargetResultOptions struct {
|
|||
func (KojiTargetResultOptions) isTargetResultOptions() {}
|
||||
|
||||
func NewKojiTargetResult(options *KojiTargetResultOptions) *TargetResult {
|
||||
return newTargetResult("org.osbuild.koji", options)
|
||||
return newTargetResult(TargetNameKoji, options)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package target
|
|||
|
||||
import "github.com/google/uuid"
|
||||
|
||||
const TargetNameLocal TargetName = "org.osbuild.local"
|
||||
|
||||
type LocalTargetOptions struct {
|
||||
ComposeId uuid.UUID `json:"compose_id"`
|
||||
ImageBuildId int `json:"image_build_id"`
|
||||
|
|
@ -12,5 +14,5 @@ type LocalTargetOptions struct {
|
|||
func (LocalTargetOptions) isTargetOptions() {}
|
||||
|
||||
func NewLocalTarget(options *LocalTargetOptions) *Target {
|
||||
return newTarget("org.osbuild.local", options)
|
||||
return newTarget(TargetNameLocal, options)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package target
|
||||
|
||||
const TargetNameOCI TargetName = "org.osbuild.oci"
|
||||
|
||||
type OCITargetOptions struct {
|
||||
User string `json:"user"`
|
||||
Tenancy string `json:"tenancy"`
|
||||
|
|
@ -15,7 +17,7 @@ type OCITargetOptions struct {
|
|||
func (OCITargetOptions) isTargetOptions() {}
|
||||
|
||||
func NewOCITarget(options *OCITargetOptions) *Target {
|
||||
return newTarget("org.osbuild.oci", options)
|
||||
return newTarget(TargetNameOCI, options)
|
||||
}
|
||||
|
||||
type OCITargetResultOptions struct {
|
||||
|
|
@ -26,5 +28,5 @@ type OCITargetResultOptions struct {
|
|||
func (OCITargetResultOptions) isTargetResultOptions() {}
|
||||
|
||||
func NewOCITargetResult(options *OCITargetResultOptions) *TargetResult {
|
||||
return newTargetResult("org.osbuild.oci", options)
|
||||
return newTargetResult(TargetNameOCI, options)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,23 +2,25 @@ package target
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
)
|
||||
|
||||
type TargetName string
|
||||
|
||||
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
|
||||
Name TargetName `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 {
|
||||
func newTarget(name TargetName, options TargetOptions) *Target {
|
||||
return &Target{
|
||||
Uuid: uuid.New(),
|
||||
Name: name,
|
||||
|
|
@ -35,7 +37,7 @@ type TargetOptions interface {
|
|||
type rawTarget struct {
|
||||
Uuid uuid.UUID `json:"uuid"`
|
||||
ImageName string `json:"image_name"`
|
||||
Name string `json:"name"`
|
||||
Name TargetName `json:"name"`
|
||||
Created time.Time `json:"created"`
|
||||
Status common.ImageBuildState `json:"status"`
|
||||
Options json.RawMessage `json:"options"`
|
||||
|
|
@ -62,31 +64,31 @@ func (target *Target) UnmarshalJSON(data []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func UnmarshalTargetOptions(targetName string, rawOptions json.RawMessage) (TargetOptions, error) {
|
||||
func UnmarshalTargetOptions(targetName TargetName, rawOptions json.RawMessage) (TargetOptions, error) {
|
||||
var options TargetOptions
|
||||
switch targetName {
|
||||
case "org.osbuild.azure":
|
||||
case TargetNameAzure:
|
||||
options = new(AzureTargetOptions)
|
||||
case "org.osbuild.aws":
|
||||
case TargetNameAWS:
|
||||
options = new(AWSTargetOptions)
|
||||
case "org.osbuild.aws.s3":
|
||||
case TargetNameAWSS3:
|
||||
options = new(AWSS3TargetOptions)
|
||||
case "org.osbuild.gcp":
|
||||
case TargetNameGCP:
|
||||
options = new(GCPTargetOptions)
|
||||
case "org.osbuild.azure.image":
|
||||
case TargetNameAzureImage:
|
||||
options = new(AzureImageTargetOptions)
|
||||
case "org.osbuild.local":
|
||||
case TargetNameLocal:
|
||||
options = new(LocalTargetOptions)
|
||||
case "org.osbuild.koji":
|
||||
case TargetNameKoji:
|
||||
options = new(KojiTargetOptions)
|
||||
case "org.osbuild.vmware":
|
||||
case TargetNameVMWare:
|
||||
options = new(VMWareTargetOptions)
|
||||
case "org.osbuild.oci":
|
||||
case TargetNameOCI:
|
||||
options = new(OCITargetOptions)
|
||||
case "org.osbuild.container":
|
||||
case TargetNameContainer:
|
||||
options = new(ContainerTargetOptions)
|
||||
default:
|
||||
return nil, errors.New("unexpected target name")
|
||||
return nil, fmt.Errorf("unexpected target name: %s", targetName)
|
||||
}
|
||||
err := json.Unmarshal(rawOptions, options)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ import (
|
|||
)
|
||||
|
||||
type TargetResult struct {
|
||||
Name string `json:"name"`
|
||||
Name TargetName `json:"name"`
|
||||
Options TargetResultOptions `json:"options"`
|
||||
}
|
||||
|
||||
func newTargetResult(name string, options TargetResultOptions) *TargetResult {
|
||||
func newTargetResult(name TargetName, options TargetResultOptions) *TargetResult {
|
||||
return &TargetResult{
|
||||
Name: name,
|
||||
Options: options,
|
||||
|
|
@ -22,7 +22,7 @@ type TargetResultOptions interface {
|
|||
}
|
||||
|
||||
type rawTargetResult struct {
|
||||
Name string `json:"name"`
|
||||
Name TargetName `json:"name"`
|
||||
Options json.RawMessage `json:"options"`
|
||||
}
|
||||
|
||||
|
|
@ -42,20 +42,20 @@ func (targetResult *TargetResult) UnmarshalJSON(data []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func UnmarshalTargetResultOptions(trName string, rawOptions json.RawMessage) (TargetResultOptions, error) {
|
||||
func UnmarshalTargetResultOptions(trName TargetName, rawOptions json.RawMessage) (TargetResultOptions, error) {
|
||||
var options TargetResultOptions
|
||||
switch trName {
|
||||
case "org.osbuild.aws":
|
||||
case TargetNameAWS:
|
||||
options = new(AWSTargetResultOptions)
|
||||
case "org.osbuild.aws.s3":
|
||||
case TargetNameAWSS3:
|
||||
options = new(AWSS3TargetResultOptions)
|
||||
case "org.osbuild.gcp":
|
||||
case TargetNameGCP:
|
||||
options = new(GCPTargetResultOptions)
|
||||
case "org.osbuild.azure.image":
|
||||
case TargetNameAzureImage:
|
||||
options = new(AzureImageTargetResultOptions)
|
||||
case "org.osbuild.koji":
|
||||
case TargetNameKoji:
|
||||
options = new(KojiTargetResultOptions)
|
||||
case "org.osbuild.oci":
|
||||
case TargetNameOCI:
|
||||
options = new(OCITargetResultOptions)
|
||||
default:
|
||||
return nil, fmt.Errorf("unexpected target result name: %s", trName)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package target
|
||||
|
||||
const TargetNameVMWare TargetName = "org.osbuild.vmware"
|
||||
|
||||
type VMWareTargetOptions struct {
|
||||
Filename string `json:"filename"`
|
||||
Host string `json:"host"`
|
||||
|
|
@ -13,5 +15,5 @@ type VMWareTargetOptions struct {
|
|||
func (VMWareTargetOptions) isTargetOptions() {}
|
||||
|
||||
func NewVMWareTarget(options *VMWareTargetOptions) *Target {
|
||||
return newTarget("org.osbuild.vmware", options)
|
||||
return newTarget(TargetNameVMWare, options)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -703,7 +703,7 @@ func TestCompose(t *testing.T) {
|
|||
Manifest: manifest,
|
||||
Targets: []*target.Target{
|
||||
{
|
||||
Name: "org.osbuild.aws",
|
||||
Name: target.TargetNameAWS,
|
||||
Status: common.IBWaiting,
|
||||
ImageName: "test_upload",
|
||||
Options: &target.AWSTargetOptions{
|
||||
|
|
|
|||
|
|
@ -250,7 +250,7 @@ func uploadRequestToTarget(u uploadRequest, imageType distro.ImageType) *target.
|
|||
|
||||
switch options := u.Settings.(type) {
|
||||
case *awsUploadSettings:
|
||||
t.Name = "org.osbuild.aws"
|
||||
t.Name = target.TargetNameAWS
|
||||
t.Options = &target.AWSTargetOptions{
|
||||
Filename: imageType.Filename(),
|
||||
Region: options.Region,
|
||||
|
|
@ -261,7 +261,7 @@ func uploadRequestToTarget(u uploadRequest, imageType distro.ImageType) *target.
|
|||
Key: options.Key,
|
||||
}
|
||||
case *awsS3UploadSettings:
|
||||
t.Name = "org.osbuild.aws.s3"
|
||||
t.Name = target.TargetNameAWSS3
|
||||
t.Options = &target.AWSS3TargetOptions{
|
||||
Filename: imageType.Filename(),
|
||||
Region: options.Region,
|
||||
|
|
@ -275,7 +275,7 @@ func uploadRequestToTarget(u uploadRequest, imageType distro.ImageType) *target.
|
|||
SkipSSLVerification: options.SkipSSLVerification,
|
||||
}
|
||||
case *azureUploadSettings:
|
||||
t.Name = "org.osbuild.azure"
|
||||
t.Name = target.TargetNameAzure
|
||||
t.Options = &target.AzureTargetOptions{
|
||||
Filename: imageType.Filename(),
|
||||
StorageAccount: options.StorageAccount,
|
||||
|
|
@ -283,7 +283,7 @@ func uploadRequestToTarget(u uploadRequest, imageType distro.ImageType) *target.
|
|||
Container: options.Container,
|
||||
}
|
||||
case *gcpUploadSettings:
|
||||
t.Name = "org.osbuild.gcp"
|
||||
t.Name = target.TargetNameGCP
|
||||
|
||||
var gcpCredentials []byte
|
||||
var err error
|
||||
|
|
@ -310,7 +310,7 @@ func uploadRequestToTarget(u uploadRequest, imageType distro.ImageType) *target.
|
|||
Credentials: gcpCredentials,
|
||||
}
|
||||
case *vmwareUploadSettings:
|
||||
t.Name = "org.osbuild.vmware"
|
||||
t.Name = target.TargetNameVMWare
|
||||
t.Options = &target.VMWareTargetOptions{
|
||||
Filename: imageType.Filename(),
|
||||
Username: options.Username,
|
||||
|
|
@ -321,7 +321,7 @@ func uploadRequestToTarget(u uploadRequest, imageType distro.ImageType) *target.
|
|||
Datastore: options.Datastore,
|
||||
}
|
||||
case *ociUploadSettings:
|
||||
t.Name = "org.osbuild.oci"
|
||||
t.Name = target.TargetNameOCI
|
||||
t.Options = &target.OCITargetOptions{
|
||||
User: options.User,
|
||||
Tenancy: options.Tenancy,
|
||||
|
|
@ -334,7 +334,7 @@ func uploadRequestToTarget(u uploadRequest, imageType distro.ImageType) *target.
|
|||
Compartment: options.Compartment,
|
||||
}
|
||||
case *containerUploadSettings:
|
||||
t.Name = "org.osbuild.container"
|
||||
t.Name = target.TargetNameContainer
|
||||
t.Options = &target.ContainerTargetOptions{
|
||||
Username: options.Username,
|
||||
Password: options.Password,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue