Skip to content

Commit

Permalink
make mimetype allow list configurable and add example config
Browse files Browse the repository at this point in the history
  • Loading branch information
wkloucek committed Sep 29, 2021
1 parent 77662bd commit 72d8b89
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ node_modules/
ocis/ocis
ocis/cmd/ocis/__debug_bin
ocis/cmd/ocis/config/
config/

.idea

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/blevesearch/bleve/v2 v2.1.0
github.com/coreos/go-oidc/v3 v3.0.0
github.com/cs3org/go-cs3apis v0.0.0-20210922150613-cb9e3c99f8de
github.com/cs3org/reva v1.13.1-0.20210927074430-7c8d9947ad32
github.com/cs3org/reva v1.13.1-0.20210928141725-92a77955b8d3
github.com/disintegration/imaging v1.6.2
github.com/glauth/glauth v1.1.3-0.20210729125545-b9aecdfcac31
github.com/go-chi/chi/v5 v5.0.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ github.com/cs3org/go-cs3apis v0.0.0-20210922150613-cb9e3c99f8de h1:N+AI8wz7yhDDq
github.com/cs3org/go-cs3apis v0.0.0-20210922150613-cb9e3c99f8de/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/reva v1.13.1-0.20210927074430-7c8d9947ad32 h1:ncv6WXy9TE14XCGv6F/5SOcGi0bCnF3vHklmTS6tE30=
github.com/cs3org/reva v1.13.1-0.20210927074430-7c8d9947ad32/go.mod h1:UNDzJq0lPzgKgWSgW1o2g6vqGkaHZKJeR7iWCB3NCIE=
github.com/cs3org/reva v1.13.1-0.20210928141725-92a77955b8d3 h1:QvbYlf2KXT5dzY3XR5pajFxGgxJltd7sc6soVkmmp3w=
github.com/cs3org/reva v1.13.1-0.20210928141725-92a77955b8d3/go.mod h1:UNDzJq0lPzgKgWSgW1o2g6vqGkaHZKJeR7iWCB3NCIE=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
Expand Down
26 changes: 26 additions & 0 deletions storage/pkg/command/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ func gatewayConfigFromStruct(c *cli.Context, cfg *config.Config, logger log.Logg
},
"appregistry": map[string]interface{}{
"driver": "static",
"drivers": map[string]interface{}{
"static": map[string]interface{}{
"mime_types": mimetypes(cfg, logger),
},
},
},
"storageregistry": map[string]interface{}{
"driver": cfg.Reva.StorageRegistry.Driver,
Expand Down Expand Up @@ -217,6 +222,27 @@ func rules(cfg *config.Config, logger log.Logger) map[string]map[string]interfac
}
}

func mimetypes(cfg *config.Config, logger log.Logger) map[string]map[string]string {

// load default app mimetypes from a json file
if cfg.Reva.AppRegistry.MimetypesJSON != "" {
data, err := ioutil.ReadFile(cfg.Reva.AppRegistry.MimetypesJSON)
if err != nil {
logger.Error().Err(err).Msg("Failed to read app registry mimetypes from JSON file: " + cfg.Reva.AppRegistry.MimetypesJSON)
return nil
}
var defaultAppMimetypes map[string]map[string]string
if err = json.Unmarshal(data, &defaultAppMimetypes); err != nil {
logger.Error().Err(err).Msg("Failed to unmarshal storage registry rules")
return nil
}
return defaultAppMimetypes
}

return make(map[string]map[string]string)

}

// GatewaySutureService allows for the storage-gateway command to be embedded and supervised by a suture supervisor tree.
type GatewaySutureService struct {
cfg *config.Config
Expand Down
7 changes: 7 additions & 0 deletions storage/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ type StorageRegistry struct {
JSON string
}

// AppRegistry defines the available app registry configuration
type AppRegistry struct {
Driver string
MimetypesJSON string
}

// AppProvider defines the available app provider configuration
type AppProvider struct {
Port
Expand Down Expand Up @@ -438,6 +444,7 @@ type Reva struct {
DataGateway DataGatewayPort
Gateway Gateway
StorageRegistry StorageRegistry
AppRegistry AppRegistry
Users Users
Groups Groups
AuthProvider Users
Expand Down
17 changes: 17 additions & 0 deletions storage/pkg/flagset/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,23 @@ func GatewayWithConfig(cfg *config.Config) []cli.Flag {
Destination: &cfg.Reva.StorageRegistry.JSON,
},

// app registry

&cli.StringFlag{
Name: "app-registry-driver",
Value: flags.OverrideDefaultString(cfg.Reva.AppRegistry.Driver, "static"),
Usage: "driver of the app registry",
EnvVars: []string{"STORAGE_APP_REGISTRY_DRIVER"},
Destination: &cfg.Reva.AppRegistry.Driver,
},
&cli.StringFlag{
Name: "app-registry-mimetypes-json",
Value: flags.OverrideDefaultString(cfg.Reva.AppRegistry.MimetypesJSON, ""),
Usage: "JSON file containing the storage registry rules",
EnvVars: []string{"STORAGE_APP_REGISTRY_MIMETYPES_JSON"},
Destination: &cfg.Reva.AppRegistry.MimetypesJSON,
},

// please note that STORAGE_FRONTEND_PUBLIC_URL is also defined in
// storage/pkg/flagset/frontend.go because this setting may be consumed
// by both the gateway and frontend service
Expand Down

0 comments on commit 72d8b89

Please sign in to comment.