From 7644c5a9c6630cd0db57a79a46c0ec583b22fb0f Mon Sep 17 00:00:00 2001 From: Benedikt Kulmann Date: Wed, 21 Oct 2020 23:26:44 +0200 Subject: [PATCH] User service user uuid in indexes --- .../pkg/indexer/index/cs3/autoincrement.go | 32 +++++++++---------- accounts/pkg/indexer/index/cs3/non_unique.go | 22 ++++++------- accounts/pkg/indexer/index/cs3/unique.go | 22 ++++++------- accounts/pkg/indexer/indexer.go | 4 +-- accounts/pkg/indexer/option/option.go | 32 ++++++++++++++----- ocis/go.sum | 9 ++++++ 6 files changed, 70 insertions(+), 51 deletions(-) diff --git a/accounts/pkg/indexer/index/cs3/autoincrement.go b/accounts/pkg/indexer/index/cs3/autoincrement.go index ec2707575c..465521588a 100644 --- a/accounts/pkg/indexer/index/cs3/autoincrement.go +++ b/accounts/pkg/indexer/index/cs3/autoincrement.go @@ -3,7 +3,6 @@ package cs3 import ( "context" "fmt" - idxerrs "github.com/owncloud/ocis/accounts/pkg/indexer/errors" "io/ioutil" "net/http" "os" @@ -13,6 +12,8 @@ import ( "strconv" "strings" + idxerrs "github.com/owncloud/ocis/accounts/pkg/indexer/errors" + user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" v1beta11 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" @@ -28,11 +29,11 @@ import ( // Autoincrement are fields for an index of type autoincrement. type Autoincrement struct { - indexBy string - typeName string - filesDir string - indexBaseDir string - indexRootDir string + indexBy string + typeName string + filesDir string + indexBaseDir string + indexRootDir string tokenManager token.Manager storageProvider provider.ProviderAPIClient @@ -53,18 +54,18 @@ func NewAutoincrementIndex(o ...option.Option) index.Index { } u := &Autoincrement{ - indexBy: opts.IndexBy, - typeName: opts.TypeName, - filesDir: opts.FilesDir, - indexBaseDir: path.Join(opts.DataDir, "index.cs3"), - indexRootDir: path.Join(path.Join(opts.DataDir, "index.cs3"), strings.Join([]string{"autoincrement", opts.TypeName, opts.IndexBy}, ".")), + indexBy: opts.IndexBy, + typeName: opts.TypeName, + filesDir: opts.FilesDir, + indexBaseDir: path.Join(opts.DataDir, "index.cs3"), + indexRootDir: path.Join(path.Join(opts.DataDir, "index.cs3"), strings.Join([]string{"autoincrement", opts.TypeName, opts.IndexBy}, ".")), cs3conf: &Config{ ProviderAddr: opts.ProviderAddr, DataURL: opts.DataURL, DataPrefix: opts.DataPrefix, JWTSecret: opts.JWTSecret, - ServiceUserName: "", - ServiceUserUUID: "", + ServiceUserName: opts.ServiceUserName, + ServiceUserUUID: opts.ServiceUserUUID, }, dataProvider: dataProviderClient{ baseURL: singleJoiningSlash(opts.DataURL, opts.DataPrefix), @@ -343,12 +344,9 @@ func (idx *Autoincrement) makeDirIfNotExists(ctx context.Context, folder string) func (idx *Autoincrement) authenticate(ctx context.Context) (token string, err error) { u := &user.User{ - Id: &user.UserId{}, + Id: &user.UserId{OpaqueId: idx.cs3conf.ServiceUserUUID}, Groups: []string{}, } - if idx.cs3conf.ServiceUserName != "" { - u.Id.OpaqueId = idx.cs3conf.ServiceUserUUID - } return idx.tokenManager.MintToken(ctx, u) } diff --git a/accounts/pkg/indexer/index/cs3/non_unique.go b/accounts/pkg/indexer/index/cs3/non_unique.go index a5ad7d4638..c017d791bf 100644 --- a/accounts/pkg/indexer/index/cs3/non_unique.go +++ b/accounts/pkg/indexer/index/cs3/non_unique.go @@ -3,6 +3,13 @@ package cs3 import ( "context" "fmt" + "io/ioutil" + "net/http" + "os" + "path" + "path/filepath" + "strings" + user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" v1beta11 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" @@ -14,12 +21,6 @@ import ( "github.com/owncloud/ocis/accounts/pkg/indexer/option" "github.com/owncloud/ocis/accounts/pkg/indexer/registry" "google.golang.org/grpc/metadata" - "io/ioutil" - "net/http" - "os" - "path" - "path/filepath" - "strings" ) func init() { @@ -69,8 +70,8 @@ func NewNonUniqueIndexWithOptions(o ...option.Option) index.Index { DataURL: opts.DataURL, DataPrefix: opts.DataPrefix, JWTSecret: opts.JWTSecret, - ServiceUserName: "", - ServiceUserUUID: "", + ServiceUserName: opts.ServiceUserName, + ServiceUserUUID: opts.ServiceUserUUID, }, dataProvider: dataProviderClient{ baseURL: singleJoiningSlash(opts.DataURL, opts.DataPrefix), @@ -316,12 +317,9 @@ func (idx *NonUnique) FilesDir() string { func (idx *NonUnique) authenticate(ctx context.Context) (token string, err error) { u := &user.User{ - Id: &user.UserId{}, + Id: &user.UserId{OpaqueId: idx.cs3conf.ServiceUserUUID}, Groups: []string{}, } - if idx.cs3conf.ServiceUserName != "" { - u.Id.OpaqueId = idx.cs3conf.ServiceUserUUID - } return idx.tokenManager.MintToken(ctx, u) } diff --git a/accounts/pkg/indexer/index/cs3/unique.go b/accounts/pkg/indexer/index/cs3/unique.go index 73d1bbf490..a5526b47cb 100644 --- a/accounts/pkg/indexer/index/cs3/unique.go +++ b/accounts/pkg/indexer/index/cs3/unique.go @@ -3,6 +3,13 @@ package cs3 import ( "context" "fmt" + "io/ioutil" + "net/http" + "os" + "path" + "path/filepath" + "strings" + user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" v1beta11 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" @@ -14,12 +21,6 @@ import ( "github.com/owncloud/ocis/accounts/pkg/indexer/option" "github.com/owncloud/ocis/accounts/pkg/indexer/registry" "google.golang.org/grpc/metadata" - "io/ioutil" - "net/http" - "os" - "path" - "path/filepath" - "strings" ) // Unique are fields for an index of type non_unique. @@ -72,8 +73,8 @@ func NewUniqueIndexWithOptions(o ...option.Option) index.Index { DataURL: opts.DataURL, DataPrefix: opts.DataPrefix, JWTSecret: opts.JWTSecret, - ServiceUserName: "", - ServiceUserUUID: "", + ServiceUserName: opts.ServiceUserName, + ServiceUserUUID: opts.ServiceUserUUID, }, dataProvider: dataProviderClient{ baseURL: singleJoiningSlash(opts.DataURL, opts.DataPrefix), @@ -364,11 +365,8 @@ func (idx *Unique) makeDirIfNotExists(ctx context.Context, folder string) error func (idx *Unique) authenticate(ctx context.Context) (token string, err error) { u := &user.User{ - Id: &user.UserId{}, + Id: &user.UserId{OpaqueId: idx.cs3conf.ServiceUserUUID}, Groups: []string{}, } - if idx.cs3conf.ServiceUserName != "" { - u.Id.OpaqueId = idx.cs3conf.ServiceUserUUID - } return idx.tokenManager.MintToken(ctx, u) } diff --git a/accounts/pkg/indexer/indexer.go b/accounts/pkg/indexer/indexer.go index efb5388b58..2731af4135 100644 --- a/accounts/pkg/indexer/indexer.go +++ b/accounts/pkg/indexer/indexer.go @@ -65,12 +65,12 @@ func (i Indexer) AddIndex(t interface{}, indexBy, pkName, entityDirName, indexTy option.WithBounds(bound), option.WithTypeName(getTypeFQN(t)), option.WithIndexBy(indexBy), - option.WithFilesDir(path.Join(i.config.Repo.Disk.Path, entityDirName)), - option.WithDataDir(i.config.Repo.Disk.Path), option.WithDataURL(i.config.Repo.CS3.DataURL), option.WithDataPrefix(i.config.Repo.CS3.DataPrefix), option.WithJWTSecret(i.config.Repo.CS3.JWTSecret), option.WithProviderAddr(i.config.Repo.CS3.ProviderAddr), + option.WithServiceUserUUID(i.config.ServiceUser.UUID), + option.WithServiceUserName(i.config.ServiceUser.Username), ) } diff --git a/accounts/pkg/indexer/option/option.go b/accounts/pkg/indexer/option/option.go index 04ff258017..df365d1ab0 100644 --- a/accounts/pkg/indexer/option/option.go +++ b/accounts/pkg/indexer/option/option.go @@ -13,7 +13,7 @@ type Bound struct { // Options defines the available options for this package. type Options struct { CaseInsensitive bool - Bound *Bound + Bound *Bound // Disk Options TypeName string @@ -25,10 +25,12 @@ type Options struct { Entity interface{} // CS3 options - DataURL string - DataPrefix string - JWTSecret string - ProviderAddr string + DataURL string + DataPrefix string + JWTSecret string + ProviderAddr string + ServiceUserUUID string + ServiceUserName string } // CaseInsensitive sets the CaseInsensitive field. @@ -94,23 +96,37 @@ func WithTypeName(val string) Option { } } -// WithIndexBy sets the option IndexBy +// WithIndexBy sets the option IndexBy. func WithIndexBy(val string) Option { return func(o *Options) { o.IndexBy = val } } -// WithFilesDir sets the option FilesDir +// WithFilesDir sets the option FilesDir. func WithFilesDir(val string) Option { return func(o *Options) { o.FilesDir = val } } -// WithProviderAddr sets the option ProviderAddr +// WithProviderAddr sets the option ProviderAddr. func WithProviderAddr(val string) Option { return func(o *Options) { o.ProviderAddr = val } } + +// WithServiceUserUUID sets the option ServiceUserUUID. +func WithServiceUserUUID(val string) Option { + return func(o *Options) { + o.ServiceUserUUID = val + } +} + +// WithServiceUserName sets the option ServiceUserName. +func WithServiceUserName(val string) Option { + return func(o *Options) { + o.ServiceUserName = val + } +} diff --git a/ocis/go.sum b/ocis/go.sum index 0061d82519..9e8e1b3ae2 100644 --- a/ocis/go.sum +++ b/ocis/go.sum @@ -126,8 +126,10 @@ github.com/aws/aws-sdk-go v1.23.19/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpi github.com/aws/aws-sdk-go v1.28.2/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aws/aws-sdk-go v1.33.19/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= github.com/aws/aws-sdk-go v1.34.2/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= +github.com/aws/aws-sdk-go v1.34.12/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= github.com/aws/aws-sdk-go v1.35.0 h1:Pxqn1MWNfBCNcX7jrXCCTfsKpg5ms2IMUMmmcGtYJuo= github.com/aws/aws-sdk-go v1.35.0/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48= +github.com/aws/aws-sdk-go v1.35.9 h1:b1HiUpdkFLJyoOQ7zas36YHzjNHH0ivHx/G5lWBeg+U= github.com/aws/aws-sdk-go v1.35.9/go.mod h1:tlPOdRjfxPBpNIwqDj61rmsnA85v9jc0Ps9+muhnW+k= github.com/aws/aws-xray-sdk-go v0.9.4/go.mod h1:XtMKdBQfpVut+tJEwI7+dJFRxxRdxHDyVNp2tHXRq04= github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc= @@ -268,11 +270,13 @@ github.com/cs3org/go-cs3apis v0.0.0-20200929101248-821df597ec8d/go.mod h1:UXha4T github.com/cs3org/reva v0.0.2-0.20200115110931-4c7513415ec5/go.mod h1:Hk3eCcdhtv4eIhKvRK736fQuOyS1HuHnUcz0Dq6NK1A= github.com/cs3org/reva v1.1.0/go.mod h1:fBzTrNuAKdQ62ybjpdu8nyhBin90/3/3s6DGQDCdBp4= github.com/cs3org/reva v1.2.1-0.20200826162318-c0f54e1f37ea/go.mod h1:FvYB+UPpuPCw0hH42qHVR1R2atZyy69METZI/zEaST8= +github.com/cs3org/reva v1.2.2-0.20200924071957-e6676516e61e/go.mod h1:DOV5SjpOBKN+aWfOHLdA4KiLQkpyC786PQaXEdRAZ0M= github.com/cs3org/reva v1.2.2-0.20201006093611-4a9be347ac29 h1:bGdr8WQI3khh8/Uo7icnWOvIyGxnGUVvSSLvtEliuIE= github.com/cs3org/reva v1.2.2-0.20201006093611-4a9be347ac29/go.mod h1:c0MYy0goE5OGC8WPb5LLMZtCqymwSk2fiKVQANzy0zg= github.com/cs3org/reva v1.2.2-0.20201007135248-bccddc4b5a48 h1:ICRTh96BemJ+oOSgp8j4EM32Ye10jh+UWjMxKbVr30g= github.com/cs3org/reva v1.2.2-0.20201007135248-bccddc4b5a48/go.mod h1:A4Q/nQ8Vs+HeAduSFnM37fqxEM3uXVxhaHrNL+gWcBY= github.com/cs3org/reva v1.3.1-0.20201021065855-dc400f81ecbc/go.mod h1:rTJhfVoZggB5iSPH5oWqQSO+W1iTQIxNmaX/ueS9GAU= +github.com/cs3org/reva v1.3.1-0.20201021130722-dd3a8c0f3881 h1:xhpamvgyDr0jCtjXZCTk8qOdnslxhz8dHym5KLh7gl8= github.com/cs3org/reva v1.3.1-0.20201021130722-dd3a8c0f3881/go.mod h1:NplJavkhPZvy8/9K9m95g6uddq3pATO62bovvevpsBw= github.com/cznic/b v0.0.0-20181122101859-a26611c4d92d h1:SwD98825d6bdB+pEuTxWOXiSjBrHdOl/UVp75eI7JT8= github.com/cznic/b v0.0.0-20181122101859-a26611c4d92d/go.mod h1:URriBxXwVq5ijiJ12C7iIZqlA69nTlI+LgI6/pwftG8= @@ -393,6 +397,7 @@ github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2 github.com/go-ldap/ldap/v3 v3.1.7/go.mod h1:5Zun81jBTabRaI8lzN7E1JjyEl1g6zI6u9pd8luAK4Q= github.com/go-ldap/ldap/v3 v3.2.3 h1:FBt+5w3q/vPVPb4eYMQSn+pOiz4zewPamYhlGMmc7yM= github.com/go-ldap/ldap/v3 v3.2.3/go.mod h1:iYS1MdmrmceOJ1QOTnRXrIs7i3kloqtmGQjRvjKpyMg= +github.com/go-ldap/ldap/v3 v3.2.4 h1:PFavAq2xTgzo/loE8qNXcQaofAaqIpI4WgaLdv+1l3E= github.com/go-ldap/ldap/v3 v3.2.4/go.mod h1:iYS1MdmrmceOJ1QOTnRXrIs7i3kloqtmGQjRvjKpyMg= github.com/go-log/log v0.1.0/go.mod h1:4mBwpdRMFLiuXZDCwU2lKQFsoSCo72j3HqBK9d81N2M= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= @@ -636,6 +641,7 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= @@ -1063,9 +1069,11 @@ github.com/ory/dockertest v3.3.5+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnh github.com/ory/fosite v0.29.0/go.mod h1:0atSZmXO7CAcs6NPMI/Qtot8tmZYj04Nddoold4S2h0= github.com/ory/fosite v0.30.2/go.mod h1:Lq9qQ9Sl6mcea2Tt8J7PU+wUeFYPZ+vg7N3zPVKGbN8= github.com/ory/fosite v0.32.2/go.mod h1:UeBhRgW6nAjTcd8S7kAo0IFsY/rTPyOXPq/t8N20Q8I= +github.com/ory/fosite v0.33.0/go.mod h1:h+ize9gk0GvRyGjabriqSEmTkMhny+O95cijb8DVqPE= github.com/ory/fosite v0.34.0 h1:lCUX4f5BoiXBIRUYKeTne+aRl0v6StgWpyYKq+7ILw0= github.com/ory/fosite v0.34.0/go.mod h1:h+ize9gk0GvRyGjabriqSEmTkMhny+O95cijb8DVqPE= github.com/ory/fosite v0.35.0/go.mod h1:h+ize9gk0GvRyGjabriqSEmTkMhny+O95cijb8DVqPE= +github.com/ory/fosite v0.35.1 h1:mGPcwVGwHA7Yy9wr/7LDps6BEXyavL32NxizL9eH53Q= github.com/ory/fosite v0.35.1/go.mod h1:h+ize9gk0GvRyGjabriqSEmTkMhny+O95cijb8DVqPE= github.com/ory/go-acc v0.0.0-20181118080137-ddc355013f90/go.mod h1:sxnvPCxChFuSmTJGj8FdMupeq1BezCiEpDjTUXQ4hf4= github.com/ory/go-acc v0.2.1/go.mod h1:0omgy2aa3nDBJ45VAKeLHH8ccPBudxLeic4xiDRtug0= @@ -1385,6 +1393,7 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4 h1:LYy1Hy3MJdrCdMwwzxA/dRok4ejH+RwNGbuoD9fCjto= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.5 h1:dntmOdLpSpHlVqbW5Eay97DelsZHe+55D+xC6i0dDS0= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=