debian-forge-composer/cmd/osbuild-worker/jobimpl-ostree-resolve.go
Achilleas Koutsou 0e4a9e586f split: replace internal packages with images library
Remove all the internal package that are now in the
github.com/osbuild/images package and vendor it.

A new function in internal/blueprint/ converts from an osbuild-composer
blueprint to an images blueprint.  This is necessary for keeping the
blueprint implementation in both packages.  In the future, the images
package will change the blueprint (and most likely rename it) and it
will only be part of the osbuild-composer internals and interface.  The
Convert() function will be responsible for converting the blueprint into
the new configuration object.
2023-07-10 21:11:19 +02:00

77 lines
1.8 KiB
Go

package main
import (
"fmt"
"github.com/sirupsen/logrus"
"github.com/osbuild/images/pkg/ostree"
"github.com/osbuild/osbuild-composer/internal/worker"
"github.com/osbuild/osbuild-composer/internal/worker/clienterrors"
)
type OSTreeResolveJobImpl struct {
}
func setError(err error, result *worker.OSTreeResolveJobResult) {
switch err.(type) {
case ostree.RefError:
result.JobError = clienterrors.WorkerClientError(
clienterrors.ErrorOSTreeRefInvalid,
"Invalid OSTree ref",
err.Error(),
)
case ostree.ResolveRefError:
result.JobError = clienterrors.WorkerClientError(
clienterrors.ErrorOSTreeRefResolution,
"Error resolving OSTree ref",
err.Error(),
)
default:
result.JobError = clienterrors.WorkerClientError(
clienterrors.ErrorOSTreeParamsInvalid,
"Invalid OSTree parameters or parameter combination",
err.Error(),
)
}
}
func (impl *OSTreeResolveJobImpl) Run(job worker.Job) error {
logWithId := logrus.WithField("jobId", job.Id())
var args worker.OSTreeResolveJob
err := job.Args(&args)
if err != nil {
return err
}
result := worker.OSTreeResolveJobResult{
Specs: make([]worker.OSTreeResolveResultSpec, len(args.Specs)),
}
logWithId.Infof("Resolving (%d) ostree commits", len(args.Specs))
for i, s := range args.Specs {
reqParams := ostree.SourceSpec(s)
commitSpec, err := ostree.Resolve(reqParams)
if err != nil {
logWithId.Infof("Resolving ostree params failed: %v", err)
setError(err, &result)
break
}
result.Specs[i] = worker.OSTreeResolveResultSpec{
URL: commitSpec.URL,
Ref: commitSpec.Ref,
Checksum: commitSpec.Checksum,
Secrets: commitSpec.Secrets,
RHSM: s.RHSM,
}
}
err = job.Update(&result)
if err != nil {
return fmt.Errorf("Error reporting job result: %v", err)
}
return nil
}