working commit
This commit is contained in:
@@ -11,8 +11,6 @@ import (
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/pkg/auxoci"
|
||||
|
||||
ocidigest "github.com/opencontainers/go-digest"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -69,7 +67,7 @@ func (oper *Operator) ManifestExists(ctx context.Context, params *ManifestExists
|
||||
}
|
||||
}
|
||||
|
||||
digest := ocidigest.SHA256.FromString(manifest.Payload)
|
||||
digest := auxoci.SHA256DigestFromString(manifest.Payload)
|
||||
payloadSize := len(manifest.Payload)
|
||||
res.ContentLength = strconv.FormatInt(int64(payloadSize), 10)
|
||||
res.ContentType = manifest.ContentType
|
||||
@@ -227,3 +225,52 @@ func (oper *Operator) PutManifest(ctx context.Context, params *PutManifestParams
|
||||
return res, http.StatusCreated, err
|
||||
|
||||
}
|
||||
|
||||
type GetManifestParams struct {
|
||||
Name string
|
||||
Reference string
|
||||
}
|
||||
type GetManifestResult struct {
|
||||
ContentLength string
|
||||
ContentType string
|
||||
DockerContentDigest string
|
||||
Payload string
|
||||
}
|
||||
|
||||
func (oper *Operator) GetManifest(ctx context.Context, params *GetManifestParams) (*GetManifestResult, int, error) {
|
||||
var err error
|
||||
res := &GetManifestResult{}
|
||||
oper.logg.Debugf("Get manifest %s:%s", params.Name, params.Reference)
|
||||
|
||||
manifestDescr := descr.Manifest{}
|
||||
var exists bool
|
||||
if stringLikeSHADigest(params.Reference) {
|
||||
digest := normalizeSHADigest(params.Reference)
|
||||
oper.logg.Debugf("Get manifest %s with digest %s", params.Name, params.Reference)
|
||||
exists, manifestDescr, err = oper.mdb.GetManifestByDigest(ctx, params.Name, digest)
|
||||
if err != nil {
|
||||
return res, http.StatusInternalServerError, err
|
||||
}
|
||||
if !exists {
|
||||
return res, http.StatusNotFound, err
|
||||
}
|
||||
} else {
|
||||
oper.logg.Debugf("Get manifest %s with tag %s", params.Name, params.Reference)
|
||||
exists, manifestDescr, err = oper.mdb.GetManifestByReference(ctx, params.Name, params.Reference)
|
||||
if err != nil {
|
||||
return res, http.StatusInternalServerError, err
|
||||
}
|
||||
if !exists {
|
||||
return res, http.StatusNotFound, err
|
||||
}
|
||||
}
|
||||
|
||||
manifestDigest := auxoci.SHA256DigestFromString(manifestDescr.Payload)
|
||||
res.DockerContentDigest = manifestDigest.String()
|
||||
|
||||
res.ContentLength = strconv.FormatInt(int64(len(manifestDescr.Payload)), 10)
|
||||
res.ContentType = manifestDescr.ContentType
|
||||
res.Payload = manifestDescr.Payload
|
||||
|
||||
return res, http.StatusOK, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user