bump reva

Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
jkoberg
2023-08-16 10:20:22 +02:00
parent 49cdcad129
commit 450801deef
12 changed files with 72 additions and 169 deletions
@@ -19,13 +19,8 @@
package eventsmiddleware
import (
"bytes"
"context"
"crypto/tls"
"crypto/x509"
"fmt"
"io"
"os"
"go-micro.dev/v4/util/log"
"google.golang.org/grpc"
@@ -42,7 +37,6 @@ import (
"github.com/cs3org/reva/v2/pkg/rgrpc"
"github.com/cs3org/reva/v2/pkg/storagespace"
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/go-micro/plugins/v4/events/natsjs"
)
const (
@@ -229,38 +223,17 @@ func publisherFromConfig(m map[string]interface{}) (events.Publisher, error) {
default:
return nil, fmt.Errorf("stream type '%s' not supported", typ)
case "nats":
address := m["address"].(string)
cid := m["clusterID"].(string)
enableTLS := m["enable-tls"].(bool)
var tlsConf *tls.Config
if enableTLS {
skipVerify := m["tls-insecure"].(bool)
var rootCAPool *x509.CertPool
if val, ok := m["tls-root-ca-cert"]; ok {
rootCACertPath := val.(string)
if rootCACertPath != "" {
f, err := os.Open(rootCACertPath)
if err != nil {
return nil, err
}
var certBytes bytes.Buffer
if _, err := io.Copy(&certBytes, f); err != nil {
return nil, err
}
rootCAPool = x509.NewCertPool()
rootCAPool.AppendCertsFromPEM(certBytes.Bytes())
skipVerify = false
}
}
tlsConf = &tls.Config{
InsecureSkipVerify: skipVerify,
RootCAs: rootCAPool,
}
var tlsCert string
val, ok := m["tls-root-ca-cert"]
if ok {
tlsCert = val.(string)
}
return stream.Nats(natsjs.TLSConfig(tlsConf), natsjs.Address(address), natsjs.ClusterID(cid))
return stream.NatsFromConfig(m["name"].(string), stream.NatsConfig{
Endpoint: m["address"].(string),
Cluster: m["clusterID"].(string),
EnableTLS: m["enable-tls"].(bool),
TLSInsecure: m["tls-insecure"].(bool),
TLSRootCACertificate: tlsCert,
})
}
}
@@ -19,13 +19,9 @@
package storageprovider
import (
"bytes"
"context"
"crypto/tls"
"crypto/x509"
"encoding/json"
"fmt"
"io"
"net/url"
"os"
"path"
@@ -49,7 +45,6 @@ import (
"github.com/cs3org/reva/v2/pkg/storage/fs/registry"
"github.com/cs3org/reva/v2/pkg/storagespace"
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/go-micro/plugins/v4/events/natsjs"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"go.opentelemetry.io/otel/attribute"
@@ -76,11 +71,11 @@ type config struct {
}
type eventconfig struct {
NatsAddress string `mapstructure:"nats_address" docs:"address of the nats server"`
NatsClusterID string `mapstructure:"nats_clusterid" docs:"clusterid of the nats server"`
EnableTLS bool `mapstructure:"nats_enable_tls" docs:"events tls switch"`
Endpoint string `mapstructure:"nats_address" docs:"address of the nats server"`
Cluster string `mapstructure:"nats_clusterid" docs:"clusterid of the nats server"`
TLSInsecure bool `mapstructure:"tls_insecure" docs:"Whether to verify the server TLS certificates."`
TLSRootCACertificate string `mapstructure:"tls_root_ca_cert" docs:"The root CA certificate used to validate the server's TLS certificate."`
EnableTLS bool `mapstructure:"nats_enable_tls" docs:"events tls switch"`
}
func (c *config) init() {
@@ -1245,38 +1240,9 @@ func (v descendingMtime) Swap(i, j int) {
}
func estreamFromConfig(c eventconfig) (events.Stream, error) {
if c.NatsAddress == "" {
if c.Endpoint == "" {
return nil, nil
}
var (
rootCAPool *x509.CertPool
tlsConf *tls.Config
)
if c.TLSRootCACertificate != "" {
rootCrtFile, err := os.Open(c.TLSRootCACertificate)
if err != nil {
return nil, err
}
var certBytes bytes.Buffer
if _, err := io.Copy(&certBytes, rootCrtFile); err != nil {
return nil, err
}
rootCAPool = x509.NewCertPool()
rootCAPool.AppendCertsFromPEM(certBytes.Bytes())
c.TLSInsecure = false
tlsConf = &tls.Config{
InsecureSkipVerify: c.TLSInsecure, //nolint:gosec
RootCAs: rootCAPool,
}
}
s, err := stream.Nats(natsjs.Address(c.NatsAddress), natsjs.ClusterID(c.NatsClusterID), natsjs.TLSConfig(tlsConf))
if err != nil {
return nil, err
}
return s, nil
return stream.NatsFromConfig("storageprovider", stream.NatsConfig(c))
}
@@ -19,13 +19,8 @@
package dataprovider
import (
"bytes"
"crypto/tls"
"crypto/x509"
"fmt"
"io"
"net/http"
"os"
"github.com/cs3org/reva/v2/pkg/appctx"
"github.com/cs3org/reva/v2/pkg/events"
@@ -35,7 +30,6 @@ import (
"github.com/cs3org/reva/v2/pkg/rhttp/router"
"github.com/cs3org/reva/v2/pkg/storage"
"github.com/cs3org/reva/v2/pkg/storage/fs/registry"
"github.com/go-micro/plugins/v4/events/natsjs"
"github.com/mitchellh/mapstructure"
"github.com/rs/zerolog"
)
@@ -86,30 +80,13 @@ func New(m map[string]interface{}, log *zerolog.Logger) (global.Service, error)
if conf.NatsAddress == "" || conf.NatsClusterID == "" {
log.Warn().Msg("missing or incomplete nats configuration. Events will not be published.")
} else {
var tlsConf *tls.Config
if conf.NatsEnableTLS {
var rootCAPool *x509.CertPool
if conf.NatsRootCACertPath != "" {
f, err := os.Open(conf.NatsRootCACertPath)
if err != nil {
return nil, err
}
var certBytes bytes.Buffer
if _, err := io.Copy(&certBytes, f); err != nil {
return nil, err
}
rootCAPool = x509.NewCertPool()
rootCAPool.AppendCertsFromPEM(certBytes.Bytes())
conf.NatsTLSInsecure = false
}
tlsConf = &tls.Config{
InsecureSkipVerify: conf.NatsTLSInsecure,
RootCAs: rootCAPool,
}
}
s, err := stream.Nats(natsjs.TLSConfig(tlsConf), natsjs.Address(conf.NatsAddress), natsjs.ClusterID(conf.NatsClusterID))
s, err := stream.NatsFromConfig("dataprovider", stream.NatsConfig{
Endpoint: conf.NatsAddress,
Cluster: conf.NatsClusterID,
EnableTLS: conf.NatsEnableTLS,
TLSInsecure: conf.NatsTLSInsecure,
TLSRootCACertificate: conf.NatsRootCACertPath,
})
if err != nil {
return nil, err
}
+3 -2
View File
@@ -25,7 +25,7 @@ type NatsConfig struct {
}
// NatsFromConfig returns a nats stream from the given config
func NatsFromConfig(cfg NatsConfig) (events.Stream, error) {
func NatsFromConfig(connName string, cfg NatsConfig) (events.Stream, error) {
var tlsConf *tls.Config
if cfg.EnableTLS {
var rootCAPool *x509.CertPool
@@ -53,11 +53,12 @@ func NatsFromConfig(cfg NatsConfig) (events.Stream, error) {
natsjs.Address(cfg.Endpoint),
natsjs.ClusterID(cfg.Cluster),
natsjs.SynchronousPublish(true),
natsjs.Name(connName),
)
}
// Nats returns a nats streaming client
// nats returns a nats streaming client
// retries exponentially to connect to a nats server
func Nats(opts ...natsjs.Option) (events.Stream, error) {
b := backoff.NewExponentialBackOff()
+5 -40
View File
@@ -19,12 +19,7 @@
package jsoncs3
import (
"bytes"
"context"
"crypto/tls"
"crypto/x509"
"io"
"os"
"strings"
"sync"
"time"
@@ -34,7 +29,6 @@ import (
rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/go-micro/plugins/v4/events/natsjs"
"github.com/google/uuid"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
@@ -131,10 +125,11 @@ type config struct {
// EventOptions are the configurable options for events
type EventOptions struct {
NatsAddress string `mapstructure:"natsaddress"`
NatsClusterID string `mapstructure:"natsclusterid"`
Endpoint string `mapstructure:"natsaddress"`
Cluster string `mapstructure:"natsclusterid"`
TLSInsecure bool `mapstructure:"tlsinsecure"`
TLSRootCACertificate string `mapstructure:"tlsrootcacertificate"`
EnableTLS bool `mapstructure:"enabletls"`
}
// Manager implements a share manager using a cs3 storage backend with local caching
@@ -176,38 +171,8 @@ func NewDefault(m map[string]interface{}) (share.Manager, error) {
}
var es events.Stream
if c.Events.NatsAddress != "" {
evtsCfg := c.Events
var (
rootCAPool *x509.CertPool
tlsConf *tls.Config
)
if evtsCfg.TLSRootCACertificate != "" {
rootCrtFile, err := os.Open(evtsCfg.TLSRootCACertificate)
if err != nil {
return nil, err
}
var certBytes bytes.Buffer
if _, err := io.Copy(&certBytes, rootCrtFile); err != nil {
return nil, err
}
rootCAPool = x509.NewCertPool()
rootCAPool.AppendCertsFromPEM(certBytes.Bytes())
evtsCfg.TLSInsecure = false
tlsConf = &tls.Config{
InsecureSkipVerify: evtsCfg.TLSInsecure, //nolint:gosec
RootCAs: rootCAPool,
}
}
es, err = stream.Nats(
natsjs.TLSConfig(tlsConf),
natsjs.Address(evtsCfg.NatsAddress),
natsjs.ClusterID(evtsCfg.NatsClusterID),
)
if c.Events.Endpoint != "" {
es, err = stream.NatsFromConfig("jsoncs3-share-manager", stream.NatsConfig(c.Events))
if err != nil {
return nil, err
}
@@ -350,17 +350,12 @@ func initNewNode(upload *Upload, n *node.Node, fsize uint64) (*lockedfile.File,
// link child name to parent if it is new
childNameLink := filepath.Join(n.ParentPath(), n.Name)
link, err := os.Readlink(childNameLink)
if err == nil && link != "../"+n.ID {
if err := os.Remove(childNameLink); err != nil {
return f, errors.Wrap(err, "Decomposedfs: could not remove symlink child entry")
}
}
if errors.Is(err, iofs.ErrNotExist) || link != "../"+n.ID {
relativeNodePath := filepath.Join("../../../../../", lookup.Pathify(n.ID, 4, 2))
if err = os.Symlink(relativeNodePath, childNameLink); err != nil {
return f, errors.Wrap(err, "Decomposedfs: could not symlink child entry")
relativeNodePath := filepath.Join("../../../../../", lookup.Pathify(n.ID, 4, 2))
if err = os.Symlink(relativeNodePath, childNameLink); err != nil {
if errors.Is(err, iofs.ErrExist) {
return nil, errtypes.AlreadyExists(n.Name)
}
return f, errors.Wrap(err, "Decomposedfs: could not symlink child entry")
}
// on a new file the sizeDiff is the fileSize