working commit
This commit is contained in:
@@ -264,3 +264,119 @@ func (cli *Client) ListFiles(ctx context.Context, catalogURI string) ([]descr.Fi
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (cli *Client) ListCollections(ctx context.Context, catalogURI string) ([]string, error) {
|
||||
var err error
|
||||
res := make([]string, 0)
|
||||
|
||||
catalogURI, username, password, err := repackServiceURI(catalogURI)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
catalogURI, err = convertCollectionsURI(catalogURI)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, catalogURI, nil)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
if username != "" && password != "" {
|
||||
basic := auxhttp.EncodeBasicAuth(username, password)
|
||||
req.Header.Add("Authorization", basic)
|
||||
}
|
||||
client := makeHTTPClient()
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
contentLength := resp.Header.Get("Content-Length")
|
||||
if contentLength == "" {
|
||||
err = fmt.Errorf("Empty Content-Length received")
|
||||
return res, err
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
err := fmt.Errorf("Received wrong status code: %s", resp.Status)
|
||||
return res, err
|
||||
}
|
||||
declSize, err := strconv.ParseInt(contentLength, 10, 64)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Wrong Content-Length value: %v", err)
|
||||
return res, err
|
||||
}
|
||||
respBuffer := bytes.NewBuffer(nil)
|
||||
size, err := io.Copy(respBuffer, resp.Body)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
respBytes := respBuffer.Bytes()
|
||||
if size != declSize {
|
||||
err := fmt.Errorf("Mismatch Content-Length and recorded filesize")
|
||||
return res, err
|
||||
}
|
||||
err = json.Unmarshal(respBytes, &res)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (cli *Client) DeleteCollection(ctx context.Context, catalogURI string) ([]descr.File, error) {
|
||||
var err error
|
||||
res := make([]descr.File, 0)
|
||||
|
||||
catalogURI, username, password, err := repackServiceURI(catalogURI)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
catalogURI, err = convertCollectionURI(catalogURI)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, catalogURI, nil)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
if username != "" && password != "" {
|
||||
basic := auxhttp.EncodeBasicAuth(username, password)
|
||||
req.Header.Add("Authorization", basic)
|
||||
}
|
||||
client := makeHTTPClient()
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
contentLength := resp.Header.Get("Content-Length")
|
||||
if contentLength == "" {
|
||||
err = fmt.Errorf("Empty Content-Length received")
|
||||
return res, err
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
err := fmt.Errorf("Received wrong status code: %s", resp.Status)
|
||||
return res, err
|
||||
}
|
||||
declSize, err := strconv.ParseInt(contentLength, 10, 64)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Wrong Content-Length value: %v", err)
|
||||
return res, err
|
||||
}
|
||||
respBuffer := bytes.NewBuffer(nil)
|
||||
size, err := io.Copy(respBuffer, resp.Body)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
respBytes := respBuffer.Bytes()
|
||||
if size != declSize {
|
||||
err := fmt.Errorf("Mismatch Content-Length and recorded filesize")
|
||||
return res, err
|
||||
}
|
||||
err = json.Unmarshal(respBytes, &res)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -59,6 +59,32 @@ func convertFilesURI(fileuri string) (string, error) {
|
||||
return res, err
|
||||
}
|
||||
|
||||
func convertCollectionsURI(fileuri string) (string, error) {
|
||||
var err error
|
||||
var res string
|
||||
uri, err := url.Parse(fileuri)
|
||||
const prefixAPI = "/v3/api/collections/"
|
||||
uri.Path, err = url.JoinPath(prefixAPI, uri.Path)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res = uri.String()
|
||||
return res, err
|
||||
}
|
||||
|
||||
func convertCollectionURI(fileuri string) (string, error) {
|
||||
var err error
|
||||
var res string
|
||||
uri, err := url.Parse(fileuri)
|
||||
const prefixAPI = "/v3/api/collection/"
|
||||
uri.Path, err = url.JoinPath(prefixAPI, uri.Path)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res = uri.String()
|
||||
return res, err
|
||||
}
|
||||
|
||||
func repackServiceURI(fileuri string) (string, string, string, error) {
|
||||
var err error
|
||||
var res, username, password string
|
||||
|
||||
+2
-6
@@ -54,7 +54,6 @@ func (cli *Client) CreateGrantByAccountID(ctx context.Context, hosturi, accountI
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
||||
func (cli *Client) CreateGrantByUsername(ctx context.Context, hosturi, username, right, pattern string) (string, error) {
|
||||
var err error
|
||||
var res string
|
||||
@@ -65,8 +64,8 @@ func (cli *Client) CreateGrantByUsername(ctx context.Context, hosturi, username,
|
||||
}
|
||||
operParams := operator.CreateGrantParams{
|
||||
Username: username,
|
||||
Right: right,
|
||||
Pattern: pattern,
|
||||
Right: right,
|
||||
Pattern: pattern,
|
||||
}
|
||||
paramsJson, err := json.Marshal(operParams)
|
||||
if err != nil {
|
||||
@@ -90,7 +89,6 @@ func (cli *Client) CreateGrantByUsername(ctx context.Context, hosturi, username,
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
||||
func (cli *Client) GetGrant(ctx context.Context, hosturi, id string) (*descr.Grant, error) {
|
||||
var err error
|
||||
res := &descr.Grant{}
|
||||
@@ -124,8 +122,6 @@ func (cli *Client) GetGrant(ctx context.Context, hosturi, id string) (*descr.Gra
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (cli *Client) UpdateGrant(ctx context.Context, hosturi, grantID, newPattern string) error {
|
||||
var err error
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
"github.com/google/go-containerregistry/pkg/v1/remote/transport"
|
||||
)
|
||||
|
||||
func (cli *Client) PullImage(ctx context.Context, filepath, imagepath string) error {
|
||||
func (cli *Client) PullImage(ctx context.Context, imagepath, filepath string) error {
|
||||
var err error
|
||||
|
||||
imagepath, username, password, err := repackReference(imagepath)
|
||||
|
||||
Reference in New Issue
Block a user