mirror of
https://github.com/project-zot/zot.git
synced 2024-12-30 22:34:13 -05:00
commit
136d389101
3 changed files with 47 additions and 38 deletions
|
@ -41,6 +41,24 @@ func TestAPI(t *testing.T) {
|
||||||
err = json.Unmarshal(resp.Body(), &repoList)
|
err = json.Unmarshal(resp.Body(), &repoList)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(len(repoList.Repositories), ShouldEqual, 0)
|
So(len(repoList.Repositories), ShouldEqual, 0)
|
||||||
|
|
||||||
|
// after newly created upload should succeed
|
||||||
|
resp, err = resty.R().Post(BaseURL + "/v2/z/blobs/uploads/")
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(resp.StatusCode(), ShouldEqual, 202)
|
||||||
|
|
||||||
|
// after newly created upload should succeed
|
||||||
|
resp, err = resty.R().Post(BaseURL + "/v2/a/b/c/d/blobs/uploads/")
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(resp.StatusCode(), ShouldEqual, 202)
|
||||||
|
|
||||||
|
resp, err = resty.R().SetResult(&api.RepositoryList{}).Get(BaseURL + "/v2/_catalog")
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(resp.StatusCode(), ShouldEqual, 200)
|
||||||
|
So(resp.String(), ShouldNotBeEmpty)
|
||||||
|
r := resp.Result().(*api.RepositoryList)
|
||||||
|
So(r.Repositories[0], ShouldEqual, "a/b/c/d")
|
||||||
|
So(r.Repositories[1], ShouldEqual, "z")
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Get images in a repository", func() {
|
Convey("Get images in a repository", func() {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/anuvu/zot/errors"
|
"github.com/anuvu/zot/errors"
|
||||||
|
@ -39,35 +40,11 @@ func NewImageStore(rootDir string, log zerolog.Logger) *ImageStore {
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(rootDir); os.IsNotExist(err) {
|
if _, err := os.Stat(rootDir); os.IsNotExist(err) {
|
||||||
_ = os.MkdirAll(rootDir, 0700)
|
_ = os.MkdirAll(rootDir, 0700)
|
||||||
} else if _, err := is.Validate(); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return is
|
return is
|
||||||
}
|
}
|
||||||
|
|
||||||
func (is *ImageStore) Validate() (bool, error) {
|
|
||||||
dir := is.rootDir
|
|
||||||
files, err := ioutil.ReadDir(dir)
|
|
||||||
if err != nil {
|
|
||||||
is.log.Error().Err(err).Str("dir", dir).Msg("unable to read directory")
|
|
||||||
return false, errors.ErrRepoNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, file := range files {
|
|
||||||
if !file.IsDir() {
|
|
||||||
is.log.Error().Err(err).Str("file", file.Name()).Msg("not a directory")
|
|
||||||
return false, errors.ErrRepoIsNotDir
|
|
||||||
}
|
|
||||||
|
|
||||||
v, err := is.ValidateRepo(file.Name())
|
|
||||||
if !v {
|
|
||||||
return v, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (is *ImageStore) InitRepo(name string) error {
|
func (is *ImageStore) InitRepo(name string) error {
|
||||||
repoDir := path.Join(is.rootDir, name)
|
repoDir := path.Join(is.rootDir, name)
|
||||||
|
|
||||||
|
@ -176,19 +153,39 @@ func (is *ImageStore) ValidateRepo(name string) (bool, error) {
|
||||||
|
|
||||||
func (is *ImageStore) GetRepositories() ([]string, error) {
|
func (is *ImageStore) GetRepositories() ([]string, error) {
|
||||||
dir := is.rootDir
|
dir := is.rootDir
|
||||||
files, err := ioutil.ReadDir(dir)
|
|
||||||
|
_, err := ioutil.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
is.log.Error().Err(err).Msg("failure walking storage root-dir")
|
is.log.Error().Err(err).Msg("failure walking storage root-dir")
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
stores := make([]string, 0)
|
stores := make([]string, 0)
|
||||||
for _, file := range files {
|
err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||||
p := path.Join(dir, file.Name())
|
if err != nil {
|
||||||
is.log.Debug().Str("dir", p).Str("name", file.Name()).Msg("found image store")
|
return err
|
||||||
stores = append(stores, file.Name())
|
}
|
||||||
}
|
|
||||||
return stores, nil
|
if !info.IsDir() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
rel, err := filepath.Rel(is.rootDir, path)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok, err := is.ValidateRepo(rel); !ok || err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
is.log.Debug().Str("dir", path).Str("name", info.Name()).Msg("found image store")
|
||||||
|
stores = append(stores, rel)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return stores, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (is *ImageStore) GetImageTags(repo string) ([]string, error) {
|
func (is *ImageStore) GetImageTags(repo string) ([]string, error) {
|
||||||
|
|
|
@ -38,11 +38,5 @@ func TestRepoLayout(t *testing.T) {
|
||||||
So(v, ShouldEqual, true)
|
So(v, ShouldEqual, true)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Validate all repos", func() {
|
|
||||||
v, err := il.Validate()
|
|
||||||
So(v, ShouldEqual, true)
|
|
||||||
So(err, ShouldBeNil)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue