Skip to content

Commit

Permalink
Merge pull request #23 from containerish/OCI-Conformance
Browse files Browse the repository at this point in the history
implemented tag/list api
  • Loading branch information
jay-dee7 authored Sep 8, 2021
2 parents 26f5a4d + cc7a70e commit 4b9f63c
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 29 deletions.
6 changes: 3 additions & 3 deletions cache/register_for_beta.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func (ds *dataStore) RegisterForBeta(ctx echo.Context) error {

err := validateEmail(body["email"])
if err != nil {
return ctx.JSON(http.StatusBadRequest, echo.Map{
"error": "invalid email format, please try again",
})
return ctx.JSON(http.StatusBadRequest, echo.Map{
"error": "invalid email format, please try again",
})
}

key := []byte("email")
Expand Down
16 changes: 4 additions & 12 deletions cache/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,20 +296,16 @@ func (ds *dataStore) ListAll() ([]byte, error) {
}

func (ds *dataStore) ListWithPrefix(prefix []byte) ([]byte, error) {
var buf []*types.LayerRef
var buf []byte

err := ds.db.View(func(txn *badger.Txn) error {
it := txn.NewIterator(badger.DefaultIteratorOptions)
defer it.Close()
for it.Seek(prefix); it.ValidForPrefix(prefix); it.Next() {
item := it.Item()
err := item.Value(func(v []byte) error {
var layerRef types.LayerRef
if err := json.Unmarshal(v, &layerRef); err != nil {
return err
}

buf = append(buf, &layerRef)
buf = make([]byte, len(v))
copy(buf, v)
return nil
})
if err != nil {
Expand All @@ -318,11 +314,7 @@ func (ds *dataStore) ListWithPrefix(prefix []byte) ([]byte, error) {
}
return nil
})
if err != nil {
return nil, err
}

return json.Marshal(buf)
return buf, err
}

func (ds *dataStore) Delete(key []byte) error {
Expand Down
14 changes: 7 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (

type (
RegistryConfig struct {
Debug bool `mapstructure:"debug"`
Environment string `mapstructure:"environment"`
Host string `mapstructure:"host"`
Port uint `mapstructure:"port"`
SkynetPortalURL string `mapstructure:"skynet_portal_url"`
SigningSecret string `mapstructure:"signing_secret"`
SkynetConfig SkynetConfig `mapstructure:"skynet_config"`
Debug bool `mapstructure:"debug"`
Environment string `mapstructure:"environment"`
Host string `mapstructure:"host"`
Port uint `mapstructure:"port"`
SkynetPortalURL string `mapstructure:"skynet_portal_url"`
SigningSecret string `mapstructure:"signing_secret"`
SkynetConfig SkynetConfig `mapstructure:"skynet_config"`
}

SkynetConfig struct {
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ func main() {

e.Add(http.MethodGet, "/v2/", reg.ApiVersion, BasicAuth(authSvc.BasicAuth))

///GET /v2/<name>/tags/list
router.Add(http.MethodGet, "/tags/list", reg.ListTags)

router.Add(http.MethodDelete, "/blobs/:digest", reg.DeleteLayer)
router.Add(http.MethodDelete, "/manifests/:digest", reg.DeleteImage)

Expand Down
54 changes: 47 additions & 7 deletions registry/v2/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"io"
"net/http"
"path"
"sort"
"strconv"
"strings"
"sync"

Expand Down Expand Up @@ -367,7 +369,52 @@ func (r *registry) DeleteImage(ctx echo.Context) error {
return ctx.NoContent(http.StatusAccepted)
}

// Content discovery GET /v2/<name>/tags/list

func (r *registry) ListTags(ctx echo.Context) error {
namespace := ctx.Param("username") + "/" + ctx.Param("imagename")
limit := ctx.QueryParam("n")

l, err := r.localCache.ListWithPrefix([]byte(namespace))
if err != nil {
errMsg := r.errorResponse(RegistryErrorCodeTagInvalid, err.Error(), nil)
return ctx.JSONBlob(http.StatusNotFound, errMsg)
}
var md types.Metadata
err = json.Unmarshal(l, &md)
if err != nil {
errMsg := r.errorResponse(RegistryErrorCodeTagInvalid, err.Error(), nil)
return ctx.JSONBlob(http.StatusNotFound, errMsg)
}
var tags []string
for _, v := range md.Manifest.Config {
tags = append(tags, v.Reference)
}
if limit != "" {
n, err := strconv.ParseInt(limit, 10, 32)
if err != nil {
errMsg := r.errorResponse(RegistryErrorCodeTagInvalid, err.Error(), nil)
return ctx.JSONBlob(http.StatusNotFound, errMsg)
}
if n > 0 {
tags = tags[0:n]
}
if n == 0 {
tags = []string{}
}
}
sort.Strings(tags)
return ctx.JSON(http.StatusOK, echo.Map{
"name": namespace,
"tags": tags,
})
}
func (r *registry) List(ctx echo.Context) error {
return fmt.Errorf("error")
}

// GET /v2/<name>/blobs/<digest>

func (r *registry) PullLayer(ctx echo.Context) error {
namespace := ctx.Param("username") + "/" + ctx.Param("imagename")
clientDigest := ctx.Param("digest")
Expand Down Expand Up @@ -536,13 +583,6 @@ func (r *registry) PushLayer(ctx echo.Context) error {
return ctx.NoContent(http.StatusAccepted)
}

func (r *registry) ListTags(ctx echo.Context) error {
return nil
}
func (r *registry) List(ctx echo.Context) error {
return nil
}

// Should also look into 401 Code
// https://docs.docker.com/registry/spec/api/
func (r *registry) ApiVersion(ctx echo.Context) error {
Expand Down
3 changes: 3 additions & 0 deletions registry/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,11 @@ type Registry interface {
LayerExists(ctx echo.Context) error

// GET /v2/<name>/manifests/<ref>

PullManifest(ctx echo.Context) error

// PUT /v2/<name>/manifests/<reference>

PushManifest(ctx echo.Context) error

// Push individual layers first, then upload a signed manifest
Expand All @@ -173,6 +175,7 @@ type Registry interface {
// Range: bytes=0-<offset>
// Content-Length: 0
// Docker-Upload-UUID: <uuid>

PushImage(ctx echo.Context) error

StartUpload(ctx echo.Context) error
Expand Down

0 comments on commit 4b9f63c

Please sign in to comment.