mirror of
https://github.com/docker/docs.git
synced 2026-03-30 15:58:53 +07:00
Removed all references of GUN from filestore
Signed-off-by: Diogo Monica <diogo@docker.com>
This commit is contained in:
@@ -81,7 +81,7 @@ func keysRemove(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
// We didn't find a certificate with this ID, let's try to see if we can find keys.
|
||||
keyList := privKeyStore.ListGUN(gunOrID)
|
||||
keyList := privKeyStore.ListDir(gunOrID)
|
||||
if len(keyList) < 1 {
|
||||
fatalf("no Private Keys found under Global Unique Name: %s", gunOrID)
|
||||
}
|
||||
@@ -99,7 +99,7 @@ func keysRemove(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
// Remove all the keys under the Global Unique Name
|
||||
err = privKeyStore.RemoveGUN(gunOrID)
|
||||
err = privKeyStore.RemoveDir(gunOrID)
|
||||
if err != nil {
|
||||
fatalf("failed to remove all Private keys under Global Unique Name: %s", gunOrID)
|
||||
}
|
||||
@@ -163,7 +163,7 @@ func keysList(cmd *cobra.Command, args []string) {
|
||||
|
||||
fmt.Println("")
|
||||
fmt.Println("# Signing keys: ")
|
||||
for _, k := range privKeyStore.List() {
|
||||
for _, k := range privKeyStore.ListAll() {
|
||||
printKey(k)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,11 @@ const private os.FileMode = 0700
|
||||
type FileStore interface {
|
||||
Add(fileName string, data []byte) error
|
||||
Remove(fileName string) error
|
||||
RemoveGUN(gun string) error
|
||||
RemoveDir(directoryName string) error
|
||||
GetData(fileName string) ([]byte, error)
|
||||
GetPath(fileName string) string
|
||||
List() []string
|
||||
ListGUN(gun string) []string
|
||||
ListAll() []string
|
||||
ListDir(directoryName string) []string
|
||||
}
|
||||
|
||||
// fileStore implements FileStore
|
||||
@@ -61,18 +61,18 @@ func (f *fileStore) Add(name string, data []byte) error {
|
||||
return ioutil.WriteFile(filePath, data, f.perms)
|
||||
}
|
||||
|
||||
// Remove removes a file identified by a name
|
||||
// TODO (diogo): We can get rid of RemoveGUN by merging with Remove
|
||||
// Remove removes a file identified by name
|
||||
func (f *fileStore) Remove(name string) error {
|
||||
// Attempt to remove
|
||||
filePath := f.genFilePath(name)
|
||||
return os.Remove(filePath)
|
||||
}
|
||||
|
||||
// RemoveGUN removes a directory identified by the Global Unique Name
|
||||
func (f *fileStore) RemoveGUN(gun string) error {
|
||||
dirPath := filepath.Join(f.baseDir, gun)
|
||||
// RemoveDir removes the directory identified by name
|
||||
func (f *fileStore) RemoveDir(name string) error {
|
||||
dirPath := filepath.Join(f.baseDir, name)
|
||||
|
||||
// Check to see if file exists
|
||||
// Check to see if directory exists
|
||||
fi, err := os.Stat(dirPath)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -80,7 +80,7 @@ func (f *fileStore) RemoveGUN(gun string) error {
|
||||
|
||||
// Check to see if it is a directory
|
||||
if !fi.IsDir() {
|
||||
return fmt.Errorf("GUN not found: %s", gun)
|
||||
return fmt.Errorf("directory not found: %s", name)
|
||||
}
|
||||
|
||||
return os.RemoveAll(dirPath)
|
||||
@@ -103,18 +103,17 @@ func (f *fileStore) GetPath(name string) string {
|
||||
}
|
||||
|
||||
// List lists all the files inside of a store
|
||||
func (f *fileStore) List() []string {
|
||||
func (f *fileStore) ListAll() []string {
|
||||
return f.list(f.baseDir)
|
||||
}
|
||||
|
||||
// ListGUN lists all the files inside of a directory identified by a Global Unique Name.
|
||||
// TODO (diogo): We can get rid of ListGUN by merging with List
|
||||
func (f *fileStore) ListGUN(gun string) []string {
|
||||
gunPath := filepath.Join(f.baseDir, gun)
|
||||
return f.list(gunPath)
|
||||
// List lists all the files inside of a directory identified by a name
|
||||
func (f *fileStore) ListDir(name string) []string {
|
||||
fullPath := filepath.Join(f.baseDir, name)
|
||||
return f.list(fullPath)
|
||||
}
|
||||
|
||||
// listGUN lists all the files in a directory given a full path
|
||||
// list lists all the files in a directory given a full path
|
||||
func (f *fileStore) list(path string) []string {
|
||||
files := make([]string, 0, 0)
|
||||
filepath.Walk(path, func(fp string, fi os.FileInfo, err error) error {
|
||||
|
||||
@@ -89,7 +89,7 @@ func TestRemoveFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveGUN(t *testing.T) {
|
||||
func TestRemoveDir(t *testing.T) {
|
||||
testName := "docker.com/diogomonica/"
|
||||
testExt := "key"
|
||||
perms := os.FileMode(0700)
|
||||
@@ -115,8 +115,8 @@ func TestRemoveGUN(t *testing.T) {
|
||||
perms: perms,
|
||||
}
|
||||
|
||||
// Call the RemoveGUN function
|
||||
err = store.RemoveGUN(testName)
|
||||
// Call the RemoveDir function
|
||||
err = store.RemoveDir(testName)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to remove directory: %v", err)
|
||||
}
|
||||
@@ -129,7 +129,7 @@ func TestRemoveGUN(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
func TestListAll(t *testing.T) {
|
||||
testName := "docker.com/notary/certificate"
|
||||
testExt := "crt"
|
||||
perms := os.FileMode(0755)
|
||||
@@ -159,13 +159,13 @@ func TestList(t *testing.T) {
|
||||
}
|
||||
|
||||
// Call the List function
|
||||
files := store.List()
|
||||
files := store.ListAll()
|
||||
if len(files) != 10 {
|
||||
t.Fatalf("expected 10 files in listing, got: %d", len(files))
|
||||
}
|
||||
}
|
||||
|
||||
func TestListGUN(t *testing.T) {
|
||||
func TestListDir(t *testing.T) {
|
||||
testName := "docker.com/notary/certificate"
|
||||
testExt := "crt"
|
||||
perms := os.FileMode(0755)
|
||||
@@ -196,16 +196,16 @@ func TestListGUN(t *testing.T) {
|
||||
perms: perms,
|
||||
}
|
||||
|
||||
// Call the ListGUN function
|
||||
files := store.ListGUN("docker.com/")
|
||||
// Call the ListDir function
|
||||
files := store.ListDir("docker.com/")
|
||||
if len(files) != 10 {
|
||||
t.Fatalf("expected 10 files in listing, got: %d", len(files))
|
||||
}
|
||||
files = store.ListGUN("docker.com/notary")
|
||||
files = store.ListDir("docker.com/notary")
|
||||
if len(files) != 10 {
|
||||
t.Fatalf("expected 10 files in listing, got: %d", len(files))
|
||||
}
|
||||
files = store.ListGUN("fakedocker.com/")
|
||||
files = store.ListDir("fakedocker.com/")
|
||||
if len(files) != 0 {
|
||||
t.Fatalf("expected 0 files in listing, got: %d", len(files))
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ func FingerprintCert(cert *x509.Certificate) CertID {
|
||||
|
||||
// loadCertsFromDir receives a store AddCertFromFile for each certificate found
|
||||
func loadCertsFromDir(s *X509FileStore) {
|
||||
certFiles := s.fileStore.List()
|
||||
certFiles := s.fileStore.ListAll()
|
||||
for _, c := range certFiles {
|
||||
s.AddCertFromFile(c)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user