This commit adds and implements org.osbuild.azure.image target. Let's talk about the already implemented org.osbuild.azure target firstly: The purpose of this target is to authenticate using the Azure Storage credentials and upload the image file as a Page Blob. Page Blob is basically an object in storage and it cannot be directly used to launch a VM. To achieve that, you need to define an actual Azure Image with the Page Blob attached. For the cloud API, we would like to create an actual Azure Image that is immediately available for new VMs. The new target accomplishes it. To achieve this, it must use a different authentication method: Azure OAuth. The other important difference is that currently, the credentials are stored on the worker and not in target options. This should lead to better security because we don't send the credentials over network. In the future, we would like to have credential-less setup using workers in Azure with the right IAM policies applied but this requires more investigation and is not implemented in this commit. Signed-off-by: Ondřej Budai <ondrej@budai.cz>
88 lines
2.2 KiB
Go
88 lines
2.2 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"`
|
|
Name string `json:"name"`
|
|
Created time.Time `json:"created"`
|
|
Status common.ImageBuildState `json:"status"`
|
|
Options TargetOptions `json:"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.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)
|
|
default:
|
|
return nil, errors.New("unexpected target name")
|
|
}
|
|
err := json.Unmarshal(rawOptions, options)
|
|
|
|
return options, err
|
|
}
|