diff --git a/go.mod b/go.mod index 42ad593473..1ba8177d26 100644 --- a/go.mod +++ b/go.mod @@ -60,7 +60,7 @@ require ( github.com/olekukonko/tablewriter v1.1.1 github.com/onsi/ginkgo v1.16.5 github.com/onsi/ginkgo/v2 v2.27.2 - github.com/onsi/gomega v1.38.2 + github.com/onsi/gomega v1.38.3 github.com/open-policy-agent/opa v1.11.1 github.com/opencloud-eu/icap-client v0.0.0-20250930132611-28a2afe62d89 github.com/opencloud-eu/libre-graph-api-go v1.0.8-0.20250724122329-41ba6b191e76 diff --git a/go.sum b/go.sum index d341b0218c..2f96fbefae 100644 --- a/go.sum +++ b/go.sum @@ -955,8 +955,8 @@ github.com/onsi/ginkgo/v2 v2.27.2/go.mod h1:ArE1D/XhNXBXCBkKOLkbsb2c81dQHCRcF5zw github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.38.2 h1:eZCjf2xjZAqe+LeWvKb5weQ+NcPwX84kqJ0cZNxok2A= -github.com/onsi/gomega v1.38.2/go.mod h1:W2MJcYxRGV63b418Ai34Ud0hEdTVXq9NW9+Sx6uXf3k= +github.com/onsi/gomega v1.38.3 h1:eTX+W6dobAYfFeGC2PV6RwXRu/MyT+cQguijutvkpSM= +github.com/onsi/gomega v1.38.3/go.mod h1:ZCU1pkQcXDO5Sl9/VVEGlDyp+zm0m1cmeG5TOzLgdh4= github.com/open-policy-agent/opa v1.11.1 h1:4bMlG6DjRZTRAswRyF+KUCgxHu1Gsk0h9EbZ4W9REvM= github.com/open-policy-agent/opa v1.11.1/go.mod h1:QimuJO4T3KYxWzrmAymqlFvsIanCjKrGjmmC8GgAdgE= github.com/opencloud-eu/go-micro-plugins/v4/store/nats-js-kv v0.0.0-20250512152754-23325793059a h1:Sakl76blJAaM6NxylVkgSzktjo2dS504iDotEFJsh3M= diff --git a/vendor/github.com/onsi/gomega/CHANGELOG.md b/vendor/github.com/onsi/gomega/CHANGELOG.md index b7d7309f3f..64b33e8b7c 100644 --- a/vendor/github.com/onsi/gomega/CHANGELOG.md +++ b/vendor/github.com/onsi/gomega/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.38.3 + +### Fixes +make string formatitng more consistent for users who use format.Object directly + ## 1.38.2 - roll back to go 1.23.0 [c404969] diff --git a/vendor/github.com/onsi/gomega/format/format.go b/vendor/github.com/onsi/gomega/format/format.go index 96f04b2104..6c23ba338b 100644 --- a/vendor/github.com/onsi/gomega/format/format.go +++ b/vendor/github.com/onsi/gomega/format/format.go @@ -262,7 +262,7 @@ func Object(object any, indentation uint) string { if err, ok := object.(error); ok && !isNilValue(value) { // isNilValue check needed here to avoid nil deref due to boxed nil commonRepresentation += "\n" + IndentString(err.Error(), indentation) + "\n" + indent } - return fmt.Sprintf("%s<%s>: %s%s", indent, formatType(value), commonRepresentation, formatValue(value, indentation)) + return fmt.Sprintf("%s<%s>: %s%s", indent, formatType(value), commonRepresentation, formatValue(value, indentation, true)) } /* @@ -306,7 +306,7 @@ func formatType(v reflect.Value) string { } } -func formatValue(value reflect.Value, indentation uint) string { +func formatValue(value reflect.Value, indentation uint, isTopLevel bool) string { if indentation > MaxDepth { return "..." } @@ -367,11 +367,11 @@ func formatValue(value reflect.Value, indentation uint) string { case reflect.Func: return fmt.Sprintf("0x%x", value.Pointer()) case reflect.Ptr: - return formatValue(value.Elem(), indentation) + return formatValue(value.Elem(), indentation, isTopLevel) case reflect.Slice: return truncateLongStrings(formatSlice(value, indentation)) case reflect.String: - return truncateLongStrings(formatString(value.String(), indentation)) + return truncateLongStrings(formatString(value.String(), indentation, isTopLevel)) case reflect.Array: return truncateLongStrings(formatSlice(value, indentation)) case reflect.Map: @@ -392,8 +392,8 @@ func formatValue(value reflect.Value, indentation uint) string { } } -func formatString(object any, indentation uint) string { - if indentation == 1 { +func formatString(object any, indentation uint, isTopLevel bool) string { + if isTopLevel { s := fmt.Sprintf("%s", object) components := strings.Split(s, "\n") result := "" @@ -416,14 +416,14 @@ func formatString(object any, indentation uint) string { func formatSlice(v reflect.Value, indentation uint) string { if v.Kind() == reflect.Slice && v.Type().Elem().Kind() == reflect.Uint8 && isPrintableString(string(v.Bytes())) { - return formatString(v.Bytes(), indentation) + return formatString(v.Bytes(), indentation, false) } l := v.Len() result := make([]string, l) longest := 0 - for i := 0; i < l; i++ { - result[i] = formatValue(v.Index(i), indentation+1) + for i := range l { + result[i] = formatValue(v.Index(i), indentation+1, false) if len(result[i]) > longest { longest = len(result[i]) } @@ -443,7 +443,7 @@ func formatMap(v reflect.Value, indentation uint) string { longest := 0 for i, key := range v.MapKeys() { value := v.MapIndex(key) - result[i] = fmt.Sprintf("%s: %s", formatValue(key, indentation+1), formatValue(value, indentation+1)) + result[i] = fmt.Sprintf("%s: %s", formatValue(key, indentation+1, false), formatValue(value, indentation+1, false)) if len(result[i]) > longest { longest = len(result[i]) } @@ -462,10 +462,10 @@ func formatStruct(v reflect.Value, indentation uint) string { l := v.NumField() result := []string{} longest := 0 - for i := 0; i < l; i++ { + for i := range l { structField := t.Field(i) fieldEntry := v.Field(i) - representation := fmt.Sprintf("%s: %s", structField.Name, formatValue(fieldEntry, indentation+1)) + representation := fmt.Sprintf("%s: %s", structField.Name, formatValue(fieldEntry, indentation+1, false)) result = append(result, representation) if len(representation) > longest { longest = len(representation) @@ -479,7 +479,7 @@ func formatStruct(v reflect.Value, indentation uint) string { } func formatInterface(v reflect.Value, indentation uint) string { - return fmt.Sprintf("<%s>%s", formatType(v.Elem()), formatValue(v.Elem(), indentation)) + return fmt.Sprintf("<%s>%s", formatType(v.Elem()), formatValue(v.Elem(), indentation, false)) } func isNilValue(a reflect.Value) bool { diff --git a/vendor/github.com/onsi/gomega/gomega_dsl.go b/vendor/github.com/onsi/gomega/gomega_dsl.go index fdba34ee9d..55c0e895e2 100644 --- a/vendor/github.com/onsi/gomega/gomega_dsl.go +++ b/vendor/github.com/onsi/gomega/gomega_dsl.go @@ -22,7 +22,7 @@ import ( "github.com/onsi/gomega/types" ) -const GOMEGA_VERSION = "1.38.2" +const GOMEGA_VERSION = "1.38.3" const nilGomegaPanic = `You are trying to make an assertion, but haven't registered Gomega's fail handler. If you're using Ginkgo then you probably forgot to put your assertion in an It(). diff --git a/vendor/github.com/onsi/gomega/matchers.go b/vendor/github.com/onsi/gomega/matchers.go index 10b6693fd6..40ba15c5e7 100644 --- a/vendor/github.com/onsi/gomega/matchers.go +++ b/vendor/github.com/onsi/gomega/matchers.go @@ -515,8 +515,8 @@ func HaveExistingField(field string) types.GomegaMatcher { // and even interface values. // // actual := 42 -// Expect(actual).To(HaveValue(42)) -// Expect(&actual).To(HaveValue(42)) +// Expect(actual).To(HaveValue(Equal(42))) +// Expect(&actual).To(HaveValue(Equal(42))) func HaveValue(matcher types.GomegaMatcher) types.GomegaMatcher { return &matchers.HaveValueMatcher{ Matcher: matcher, diff --git a/vendor/github.com/onsi/gomega/matchers/have_key_matcher.go b/vendor/github.com/onsi/gomega/matchers/have_key_matcher.go index 9e16dcf5d6..16630c18e3 100644 --- a/vendor/github.com/onsi/gomega/matchers/have_key_matcher.go +++ b/vendor/github.com/onsi/gomega/matchers/have_key_matcher.go @@ -39,7 +39,7 @@ func (matcher *HaveKeyMatcher) Match(actual any) (success bool, err error) { } keys := reflect.ValueOf(actual).MapKeys() - for i := 0; i < len(keys); i++ { + for i := range keys { success, err := keyMatcher.Match(keys[i].Interface()) if err != nil { return false, fmt.Errorf("HaveKey's key matcher failed with:\n%s%s", format.Indent, err.Error()) diff --git a/vendor/github.com/onsi/gomega/matchers/have_key_with_value_matcher.go b/vendor/github.com/onsi/gomega/matchers/have_key_with_value_matcher.go index 1c53f1e56a..0cd7081532 100644 --- a/vendor/github.com/onsi/gomega/matchers/have_key_with_value_matcher.go +++ b/vendor/github.com/onsi/gomega/matchers/have_key_with_value_matcher.go @@ -52,7 +52,7 @@ func (matcher *HaveKeyWithValueMatcher) Match(actual any) (success bool, err err } keys := reflect.ValueOf(actual).MapKeys() - for i := 0; i < len(keys); i++ { + for i := range keys { success, err := keyMatcher.Match(keys[i].Interface()) if err != nil { return false, fmt.Errorf("HaveKeyWithValue's key matcher failed with:\n%s%s", format.Indent, err.Error()) diff --git a/vendor/github.com/onsi/gomega/matchers/support/goraph/edge/edge.go b/vendor/github.com/onsi/gomega/matchers/support/goraph/edge/edge.go index 8c38411b28..72edba20f7 100644 --- a/vendor/github.com/onsi/gomega/matchers/support/goraph/edge/edge.go +++ b/vendor/github.com/onsi/gomega/matchers/support/goraph/edge/edge.go @@ -1,6 +1,9 @@ package edge -import . "github.com/onsi/gomega/matchers/support/goraph/node" +import ( + . "github.com/onsi/gomega/matchers/support/goraph/node" + "slices" +) type Edge struct { Node1 int @@ -20,13 +23,7 @@ func (ec EdgeSet) Free(node Node) bool { } func (ec EdgeSet) Contains(edge Edge) bool { - for _, e := range ec { - if e == edge { - return true - } - } - - return false + return slices.Contains(ec, edge) } func (ec EdgeSet) FindByNodes(node1, node2 Node) (Edge, bool) { diff --git a/vendor/github.com/opencloud-eu/reva/v2/pkg/micro/ocdav/loader.go b/vendor/github.com/opencloud-eu/reva/v2/pkg/micro/ocdav/loader.go deleted file mode 100644 index aa564464c6..0000000000 --- a/vendor/github.com/opencloud-eu/reva/v2/pkg/micro/ocdav/loader.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2018-2021 CERN -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// In applying this license, CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -package ocdav - -import ( - // initialize reva registries by importing the relevant loader packages - // see cmd/revad/runtime/loader.go for other loaders if a service is not found - _ "github.com/opencloud-eu/reva/v2/internal/http/interceptors/auth/credential/loader" - _ "github.com/opencloud-eu/reva/v2/internal/http/interceptors/auth/token/loader" - _ "github.com/opencloud-eu/reva/v2/internal/http/interceptors/auth/tokenwriter/loader" - _ "github.com/opencloud-eu/reva/v2/pkg/token/manager/loader" -) diff --git a/vendor/github.com/opencloud-eu/reva/v2/pkg/micro/ocdav/option.go b/vendor/github.com/opencloud-eu/reva/v2/pkg/micro/ocdav/option.go deleted file mode 100644 index 37e3a6fa76..0000000000 --- a/vendor/github.com/opencloud-eu/reva/v2/pkg/micro/ocdav/option.go +++ /dev/null @@ -1,376 +0,0 @@ -// Copyright 2018-2021 CERN -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// In applying this license, CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -package ocdav - -import ( - "context" - "crypto/tls" - "time" - - gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" - "github.com/opencloud-eu/reva/v2/internal/http/services/owncloud/ocdav" - "github.com/opencloud-eu/reva/v2/internal/http/services/owncloud/ocdav/config" - "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" - "github.com/opencloud-eu/reva/v2/pkg/storage/favorite" - "github.com/rs/zerolog" - "go-micro.dev/v4/broker" - "go.opentelemetry.io/otel/trace" -) - -// Option defines a single option function. -type Option func(o *Options) - -// Options defines the available options for this package. -type Options struct { - TLSConfig *tls.Config - Broker broker.Broker - Address string - Logger zerolog.Logger - Context context.Context - // Metrics *metrics.Metrics - // Flags []cli.Flag - Name string - JWTSecret string - - FavoriteManager favorite.Manager - GatewaySelector pool.Selectable[gateway.GatewayAPIClient] - - TracesExporter string - - TraceProvider trace.TracerProvider - - MetricsEnabled bool - MetricsNamespace string - MetricsSubsystem string - - // ocdav.* is internal so we need to set config options individually - config config.Config - lockSystem ocdav.LockSystem - AllowCredentials bool - AllowedOrigins []string - AllowedHeaders []string - AllowedMethods []string - AllowDepthInfinity bool - - RegisterTTL time.Duration - RegisterInterval time.Duration -} - -// newOptions initializes the available default options. -func newOptions(opts ...Option) Options { - opt := Options{} - - for _, o := range opts { - o(&opt) - } - - return opt -} - -// TLSConfig provides a function to set the TLSConfig option. -func TLSConfig(config *tls.Config) Option { - return func(o *Options) { - o.TLSConfig = config - } -} - -// Broker provides a function to set the Broker option. -func Broker(b broker.Broker) Option { - return func(o *Options) { - o.Broker = b - } -} - -// Address provides a function to set the address option. -func Address(val string) Option { - return func(o *Options) { - o.Address = val - } -} - -func AllowDepthInfinity(val bool) Option { - return func(o *Options) { - o.AllowDepthInfinity = val - } -} - -// JWTSecret provides a function to set the jwt secret option. -func JWTSecret(s string) Option { - return func(o *Options) { - o.JWTSecret = s - } -} - -// MachineAuthAPIKey provides a function to set the machine auth api key option. -func MachineAuthAPIKey(s string) Option { - return func(o *Options) { - o.config.MachineAuthAPIKey = s - } -} - -// Context provides a function to set the context option. -func Context(val context.Context) Option { - return func(o *Options) { - o.Context = val - } -} - -// Logger provides a function to set the logger option. -func Logger(val zerolog.Logger) Option { - return func(o *Options) { - o.Logger = val - } -} - -// Name provides a function to set the Name option. -func Name(val string) Option { - return func(o *Options) { - o.Name = val - } -} - -// Prefix provides a function to set the prefix config option. -func Prefix(val string) Option { - return func(o *Options) { - o.config.Prefix = val - } -} - -// FilesNamespace provides a function to set the FilesNamespace config option. -func FilesNamespace(val string) Option { - return func(o *Options) { - o.config.FilesNamespace = val - } -} - -// WebdavNamespace provides a function to set the WebdavNamespace config option. -func WebdavNamespace(val string) Option { - return func(o *Options) { - o.config.WebdavNamespace = val - } -} - -// SharesNamespace provides a function to set the SharesNamespace config option. -func SharesNamespace(val string) Option { - return func(o *Options) { - o.config.SharesNamespace = val - } -} - -// OCMNamespace provides a function to set the OCMNamespace config option. -func OCMNamespace(val string) Option { - return func(o *Options) { - o.config.OCMNamespace = val - } -} - -// GatewaySvc provides a function to set the GatewaySvc config option. -func GatewaySvc(val string) Option { - return func(o *Options) { - o.config.GatewaySvc = val - } -} - -// Timeout provides a function to set the Timeout config option. -func Timeout(val int64) Option { - return func(o *Options) { - o.config.Timeout = val - } -} - -// Insecure provides a function to set the Insecure config option. -func Insecure(val bool) Option { - return func(o *Options) { - o.config.Insecure = val - } -} - -// PublicURL provides a function to set the PublicURL config option. -func PublicURL(val string) Option { - return func(o *Options) { - o.config.PublicURL = val - } -} - -// FavoriteManager provides a function to set the FavoriteManager option. -func FavoriteManager(val favorite.Manager) Option { - return func(o *Options) { - o.FavoriteManager = val - } -} - -// GatewaySelector provides a function to set the GatewaySelector option. -func GatewaySelector(val pool.Selectable[gateway.GatewayAPIClient]) Option { - return func(o *Options) { - o.GatewaySelector = val - } -} - -// LockSystem provides a function to set the LockSystem option. -func LockSystem(val ocdav.LockSystem) Option { - return func(o *Options) { - o.lockSystem = val - } -} - -// WithTracesExporter option -func WithTracesExporter(exporter string) Option { - return func(o *Options) { - o.TracesExporter = exporter - } -} - -// WithTracingExporter option -// Deprecated: unused -func WithTracingExporter(exporter string) Option { - return func(o *Options) {} -} - -// WithTraceProvider option -func WithTraceProvider(provider trace.TracerProvider) Option { - return func(o *Options) { - o.TraceProvider = provider - } -} - -// Version provides a function to set the Version config option. -func Version(val string) Option { - return func(o *Options) { - o.config.Version = val - } -} - -// VersionString provides a function to set the VersionString config option. -func VersionString(val string) Option { - return func(o *Options) { - o.config.VersionString = val - } -} - -// Edition provides a function to set the Edition config option. -func Edition(val string) Option { - return func(o *Options) { - o.config.Edition = val - } -} - -// Product provides a function to set the Product config option. -func Product(val string) Option { - return func(o *Options) { - o.config.Product = val - } -} - -// ProductName provides a function to set the ProductName config option. -func ProductName(val string) Option { - return func(o *Options) { - o.config.ProductName = val - } -} - -// ProductVersion provides a function to set the ProductVersion config option. -func ProductVersion(val string) Option { - return func(o *Options) { - o.config.ProductVersion = val - } -} - -// MetricsEnabled provides a function to set the MetricsEnabled config option. -func MetricsEnabled(val bool) Option { - return func(o *Options) { - o.MetricsEnabled = val - } -} - -// MetricsNamespace provides a function to set the MetricsNamespace config option. -func MetricsNamespace(val string) Option { - return func(o *Options) { - o.MetricsNamespace = val - } -} - -// MetricsSubsystem provides a function to set the MetricsSubsystem config option. -func MetricsSubsystem(val string) Option { - return func(o *Options) { - o.MetricsSubsystem = val - } -} - -// AllowCredentials provides a function to set the AllowCredentials option. -func AllowCredentials(val bool) Option { - return func(o *Options) { - o.AllowCredentials = val - } -} - -// AllowedOrigins provides a function to set the AllowedOrigins option. -func AllowedOrigins(val []string) Option { - return func(o *Options) { - o.AllowedOrigins = val - } -} - -// AllowedMethods provides a function to set the AllowedMethods option. -func AllowedMethods(val []string) Option { - return func(o *Options) { - o.AllowedMethods = val - } -} - -// AllowedHeaders provides a function to set the AllowedHeaders option. -func AllowedHeaders(val []string) Option { - return func(o *Options) { - o.AllowedHeaders = val - } -} - -// ItemNameInvalidChars provides a function to set forbidden characters in file or folder names -func ItemNameInvalidChars(chars []string) Option { - return func(o *Options) { - o.config.NameValidation.InvalidChars = chars - } -} - -// ItemNameMaxLength provides a function to set the maximum length of a file or folder name -func ItemNameMaxLength(i int) Option { - return func(o *Options) { - o.config.NameValidation.MaxLength = i - } -} - -// RegisterTTL provides a function to set the RegisterTTL option. -func RegisterTTL(ttl time.Duration) Option { - return func(o *Options) { - o.RegisterTTL = ttl - } -} - -// RegisterInterval provides a function to set the RegisterInterval option. -func RegisterInterval(interval time.Duration) Option { - return func(o *Options) { - o.RegisterInterval = interval - } -} - -// URLSigningSharedSecret provides a function to set the URLSigningSharedSecret config option. -func URLSigningSharedSecret(secret string) Option { - return func(o *Options) { - o.config.URLSigningSharedSecret = secret - } -} diff --git a/vendor/github.com/opencloud-eu/reva/v2/pkg/micro/ocdav/service.go b/vendor/github.com/opencloud-eu/reva/v2/pkg/micro/ocdav/service.go deleted file mode 100644 index 0553772a3e..0000000000 --- a/vendor/github.com/opencloud-eu/reva/v2/pkg/micro/ocdav/service.go +++ /dev/null @@ -1,229 +0,0 @@ -// Copyright 2018-2021 CERN -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// In applying this license, CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -package ocdav - -import ( - "net/http" - "strings" - - "github.com/go-chi/chi/v5" - "github.com/go-chi/chi/v5/middleware" - httpServer "github.com/go-micro/plugins/v4/server/http" - "github.com/opencloud-eu/opencloud/pkg/registry" - "github.com/opencloud-eu/reva/v2/internal/http/interceptors/appctx" - "github.com/opencloud-eu/reva/v2/internal/http/interceptors/auth" - cors2 "github.com/opencloud-eu/reva/v2/internal/http/interceptors/cors" - revaLogMiddleware "github.com/opencloud-eu/reva/v2/internal/http/interceptors/log" - "github.com/opencloud-eu/reva/v2/internal/http/services/owncloud/ocdav" - "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" - "github.com/opencloud-eu/reva/v2/pkg/rhttp/global" - "github.com/opencloud-eu/reva/v2/pkg/storage/favorite/memory" - rtrace "github.com/opencloud-eu/reva/v2/pkg/trace" - "github.com/pkg/errors" - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promauto" - "go-micro.dev/v4" - "go-micro.dev/v4/server" - "go.opentelemetry.io/otel/propagation" - "go.opentelemetry.io/otel/trace" -) - -func init() { - // register method with chi before any routing is set up - chi.RegisterMethod(ocdav.MethodPropfind) - chi.RegisterMethod(ocdav.MethodProppatch) - chi.RegisterMethod(ocdav.MethodLock) - chi.RegisterMethod(ocdav.MethodUnlock) - chi.RegisterMethod(ocdav.MethodCopy) - chi.RegisterMethod(ocdav.MethodMove) - chi.RegisterMethod(ocdav.MethodMkcol) - chi.RegisterMethod(ocdav.MethodReport) -} - -const ( - // ServerName to use when announcing the service to the registry - ServerName = "ocdav" -) - -// Service initializes the ocdav service and underlying http server. -func Service(opts ...Option) (micro.Service, error) { - sopts := newOptions(opts...) - - // set defaults - if err := setDefaults(&sopts); err != nil { - return nil, err - } - - sopts.Logger = sopts.Logger.With().Str("name", sopts.Name).Logger() - - srv := httpServer.NewServer( - server.Broker(sopts.Broker), - server.TLSConfig(sopts.TLSConfig), - server.Name(sopts.Name), - server.Address(sopts.Address), // Address defaults to ":0" and will pick any free port - server.Version(sopts.config.VersionString), - server.RegisterTTL(sopts.RegisterTTL), - server.RegisterInterval(sopts.RegisterInterval), - ) - - revaService, err := ocdav.NewWith(&sopts.config, sopts.FavoriteManager, sopts.lockSystem, &sopts.Logger, sopts.GatewaySelector) - if err != nil { - return nil, err - } - - r := chi.NewRouter() - tp := sopts.TraceProvider - - if tp == nil { - tp = rtrace.NewTracerProvider(sopts.Name, sopts.TracesExporter) - } - if err := useMiddlewares(r, &sopts, revaService, tp); err != nil { - return nil, err - } - - r.Handle("/*", revaService.Handler()) - - _ = chi.Walk(r, func(method string, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error { - sopts.Logger.Debug().Str("service", "ocdav").Str("method", method).Str("route", route).Int("middlewares", len(middlewares)).Msg("serving endpoint") - return nil - }) - - hd := srv.NewHandler(r) - if err := srv.Handle(hd); err != nil { - return nil, err - } - - service := micro.NewService( - micro.Server(srv), - micro.Registry(registry.GetRegistry()), - ) - - // finally, return the service so it can be Run() by the caller himself - return service, nil -} - -func setDefaults(sopts *Options) error { - // set defaults - if sopts.Name == "" { - sopts.Name = ServerName - } - if sopts.lockSystem == nil { - selector, err := pool.GatewaySelector(sopts.config.GatewaySvc) - if err != nil { - return errors.Wrap(err, "error getting gateway selector") - } - sopts.lockSystem = ocdav.NewCS3LS(selector) - } - if sopts.FavoriteManager == nil { - sopts.FavoriteManager, _ = memory.New(map[string]interface{}{}) - } - if !strings.HasPrefix(sopts.config.Prefix, "/") { - sopts.config.Prefix = "/" + sopts.config.Prefix - } - if sopts.config.VersionString == "" { - sopts.config.VersionString = "0.0.0" - } - - sopts.config.AllowPropfindDepthInfinitiy = sopts.AllowDepthInfinity - - return nil -} - -func useMiddlewares(r *chi.Mux, sopts *Options, svc global.Service, tp trace.TracerProvider) error { - // auth - for _, v := range svc.Unprotected() { - sopts.Logger.Info().Str("url", v).Msg("unprotected URL") - } - authMiddle, err := auth.New(map[string]interface{}{ - "gatewaysvc": sopts.config.GatewaySvc, - "token_managers": map[string]interface{}{ - "jwt": map[string]interface{}{ - "secret": sopts.JWTSecret, - }, - }, - }, svc.Unprotected(), tp) - if err != nil { - return err - } - - // log - lm := revaLogMiddleware.New() - - cors, _, err := cors2.New(map[string]interface{}{ - "allow_credentials": sopts.AllowCredentials, - "allowed_methods": sopts.AllowedMethods, - "allowed_headers": sopts.AllowedHeaders, - "allowed_origins": sopts.AllowedOrigins, - }) - if err != nil { - return err - } - - // tracing - tm := traceHandler(tp, "ocdav") - - // metrics - pm := func(h http.Handler) http.Handler { return h } - if sopts.MetricsEnabled { - namespace := sopts.MetricsNamespace - if namespace == "" { - namespace = "reva" - } - subsystem := sopts.MetricsSubsystem - if subsystem == "" { - subsystem = "ocdav" - } - counter := promauto.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: subsystem, - Name: "http_requests_total", - Help: "The total number of processed " + subsystem + " HTTP requests for " + namespace, - }) - pm = func(h http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - h.ServeHTTP(w, r) - counter.Inc() - }) - } - } - - // ctx - cm := appctx.New(sopts.Logger, tp) - - // request-id - rm := middleware.RequestID - - // actually register - r.Use(pm, tm, lm, authMiddle, rm, cm, cors) - return nil -} - -func traceHandler(tp trace.TracerProvider, name string) func(http.Handler) http.Handler { - return func(h http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - ctx := rtrace.Propagator.Extract(r.Context(), propagation.HeaderCarrier(r.Header)) - t := tp.Tracer("reva") - ctx, span := t.Start(ctx, name) - defer span.End() - - rtrace.Propagator.Inject(ctx, propagation.HeaderCarrier(r.Header)) - h.ServeHTTP(w, r.WithContext(ctx)) - }) - } -} diff --git a/vendor/modules.txt b/vendor/modules.txt index 2eee16cb61..6f2e3f4c5d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1263,7 +1263,7 @@ github.com/onsi/ginkgo/v2/internal/reporters github.com/onsi/ginkgo/v2/internal/testingtproxy github.com/onsi/ginkgo/v2/reporters github.com/onsi/ginkgo/v2/types -# github.com/onsi/gomega v1.38.2 +# github.com/onsi/gomega v1.38.3 ## explicit; go 1.23.0 github.com/onsi/gomega github.com/onsi/gomega/format @@ -1556,7 +1556,6 @@ github.com/opencloud-eu/reva/v2/pkg/metrics/driver/loader github.com/opencloud-eu/reva/v2/pkg/metrics/driver/registry github.com/opencloud-eu/reva/v2/pkg/metrics/driver/xcloud github.com/opencloud-eu/reva/v2/pkg/metrics/reader -github.com/opencloud-eu/reva/v2/pkg/micro/ocdav github.com/opencloud-eu/reva/v2/pkg/mime github.com/opencloud-eu/reva/v2/pkg/ocm/client github.com/opencloud-eu/reva/v2/pkg/ocm/invite