add accntcli

This commit is contained in:
2026-03-07 19:11:20 +02:00
parent 46bcc465ee
commit efdabf3efc
23 changed files with 698 additions and 96 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ func (cli *Client) BlobExists(ctx context.Context, rawrepo string, digest string
var exist bool
var size int64
ref, err := NewRepository(rawrepo)
ref, err := NewReferer(rawrepo)
if err != nil {
return exist, size, err
}
+1 -1
View File
@@ -10,7 +10,7 @@ func (cli *Client) DeleteBlob(ctx context.Context, rawrepo, digest string) (bool
var err error
var exist bool
ref, err := NewRepository(rawrepo)
ref, err := NewReferer(rawrepo)
if err != nil {
return exist, err
}
+1 -1
View File
@@ -10,7 +10,7 @@ func (cli *Client) DeleteManifest(ctx context.Context, rawrepo, tag string) (boo
var err error
var exist bool
ref, err := NewRepository(rawrepo)
ref, err := NewReferer(rawrepo)
if err != nil {
return exist, err
}
+1 -1
View File
@@ -12,7 +12,7 @@ func (cli *Client) GetBlob(ctx context.Context, rawrepo string, writer io.Writer
var err error
var exist bool
ref, err := NewRepository(rawrepo)
ref, err := NewReferer(rawrepo)
if err != nil {
return exist, err
}
+1 -1
View File
@@ -19,7 +19,7 @@ func (cli *Client) GetManifest(ctx context.Context, rawrepo, tag string) (bool,
var mime string
var man []byte
ref, err := NewRepository(rawrepo)
ref, err := NewReferer(rawrepo)
if err != nil {
return exist, mime, man, err
}
+1 -1
View File
@@ -10,7 +10,7 @@ func (cli *Client) GetUpload(ctx context.Context, rawrepo string) (string, error
var err error
var loc string
ref, err := NewRepository(rawrepo)
ref, err := NewReferer(rawrepo)
if err != nil {
return loc, err
}
+1 -1
View File
@@ -14,7 +14,7 @@ func (cli *Client) ManifestExists(ctx context.Context, rawrepo, tag string) (boo
var size int64
var csum string
ref, err := NewRepository(rawrepo)
ref, err := NewReferer(rawrepo)
if err != nil {
return exist, mime, size, csum, err
}
+45
View File
@@ -0,0 +1,45 @@
package repocli
import (
"context"
"fmt"
"io"
"net/http"
"strconv"
)
func (cli *Client) PatchUpload(ctx context.Context, rawrepo string, src io.Reader, uploc string, size int64) (string, error) {
var err error
var ouloc string
ref, err := NewReferer(rawrepo)
if err != nil {
return ouloc, err
}
uri, err := ref.Patch(uploc)
if err != nil {
return ouloc, err
}
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, uri, src)
if err != nil {
return ouloc, err
}
req.Header.Set("User-Agent", cli.userAgent)
req.Header.Set("Content-Type", "application/octet-stream")
req.Header.Set("Content-Length", strconv.FormatInt(size, 10))
resp, err := cli.httpClient.Do(req)
if err != nil {
return ouloc, err
}
resp.Body.Close()
if resp.StatusCode != http.StatusAccepted {
err = fmt.Errorf("Upload not accepted, code %d", resp.StatusCode)
return ouloc, err
}
ouloc = resp.Header.Get("Location")
if ouloc == "" {
err := fmt.Errorf("Empty blob location declaration")
return ouloc, err
}
return ouloc, err
}
+1 -1
View File
@@ -12,7 +12,7 @@ import (
func (cli *Client) PutManifest(ctx context.Context, rawrepo, tag string, man []byte, mime string) error {
var err error
ref, err := NewRepository(rawrepo)
ref, err := NewReferer(rawrepo)
if err != nil {
return err
}
+1 -1
View File
@@ -12,7 +12,7 @@ func (cli *Client) PutUpload(ctx context.Context, rawrepo string, src io.Reader,
var err error
var bloc string
ref, err := NewRepository(rawrepo)
ref, err := NewReferer(rawrepo)
if err != nil {
return bloc, err
}
+10 -10
View File
@@ -5,14 +5,14 @@ import (
"strings"
)
type Repository struct {
type Referer struct {
urlobj *url.URL
user, pass string
base string
}
func NewRepository(rawrepo string) (*Repository, error) {
repo := &Repository{}
func NewReferer(rawrepo string) (*Referer, error) {
repo := &Referer{}
if !strings.Contains(rawrepo, "://") {
rawrepo = "https://" + rawrepo
}
@@ -33,27 +33,27 @@ func NewRepository(rawrepo string) (*Repository, error) {
return repo, err
}
func (repo *Repository) String() string {
func (repo *Referer) String() string {
curl := repo.urlobj.JoinPath(repo.base)
return curl.String()
}
func (repo *Repository) Manifest(tag string) string {
func (repo *Referer) Manifest(tag string) string {
curl := repo.urlobj.JoinPath("/v2", repo.base, "/manifests", tag)
return curl.String()
}
func (repo *Repository) Blob(digest string) string {
func (repo *Referer) Blob(digest string) string {
curl := repo.urlobj.JoinPath("/v2", repo.base, "/blobs", digest)
return curl.String()
}
func (repo *Repository) Upload() string {
func (repo *Referer) Upload() string {
curl := repo.urlobj.JoinPath("/v2", repo.base, "/blobs/uploads/")
return curl.String()
}
func (repo *Repository) Patch(loc string) (string, error) {
func (repo *Referer) Patch(loc string) (string, error) {
var curl *url.URL
var out string
var err error
@@ -73,7 +73,7 @@ func (repo *Repository) Patch(loc string) (string, error) {
return out, err
}
func (repo *Repository) Put(loc, digest string) (string, error) {
func (repo *Referer) Put(loc, digest string) (string, error) {
var curl *url.URL
var out string
var err error
@@ -95,6 +95,6 @@ func (repo *Repository) Put(loc, digest string) (string, error) {
return out, err
}
func (repo *Repository) Userinfo() (string, string) {
func (repo *Referer) Userinfo() (string, string) {
return repo.user, repo.pass
}
@@ -10,7 +10,7 @@ import (
)
func xxxTestResrerer(t *testing.T) {
ref, err := NewRepository("registry.example.com/lib/alpine")
ref, err := NewReferer("registry.example.com/lib/alpine")
require.NoError(t, err)
fmt.Printf("Manifest:\t%s\n", ref.Manifest("3.30.0"))