forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile_package_with_signed_url.go
89 lines (72 loc) · 2.42 KB
/
compile_package_with_signed_url.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
78
79
80
81
82
83
84
85
86
87
88
89
package action
import (
"errors"
boshmodels "github.com/cloudfoundry/bosh-agent/agent/applier/models"
boshcomp "github.com/cloudfoundry/bosh-agent/agent/compiler"
boshcrypto "github.com/cloudfoundry/bosh-utils/crypto"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
type CompilePackageWithSignedURLRequest struct {
PackageGetSignedURL string `json:"package_get_signed_url"`
UploadSignedURL string `json:"upload_signed_url"`
BlobstoreHeaders map[string]string `json:"blobstore_headers"`
Digest boshcrypto.MultipleDigest `json:"digest"`
Name string `json:"name"`
Version string `json:"version"`
Deps boshcomp.Dependencies `json:"deps"`
}
type CompilePackageWithSignedURL struct {
compiler boshcomp.Compiler
}
func NewCompilePackageWithSignedURL(compiler boshcomp.Compiler) (compilePackage CompilePackageWithSignedURL) {
return CompilePackageWithSignedURL{
compiler: compiler,
}
}
func (a CompilePackageWithSignedURL) Run(request CompilePackageWithSignedURLRequest) (map[string]interface{}, error) {
pkg := boshcomp.Package{
Name: request.Name,
Sha1: request.Digest,
Version: request.Version,
PackageGetSignedURL: request.PackageGetSignedURL,
UploadSignedURL: request.UploadSignedURL,
BlobstoreHeaders: request.BlobstoreHeaders,
}
modelsDeps := []boshmodels.Package{}
for _, dep := range request.Deps {
modelsDeps = append(modelsDeps, boshmodels.Package{
Name: dep.Name,
Version: dep.Version,
Source: boshmodels.Source{
Sha1: dep.Sha1,
BlobstoreID: dep.BlobstoreID,
SignedURL: dep.PackageGetSignedURL,
},
})
}
_, uploadedDigest, err := a.compiler.Compile(pkg, modelsDeps)
if err != nil {
return map[string]interface{}{}, bosherr.WrapErrorf(err, "Compiling package %s", pkg.Name)
}
result := map[string]string{
"sha1": uploadedDigest.String(),
}
return map[string]interface{}{
"result": result,
}, nil
}
func (a CompilePackageWithSignedURL) Resume() (interface{}, error) {
return nil, errors.New("not supported")
}
func (a CompilePackageWithSignedURL) Cancel() error {
return errors.New("not supported")
}
func (a CompilePackageWithSignedURL) IsAsynchronous(_ ProtocolVersion) bool {
return true
}
func (a CompilePackageWithSignedURL) IsPersistent() bool {
return false
}
func (a CompilePackageWithSignedURL) IsLoggable() bool {
return true
}