forked from Deuxfleurs/bagage
Handle missing trailing slashes + Add Dockerfile
This commit is contained in:
parent
36cef67f6b
commit
1cc0de75a6
2 changed files with 29 additions and 5 deletions
12
Dockerfile
Normal file
12
Dockerfile
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
FROM golang:1.17.0-alpine3.14 as builder
|
||||||
|
ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64
|
||||||
|
RUN apk update && apk add --no-cache ca-certificates && update-ca-certificates
|
||||||
|
WORKDIR /opt
|
||||||
|
COPY main.go go.mod go.sum /opt/
|
||||||
|
RUN go build .
|
||||||
|
|
||||||
|
FROM scratch
|
||||||
|
COPY --from=builder /opt/bagage /
|
||||||
|
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||||
|
USER 1000:1000
|
||||||
|
ENTRYPOINT ["/bagage"]
|
20
main.go
20
main.go
|
@ -39,6 +39,8 @@ func EnvOrDefault(key, def string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
log.Println("=== Starting Bagage ===")
|
||||||
|
HttpListen := EnvOrDefault("BAGAGE_HTTP_LISTEN", ":8080")
|
||||||
pathPrefix := EnvOrDefault("BAGAGE_WEBDAV_PREFIX", "/webdav")
|
pathPrefix := EnvOrDefault("BAGAGE_WEBDAV_PREFIX", "/webdav")
|
||||||
LdapServer := EnvOrDefault("BAGAGE_LDAP_ENDPOINT", "127.0.0.1:1389")
|
LdapServer := EnvOrDefault("BAGAGE_LDAP_ENDPOINT", "127.0.0.1:1389")
|
||||||
UserBaseDN := EnvOrDefault("BAGAGE_LDAP_USER_BASE_DN", "ou=users,dc=deuxfleurs,dc=fr")
|
UserBaseDN := EnvOrDefault("BAGAGE_LDAP_USER_BASE_DN", "ou=users,dc=deuxfleurs,dc=fr")
|
||||||
|
@ -132,7 +134,7 @@ func main() {
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := http.ListenAndServe(":8080", nil); err != nil {
|
if err := http.ListenAndServe(HttpListen, nil); err != nil {
|
||||||
log.Fatalf("Error with WebDAV server: %v", err)
|
log.Fatalf("Error with WebDAV server: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,6 +173,7 @@ func (s *GarageFS) Mkdir(ctx context.Context, name string, perm os.FileMode) err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GarageFS) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (webdav.File, error) {
|
func (s *GarageFS) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (webdav.File, error) {
|
||||||
|
log.Println("Stat from GarageFS.OpenFile()", name)
|
||||||
NewGarageStatFromFile(ctx, name)
|
NewGarageStatFromFile(ctx, name)
|
||||||
return NewGarageFile(ctx, name)
|
return NewGarageFile(ctx, name)
|
||||||
}
|
}
|
||||||
|
@ -184,7 +187,7 @@ func (s *GarageFS) Rename(ctx context.Context, oldName, newName string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GarageFS) Stat(ctx context.Context, name string) (os.FileInfo, error) {
|
func (s *GarageFS) Stat(ctx context.Context, name string) (os.FileInfo, error) {
|
||||||
log.Println("Stat from GarageFS")
|
log.Println("Stat from GarageFS.Stat()", name)
|
||||||
return NewGarageStat(ctx, name)
|
return NewGarageStat(ctx, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,6 +322,7 @@ func (gf *GarageFile) readDirRoot(count int) ([]fs.FileInfo, error) {
|
||||||
|
|
||||||
entries := make([]fs.FileInfo, 0, len(buckets))
|
entries := make([]fs.FileInfo, 0, len(buckets))
|
||||||
for _, bucket := range buckets {
|
for _, bucket := range buckets {
|
||||||
|
log.Println("Stat from GarageFile.readDirRoot()", "/"+bucket.Name)
|
||||||
ngf, err := NewGarageStat(gf.ctx, "/"+bucket.Name)
|
ngf, err := NewGarageStat(gf.ctx, "/"+bucket.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -330,8 +334,13 @@ func (gf *GarageFile) readDirRoot(count int) ([]fs.FileInfo, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gf *GarageFile) readDirChild(count int) ([]fs.FileInfo, error) {
|
func (gf *GarageFile) readDirChild(count int) ([]fs.FileInfo, error) {
|
||||||
|
prefix := gf.path.key
|
||||||
|
if prefix[len(prefix)-1:] != "/" {
|
||||||
|
prefix = prefix + "/"
|
||||||
|
}
|
||||||
|
|
||||||
objs_info := gf.mc.ListObjects(gf.ctx, gf.path.bucket, minio.ListObjectsOptions{
|
objs_info := gf.mc.ListObjects(gf.ctx, gf.path.bucket, minio.ListObjectsOptions{
|
||||||
Prefix: gf.path.key,
|
Prefix: prefix,
|
||||||
Recursive: false,
|
Recursive: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -340,6 +349,7 @@ func (gf *GarageFile) readDirChild(count int) ([]fs.FileInfo, error) {
|
||||||
if object.Err != nil {
|
if object.Err != nil {
|
||||||
return nil, object.Err
|
return nil, object.Err
|
||||||
}
|
}
|
||||||
|
log.Println("Stat from GarageFile.readDirChild()", path.Join("/", gf.path.bucket, object.Key))
|
||||||
ngf, err := NewGarageStatFromObjectInfo(gf.ctx, gf.path.bucket, object)
|
ngf, err := NewGarageStatFromObjectInfo(gf.ctx, gf.path.bucket, object)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -351,6 +361,7 @@ func (gf *GarageFile) readDirChild(count int) ([]fs.FileInfo, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gf *GarageFile) Stat() (fs.FileInfo, error) {
|
func (gf *GarageFile) Stat() (fs.FileInfo, error) {
|
||||||
|
log.Println("Stat from GarageFile.Stat()", gf.path.path)
|
||||||
return NewGarageStatFromFile(gf.ctx, gf.path.path)
|
return NewGarageStatFromFile(gf.ctx, gf.path.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,7 +388,9 @@ func NewGarageStatFromFile(ctx context.Context, path string) (*GarageStat, error
|
||||||
gs := new(GarageStat)
|
gs := new(GarageStat)
|
||||||
gs.ctx = ctx
|
gs.ctx = ctx
|
||||||
gs.path = NewS3Path(path)
|
gs.path = NewS3Path(path)
|
||||||
|
if gs.path.class == OPAQUE_KEY {
|
||||||
gs.path.class = OBJECT // known because called from GarageFile
|
gs.path.class = OBJECT // known because called from GarageFile
|
||||||
|
}
|
||||||
gs.obj.Key = gs.path.key
|
gs.obj.Key = gs.path.key
|
||||||
gs.obj.LastModified = time.Now()
|
gs.obj.LastModified = time.Now()
|
||||||
|
|
||||||
|
@ -409,7 +422,6 @@ func NewGarageStatFromObjectInfo(ctx context.Context, bucket string, obj minio.O
|
||||||
* Stat a path without additional information
|
* Stat a path without additional information
|
||||||
*/
|
*/
|
||||||
func NewGarageStat(ctx context.Context, path string) (*GarageStat, error) {
|
func NewGarageStat(ctx context.Context, path string) (*GarageStat, error) {
|
||||||
log.Println("Probe file", path)
|
|
||||||
cache := ctx.Value(garageEntry).(garageCtx).StatCache
|
cache := ctx.Value(garageEntry).(garageCtx).StatCache
|
||||||
if entry, ok := cache[path]; ok {
|
if entry, ok := cache[path]; ok {
|
||||||
return entry, nil
|
return entry, nil
|
||||||
|
|
Loading…
Reference in a new issue