/
jobimpl-ostree-resolve.go
77 lines (65 loc) · 1.8 KB
/
jobimpl-ostree-resolve.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"fmt"
"github.com/sirupsen/logrus"
"github.com/osbuild/images/pkg/ostree"
"github.com/ondrejbudai/osbuild-composer-public/public/worker"
"github.com/ondrejbudai/osbuild-composer-public/public/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
}