splitted one operator module to file, account, image operators; splitted operator functions; etc
This commit is contained in:
@@ -26,7 +26,6 @@ import (
|
||||
const (
|
||||
indexMediaType = "application/vnd.oci.image.index.v1+json"
|
||||
manifestMediaType = "application/vnd.oci.image.manifest.v1+json"
|
||||
|
||||
)
|
||||
|
||||
func (cli *Client) ImageManifest(ctx context.Context, imagepath string) (any, error) {
|
||||
|
||||
+16
-21
@@ -10,7 +10,7 @@
|
||||
package descr
|
||||
|
||||
import (
|
||||
"path"
|
||||
"path"
|
||||
)
|
||||
|
||||
type File struct {
|
||||
@@ -26,43 +26,38 @@ type File struct {
|
||||
UpdatedBy string `db:"updated_by" json:"updatedBy,omitempty" yaml:"updatedBy,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
|
||||
type Files struct {
|
||||
files []File
|
||||
files []File
|
||||
}
|
||||
|
||||
func NewFiles() *Files {
|
||||
return &Files{
|
||||
files: make([]File, 0),
|
||||
}
|
||||
return &Files{
|
||||
files: make([]File, 0),
|
||||
}
|
||||
}
|
||||
|
||||
func xxxNewFiles(files []File) *Files {
|
||||
return &Files{
|
||||
files: files,
|
||||
}
|
||||
return &Files{
|
||||
files: files,
|
||||
}
|
||||
}
|
||||
|
||||
func (fi *Files) Set(files []File) {
|
||||
fi.files = files
|
||||
fi.files = files
|
||||
}
|
||||
|
||||
func (fi *Files) ArrayPtr() *[]File {
|
||||
return &fi.files
|
||||
return &fi.files
|
||||
}
|
||||
|
||||
func (fi *Files) Array() []File {
|
||||
return fi.files
|
||||
return fi.files
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (fi *Files) List() []string {
|
||||
list := make([]string, 0)
|
||||
for _, file := range fi.files {
|
||||
list = append(list, path.Join(file.Collection, file.Name))
|
||||
}
|
||||
return list
|
||||
list := make([]string, 0)
|
||||
for _, file := range fi.files {
|
||||
list = append(list, path.Join(file.Collection, file.Name))
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ func NewClient(transport http.RoundTripper, mwFuncs ...MiddlewareFunc) *Client {
|
||||
if transport == nil {
|
||||
transport = NewDefaultTransport()
|
||||
}
|
||||
for _, mwFunc := range mwFuncs {
|
||||
transport = mwFunc(transport)
|
||||
}
|
||||
for _, mwFunc := range mwFuncs {
|
||||
transport = mwFunc(transport)
|
||||
}
|
||||
httpClient := &http.Client{
|
||||
Transport: transport,
|
||||
}
|
||||
@@ -38,7 +38,6 @@ func (cli *Client) UseMiddleware(mwFunc MiddlewareFunc) {
|
||||
cli.httpClient.Transport = mwFunc(cli.httpClient.Transport)
|
||||
}
|
||||
|
||||
|
||||
// BasicAuthMiddleware
|
||||
func NewBasicAuthMiddleware(user, pass string) MiddlewareFunc {
|
||||
return func(next http.RoundTripper) http.RoundTripper {
|
||||
@@ -60,10 +59,10 @@ func newBasicAuthMW(next http.RoundTripper, user, pass string) *BasicAuthMW {
|
||||
}
|
||||
|
||||
func (tran BasicAuthMW) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
if tran.user != "" && tran.pass != "" {
|
||||
pair := base64.StdEncoding.EncodeToString([]byte(tran.user + ":" + tran.pass))
|
||||
req.Header.Set("Authorization", "Basic "+pair)
|
||||
}
|
||||
if tran.user != "" && tran.pass != "" {
|
||||
pair := base64.StdEncoding.EncodeToString([]byte(tran.user + ":" + tran.pass))
|
||||
req.Header.Set("Authorization", "Basic "+pair)
|
||||
}
|
||||
return tran.next.RoundTrip(req)
|
||||
}
|
||||
|
||||
@@ -110,7 +109,6 @@ func (wrap *DefaultTransport) RoundTrip(req *http.Request) (*http.Response, erro
|
||||
return wrap.transport.RoundTrip(req)
|
||||
}
|
||||
|
||||
|
||||
// ExampleMiddleware
|
||||
func NewExampleMiddleware() MiddlewareFunc {
|
||||
return func(next http.RoundTripper) http.RoundTripper {
|
||||
|
||||
@@ -11,7 +11,7 @@ func (cli *Client) FileInfo(ctx context.Context, rawpath string) (bool, int64, s
|
||||
var err error
|
||||
var exist bool
|
||||
var size int64
|
||||
var digest string
|
||||
var digest string
|
||||
|
||||
ref, err := ParsePath(rawpath)
|
||||
if err != nil {
|
||||
|
||||
+12
-12
@@ -3,8 +3,8 @@ package filecli
|
||||
import (
|
||||
"net/url"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -17,13 +17,13 @@ type Repository struct {
|
||||
urlobj *url.URL
|
||||
user, pass string
|
||||
resource string
|
||||
values url.Values
|
||||
values url.Values
|
||||
}
|
||||
|
||||
func ParsePath(rawpath string) (*Repository, error) {
|
||||
repo := &Repository{
|
||||
values: url.Values{},
|
||||
}
|
||||
values: url.Values{},
|
||||
}
|
||||
if !strings.Contains(rawpath, "://") {
|
||||
rawpath = "https://" + rawpath
|
||||
}
|
||||
@@ -39,17 +39,17 @@ func ParsePath(rawpath string) (*Repository, error) {
|
||||
repo.resource = path.Join("/", urlobj.Path)
|
||||
urlobj.Path = "/"
|
||||
repo.urlobj = urlobj
|
||||
repo.values = urlobj.Query()
|
||||
repo.values = urlobj.Query()
|
||||
return repo, err
|
||||
}
|
||||
|
||||
func (repo *Repository) Raw() string {
|
||||
res := path.Join(repo.urlobj.Host, repo.resource)
|
||||
query := repo.values.Encode()
|
||||
if query != "" {
|
||||
return res + "?" + query
|
||||
}
|
||||
return res
|
||||
query := repo.values.Encode()
|
||||
if query != "" {
|
||||
return res + "?" + query
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func (repo *Repository) SetResource(resource string) {
|
||||
@@ -61,11 +61,11 @@ func (repo *Repository) JoinResource(resource string) {
|
||||
}
|
||||
|
||||
func (repo *Repository) PathType(typ string) {
|
||||
repo.values.Set("pathType", typ)
|
||||
repo.values.Set("pathType", typ)
|
||||
}
|
||||
|
||||
func (repo *Repository) DryRun(yesno bool) {
|
||||
repo.values.Set("dryRun", strconv.FormatBool(yesno))
|
||||
repo.values.Set("dryRun", strconv.FormatBool(yesno))
|
||||
}
|
||||
|
||||
func (repo *Repository) File() string {
|
||||
|
||||
@@ -87,10 +87,10 @@ func newBasicAuthMW(next http.RoundTripper, user, pass string) *BasicAuthMW {
|
||||
}
|
||||
|
||||
func (tran BasicAuthMW) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
if tran.user != "" && tran.pass != "" {
|
||||
pair := base64.StdEncoding.EncodeToString([]byte(tran.user + ":" + tran.pass))
|
||||
req.Header.Set("Authorization", "Basic "+pair)
|
||||
}
|
||||
if tran.user != "" && tran.pass != "" {
|
||||
pair := base64.StdEncoding.EncodeToString([]byte(tran.user + ":" + tran.pass))
|
||||
req.Header.Set("Authorization", "Basic "+pair)
|
||||
}
|
||||
return tran.next.RoundTrip(req)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package repocli
|
||||
|
||||
const (
|
||||
//MediaTypeDDMLv2 = "application/vnd.docker.distribution.manifest.list.v2+json"
|
||||
//MediaTypeDDMv2 = "application/vnd.docker.distribution.manifest.v2+json"
|
||||
// MediaTypeDDMLv2 = "application/vnd.docker.distribution.manifest.list.v2+json"
|
||||
// MediaTypeDDMv2 = "application/vnd.docker.distribution.manifest.v2+json"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user