go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/os/connection/docker_fs.go (about) 1 // Copyright (c) Mondoo, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package connection 5 6 import ( 7 "errors" 8 "os" 9 "strings" 10 "time" 11 12 "github.com/docker/docker/client" 13 "github.com/spf13/afero" 14 "go.mondoo.com/cnquery/providers/os/connection/ssh/cat" 15 ) 16 17 type FS struct { 18 Container string 19 dockerClient *client.Client 20 Connection *DockerContainerConnection 21 catFS *cat.Fs 22 } 23 24 func (fs *FS) Name() string { 25 return "dockerfs" 26 } 27 28 func (fs *FS) Create(name string) (afero.File, error) { 29 return nil, errors.New("create not implemented") 30 } 31 32 func (fs *FS) Mkdir(name string, perm os.FileMode) error { 33 return errors.New("mkdir not implemented") 34 } 35 36 func (fs *FS) MkdirAll(path string, perm os.FileMode) error { 37 return errors.New("mkdirall not implemented") 38 } 39 40 func isDockerClientSupported(path string) bool { 41 // This is incomplete. There are other things that are 42 // unsupported like tmpfs and paths the user mounted 43 // in the container. 44 // See https://docs.docker.com/engine/reference/commandline/cp/#corner-cases 45 unsupported := []string{"/proc", "/dev", "/sys"} 46 for _, v := range unsupported { 47 if v == path || strings.HasPrefix(path, v) { 48 return false 49 } 50 } 51 return true 52 } 53 54 func (fs *FS) Open(name string) (afero.File, error) { 55 if isDockerClientSupported(name) { 56 return FileOpen(fs.dockerClient, name, fs.Container, fs.Connection, fs.catFS) 57 } else { 58 return fs.catFS.Open(name) 59 } 60 } 61 62 func (fs *FS) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error) { 63 return nil, errors.New("openfile not implemented") 64 } 65 66 func (fs *FS) Remove(name string) error { 67 return errors.New("remove not implemented") 68 } 69 70 func (fs *FS) RemoveAll(path string) error { 71 return errors.New("removeall not implemented") 72 } 73 74 func (fs *FS) Rename(oldname, newname string) error { 75 return errors.New("rename not implemented") 76 } 77 78 func (fs *FS) Stat(name string) (os.FileInfo, error) { 79 return fs.catFS.Stat(name) 80 } 81 82 func (fs *FS) Chmod(name string, mode os.FileMode) error { 83 return errors.New("chmod not implemented") 84 } 85 86 func (fs *FS) Chtimes(name string, atime time.Time, mtime time.Time) error { 87 return errors.New("chtimes not implemented") 88 } 89 90 func (fs *FS) Chown(name string, uid, gid int) error { 91 return errors.New("chown not implemented") 92 }