From 6c2a1999c4350da5b6d5ddfd1f7eba1a181ac3f4 Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Fri, 4 Nov 2022 13:01:18 +0100 Subject: [PATCH] add requestID middleware (#4974) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add requestID middleware * Update services/ocdav/pkg/config/config.go * remove unnecessary config structs Signed-off-by: Jörn Friedrich Dreyer Signed-off-by: Jörn Friedrich Dreyer Co-authored-by: Jörn Friedrich Dreyer Co-authored-by: Jörn Friedrich Dreyer --- changelog/unreleased/logging-improvements.md | 1 + services/frontend/pkg/revaconfig/config.go | 1 + services/ocdav/pkg/config/config.go | 13 +------------ .../pkg/config/defaults/defaultconfig.go | 19 +++++++------------ .../storage-users/pkg/revaconfig/config.go | 3 +++ 5 files changed, 13 insertions(+), 24 deletions(-) diff --git a/changelog/unreleased/logging-improvements.md b/changelog/unreleased/logging-improvements.md index 28dd126d54..7110244fb7 100644 --- a/changelog/unreleased/logging-improvements.md +++ b/changelog/unreleased/logging-improvements.md @@ -3,3 +3,4 @@ Enhancement: Logging improvements We improved the logging of several http services. If possible and present, we now log the `X-Request-Id`. https://github.com/owncloud/ocis/pull/4815 +https://github.com/owncloud/ocis/pull/4974 diff --git a/services/frontend/pkg/revaconfig/config.go b/services/frontend/pkg/revaconfig/config.go index 89ed9bef8c..5b84499c32 100644 --- a/services/frontend/pkg/revaconfig/config.go +++ b/services/frontend/pkg/revaconfig/config.go @@ -99,6 +99,7 @@ func FrontendConfigFromStruct(cfg *config.Config) (map[string]interface{}, error "namespace": "ocis", "subsystem": "frontend", }, + "requestid": map[string]interface{}{}, }, // TODO build services dynamically "services": map[string]interface{}{ diff --git a/services/ocdav/pkg/config/config.go b/services/ocdav/pkg/config/config.go index 9f2d3f12f6..e03a095b7c 100644 --- a/services/ocdav/pkg/config/config.go +++ b/services/ocdav/pkg/config/config.go @@ -29,8 +29,7 @@ type Config struct { // Insecure certificates allowed when making requests to the gateway Insecure bool `yaml:"insecure" env:"OCIS_INSECURE;OCDAV_INSECURE" desc:"Allow insecure connections to the GATEWAY service."` // Timeout in seconds when making requests to the gateway - Timeout int64 `yaml:"gateway_request_timeout" env:"OCDAV_GATEWAY_REQUEST_TIMEOUT" desc:"Request timeout in seconds for requests from the oCDAV service to the GATEWAY service."` - Middleware Middleware `yaml:"middleware"` + Timeout int64 `yaml:"gateway_request_timeout" env:"OCDAV_GATEWAY_REQUEST_TIMEOUT" desc:"Request timeout in seconds for requests from the oCDAV service to the GATEWAY service."` MachineAuthAPIKey string `yaml:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;OCDAV_MACHINE_AUTH_API_KEY" desc:"Machine auth API key used to validate internal requests necessary for the access to resources from other services."` @@ -69,16 +68,6 @@ type HTTPConfig struct { Prefix string `yaml:"prefix" env:"OCDAV_HTTP_PREFIX" desc:"A URL path prefix for the handler."` } -// Middleware configures reva middlewares. -type Middleware struct { - Auth Auth `yaml:"auth"` -} - -// Auth configures reva http auth middleware. -type Auth struct { - CredentialsByUserAgent map[string]string `yaml:"credentials_by_user_agent"` -} - // Status holds the configurable values for the status.php type Status struct { Version string diff --git a/services/ocdav/pkg/config/defaults/defaultconfig.go b/services/ocdav/pkg/config/defaults/defaultconfig.go index ddfb0d5a99..6d6fae5223 100644 --- a/services/ocdav/pkg/config/defaults/defaultconfig.go +++ b/services/ocdav/pkg/config/defaults/defaultconfig.go @@ -30,18 +30,13 @@ func DefaultConfig() *config.Config { Service: config.Service{ Name: "ocdav", }, - Reva: shared.DefaultRevaConfig(), - WebdavNamespace: "/users/{{.Id.OpaqueId}}", - FilesNamespace: "/users/{{.Id.OpaqueId}}", - SharesNamespace: "/Shares", - PublicURL: "https://localhost:9200", - Insecure: false, - Timeout: 84300, - Middleware: config.Middleware{ - Auth: config.Auth{ - CredentialsByUserAgent: map[string]string{}, - }, - }, + Reva: shared.DefaultRevaConfig(), + WebdavNamespace: "/users/{{.Id.OpaqueId}}", + FilesNamespace: "/users/{{.Id.OpaqueId}}", + SharesNamespace: "/Shares", + PublicURL: "https://localhost:9200", + Insecure: false, + Timeout: 84300, MachineAuthAPIKey: "", Status: config.Status{ Version: version.Legacy, diff --git a/services/storage-users/pkg/revaconfig/config.go b/services/storage-users/pkg/revaconfig/config.go index fa225fd7d6..91e2ad06d3 100644 --- a/services/storage-users/pkg/revaconfig/config.go +++ b/services/storage-users/pkg/revaconfig/config.go @@ -57,6 +57,9 @@ func StorageUsersConfigFromStruct(cfg *config.Config) map[string]interface{} { "http": map[string]interface{}{ "network": cfg.HTTP.Protocol, "address": cfg.HTTP.Addr, + "middlewares": map[string]interface{}{ + "requestid": map[string]interface{}{}, + }, // TODO build services dynamically "services": map[string]interface{}{ "dataprovider": map[string]interface{}{