From 1bdde93660e8bc5dcc3b5178b27dc16f67849147 Mon Sep 17 00:00:00 2001 From: David Christofas Date: Mon, 26 Oct 2020 17:04:15 +0100 Subject: [PATCH] delete user home directory when deleting user Signed-off-by: David Christofas --- changelog/unreleased/delete-user-home.md | 5 ++ ocis/go.sum | 1 - ocs/go.mod | 3 + ocs/go.sum | 5 ++ ocs/pkg/command/server.go | 23 ++++++++ ocs/pkg/config/config.go | 6 ++ ocs/pkg/flagset/flagset.go | 7 +++ ocs/pkg/server/http/option.go | 20 ++++++- ocs/pkg/server/http/server.go | 2 + ocs/pkg/server/http/svc_test.go | 37 +++++++++++++ ocs/pkg/service/v0/option.go | 18 ++++++ ocs/pkg/service/v0/service.go | 8 ++- ocs/pkg/service/v0/users.go | 70 +++++++++++++++++++++++- 13 files changed, 201 insertions(+), 4 deletions(-) create mode 100644 changelog/unreleased/delete-user-home.md diff --git a/changelog/unreleased/delete-user-home.md b/changelog/unreleased/delete-user-home.md new file mode 100644 index 00000000000..3ac9c1b0f3f --- /dev/null +++ b/changelog/unreleased/delete-user-home.md @@ -0,0 +1,5 @@ +Enhancement: Delete user home directory + +Extended the delete user method to also delete the user home folder on top of deleting the user in the accounts service. + +https://github.com/owncloud/ocis/pull/755 diff --git a/ocis/go.sum b/ocis/go.sum index e2d77c9646a..c332f972827 100644 --- a/ocis/go.sum +++ b/ocis/go.sum @@ -248,7 +248,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/crewjam/httperr v0.0.0-20190612203328-a946449404da h1:WXnT88cFG2davqSFqvaFfzkSMC0lqh/8/rKZ+z7tYvI= github.com/crewjam/httperr v0.0.0-20190612203328-a946449404da/go.mod h1:+rmNIXRvYMqLQeR4DHyTvs6y0MEMymTz4vyFpFkKTPs= github.com/crewjam/httperr v0.2.0 h1:b2BfXR8U3AlIHwNeFFvZ+BV1LFvKLlzMjzaTnZMybNo= github.com/crewjam/httperr v0.2.0/go.mod h1:Jlz+Sg/XqBQhyMjdDiC+GNNRzZTD7x39Gu3pglZ5oH4= diff --git a/ocs/go.mod b/ocs/go.mod index 867e3335280..fa426183a7b 100644 --- a/ocs/go.mod +++ b/ocs/go.mod @@ -7,6 +7,7 @@ require ( contrib.go.opencensus.io/exporter/ocagent v0.7.0 contrib.go.opencensus.io/exporter/zipkin v0.1.1 github.com/UnnoTed/fileb0x v1.1.4 + github.com/cs3org/go-cs3apis v0.0.0-20200929101248-821df597ec8d github.com/cs3org/reva v1.3.1-0.20201021065855-dc400f81ecbc github.com/go-chi/chi v4.1.2+incompatible github.com/go-chi/render v1.0.1 @@ -20,12 +21,14 @@ require ( github.com/owncloud/ocis/ocis-pkg v0.0.0-20200918114005-1a0ddd2190ee github.com/owncloud/ocis/settings v0.0.0-20200918114005-1a0ddd2190ee github.com/owncloud/ocis/store v0.0.0-20200918125107-fcca9faa81c8 + github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.7.1 github.com/restic/calens v0.2.0 github.com/spf13/viper v1.7.0 github.com/stretchr/testify v1.6.1 go.opencensus.io v0.22.5 golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect + google.golang.org/grpc v1.32.0 google.golang.org/protobuf v1.25.0 ) diff --git a/ocs/go.sum b/ocs/go.sum index ab7e37ced35..0e9a3a3be5f 100644 --- a/ocs/go.sum +++ b/ocs/go.sum @@ -307,6 +307,7 @@ github.com/cs3org/go-cs3apis v0.0.0-20200730121022-c4f3d4f7ddfd h1:uMaudkC7znaiI github.com/cs3org/go-cs3apis v0.0.0-20200730121022-c4f3d4f7ddfd/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= github.com/cs3org/go-cs3apis v0.0.0-20200810113633-b00aca449666 h1:E7VsSSN/2YZLSwrDMJJdAWU11lP7W1qkcXbrslb0PM0= github.com/cs3org/go-cs3apis v0.0.0-20200810113633-b00aca449666/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= +github.com/cs3org/go-cs3apis v0.0.0-20200929101248-821df597ec8d h1:YDnGz3eTIYQDXzJd/zefEsl0qbz/P63e8KWjSjYlb5Q= github.com/cs3org/go-cs3apis v0.0.0-20200929101248-821df597ec8d/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= github.com/cs3org/reva v0.0.2-0.20200115110931-4c7513415ec5/go.mod h1:Hk3eCcdhtv4eIhKvRK736fQuOyS1HuHnUcz0Dq6NK1A= github.com/cs3org/reva v0.1.0 h1:PYzDejKm/+xG3OTS2WgzBxcksVogEGmPgjJVegwSR2c= @@ -699,6 +700,7 @@ github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0 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= @@ -845,6 +847,7 @@ github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw= github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= +github.com/iancoleman/strcase v0.1.2 h1:gnomlvw9tnV3ITTAxzKSgTF+8kFWcU/f+TgttpXGz1U= github.com/iancoleman/strcase v0.1.2/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4= @@ -1605,6 +1608,7 @@ go.opencensus.io v0.22.3 h1:8sGtKOrtQqkN1bp2AtX+misvLIlOmsEsNd+9NIcPEm8= 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= @@ -1894,6 +1898,7 @@ golang.org/x/sys v0.0.0-20200720211630-cb9d2d5c5666/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6 h1:DvY3Zkh7KabQE/kfzMvYvKirSiguP9Q/veMtkYyf0o8= golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200918174421-af09f7315aff h1:1CPUrky56AcgSpxz/KfgzQWzfG09u5YOL8MvPYBlrL8= golang.org/x/sys v0.0.0-20200918174421-af09f7315aff/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/ocs/pkg/command/server.go b/ocs/pkg/command/server.go index 76e6b66ba7c..73e87763eaa 100644 --- a/ocs/pkg/command/server.go +++ b/ocs/pkg/command/server.go @@ -2,6 +2,8 @@ package command import ( "context" + "github.com/cs3org/reva/pkg/rgrpc/todo/pool" + "github.com/cs3org/reva/pkg/token/manager/jwt" "os" "os/signal" "strings" @@ -138,10 +140,31 @@ func Server(cfg *config.Config) *cli.Command { metrics.BuildInfo.WithLabelValues(cfg.Service.Version).Set(1) { + tm, err := jwt.New(map[string]interface{}{ + "secret": cfg.TokenManager.JWTSecret, + "expires": int64(60), + }) + if err != nil { + logger.Error(). + Err(err). + Msg("could not create token manager") + return err + } + + gwc, err := pool.GetGatewayServiceClient(cfg.RevaGateway.Address) + if err != nil { + logger.Error(). + Err(err). + Msg("could not create reva gateway client") + return err + } + server, err := http.Server( http.Logger(logger), http.Context(ctx), http.Config(cfg), + http.TokenManager(tm), + http.RevaClient(gwc), http.Metrics(metrics), http.Flags(flagset.RootWithConfig(config.New())), http.Flags(flagset.ServerWithConfig(config.New())), diff --git a/ocs/pkg/config/config.go b/ocs/pkg/config/config.go index b8589533d70..3adaa94a6a4 100644 --- a/ocs/pkg/config/config.go +++ b/ocs/pkg/config/config.go @@ -42,6 +42,11 @@ type TokenManager struct { JWTSecret string } +// RevaGateway is the config for using the reva token manager +type RevaGateway struct { + Address string +} + // Config combines all available configuration parts. type Config struct { File string @@ -51,6 +56,7 @@ type Config struct { Tracing Tracing TokenManager TokenManager Service Service + RevaGateway RevaGateway } // New initializes a new configuration with or without defaults. diff --git a/ocs/pkg/flagset/flagset.go b/ocs/pkg/flagset/flagset.go index 0e030a35c03..545515ffc74 100644 --- a/ocs/pkg/flagset/flagset.go +++ b/ocs/pkg/flagset/flagset.go @@ -152,6 +152,13 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"OCS_JWT_SECRET"}, Destination: &cfg.TokenManager.JWTSecret, }, + &cli.StringFlag{ + Name: "reva-gateway-addr", + Value: "127.0.0.1:9142", + Usage: "REVA Gateway Endpoint", + EnvVars: []string{"OCS_REVA_GATEWAY_ADDR"}, + Destination: &cfg.RevaGateway.Address, + }, } } diff --git a/ocs/pkg/server/http/option.go b/ocs/pkg/server/http/option.go index fadc9e00d0b..56d38129e35 100644 --- a/ocs/pkg/server/http/option.go +++ b/ocs/pkg/server/http/option.go @@ -2,11 +2,13 @@ package http import ( "context" + gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" + "github.com/cs3org/reva/pkg/token" "github.com/micro/cli/v2" + "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocs/pkg/config" "github.com/owncloud/ocis/ocs/pkg/metrics" - "github.com/owncloud/ocis/ocis-pkg/log" ) // Option defines a single option function. @@ -20,6 +22,8 @@ type Options struct { Config *config.Config Metrics *metrics.Metrics Flags []cli.Flag + TokenManager token.Manager + RevaClient gatewayv1beta1.GatewayAPIClient } // newOptions initializes the available default options. @@ -74,3 +78,17 @@ func Namespace(val string) Option { o.Namespace = val } } + +// TokenManager provides a function to set the TokenManager option. +func TokenManager(tm token.Manager) Option { + return func(o *Options) { + o.TokenManager = tm + } +} + +// RevaClient provides a function to set the RevaClient option. +func RevaClient(c gatewayv1beta1.GatewayAPIClient) Option { + return func(o *Options) { + o.RevaClient = c + } +} diff --git a/ocs/pkg/server/http/server.go b/ocs/pkg/server/http/server.go index 08aa12e2af6..82c045d7b3d 100644 --- a/ocs/pkg/server/http/server.go +++ b/ocs/pkg/server/http/server.go @@ -23,6 +23,8 @@ func Server(opts ...Option) (http.Service, error) { handle := svc.NewService( svc.Logger(options.Logger), svc.Config(options.Config), + svc.TokenManager(options.TokenManager), + svc.RevaClient(options.RevaClient), svc.Middleware( middleware.RealIP, middleware.RequestID, diff --git a/ocs/pkg/server/http/svc_test.go b/ocs/pkg/server/http/svc_test.go index 5d826c53a2b..cef1a02fd52 100644 --- a/ocs/pkg/server/http/svc_test.go +++ b/ocs/pkg/server/http/svc_test.go @@ -6,6 +6,10 @@ import ( "encoding/json" "encoding/xml" "fmt" + gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" + providerv1beta1 "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + ggrpc "google.golang.org/grpc" + "github.com/cs3org/reva/pkg/token/manager/jwt" "io/ioutil" "log" "net/http" @@ -467,6 +471,29 @@ func sendRequest(method, endpoint, body, auth string) (*httptest.ResponseRecorde return rr, nil } +type mockRevaClient struct { + gatewayv1beta1.GatewayAPIClient +} + +func(c mockRevaClient) GetHome(ctx context.Context, req *providerv1beta1.GetHomeRequest, options ...ggrpc.CallOption) (*providerv1beta1.GetHomeResponse, error){ + return &providerv1beta1.GetHomeResponse{ + Path: "/home", + }, nil +} + +func(c mockRevaClient) Stat(ctx context.Context, req *providerv1beta1.StatRequest, options ...ggrpc.CallOption) (*providerv1beta1.StatResponse, error){ + return &providerv1beta1.StatResponse{ + Info: &providerv1beta1.ResourceInfo{Id: &providerv1beta1.ResourceId{ + OpaqueId: "", + StorageId: "", + }, + }, + }, nil +} + +func (o mockRevaClient) Delete(ctx context.Context, req * providerv1beta1.DeleteRequest, options ...ggrpc.CallOption) (*providerv1beta1.DeleteResponse, error) { + return nil, nil +} func getService() svc.Service { c := &config.Config{ @@ -484,9 +511,19 @@ func getService() svc.Service { var logger ocisLog.Logger + tm, _ := jwt.New(map[string]interface{}{ + "secret": c.TokenManager.JWTSecret, + "expires": int64(60), + }) + + + + return svc.NewService( svc.Logger(logger), svc.Config(c), + svc.TokenManager(tm), + svc.RevaClient(mockRevaClient{}), ) } diff --git a/ocs/pkg/service/v0/option.go b/ocs/pkg/service/v0/option.go index de898ebd281..584252e169b 100644 --- a/ocs/pkg/service/v0/option.go +++ b/ocs/pkg/service/v0/option.go @@ -1,6 +1,8 @@ package svc import ( + gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" + "github.com/cs3org/reva/pkg/token" "net/http" "github.com/owncloud/ocis/ocs/pkg/config" @@ -15,6 +17,8 @@ type Options struct { Logger log.Logger Config *config.Config Middleware []func(http.Handler) http.Handler + TokenManager token.Manager + RevaClient gatewayv1beta1.GatewayAPIClient } // newOptions initializes the available default options. @@ -48,3 +52,17 @@ func Middleware(val ...func(http.Handler) http.Handler) Option { o.Middleware = val } } + +// TokenManager provides a function to set the TokenManager option. +func TokenManager(tm token.Manager) Option { + return func(o *Options) { + o.TokenManager = tm + } +} + +// RevaClient provides a function to set the RevaClient option. +func RevaClient(c gatewayv1beta1.GatewayAPIClient) Option { + return func(o *Options) { + o.RevaClient = c + } +} diff --git a/ocs/pkg/service/v0/service.go b/ocs/pkg/service/v0/service.go index c1beb845c6d..ea411748194 100644 --- a/ocs/pkg/service/v0/service.go +++ b/ocs/pkg/service/v0/service.go @@ -1,6 +1,8 @@ package svc import ( + gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" + "github.com/cs3org/reva/pkg/token" "net/http" "github.com/go-chi/chi" @@ -9,11 +11,11 @@ import ( "github.com/micro/go-micro/v2/client/grpc" accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0" + "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocs/pkg/config" ocsm "github.com/owncloud/ocis/ocs/pkg/middleware" "github.com/owncloud/ocis/ocs/pkg/service/v0/data" "github.com/owncloud/ocis/ocs/pkg/service/v0/response" - "github.com/owncloud/ocis/ocis-pkg/log" ) var defaultClient = grpc.NewClient() @@ -35,6 +37,8 @@ func NewService(opts ...Option) Service { config: options.Config, mux: m, logger: options.Logger, + tokenManager: options.TokenManager, + revaClient: options.RevaClient, } m.Route(options.Config.HTTP.Root, func(r chi.Router) { @@ -89,6 +93,8 @@ type Ocs struct { config *config.Config logger log.Logger mux *chi.Mux + tokenManager token.Manager + revaClient gatewayv1beta1.GatewayAPIClient } // ServeHTTP implements the Service interface. diff --git a/ocs/pkg/service/v0/users.go b/ocs/pkg/service/v0/users.go index 4e257c81bbc..dd57adac40e 100644 --- a/ocs/pkg/service/v0/users.go +++ b/ocs/pkg/service/v0/users.go @@ -5,11 +5,17 @@ import ( "crypto/rand" "encoding/hex" "fmt" + revauser "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" + provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" + "github.com/cs3org/reva/pkg/token" + "github.com/cs3org/reva/pkg/user" + "github.com/pkg/errors" + "google.golang.org/grpc/metadata" "net/http" "strconv" "strings" - "github.com/cs3org/reva/pkg/user" "github.com/go-chi/chi" "github.com/go-chi/render" "google.golang.org/protobuf/types/known/fieldmaskpb" @@ -267,6 +273,46 @@ func (o Ocs) DeleteUser(w http.ResponseWriter, r *http.Request) { return } + t, err := o.mintTokenForUser(r.Context(), account) + if err != nil { + render.Render(w,r, response.ErrRender(data.MetaServerError.StatusCode, errors.Wrap(err, "could not mint token").Error())) + return + } + + ctx := metadata.AppendToOutgoingContext(r.Context(), token.TokenHeader, t) + + homeResp, err := o.revaClient.GetHome(ctx, &provider.GetHomeRequest{} ) + if err != nil { + render.Render(w,r, response.ErrRender(data.MetaServerError.StatusCode, errors.Wrap(err, "could not get home").Error())) + return + } + + statResp, err := o.revaClient.Stat(ctx, &provider.StatRequest{ + Ref: &provider.Reference { + Spec: &provider.Reference_Path{ + Path: homeResp.Path, + }, + }, + }) + if err != nil { + render.Render(w,r, response.ErrRender(data.MetaServerError.StatusCode, errors.Wrap(err, "could not stat home").Error())) + return + } + + delReq := &provider.DeleteRequest{ + Ref: &provider.Reference { + Spec: &provider.Reference_Id{ + Id: statResp.Info.Id, + }, + }, + } + + _, err = o.revaClient.Delete(ctx, delReq) + if err != nil { + render.Render(w,r, response.ErrRender(data.MetaServerError.StatusCode, errors.Wrap(err, "could not delete home").Error())) + return + } + req := accounts.DeleteAccountRequest{ Id: account.Id, } @@ -384,6 +430,28 @@ func (o Ocs) ListUsers(w http.ResponseWriter, r *http.Request) { render.Render(w, r, response.DataRender(&data.Users{Users: users})) } +func (o Ocs) mintTokenForUser(ctx context.Context, account *accounts.Account) (string, error) { + u := &revauser.User{ + Id: &revauser.UserId{ + OpaqueId: account.Id, + }, + Groups: []string{}, + Opaque: &types.Opaque{ + Map: map[string]*types.OpaqueEntry{ + "uid": { + Decoder: "plain", + Value: []byte(strconv.FormatInt(account.UidNumber, 10)), + }, + "gid": { + Decoder: "plain", + Value: []byte(strconv.FormatInt(account.GidNumber, 10)), + }, + }, + }, + } + return o.tokenManager.MintToken(ctx, u) +} + // escapeValue escapes all special characters in the value func escapeValue(value string) string { return strings.ReplaceAll(value, "'", "''")