forked from kata-containers/kata-containers
/
packagecloud.go
69 lines (57 loc) · 1.53 KB
/
packagecloud.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
// Copyright (c) 2017-2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package main
import (
"path"
"github.com/mlafeldt/pkgcloud"
"github.com/sirupsen/logrus"
)
type PCClient struct {
*pkgcloud.Client
Repo string
}
func (pc *PCClient) PackagecloudClient(user string, token string, repo string) error {
client, err := pkgcloud.NewClient(token)
if err != nil {
return err
}
*pc = PCClient{client, path.Join(user, repo)}
pc.ShowProgress(true)
return nil
}
func (pc PCClient) PackagecloudList() ([]pkgcloud.Package, error) {
logrus.WithFields(logrus.Fields{
"repo": pc.Repo,
}).Debug("Packagecloud listing package(s)")
return pc.All(pc.Repo)
}
func (pc PCClient) PackagecloudSearchPackage(pkg string) ([]pkgcloud.Package, error) {
logrus.WithFields(logrus.Fields{
"repo": pc.Repo,
"pkg": pkg,
}).Debug("Packagecloud searching package")
return pc.Search(pc.Repo, pkg, "", "", 0)
}
func (pc PCClient) PackagecloudPush(packages []string, distro string) error {
logrus.WithFields(logrus.Fields{
"repo": pc.Repo,
"#": len(packages),
"distro": distro,
}).Debug("Packagecloud pushing package")
for _, pkg := range packages {
if err := pc.CreatePackage(pc.Repo, distro, pkg); err != nil {
return err
}
}
return nil
}
func (pc PCClient) PackagecloudDelete(filename string, distro string) error {
logrus.WithFields(logrus.Fields{
"repo": pc.Repo,
"filename": filename,
"distro": distro,
}).Debug("Packagecloud delete package")
return pc.Destroy(pc.Repo, path.Join(distro, filename))
}