From a22342ea2889c20c80def19d1ed751e8d4bce8f9 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 15 Nov 2021 10:03:42 +0100 Subject: [PATCH] fix code smells --- proxy/pkg/config/config.go | 51 +++++++++++++++++--------------- proxy/pkg/server/debug/server.go | 8 +++-- storage/pkg/config/config.go | 1 - 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 18a20ba1da..dafa8a7997 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -256,6 +256,10 @@ func DefaultConfig() *Config { } func defaultPolicies() []Policy { + const idpBackend = "http://localhost:9130" + const revaBackend = "http://localhost:9140" + const namedDemoBackend = "https://demo.owncloud.com" + return []Policy{ { Name: "ocis", @@ -266,19 +270,19 @@ func defaultPolicies() []Policy { }, { Endpoint: "/.well-known/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/konnect/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/signin/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/archiver", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Type: RegexRoute, @@ -287,7 +291,7 @@ func defaultPolicies() []Policy { }, { Endpoint: "/ocs/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Type: QueryRoute, @@ -296,31 +300,31 @@ func defaultPolicies() []Policy { }, { Endpoint: "/remote.php/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/dav/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/webdav/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/status.php", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/index.php/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/data", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/app/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/graph/", @@ -335,7 +339,6 @@ func defaultPolicies() []Policy { Endpoint: "/api/v0/accounts", Backend: "http://localhost:9181", }, - // TODO the lookup needs a better mechanism { Endpoint: "/accounts.js", Backend: "http://localhost:9181", @@ -359,53 +362,53 @@ func defaultPolicies() []Policy { }, { Endpoint: "/.well-known/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/konnect/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/signin/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/archiver", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/ocs/", - Backend: "https://demo.owncloud.com", + Backend: namedDemoBackend, ApacheVHost: true, }, { Endpoint: "/remote.php/", - Backend: "https://demo.owncloud.com", + Backend: namedDemoBackend, ApacheVHost: true, }, { Endpoint: "/dav/", - Backend: "https://demo.owncloud.com", + Backend: namedDemoBackend, ApacheVHost: true, }, { Endpoint: "/webdav/", - Backend: "https://demo.owncloud.com", + Backend: namedDemoBackend, ApacheVHost: true, }, { Endpoint: "/status.php", - Backend: "https://demo.owncloud.com", + Backend: namedDemoBackend, ApacheVHost: true, }, { Endpoint: "/index.php/", - Backend: "https://demo.owncloud.com", + Backend: namedDemoBackend, ApacheVHost: true, }, { Endpoint: "/data", - Backend: "https://demo.owncloud.com", + Backend: namedDemoBackend, ApacheVHost: true, }, }, diff --git a/proxy/pkg/server/debug/server.go b/proxy/pkg/server/debug/server.go index b4106f2a8c..e2a7f1e32b 100644 --- a/proxy/pkg/server/debug/server.go +++ b/proxy/pkg/server/debug/server.go @@ -27,10 +27,12 @@ func Server(opts ...Option) (*http.Server, error) { ), nil } +const contentTypeHeader = "Content-Type" + // health implements the health check. func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") + w.Header().Set(contentTypeHeader, "text/plain") w.WriteHeader(http.StatusOK) // TODO(tboerger): check if services are up and running @@ -44,7 +46,7 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { // ready implements the ready check. func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") + w.Header().Set(contentTypeHeader, "text/plain") w.WriteHeader(http.StatusOK) // TODO(tboerger): check if services are up and running @@ -58,7 +60,7 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { // configDump implements the config dump func configDump(cfg *config.Config) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json") + w.Header().Set(contentTypeHeader, "application/json") b, err := json.Marshal(cfg) if err != nil { diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 19c45739b5..1e34e47b61 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -220,7 +220,6 @@ type StorageConfig struct { S3 DriverS3 S3NG DriverS3NG OCIS DriverOCIS - // TODO checksums ... figure out what that is supposed to do } // DriverCommon defines common driver configuration options.