mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-04 15:04:25 +01:00
packaging: merge packaging repository
git-subtree-dir: tools/packaging git-subtree-mainline:f818b46a41git-subtree-split:1f22d72d5dSigned-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
20
tools/packaging/cmd/kata-pkgsync/vendor/github.com/mlafeldt/pkgcloud/.travis.yml
generated
vendored
Normal file
20
tools/packaging/cmd/kata-pkgsync/vendor/github.com/mlafeldt/pkgcloud/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
language: go
|
||||
|
||||
go:
|
||||
- "1.9"
|
||||
- "1.10"
|
||||
- "1.11"
|
||||
|
||||
sudo: false
|
||||
|
||||
before_script:
|
||||
- go get -d gopkg.in/cheggaaa/pb.v1
|
||||
- go get -d github.com/peterhellberg/link
|
||||
|
||||
script:
|
||||
- make all
|
||||
- make test
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
202
tools/packaging/cmd/kata-pkgsync/vendor/github.com/mlafeldt/pkgcloud/LICENSE
generated
vendored
Normal file
202
tools/packaging/cmd/kata-pkgsync/vendor/github.com/mlafeldt/pkgcloud/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
21
tools/packaging/cmd/kata-pkgsync/vendor/github.com/mlafeldt/pkgcloud/Makefile
generated
vendored
Normal file
21
tools/packaging/cmd/kata-pkgsync/vendor/github.com/mlafeldt/pkgcloud/Makefile
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
.PHONY: all
|
||||
all: pkgcloud-push build
|
||||
|
||||
build:
|
||||
go build
|
||||
|
||||
pkgcloud-push:
|
||||
go build ./cmd/$@
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
go test -v ./...
|
||||
|
||||
.PHONY: generate
|
||||
generate:
|
||||
go generate -x ./...
|
||||
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f pkgcloud-push
|
||||
40
tools/packaging/cmd/kata-pkgsync/vendor/github.com/mlafeldt/pkgcloud/README.md
generated
vendored
Normal file
40
tools/packaging/cmd/kata-pkgsync/vendor/github.com/mlafeldt/pkgcloud/README.md
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
# pkgcloud
|
||||
|
||||
[](https://travis-ci.org/mlafeldt/pkgcloud)
|
||||
[](https://godoc.org/github.com/mlafeldt/pkgcloud)
|
||||
|
||||
Talk to the [packagecloud API](https://packagecloud.io/docs/api), in Go.
|
||||
|
||||
## Installation
|
||||
|
||||
$ go get github.com/mlafeldt/pkgcloud/...
|
||||
|
||||
## API Usage
|
||||
|
||||
See [Godoc](https://godoc.org/github.com/mlafeldt/pkgcloud) and
|
||||
[pkgcloud.go](pkgcloud.go) to learn about the API.
|
||||
|
||||
## Client Usage
|
||||
|
||||
### Pushing packages
|
||||
|
||||
Pushing packages with `pkgcloud-push` is the only operation supported so far.
|
||||
The tool is a simple and fast replacement for the original `package_cloud push`
|
||||
command. If you pass more than one package, `pkgcloud-push` will push them in
|
||||
parallel! Before using it, however, make sure that `PACKAGECLOUD_TOKEN` is set
|
||||
in your environment.
|
||||
|
||||
Usage:
|
||||
|
||||
$ pkgcloud-push user/repo[/distro/version] /path/to/packages
|
||||
|
||||
Examples:
|
||||
|
||||
# Debian
|
||||
$ pkgcloud-push mlafeldt/myrepo/ubuntu/trusty example_1.2.3_amd64.deb
|
||||
|
||||
# RPM
|
||||
$ pkgcloud-push mlafeldt/myrepo/el/7 *.rpm
|
||||
|
||||
# RubyGem
|
||||
$ pkgcloud-push mlafeldt/myrepo example-1.2.3.gem
|
||||
108
tools/packaging/cmd/kata-pkgsync/vendor/github.com/mlafeldt/pkgcloud/distros.go
generated
vendored
Normal file
108
tools/packaging/cmd/kata-pkgsync/vendor/github.com/mlafeldt/pkgcloud/distros.go
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
// Generated with ./gendistros.py
|
||||
|
||||
package pkgcloud
|
||||
|
||||
var supportedDistros = map[string]int{
|
||||
"ubuntu/warty": 1,
|
||||
"ubuntu/hoary": 2,
|
||||
"ubuntu/breezy": 3,
|
||||
"ubuntu/dapper": 4,
|
||||
"ubuntu/edgy": 5,
|
||||
"ubuntu/feisty": 6,
|
||||
"ubuntu/gutsy": 7,
|
||||
"ubuntu/hardy": 8,
|
||||
"ubuntu/intrepid": 9,
|
||||
"ubuntu/jaunty": 10,
|
||||
"ubuntu/karmic": 11,
|
||||
"ubuntu/lucid": 12,
|
||||
"ubuntu/maverick": 13,
|
||||
"ubuntu/natty": 14,
|
||||
"ubuntu/oneiric": 15,
|
||||
"ubuntu/precise": 16,
|
||||
"ubuntu/quantal": 17,
|
||||
"ubuntu/raring": 18,
|
||||
"ubuntu/saucy": 19,
|
||||
"ubuntu/trusty": 20,
|
||||
"debian/etch": 21,
|
||||
"debian/lenny": 22,
|
||||
"debian/squeeze": 23,
|
||||
"debian/wheezy": 24,
|
||||
"debian/jessie": 25,
|
||||
"el/5": 26,
|
||||
"el/6": 27,
|
||||
"fedora/14": 28,
|
||||
"fedora/15": 29,
|
||||
"fedora/16": 30,
|
||||
"fedora/17": 31,
|
||||
"fedora/18": 32,
|
||||
"fedora/19": 33,
|
||||
"fedora/20": 34,
|
||||
"any/any": 35,
|
||||
"scientific/5": 138,
|
||||
"scientific/6": 139,
|
||||
"el/7": 140,
|
||||
"scientific/7": 141,
|
||||
"ubuntu/utopic": 142,
|
||||
"fedora/21": 143,
|
||||
"ol/5": 144,
|
||||
"ol/6": 145,
|
||||
"ol/7": 146,
|
||||
"fedora/22": 147,
|
||||
"ubuntu/vivid": 148,
|
||||
"debian/stretch": 149,
|
||||
"debian/buster": 150,
|
||||
"fedora/23": 151,
|
||||
"ubuntu/wily": 152,
|
||||
"raspbian/wheezy": 153,
|
||||
"raspbian/jessie": 154,
|
||||
"raspbian/stretch": 155,
|
||||
"raspbian/buster": 156,
|
||||
"linuxmint/petra": 157,
|
||||
"linuxmint/qiana": 158,
|
||||
"linuxmint/rebecca": 159,
|
||||
"linuxmint/rafaela": 160,
|
||||
"linuxmint/rosa": 161,
|
||||
"elementaryos/jupiter": 162,
|
||||
"elementaryos/luna": 163,
|
||||
"elementaryos/freya": 164,
|
||||
"ubuntu/xenial": 165,
|
||||
"python": 166,
|
||||
"java/maven2": 167,
|
||||
"ubuntu/yakkety": 168,
|
||||
"fedora/24": 169,
|
||||
"linuxmint/sarah": 170,
|
||||
"poky/jethro": 171,
|
||||
"poky/krogoth": 172,
|
||||
"opensuse/13.1": 173,
|
||||
"opensuse/13.2": 174,
|
||||
"opensuse/42.1": 175,
|
||||
"sles/11.4": 176,
|
||||
"sles/12.0": 177,
|
||||
"sles/12.1": 178,
|
||||
"fedora/25": 179,
|
||||
"linuxmint/serena": 180,
|
||||
"opensuse/42.2": 181,
|
||||
"sles/12.2": 182,
|
||||
"ubuntu/zesty": 183,
|
||||
"fedora/26": 184,
|
||||
"linuxmint/sonya": 185,
|
||||
"opensuse/42.3": 186,
|
||||
"ubuntu/artful": 187,
|
||||
"fedora/27": 188,
|
||||
"linuxmint/sylvia": 189,
|
||||
"ubuntu/bionic": 190,
|
||||
"node/1": 191,
|
||||
"sles/12.3": 192,
|
||||
"elementaryos/loki": 193,
|
||||
"fedora/28": 194,
|
||||
"linuxmint/tara": 195,
|
||||
"opensuse/15.0": 196,
|
||||
"opensuse/15.1": 197,
|
||||
"sles/15.0": 198,
|
||||
"ubuntu/cosmic": 199,
|
||||
"elementaryos/juno": 200,
|
||||
"fedora/29": 201,
|
||||
"linuxmint/tessa": 202,
|
||||
"ubuntu/disco": 203,
|
||||
"fedora/30": 204,
|
||||
}
|
||||
34
tools/packaging/cmd/kata-pkgsync/vendor/github.com/mlafeldt/pkgcloud/gendistros.py
generated
vendored
Executable file
34
tools/packaging/cmd/kata-pkgsync/vendor/github.com/mlafeldt/pkgcloud/gendistros.py
generated
vendored
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python
|
||||
# Generate Go map of distros supported by Packagecloud API
|
||||
# By generating the list once, we save an expensive API call.
|
||||
# See https://packagecloud.io/docs/api#resource_distributions
|
||||
|
||||
import os, sys
|
||||
import urllib
|
||||
import json
|
||||
|
||||
var = sys.argv[1]
|
||||
token = os.environ['PACKAGECLOUD_TOKEN']
|
||||
|
||||
url = 'https://%s:@packagecloud.io/api/v1/distributions.json' % token
|
||||
resp = urllib.urlopen(url)
|
||||
data = json.loads(resp.read())
|
||||
|
||||
result = {}
|
||||
for distros in data.values():
|
||||
for d in distros:
|
||||
for v in d['versions']:
|
||||
k = d['index_name']
|
||||
if 'index_name' in v:
|
||||
k = '/'.join([k, v['index_name']])
|
||||
v = v['id']
|
||||
result[k] = v
|
||||
|
||||
print '// Generated with %s' % __file__
|
||||
print
|
||||
print 'package pkgcloud'
|
||||
print
|
||||
print 'var %s = map[string]int{' % var
|
||||
for k, v in sorted(result.items(),key=lambda x:x[1]):
|
||||
print "\t\"%s\": %d," % (k, v)
|
||||
print '}'
|
||||
241
tools/packaging/cmd/kata-pkgsync/vendor/github.com/mlafeldt/pkgcloud/pkgcloud.go
generated
vendored
Normal file
241
tools/packaging/cmd/kata-pkgsync/vendor/github.com/mlafeldt/pkgcloud/pkgcloud.go
generated
vendored
Normal file
@@ -0,0 +1,241 @@
|
||||
// Package pkgcloud allows you to talk to the packagecloud API.
|
||||
// See https://packagecloud.io/docs/api
|
||||
package pkgcloud
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
||||
"github.com/mlafeldt/pkgcloud/upload"
|
||||
"github.com/peterhellberg/link"
|
||||
pb "gopkg.in/cheggaaa/pb.v1"
|
||||
)
|
||||
|
||||
//go:generate bash -c "./gendistros.py supportedDistros | gofmt > distros.go"
|
||||
|
||||
// ServiceURL is the URL of packagecloud's API.
|
||||
const ServiceURL = "https://packagecloud.io/api/v1"
|
||||
|
||||
const UserAgent = "pkgcloud Go client"
|
||||
|
||||
// A Client is a packagecloud client.
|
||||
type Client struct {
|
||||
token string
|
||||
progressBar bool
|
||||
}
|
||||
|
||||
// NewClient creates a packagecloud client. API requests are authenticated
|
||||
// using an API token. If no token is passed, it will be read from the
|
||||
// PACKAGECLOUD_TOKEN environment variable.
|
||||
func NewClient(token string) (*Client, error) {
|
||||
if token == "" {
|
||||
token = os.Getenv("PACKAGECLOUD_TOKEN")
|
||||
if token == "" {
|
||||
return nil, errors.New("PACKAGECLOUD_TOKEN unset")
|
||||
}
|
||||
}
|
||||
return &Client{token, false}, nil
|
||||
}
|
||||
|
||||
// Print a progress bar of paginated API requests when show is set to true
|
||||
func (c *Client) ShowProgress(show bool) {
|
||||
c.progressBar = show
|
||||
}
|
||||
|
||||
// decodeResponse checks http status code and tries to decode json body
|
||||
func decodeResponse(resp *http.Response, respJson interface{}) error {
|
||||
switch resp.StatusCode {
|
||||
case http.StatusOK, http.StatusCreated:
|
||||
return json.NewDecoder(resp.Body).Decode(respJson)
|
||||
case http.StatusUnauthorized, http.StatusNotFound:
|
||||
return fmt.Errorf("HTTP status: %s", http.StatusText(resp.StatusCode))
|
||||
case 422: // Unprocessable Entity
|
||||
var v map[string][]string
|
||||
if err := json.NewDecoder(resp.Body).Decode(&v); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, messages := range v {
|
||||
for _, msg := range messages {
|
||||
// Only return the very first error message
|
||||
return errors.New(msg)
|
||||
}
|
||||
break
|
||||
}
|
||||
return fmt.Errorf("invalid HTTP body")
|
||||
default:
|
||||
return fmt.Errorf("unexpected HTTP status: %d", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
// CreatePackage pushes a new package to packagecloud.
|
||||
func (c Client) CreatePackage(repo, distro, pkgFile string) error {
|
||||
var extraParams map[string]string
|
||||
if distro != "" {
|
||||
distID, ok := supportedDistros[distro]
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid distro name: %s", distro)
|
||||
}
|
||||
extraParams = map[string]string{
|
||||
"package[distro_version_id]": strconv.Itoa(distID),
|
||||
}
|
||||
}
|
||||
|
||||
endpoint := fmt.Sprintf("%s/repos/%s/packages.json", ServiceURL, repo)
|
||||
request, err := upload.NewRequest(endpoint, extraParams, "package[package_file]", pkgFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
request.SetBasicAuth(c.token, "")
|
||||
request.Header.Add("User-Agent", UserAgent)
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
return decodeResponse(resp, &struct{}{})
|
||||
}
|
||||
|
||||
type Package struct {
|
||||
Name string `json:"name"`
|
||||
Filename string `json:"filename"`
|
||||
DistroVersion string `json:"distro_version"`
|
||||
Version string `json:"version"`
|
||||
Release string `json:"release"`
|
||||
Type string `json:"type"`
|
||||
PackageUrl string `json:"package_url"`
|
||||
PackageHtmlUrl string `json:"package_html_url"`
|
||||
}
|
||||
|
||||
// All list all packages in repository
|
||||
func (c Client) All(repo string) ([]Package, error) {
|
||||
endpoint := fmt.Sprintf("%s/repos/%s/packages.json", ServiceURL, repo)
|
||||
return c.paginatedRequest(http.MethodGet, endpoint)
|
||||
}
|
||||
|
||||
// Destroy removes package from repository.
|
||||
//
|
||||
// repo should be full path to repository
|
||||
// (e.g. youruser/repository/ubuntu/xenial).
|
||||
func (c Client) Destroy(repo, packageFilename string) error {
|
||||
endpoint := fmt.Sprintf("%s/repos/%s/%s", ServiceURL, repo, packageFilename)
|
||||
_, err := c.apiRequest(http.MethodDelete, endpoint, &struct{}{})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Search searches packages from repository.
|
||||
// repo should be full path to repository
|
||||
// (e.g. youruser/repository/ubuntu/xenial).
|
||||
// q: The query string to search for package filename. If empty string is passed, all packages are returned
|
||||
// filter: Search by package type (RPMs, Debs, DSCs, Gem, Python) - Ignored when dist != ""
|
||||
// dist: The name of the distribution the package is in. (i.e. ubuntu, el/6) - Overrides filter.
|
||||
// perPage: The number of packages to return from the results set. If nothing passed, default is 30
|
||||
func (c Client) Search(repo, q, filter, dist string, perPage int) ([]Package, error) {
|
||||
endpoint := fmt.Sprintf("%s/repos/%s/search.json?q=%s&filter=%s&dist=%s&per_page=%d", ServiceURL, repo, q, filter, dist, perPage)
|
||||
return c.paginatedRequest(http.MethodGet, endpoint)
|
||||
}
|
||||
|
||||
|
||||
func (c Client) paginatedRequest(method string, endpoint string) ([]Package, error) {
|
||||
var (
|
||||
allPackages []Package
|
||||
getLastPage bool
|
||||
)
|
||||
|
||||
newPage := make(chan bool)
|
||||
total := make(chan int)
|
||||
|
||||
if c.progressBar {
|
||||
getLastPage = true
|
||||
progBar := pb.New(0)
|
||||
progBar.SetMaxWidth(100)
|
||||
progBar.Start()
|
||||
defer func() {
|
||||
progBar.Increment()
|
||||
progBar.Finish()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case np := <-newPage:
|
||||
if !np {
|
||||
return
|
||||
}
|
||||
progBar.Increment()
|
||||
case t := <-total:
|
||||
progBar.SetTotal(t)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
for {
|
||||
var pkgs []Package
|
||||
var group link.Group
|
||||
group, err := c.apiRequest(method, endpoint, &pkgs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
allPackages = append(allPackages, pkgs...)
|
||||
|
||||
next, found := group["next"]
|
||||
newPage <- found
|
||||
if !found {
|
||||
break
|
||||
}
|
||||
endpoint = next.URI
|
||||
|
||||
if !getLastPage {
|
||||
continue
|
||||
}
|
||||
|
||||
if last, found := group["last"]; found {
|
||||
re := regexp.MustCompile(`page=(\d+)$`)
|
||||
pages, err := strconv.Atoi(re.FindStringSubmatch(last.URI)[1])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
getLastPage = false
|
||||
total <- pages
|
||||
}
|
||||
}
|
||||
|
||||
return allPackages, nil
|
||||
|
||||
}
|
||||
|
||||
func (c Client) apiRequest(method string, endpoint string, decodedResp interface{}) (link.Group, error) {
|
||||
req, err := http.NewRequest(method, endpoint, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.SetBasicAuth(c.token, "")
|
||||
req.Header.Add("User-Agent", UserAgent)
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
err = decodeResponse(resp, decodedResp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// API are paginated, with next page in the response header, as "Link"
|
||||
// element
|
||||
return link.ParseResponse(resp), nil
|
||||
}
|
||||
45
tools/packaging/cmd/kata-pkgsync/vendor/github.com/mlafeldt/pkgcloud/upload/upload.go
generated
vendored
Normal file
45
tools/packaging/cmd/kata-pkgsync/vendor/github.com/mlafeldt/pkgcloud/upload/upload.go
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
package upload
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// NewRequest creates a new file upload HTTP request with optional extra params.
|
||||
// Based on https://gist.github.com/mattetti/5914158
|
||||
func NewRequest(url string, params map[string]string, paramName, path string) (*http.Request, error) {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
var body bytes.Buffer
|
||||
writer := multipart.NewWriter(&body)
|
||||
part, err := writer.CreateFormFile(paramName, filepath.Base(path))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err = io.Copy(part, file); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for k, v := range params {
|
||||
if err := writer.WriteField(k, v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err := writer.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
request, err := http.NewRequest("POST", url, &body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
request.Header.Add("Content-Type", writer.FormDataContentType())
|
||||
return request, nil
|
||||
}
|
||||
Reference in New Issue
Block a user