diff --git a/Dockerfile b/Dockerfile index 084217a..324eb1b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ COPY ./go.mod ./ COPY ./go.sum ./ RUN go mod download COPY . . -RUN export GO111MODULE=on && CGO_ENABLED=0 GOOS=linux go build -ldflags "-s -w" -o build/casmesh cmd/app/main.go +RUN export GO111MODULE=on && CGO_ENABLED=0 GOOS=linux go build -ldflags "-s -w" -o build/casmesh cmd/app/*.go FROM alpine:latest diff --git a/cmd/cli/auth.go b/client/v2/auth.go similarity index 98% rename from cmd/cli/auth.go rename to client/v2/auth.go index 231a6c6..f2f4e4a 100644 --- a/cmd/cli/auth.go +++ b/client/v2/auth.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package main +package client type AuthType = string diff --git a/cmd/cli/client.go b/client/v2/client.go similarity index 71% rename from cmd/cli/client.go rename to client/v2/client.go index 616a233..1f6f067 100644 --- a/cmd/cli/client.go +++ b/client/v2/client.go @@ -1,21 +1,18 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you 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 +// Copyright 2022 The casbin-neo Authors. All Rights Reserved. // -// http://www.apache.org/licenses/LICENSE-2.0 +// 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 // -// 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. +// 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. -package main +package client import ( "context" @@ -29,7 +26,7 @@ import ( "time" ) -type client struct { +type Client struct { grpcClient command.CasbinMeshClient } @@ -37,7 +34,7 @@ var ( MarshalFailed = errors.New("marshal failed") ) -func (c client) ShowStats(ctx context.Context) ([]byte, error) { +func (c Client) ShowStats(ctx context.Context) ([]byte, error) { resp, err := c.grpcClient.ShowStats(ctx, &command.StatsRequest{}) if err != nil { return nil, err @@ -45,7 +42,7 @@ func (c client) ShowStats(ctx context.Context) ([]byte, error) { return resp.Payload, nil } -func (c client) AddPolicies(ctx context.Context, namespace, sec, ptype string, rules [][]string) ([][]string, error) { +func (c Client) AddPolicies(ctx context.Context, namespace, sec, ptype string, rules [][]string) ([][]string, error) { payload := command.AddPoliciesPayload{ Sec: sec, PType: ptype, @@ -70,7 +67,7 @@ func (c client) AddPolicies(ctx context.Context, namespace, sec, ptype string, r return command.ToStringArray(resp.EffectedRules), nil } -func (c client) RemovePolicies(ctx context.Context, namespace, sec, ptype string, rules [][]string) ([][]string, error) { +func (c Client) RemovePolicies(ctx context.Context, namespace, sec, ptype string, rules [][]string) ([][]string, error) { payload := command.RemovePoliciesPayload{ Sec: sec, PType: ptype, @@ -95,7 +92,7 @@ func (c client) RemovePolicies(ctx context.Context, namespace, sec, ptype string return command.ToStringArray(resp.EffectedRules), nil } -func (c client) UpdatePolicies(ctx context.Context, namespace, sec, ptype string, old, new [][]string) (bool, error) { +func (c Client) UpdatePolicies(ctx context.Context, namespace, sec, ptype string, old, new [][]string) (bool, error) { log.Printf("sec:%s,ptype:%s,or%v,nr:%v", sec, ptype, old, new) payload := command.UpdatePoliciesPayload{ Sec: sec, @@ -122,7 +119,7 @@ func (c client) UpdatePolicies(ctx context.Context, namespace, sec, ptype string return resp.Effected, nil } -func (c client) ListNamespaces(ctx context.Context) ([]string, error) { +func (c Client) ListNamespaces(ctx context.Context) ([]string, error) { resp, err := c.grpcClient.ListNamespaces(ctx, &command.ListNamespacesRequest{}) if err != nil { return nil, err @@ -133,7 +130,7 @@ func (c client) ListNamespaces(ctx context.Context) ([]string, error) { return resp.Namespace, nil } -func (c client) ListPolicies(ctx context.Context, namespace string) ([][]string, error) { +func (c Client) ListPolicies(ctx context.Context, namespace string) ([][]string, error) { resp, err := c.grpcClient.ListPolicies(ctx, &command.ListPoliciesRequest{Namespace: namespace}) if err != nil { return nil, err @@ -141,7 +138,7 @@ func (c client) ListPolicies(ctx context.Context, namespace string) ([][]string, return command.ToStringArray(resp.Policies), nil } -func (c client) Enforce(ctx context.Context, namespace string, level command.EnforcePayload_Level, freshness int64, params ...interface{}) (bool, error) { +func (c Client) Enforce(ctx context.Context, namespace string, level command.EnforcePayload_Level, freshness int64, params ...interface{}) (bool, error) { var B [][]byte for _, p := range params { b, err := json.Marshal(p) @@ -170,7 +167,7 @@ func (c client) Enforce(ctx context.Context, namespace string, level command.Enf return result.Ok, nil } -func (c client) PrintModel(ctx context.Context, namespace string) (string, error) { +func (c Client) PrintModel(ctx context.Context, namespace string) (string, error) { resp, err := c.grpcClient.PrintModel(ctx, &command.PrintModelRequest{Namespace: namespace}) if err != nil { return "", err @@ -181,31 +178,31 @@ func (c client) PrintModel(ctx context.Context, namespace string) (string, error return resp.Model, nil } -type options struct { - target string - authType AuthType - username string - password string +type Options struct { + Target string + AuthType AuthType + Username string + Password string } -func NewClient(op options) *client { +func NewClient(op Options) *Client { var opts []grpc.DialOption ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() opts = append(opts, grpc.WithInsecure()) opts = append(opts, grpc.WithBlock()) - switch op.authType { + switch op.AuthType { case Basic: - opts = append(opts, grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(BasicAuthor(op.username, op.password)))) + opts = append(opts, grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(BasicAuthor(op.Username, op.Password)))) } - conn, err := grpc.DialContext(ctx, op.target, opts...) + conn, err := grpc.DialContext(ctx, op.Target, opts...) if err != nil { log.Fatalf("fail to dial: %v", err) } log.Println("login success!") //defer conn.Close() c := command.NewCasbinMeshClient(conn) - return &client{grpcClient: c} + return &Client{grpcClient: c} } diff --git a/cmd/cli/client_test.go b/client/v2/client_test.go similarity index 98% rename from cmd/cli/client_test.go rename to client/v2/client_test.go index 90a7788..15d0d3c 100644 --- a/cmd/cli/client_test.go +++ b/client/v2/client_test.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package main +package client import ( "context" @@ -26,7 +26,7 @@ import ( ) var ( - c *client + c *Client ) func TestMain(m *testing.M) { diff --git a/client/v2/go.mod b/client/v2/go.mod new file mode 100644 index 0000000..46299c8 --- /dev/null +++ b/client/v2/go.mod @@ -0,0 +1,18 @@ +module github.com/casbin/casbin-mesh/client/v2 + +go 1.18 + +require ( + github.com/casbin/casbin-mesh v0.0.0-20220510133536-c1b32d87368a + github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 + google.golang.org/grpc v1.47.0 +) + +require ( + github.com/golang/protobuf v1.5.2 // indirect + golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb // indirect + golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 // indirect + golang.org/x/text v0.3.3 // indirect + google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect + google.golang.org/protobuf v1.27.1 // indirect +) diff --git a/client/v2/go.sum b/client/v2/go.sum new file mode 100644 index 0000000..540c381 --- /dev/null +++ b/client/v2/go.sum @@ -0,0 +1,356 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= +github.com/BBVA/raft-badger v1.1.0/go.mod h1:6aj0Kov2CDas5dHHKyym9nwfntRUE4J4Q0J/5WaNhwI= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= +github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= +github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878/go.mod h1:3AMJUQhVx52RsWOnlkpikZr01T/yAVN2gn0861vByNg= +github.com/atotto/clipboard v0.1.2/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= +github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= +github.com/c-bata/go-prompt v0.2.6/go.mod h1:/LMAke8wD2FsNu9EXNdHxNLbd9MedkPnCdfpU9wwHfY= +github.com/casbin/casbin-mesh v0.0.0-20220510133536-c1b32d87368a h1:hjFclFVTh3mNGTMKnTkdfbLsUXdab62ZJtF45wpVZkk= +github.com/casbin/casbin-mesh v0.0.0-20220510133536-c1b32d87368a/go.mod h1:SMdo5CzVoMClW84zLLo5WaHARbEiDbz34vUe8m3+UfA= +github.com/casbin/casbin/v2 v2.31.10/go.mod h1:vByNa/Fchek0KZUgG5wEsl7iFsiviAYKRtgrQfcJqHg= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/charmbracelet/bubbles v0.8.0/go.mod h1:5WX1sSSjNCgCrzvRMN/z23HxvWaa+AI16Ch0KPZPeDs= +github.com/charmbracelet/bubbletea v0.13.1/go.mod h1:tp9tr9Dadh0PLhgiwchE5zZJXm5543JYjHG9oY+5qSg= +github.com/charmbracelet/bubbletea v0.16.0/go.mod h1:YTZSs2p3odhwYZdhqJheYHVUjU37c9OLgS85kw6NGQY= +github.com/charmbracelet/lipgloss v0.1.2/go.mod h1:5D8zradw52m7QmxRF6QgwbwJi9je84g8MkWiGN07uKg= +github.com/charmbracelet/lipgloss v0.3.0/go.mod h1:VkhdBS2eNAmRkTwRKLJCFhCOVkjntMusBDxv7TXahuk= +github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= +github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= +github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/containerd/console v1.0.1/go.mod h1:XUsP6YE/mKtz6bxc+I8UiKKTP04qjQL4qcS3XoQ5xkw= +github.com/containerd/console v1.0.2/go.mod h1:ytZPjGgY2oeTkAONYafi2kSj0aYggsf8acV1PGKCbzQ= +github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/cosiner/argv v0.1.0/go.mod h1:EusR6TucWKX+zFgtdUsKT2Cvg45K5rtpCcWz4hK06d8= +github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgraph-io/badger/v3 v3.2011.1/go.mod h1:0rLLrQpKVQAL0or/lBLMQznhr6dWWX7h5AKnmnqx268= +github.com/dgraph-io/ristretto v0.0.4-0.20210122082011-bb5d392ed82d/go.mod h1:tv2ec8nA7vRpSYX7/MbP52ihrUMXIHit54CQMq8npXQ= +github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= +github.com/dgryski/go-farm v0.0.0-20191112170834-c2139c5d712b/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= +github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= +github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/erikgeiser/promptkit v0.6.0/go.mod h1:NfO1VleTDkelTUpIPkrxEifJxkU2M3cToKaVHFjxEa0= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fzipp/gocyclo v0.3.1/go.mod h1:DJHO6AUmbdqj2ET4Z9iArSuwWgYDRryYt2wASxc7x3E= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do= +github.com/go-delve/delve v1.5.0/go.mod h1:c6b3a1Gry6x8a4LGCe/CWzrocrfaHvkUxCj3k4bvSUQ= +github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= +github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= +github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY= +github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= +github.com/go-playground/validator v9.31.0+incompatible/go.mod h1:yrEkQXlcI+PugkyDjY2bRrL/UBU4f3rvrgkN3V8JEig= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/flatbuffers v1.12.0/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-dap v0.2.0/go.mod h1:5q8aYQFnHOAZEMP+6vmq25HKYAEwE+LF5yh7JKrrhSQ= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/goterm v0.0.0-20190703233501-fc88cf888a3f/go.mod h1:nOFQdrUlIlx6M6ODdSpBj1NVA+VgLC6kmw60mkw34H4= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 h1:+9834+KizmvFV7pXQGSXQTsaWhq2GjuNUt0aUU0YBYw= +github.com/grpc-ecosystem/go-grpc-middleware v1.3.0/go.mod h1:z0ButlSOZa5vEBq9m2m2hlwIgKw+rp3sdCBRoJY+30Y= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-hclog v0.9.1/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= +github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= +github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= +github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hashicorp/raft v1.1.1/go.mod h1:vPAJM8Asw6u8LxC3eJCUZmRP/E4QmUGE1R7g7k8sG/8= +github.com/hashicorp/raft v1.3.1/go.mod h1:4Ak7FSPnuvmb0GV6vgIAJ4vYT4bek9bb6Q+7HVbyzqM= +github.com/hashicorp/raft-boltdb v0.0.0-20171010151810-6e5ba93211ea/go.mod h1:pNv7Wc3ycL6F5oOWn+tPGo2gWD4a5X+yp/ntwdKLjRk= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jedib0t/go-pretty/v6 v6.2.4/go.mod h1:+nE9fyyHGil+PuISTCrp7avEdo6bqoMwqZnuiK2r2a0= +github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= +github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= +github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mattn/go-colorable v0.0.0-20170327083344-ded68f7a9561/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= +github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= +github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvrWyR0= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mmcloughlin/avo v0.0.0-20201105074841-5d2f697d268f/go.mod h1:6aKT4zZIrpGqB3RpFU14ByCSSyKY6LfJz4J/JJChHfI= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ= +github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= +github.com/muesli/termenv v0.7.2/go.mod h1:ct2L5N2lmix82RaY3bMWwVu/jUFc9Ule0KGDCiKYPh8= +github.com/muesli/termenv v0.8.1/go.mod h1:kzt/D/4a88RoheZmwfqorY3A+tnsSMA9HJC/fQSFKo0= +github.com/muesli/termenv v0.9.0/go.mod h1:R/LzAKf+suGs4IsO95y7+7DpFHO0KABgnZqtlyx2mBw= +github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/peterh/liner v0.0.0-20170317030525-88609521dc4b/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA= +github.com/pkg/term v1.2.0-beta.2/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/rs/cors v1.8.0/go.mod h1:EBwu+T5AvHOcXwvZIkQFjUN6s8Czyqw12GL/Y0tUyRM= +github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= +github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v0.0.0-20170417170307-b6cb39589372/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v0.0.0-20170417173400-9e4c21054fa1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= +github.com/twitchyliquid64/golang-asm v0.15.0/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= +github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= +github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= +github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= +go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= +go.starlark.net v0.0.0-20190702223751-32f345186213/go.mod h1:c1/X6cHgvdXj6pUlmWKMkuqRnW4K8x2vwt6JAaaircg= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +golang.org/x/arch v0.0.0-20190927153633-4e8777c89be4/go.mod h1:flIaEI6LNU6xOCD5PaJvn9wGP0agmIOqjrtsKGRguv4= +golang.org/x/arch v0.0.0-20201008161808-52c3e6f60cff/go.mod h1:flIaEI6LNU6xOCD5PaJvn9wGP0agmIOqjrtsKGRguv4= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb h1:eBmm0M9fYhWpKZLjQUUKka/LtIxf46G4fxeEz5KJr9U= +golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180816055513-1c9583448a9c/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190523142557-0e01d883c5c5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200916030750-2334cc1a136f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200918174421-af09f7315aff/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 h1:uCLL3g5wH2xjxVREVuAbP9JM5PPKjRbXKRa6IBjkzmU= +golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20210422114643-f5beecf764ed/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191127201027-ecd32218bd7f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20201105001634-bc3cf281b174/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.39.0/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE= +google.golang.org/grpc v1.47.0 h1:9n77onPX5F3qfFCqjy9dhn8PbNQsIKeVU04J9G7umt8= +google.golang.org/grpc v1.47.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= +gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/cmd/cli/middleware.go b/client/v2/middleware.go similarity index 98% rename from cmd/cli/middleware.go rename to client/v2/middleware.go index 12ee81c..5128328 100644 --- a/cmd/cli/middleware.go +++ b/client/v2/middleware.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package main +package client import ( "context" diff --git a/cmd/app/app.go b/cmd/app/app.go new file mode 100644 index 0000000..02a8f58 --- /dev/null +++ b/cmd/app/app.go @@ -0,0 +1,420 @@ +// Copyright 2022 The casbin-mesh Authors. All Rights Reserved. +// +// 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. + +package main + +import ( + "bufio" + "context" + "crypto/tls" + "crypto/x509" + "fmt" + "github.com/casbin/casbin-mesh/pkg/auth" + "github.com/casbin/casbin-mesh/pkg/cluster" + "github.com/casbin/casbin-mesh/pkg/core" + "github.com/casbin/casbin-mesh/pkg/store" + "github.com/casbin/casbin-mesh/pkg/transport/tcp" + "github.com/rs/cors" + "github.com/soheilhy/cmux" + "io" + "io/ioutil" + "log" + "net" + "net/http" + "os" + "path/filepath" + "runtime" + "runtime/pprof" + "strings" + "time" +) + +func New(cfg *Config) (close func() error) { + // Configure logging and pump out initial message. + log.SetFlags(log.LstdFlags) + log.SetOutput(os.Stderr) + log.SetPrefix(fmt.Sprintf("[%s] ", name)) + log.Printf("%s, target architecture is %s, operating system target is %s", runtime.Version(), runtime.GOARCH, runtime.GOOS) + log.Printf("launch command: %s", strings.Join(os.Args, " ")) + + // Start requested profiling. + startProfile(cfg.cpuProfile, cfg.memProfile) + + listenerAddresses := strings.Split(cfg.raftAddr, ",") + if len(listenerAddresses) == 0 { + log.Fatal("fatal: raft-address cannot empty") + } + + advAddr := listenerAddresses[0] + if cfg.raftAdv != "" { + advAddr = cfg.raftAdv + } + + // Create peer communication network layer. + var lns []net.Listener + for _, address := range listenerAddresses { + if cfg.encrypt { + log.Printf("enabling encryption with cert: %s, key: %s", cfg.x509Cert, cfg.x509Key) + cfg, err := tcp.CreateTLSConfig(cfg.x509Cert, cfg.x509Key) + if err != nil { + log.Fatalf("failed to create tls config: %s", err.Error()) + } + ln, err := tls.Listen("tcp", address, cfg) + if err != nil { + log.Fatalf("failed to open internode network layer: %s", err.Error()) + } + lns = append(lns, ln) + } else { + ln, err := net.Listen("tcp", cfg.raftAddr) + if err != nil { + log.Fatalf("failed to open internode network layer: %s", err.Error()) + } + lns = append(lns, ln) + } + } + + ln, err := cluster.NewListener(lns, advAddr) + if err != nil { + log.Fatalf("failed to create cluster listener: %s", err.Error()) + } + + // ---------------------------------------------- Setup listeners ---------------------------------------------- + mux := cmux.New(ln) + + // ----------------------------------------- Peer communication layer ------------------------------------------ + // MATCH 1st bytes in { 0 1 2 3 } + raftLnBase := mux.Match(RaftRPCMatcher()) + // ----------------------------------------- Peer communication layer ------------------------------------------ + + // ----------------------------------------------- Endpoint layer ---------------------------------------------- + // MATCH ClientPreface = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" + grpcLn := mux.MatchWithWriters(cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc")) + // MATCH {METHOD} {URL} HTTP/1.1 + httpLn := mux.Match(cmux.HTTP1Fast()) + // ----------------------------------------------- Endpoint layer ---------------------------------------------- + + go mux.Serve() + var raftLn *tcp.Transport + if cfg.encrypt { + raftLn = tcp.NewTransportFromListener(raftLnBase, true, cfg.noVerify, advAddr) + } else { + raftLn = tcp.NewTransportFromListener(raftLnBase, false, false, advAddr) + } + + // Create and open the store. + cfg.dataPath, err = filepath.Abs(cfg.dataPath) + if err != nil { + log.Fatalf("failed to determine absolute data path: %s", err.Error()) + } + + authType := auth.Noop + var credentialsStore *auth.CredentialsStore + if cfg.enableAuth { + log.Println("auth type basic") + authType = auth.Basic + credentialsStore = auth.NewCredentialsStore() + err = credentialsStore.Add(cfg.rootUsername, cfg.rootPassword) + if err != nil { + log.Fatalf("failed to init credentialsStore:%s", err.Error()) + } + } + + str := store.New(raftLn, &store.StoreConfig{ + Dir: cfg.dataPath, + ID: idOrRaftAddr(cfg), + AuthType: authType, + CredentialsStore: credentialsStore, + }) + + // Set optional parameters on store. + str.RaftLogLevel = cfg.raftLogLevel + str.ShutdownOnRemove = cfg.raftShutdownOnRemove + str.SnapshotThreshold = cfg.raftSnapThreshold + str.SnapshotInterval, err = time.ParseDuration(cfg.raftSnapInterval) + if err != nil { + log.Fatalf("failed to parse Raft Snapsnot interval %s: %s", cfg.raftSnapInterval, err.Error()) + } + str.LeaderLeaseTimeout, err = time.ParseDuration(cfg.raftLeaderLeaseTimeout) + if err != nil { + log.Fatalf("failed to parse Raft Leader lease timeout %s: %s", cfg.raftLeaderLeaseTimeout, err.Error()) + } + str.HeartbeatTimeout, err = time.ParseDuration(cfg.raftHeartbeatTimeout) + if err != nil { + log.Fatalf("failed to parse Raft heartbeat timeout %s: %s", cfg.raftHeartbeatTimeout, err.Error()) + } + str.ElectionTimeout, err = time.ParseDuration(cfg.raftElectionTimeout) + if err != nil { + log.Fatalf("failed to parse Raft election timeout %s: %s", cfg.raftElectionTimeout, err.Error()) + } + str.ApplyTimeout, err = time.ParseDuration(cfg.raftApplyTimeout) + if err != nil { + log.Fatalf("failed to parse Raft apply timeout %s: %s", cfg.raftApplyTimeout, err.Error()) + } + + // Any prexisting node state? + var enableBootstrap bool + isNew := store.IsNewNode(cfg.dataPath) + if isNew { + log.Printf("no preexisting node state detected in %s, node may be bootstrapping", cfg.dataPath) + enableBootstrap = true // New node, so we may be bootstrapping + } else { + log.Printf("preexisting node state detected in %s", cfg.dataPath) + } + + // Determine join addresses + var joins []string + joins, err = determineJoinAddresses(cfg) + if err != nil { + log.Fatalf("unable to determine join addresses: %s", err.Error()) + } + + // Supplying join addresses means bootstrapping a new cluster won't + // be required. + if len(joins) > 0 { + enableBootstrap = false + log.Println("join addresses specified, node is not bootstrapping") + } else { + log.Println("no join addresses set") + } + + // Join address supplied, but we don't need them! + if !isNew && len(joins) > 0 { + log.Println("node is already member of cluster, ignoring join addresses") + } + + // Now, open store. + if err := str.Open(enableBootstrap); err != nil { + log.Fatalf("failed to open store: %s", err.Error()) + } + + // Prepare metadata for join command. + apiAdv := cfg.raftAddr + apiProto := "http" + if cfg.x509Cert != "" { + apiProto = "https" + } + meta := map[string]string{ + "api_addr": apiAdv, + "api_proto": apiProto, + } + + // Execute any requested join operation. + if len(joins) > 0 && isNew { + log.Println("join addresses are:", joins) + advAddr := cfg.raftAddr + if cfg.raftAdv != "" { + advAddr = cfg.raftAdv + } + + joinDur, err := time.ParseDuration(cfg.joinInterval) + if err != nil { + log.Fatalf("failed to parse Join interval %s: %s", cfg.joinInterval, err.Error()) + } + + tlsConfig := tls.Config{InsecureSkipVerify: cfg.noVerify} + if cfg.x509CACert != "" { + asn1Data, err := ioutil.ReadFile(cfg.x509CACert) + if err != nil { + log.Fatalf("ioutil.ReadFile failed: %s", err.Error()) + } + tlsConfig.RootCAs = x509.NewCertPool() + ok := tlsConfig.RootCAs.AppendCertsFromPEM([]byte(asn1Data)) + if !ok { + log.Fatalf("failed to parse root CA certificate(s) in %q", cfg.x509CACert) + } + } + + if j, err := cluster.Join(cfg.joinSrcIP, joins, str.ID(), advAddr, !cfg.raftNonVoter, meta, + cfg.joinAttempts, joinDur, &tlsConfig, auth.AuthConfig{AuthType: authType, Username: cfg.rootUsername, Password: cfg.rootPassword}); err != nil { + log.Fatalf("failed to join cluster at %s: %s", joins, err.Error()) + } else { + log.Println("successfully joined cluster at", j) + } + + } + + // Wait until the store is in full consensus. + if err := waitForConsensus(str, cfg); err != nil { + log.Fatalf(err.Error()) + } + // Init Auth Enforce + if isNew && cfg.enableAuth { + if err := str.InitAuth(context.TODO(), cfg.rootUsername); err != nil { + log.Printf("failed to init auth: %s", err.Error()) + } + } + // This may be a standalone server. In that case set its own metadata. + if err := str.SetMetadata(meta); err != nil && err != store.ErrNotLeader { + // Non-leader errors are OK, since metadata will then be set through + // consensus as a result of a join. All other errors indicate a problem. + log.Fatalf("failed to set store metadata: %s", err.Error()) + } + + c := core.New(str) + //Start the HTTP API server. + if err = startHTTPService(c, httpLn); err != nil { + log.Fatalf("failed to start HTTP server: %s", err.Error()) + } + var grpcCloser func() + if grpcCloser, err = startGrpcService(c, grpcLn); err != nil { + log.Fatalf("failed to start grpc server: %s", err.Error()) + } + + log.Println("node is ready") + + close = func() error { + if err := str.Close(true); err != nil { + log.Printf("failed to close store: %s", err.Error()) + } + mux.Close() + grpcCloser() + stopProfile() + log.Println("casbin-mesh server stopped") + + return err + } + return close +} + +func RaftRPCMatcher() cmux.Matcher { + return func(r io.Reader) bool { + br := bufio.NewReader(&io.LimitedReader{R: r, N: 1}) + byt, err := br.ReadByte() + if err != nil { + log.Printf("Raft RPC Unmatched incoming: %s\n", err) + return false + } + switch byt { + case 0, 1, 2, 3: + return true + } + return false + } +} + +func determineJoinAddresses(cfg *Config) ([]string, error) { + //raftAdv := httpAddr + //if httpAdv != "" { + // raftAdv = httpAdv + //} + + var addrs []string + if cfg.joinAddr != "" { + // Explicit join addresses are first priority. + addrs = strings.Split(cfg.joinAddr, ",") + } + + return addrs, nil +} + +func waitForConsensus(str *store.Store, cfg *Config) error { + openTimeout, err := time.ParseDuration(cfg.raftOpenTimeout) + if err != nil { + return fmt.Errorf("failed to parse Raft open timeout %s: %s", cfg.raftOpenTimeout, err.Error()) + } + if _, err := str.WaitForLeader(openTimeout); err != nil { + if cfg.raftWaitForLeader { + return fmt.Errorf("leader did not appear within timeout: %s", err.Error()) + } + log.Println("ignoring error while waiting for leader") + } + if openTimeout != 0 { + if err := str.WaitForApplied(openTimeout); err != nil { + return fmt.Errorf("log was not fully applied within timeout: %s", err.Error()) + } + } else { + log.Println("not waiting for logs to be applied") + } + return nil +} + +func startHTTPService(c core.Core, ln net.Listener) error { + httpd := core.NewHttpService(c) + handler := cors.AllowAll().Handler(httpd) + go func() { + err := http.Serve(ln, handler) + if err != nil { + log.Println("HTTP service Serve() returned:", err.Error()) + } + }() + + return nil +} + +func startGrpcService(c core.Core, ln net.Listener) (close func(), err error) { + grpcd := core.NewGrpcService(c) + go func() { + err := grpcd.Serve(ln) + if err != nil { + log.Println("Grpc service Serve() returned:", err.Error()) + } + }() + close = func() { + grpcd.Stop() + } + return close, nil +} + +func idOrRaftAddr(cfg *Config) string { + if cfg.nodeID != "" { + return cfg.nodeID + } + if cfg.raftAdv == "" { + return cfg.raftAddr + } + return cfg.raftAdv +} + +// prof stores the file locations of active profiles. +var prof struct { + cpu *os.File + mem *os.File +} + +// startProfile initializes the CPU and memory profile, if specified. +func startProfile(cpuprofile, memprofile string) { + if cpuprofile != "" { + f, err := os.Create(cpuprofile) + if err != nil { + log.Fatalf("failed to create CPU profile file at %s: %s", cpuprofile, err.Error()) + } + log.Printf("writing CPU profile to: %s\n", cpuprofile) + prof.cpu = f + pprof.StartCPUProfile(prof.cpu) + } + + if memprofile != "" { + f, err := os.Create(memprofile) + if err != nil { + log.Fatalf("failed to create memory profile file at %s: %s", cpuprofile, err.Error()) + } + log.Printf("writing memory profile to: %s\n", memprofile) + prof.mem = f + runtime.MemProfileRate = 4096 + } +} + +// stopProfile closes the CPU and memory profiles if they are running. +func stopProfile() { + if prof.cpu != nil { + pprof.StopCPUProfile() + prof.cpu.Close() + log.Println("CPU profiling stopped") + } + if prof.mem != nil { + pprof.Lookup("heap").WriteTo(prof.mem, 0) + prof.mem.Close() + log.Println("memory profiling stopped") + } +} diff --git a/cmd/app/flags.go b/cmd/app/flags.go new file mode 100644 index 0000000..3f855d7 --- /dev/null +++ b/cmd/app/flags.go @@ -0,0 +1,128 @@ +// Copyright 2022 The casbin-mesh Authors. All Rights Reserved. +// +// 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. + +package main + +import ( + "flag" + "fmt" + "os" + "runtime" +) + +type Config struct { + enableAuth bool + rootUsername string + rootPassword string + raftAddr string + raftAdv string + joinSrcIP string + x509CACert string + x509Cert string + x509Key string + nodeID string + joinAddr string + joinAttempts int + joinInterval string + noVerify bool + pprofEnabled bool + raftLogLevel string + raftNonVoter bool + raftSnapThreshold uint64 + raftSnapInterval string + raftLeaderLeaseTimeout string + raftHeartbeatTimeout string + raftElectionTimeout string + raftApplyTimeout string + raftOpenTimeout string + raftWaitForLeader bool + raftShutdownOnRemove bool + compressionSize int + compressionBatch int + showVersion bool + cpuProfile string + memProfile string + encrypt bool + dataPath string +} + +func parseFlags() (cfg *Config) { + flag.BoolVar(&cfg.enableAuth, "enable-basic", false, "Enable Basic Auth") + flag.StringVar(&cfg.rootUsername, "root-username", "root", "Root Account Username") + flag.StringVar(&cfg.rootPassword, "root-password", "root", "Root Account Password") + flag.StringVar(&cfg.nodeID, "node-id", "", "Unique name for node. If not set, set to hostname") + flag.StringVar(&cfg.raftAddr, "raft-address", "localhost:4002", "Raft communication bind address, supports multiple addresses by commas") + flag.StringVar(&cfg.raftAdv, "raft-advertise-address", "", "Advertised Raft communication address. If not set, same as Raft bind") + flag.StringVar(&cfg.joinSrcIP, "join-source-ip", "", "Set source IP address during Join request") + flag.BoolVar(&cfg.encrypt, "tls-encrypt", false, "Enable encryption") + flag.StringVar(&cfg.x509CACert, "endpoint-ca-cert", "", "Path to root X.509 certificate for API endpoint") + flag.StringVar(&cfg.x509Cert, "endpoint-cert", "", "Path to X.509 certificate for API endpoint") + flag.StringVar(&cfg.x509Key, "endpoint-key", "", "Path to X.509 private key for API endpoint") + flag.BoolVar(&cfg.noVerify, "endpoint-no-verify", false, "Skip verification of remote HTTPS cert when joining cluster") + flag.StringVar(&cfg.joinAddr, "join", "", "Comma-delimited list of nodes, through which a cluster can be joined (proto://host:port)") + flag.IntVar(&cfg.joinAttempts, "join-attempts", 5, "Number of join attempts to make") + flag.StringVar(&cfg.joinInterval, "join-interval", "5s", "Period between join attempts") + flag.BoolVar(&cfg.pprofEnabled, "pprof", true, "Serve pprof data on API server") + flag.BoolVar(&cfg.showVersion, "version", false, "Show version information and exit") + flag.BoolVar(&cfg.raftNonVoter, "raft-non-voter", false, "Configure as non-voting node") + flag.StringVar(&cfg.raftHeartbeatTimeout, "raft-timeout", "1s", "Raft heartbeat timeout") + flag.StringVar(&cfg.raftElectionTimeout, "raft-election-timeout", "1s", "Raft election timeout") + flag.StringVar(&cfg.raftApplyTimeout, "raft-apply-timeout", "10s", "Raft apply timeout") + flag.StringVar(&cfg.raftOpenTimeout, "raft-open-timeout", "120s", "Time for initial Raft logs to be applied. Use 0s duration to skip wait") + flag.BoolVar(&cfg.raftWaitForLeader, "raft-leader-wait", true, "Node waits for a leader before answering requests") + flag.Uint64Var(&cfg.raftSnapThreshold, "raft-snap", 8192, "Number of outstanding log entries that trigger snapshot") + flag.StringVar(&cfg.raftSnapInterval, "raft-snap-int", "30s", "Snapshot threshold check interval") + flag.StringVar(&cfg.raftLeaderLeaseTimeout, "raft-leader-lease-timeout", "0s", "Raft leader lease timeout. Use 0s for Raft default") + flag.BoolVar(&cfg.raftShutdownOnRemove, "raft-remove-shutdown", false, "Shutdown Raft if node removed") + flag.StringVar(&cfg.raftLogLevel, "raft-log-level", "INFO", "Minimum log level for Raft module") + flag.IntVar(&cfg.compressionSize, "compression-size", 150, "Request query size for compression attempt") + flag.IntVar(&cfg.compressionBatch, "compression-batch", 5, "Request batch threshold for compression attempt") + flag.StringVar(&cfg.cpuProfile, "cpu-profile", "", "Path to file for CPU profiling information") + flag.StringVar(&cfg.memProfile, "mem-profile", "", "Path to file for memory profiling information") + + flag.Usage = func() { + fmt.Fprintf(os.Stderr, "%s\n\n", desc) + fmt.Fprintf(os.Stderr, "Usage: %s [flags] \n", name) + flag.PrintDefaults() + } + flag.Parse() + if cfg.showVersion { + msg := fmt.Sprintf("%s %s %s %s (compiler %s)", + name, runtime.GOOS, runtime.GOARCH, runtime.Version(), runtime.Compiler) + errorExit(0, msg) + } + + // Ensure the data path is set. + if flag.NArg() < 1 { + fmt.Fprintf(os.Stderr, "fatal: no data directory set\n") + os.Exit(1) + } + + // Ensure no args come after the data directory. + if flag.NArg() > 1 { + fmt.Fprintf(os.Stderr, "fatal: arguments after data directory are not accepted\n") + os.Exit(1) + } + cfg.dataPath = flag.Arg(0) + + return +} + +func errorExit(code int, msg string) { + if code != 0 { + fmt.Fprintf(os.Stderr, "fatal: ") + } + fmt.Fprintf(os.Stderr, fmt.Sprintf("%s\n", msg)) + os.Exit(code) +} diff --git a/cmd/app/main.go b/cmd/app/main.go index b7dca96..f2b092b 100644 --- a/cmd/app/main.go +++ b/cmd/app/main.go @@ -18,485 +18,21 @@ package main import ( - "bufio" - "context" - "crypto/tls" - "crypto/x509" - "flag" - "fmt" - "github.com/casbin/casbin-mesh/pkg/auth" - "github.com/rs/cors" - "io" - "io/ioutil" - "log" - "net" - "net/http" "os" "os/signal" - "path/filepath" - "runtime" - "runtime/pprof" - "strings" - "time" - - "github.com/casbin/casbin-mesh/pkg/cluster" - "github.com/casbin/casbin-mesh/pkg/core" - "github.com/casbin/casbin-mesh/pkg/store" - "github.com/casbin/casbin-mesh/pkg/transport/tcp" - "github.com/soheilhy/cmux" ) const name = `casmesh` const desc = `casmesh is a lightweight, distributed casbin service, which uses casbin as its engine.` -var ( - enableAuth bool - rootUsername string - rootPassword string - raftAddr string - raftAdv string - joinSrcIP string - x509CACert string - x509Cert string - x509Key string - nodeID string - joinAddr string - joinAttempts int - joinInterval string - noVerify bool - pprofEnabled bool - raftLogLevel string - raftNonVoter bool - raftSnapThreshold uint64 - raftSnapInterval string - raftLeaderLeaseTimeout string - raftHeartbeatTimeout string - raftElectionTimeout string - raftApplyTimeout string - raftOpenTimeout string - raftWaitForLeader bool - raftShutdownOnRemove bool - compressionSize int - compressionBatch int - showVersion bool - cpuProfile string - memProfile string - encrypt bool -) - -func init() { - flag.BoolVar(&enableAuth, "enable-basic", false, "Enable Basic Auth") - flag.StringVar(&rootUsername, "root-username", "root", "Root Account Username") - flag.StringVar(&rootPassword, "root-password", "root", "Root Account Password") - flag.StringVar(&nodeID, "node-id", "", "Unique name for node. If not set, set to hostname") - flag.StringVar(&raftAddr, "raft-address", "localhost:4002", "Raft communication bind address, supports multiple addresses by commas") - flag.StringVar(&raftAdv, "raft-advertise-address", "", "Advertised Raft communication address. If not set, same as Raft bind") - flag.StringVar(&joinSrcIP, "join-source-ip", "", "Set source IP address during Join request") - flag.BoolVar(&encrypt, "tls-encrypt", false, "Enable encryption") - flag.StringVar(&x509CACert, "endpoint-ca-cert", "", "Path to root X.509 certificate for API endpoint") - flag.StringVar(&x509Cert, "endpoint-cert", "", "Path to X.509 certificate for API endpoint") - flag.StringVar(&x509Key, "endpoint-key", "", "Path to X.509 private key for API endpoint") - flag.BoolVar(&noVerify, "endpoint-no-verify", false, "Skip verification of remote HTTPS cert when joining cluster") - flag.StringVar(&joinAddr, "join", "", "Comma-delimited list of nodes, through which a cluster can be joined (proto://host:port)") - flag.IntVar(&joinAttempts, "join-attempts", 5, "Number of join attempts to make") - flag.StringVar(&joinInterval, "join-interval", "5s", "Period between join attempts") - flag.BoolVar(&pprofEnabled, "pprof", true, "Serve pprof data on API server") - flag.BoolVar(&showVersion, "version", false, "Show version information and exit") - flag.BoolVar(&raftNonVoter, "raft-non-voter", false, "Configure as non-voting node") - flag.StringVar(&raftHeartbeatTimeout, "raft-timeout", "1s", "Raft heartbeat timeout") - flag.StringVar(&raftElectionTimeout, "raft-election-timeout", "1s", "Raft election timeout") - flag.StringVar(&raftApplyTimeout, "raft-apply-timeout", "10s", "Raft apply timeout") - flag.StringVar(&raftOpenTimeout, "raft-open-timeout", "120s", "Time for initial Raft logs to be applied. Use 0s duration to skip wait") - flag.BoolVar(&raftWaitForLeader, "raft-leader-wait", true, "Node waits for a leader before answering requests") - flag.Uint64Var(&raftSnapThreshold, "raft-snap", 8192, "Number of outstanding log entries that trigger snapshot") - flag.StringVar(&raftSnapInterval, "raft-snap-int", "30s", "Snapshot threshold check interval") - flag.StringVar(&raftLeaderLeaseTimeout, "raft-leader-lease-timeout", "0s", "Raft leader lease timeout. Use 0s for Raft default") - flag.BoolVar(&raftShutdownOnRemove, "raft-remove-shutdown", false, "Shutdown Raft if node removed") - flag.StringVar(&raftLogLevel, "raft-log-level", "INFO", "Minimum log level for Raft module") - flag.IntVar(&compressionSize, "compression-size", 150, "Request query size for compression attempt") - flag.IntVar(&compressionBatch, "compression-batch", 5, "Request batch threshold for compression attempt") - flag.StringVar(&cpuProfile, "cpu-profile", "", "Path to file for CPU profiling information") - flag.StringVar(&memProfile, "mem-profile", "", "Path to file for memory profiling information") - - flag.Usage = func() { - fmt.Fprintf(os.Stderr, "%s\n\n", desc) - fmt.Fprintf(os.Stderr, "Usage: %s [flags] \n", name) - flag.PrintDefaults() - } -} - func main() { - flag.Parse() - // Ensure the data path is set. - if flag.NArg() < 1 { - fmt.Fprintf(os.Stderr, "fatal: no data directory set\n") - os.Exit(1) - } - - // Ensure no args come after the data directory. - if flag.NArg() > 1 { - fmt.Fprintf(os.Stderr, "fatal: arguments after data directory are not accepted\n") - os.Exit(1) - } - - dataPath := flag.Arg(0) - // Configure logging and pump out initial message. - log.SetFlags(log.LstdFlags) - log.SetOutput(os.Stderr) - log.SetPrefix(fmt.Sprintf("[%s] ", name)) - log.Printf("%s, target architecture is %s, operating system target is %s", runtime.Version(), runtime.GOARCH, runtime.GOOS) - log.Printf("launch command: %s", strings.Join(os.Args, " ")) - - // Start requested profiling. - startProfile(cpuProfile, memProfile) - - listenerAddresses := strings.Split(raftAddr, ",") - if len(listenerAddresses) == 0 { - log.Fatal("fatal: raft-address cannot empty") - } - - advAddr := listenerAddresses[0] - if raftAdv != "" { - advAddr = raftAdv - } - - // Create internode network layer. - var lns []net.Listener - for _, address := range listenerAddresses { - if encrypt { - log.Printf("enabling encryption with cert: %s, key: %s", x509Cert, x509Key) - cfg, err := tcp.CreateTLSConfig(x509Cert, x509Key) - if err != nil { - log.Fatalf("failed to create tls config: %s", err.Error()) - } - ln, err := tls.Listen("tcp", address, cfg) - if err != nil { - log.Fatalf("failed to open internode network layer: %s", err.Error()) - } - lns = append(lns, ln) - } else { - ln, err := net.Listen("tcp", raftAddr) - if err != nil { - log.Fatalf("failed to open internode network layer: %s", err.Error()) - } - lns = append(lns, ln) - } - } - - ln, err := cluster.NewListener(lns, advAddr) - if err != nil { - log.Fatalf("failed to create cluster listener: %s", err.Error()) - } - - mux := cmux.New(ln) - // MATCH 1st bytes in { 0 1 2 3 } - raftLnBase := mux.Match(RaftRPCMatcher()) - // MATCH ClientPreface = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" - grpcLn := mux.MatchWithWriters(cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc")) - // MATCH {METHOD} {URL} HTTP/1.1 - httpLn := mux.Match(cmux.HTTP1Fast()) - go mux.Serve() - var raftLn *tcp.Transport - if encrypt { - raftLn = tcp.NewTransportFromListener(raftLnBase, true, noVerify, advAddr) - } else { - raftLn = tcp.NewTransportFromListener(raftLnBase, false, false, advAddr) - } - - // Create and open the store. - dataPath, err = filepath.Abs(dataPath) - if err != nil { - log.Fatalf("failed to determine absolute data path: %s", err.Error()) - } - - authType := auth.Noop - var credentialsStore *auth.CredentialsStore - if enableAuth { - log.Println("auth type basic") - authType = auth.Basic - credentialsStore = auth.NewCredentialsStore() - err = credentialsStore.Add(rootUsername, rootPassword) - if err != nil { - log.Fatalf("failed to init credentialsStore:%s", err.Error()) - } - } - - str := store.New(raftLn, &store.StoreConfig{ - Dir: dataPath, - ID: idOrRaftAddr(), - AuthType: authType, - CredentialsStore: credentialsStore, - }) - - // Set optional parameters on store. - str.RaftLogLevel = raftLogLevel - str.ShutdownOnRemove = raftShutdownOnRemove - str.SnapshotThreshold = raftSnapThreshold - str.SnapshotInterval, err = time.ParseDuration(raftSnapInterval) - if err != nil { - log.Fatalf("failed to parse Raft Snapsnot interval %s: %s", raftSnapInterval, err.Error()) - } - str.LeaderLeaseTimeout, err = time.ParseDuration(raftLeaderLeaseTimeout) - if err != nil { - log.Fatalf("failed to parse Raft Leader lease timeout %s: %s", raftLeaderLeaseTimeout, err.Error()) - } - str.HeartbeatTimeout, err = time.ParseDuration(raftHeartbeatTimeout) - if err != nil { - log.Fatalf("failed to parse Raft heartbeat timeout %s: %s", raftHeartbeatTimeout, err.Error()) - } - str.ElectionTimeout, err = time.ParseDuration(raftElectionTimeout) - if err != nil { - log.Fatalf("failed to parse Raft election timeout %s: %s", raftElectionTimeout, err.Error()) - } - str.ApplyTimeout, err = time.ParseDuration(raftApplyTimeout) - if err != nil { - log.Fatalf("failed to parse Raft apply timeout %s: %s", raftApplyTimeout, err.Error()) - } - - // Any prexisting node state? - var enableBootstrap bool - isNew := store.IsNewNode(dataPath) - if isNew { - log.Printf("no preexisting node state detected in %s, node may be bootstrapping", dataPath) - enableBootstrap = true // New node, so we may be bootstrapping - } else { - log.Printf("preexisting node state detected in %s", dataPath) - } - - // Determine join addresses - var joins []string - joins, err = determineJoinAddresses() - if err != nil { - log.Fatalf("unable to determine join addresses: %s", err.Error()) - } - - // Supplying join addresses means bootstrapping a new cluster won't - // be required. - if len(joins) > 0 { - enableBootstrap = false - log.Println("join addresses specified, node is not bootstrapping") - } else { - log.Println("no join addresses set") - } - - // Join address supplied, but we don't need them! - if !isNew && len(joins) > 0 { - log.Println("node is already member of cluster, ignoring join addresses") - } - - // Now, open store. - if err := str.Open(enableBootstrap); err != nil { - log.Fatalf("failed to open store: %s", err.Error()) - } - - // Prepare metadata for join command. - apiAdv := raftAddr - apiProto := "http" - if x509Cert != "" { - apiProto = "https" - } - meta := map[string]string{ - "api_addr": apiAdv, - "api_proto": apiProto, - } - - // Execute any requested join operation. - if len(joins) > 0 && isNew { - log.Println("join addresses are:", joins) - advAddr := raftAddr - if raftAdv != "" { - advAddr = raftAdv - } - - joinDur, err := time.ParseDuration(joinInterval) - if err != nil { - log.Fatalf("failed to parse Join interval %s: %s", joinInterval, err.Error()) - } + cfg := parseFlags() - tlsConfig := tls.Config{InsecureSkipVerify: noVerify} - if x509CACert != "" { - asn1Data, err := ioutil.ReadFile(x509CACert) - if err != nil { - log.Fatalf("ioutil.ReadFile failed: %s", err.Error()) - } - tlsConfig.RootCAs = x509.NewCertPool() - ok := tlsConfig.RootCAs.AppendCertsFromPEM([]byte(asn1Data)) - if !ok { - log.Fatalf("failed to parse root CA certificate(s) in %q", x509CACert) - } - } - - if j, err := cluster.Join(joinSrcIP, joins, str.ID(), advAddr, !raftNonVoter, meta, - joinAttempts, joinDur, &tlsConfig, auth.AuthConfig{AuthType: authType, Username: rootUsername, Password: rootPassword}); err != nil { - log.Fatalf("failed to join cluster at %s: %s", joins, err.Error()) - } else { - log.Println("successfully joined cluster at", j) - } - - } - - // Wait until the store is in full consensus. - if err := waitForConsensus(str); err != nil { - log.Fatalf(err.Error()) - } - // Init Auth Enforce - if isNew && enableAuth { - if err := str.InitAuth(context.TODO(), rootUsername); err != nil { - log.Printf("failed to init auth: %s", err.Error()) - } - } - // This may be a standalone server. In that case set its own metadata. - if err := str.SetMetadata(meta); err != nil && err != store.ErrNotLeader { - // Non-leader errors are OK, since metadata will then be set through - // consensus as a result of a join. All other errors indicate a problem. - log.Fatalf("failed to set store metadata: %s", err.Error()) - } - c := core.New(str) - //Start the HTTP API server. - if err = startHTTPService(c, httpLn); err != nil { - log.Fatalf("failed to start HTTP server: %s", err.Error()) - } - if err = startGrpcService(c, grpcLn); err != nil { - log.Fatalf("failed to start grpc server: %s", err.Error()) - } - - log.Println("node is ready") + closer := New(cfg) // Block until signalled. terminate := make(chan os.Signal, 1) signal.Notify(terminate, os.Interrupt) <-terminate - if err := str.Close(true); err != nil { - log.Printf("failed to close store: %s", err.Error()) - } - stopProfile() - log.Println("casbin-mesh server stopped") -} - -func RaftRPCMatcher() cmux.Matcher { - return func(r io.Reader) bool { - br := bufio.NewReader(&io.LimitedReader{R: r, N: 1}) - byt, err := br.ReadByte() - if err != nil { - log.Printf("Raft RPC Unmatched incoming: %s\n", err) - return false - } - switch byt { - case 0, 1, 2, 3: - return true - } - return false - } -} - -func determineJoinAddresses() ([]string, error) { - //raftAdv := httpAddr - //if httpAdv != "" { - // raftAdv = httpAdv - //} - - var addrs []string - if joinAddr != "" { - // Explicit join addresses are first priority. - addrs = strings.Split(joinAddr, ",") - } - - return addrs, nil -} - -func waitForConsensus(str *store.Store) error { - openTimeout, err := time.ParseDuration(raftOpenTimeout) - if err != nil { - return fmt.Errorf("failed to parse Raft open timeout %s: %s", raftOpenTimeout, err.Error()) - } - if _, err := str.WaitForLeader(openTimeout); err != nil { - if raftWaitForLeader { - return fmt.Errorf("leader did not appear within timeout: %s", err.Error()) - } - log.Println("ignoring error while waiting for leader") - } - if openTimeout != 0 { - if err := str.WaitForApplied(openTimeout); err != nil { - return fmt.Errorf("log was not fully applied within timeout: %s", err.Error()) - } - } else { - log.Println("not waiting for logs to be applied") - } - return nil -} - -func startHTTPService(c core.Core, ln net.Listener) error { - httpd := core.NewHttpService(c) - handler := cors.AllowAll().Handler(httpd) - go func() { - err := http.Serve(ln, handler) - if err != nil { - log.Println("HTTP service Serve() returned:", err.Error()) - } - }() - return nil -} - -func startGrpcService(c core.Core, ln net.Listener) error { - grpcd := core.NewGrpcService(c) - go func() { - err := grpcd.Serve(ln) - if err != nil { - log.Println("Grpc service Serve() returned:", err.Error()) - } - }() - return nil -} - -func idOrRaftAddr() string { - if nodeID != "" { - return nodeID - } - if raftAdv == "" { - return raftAddr - } - return raftAdv -} - -// prof stores the file locations of active profiles. -var prof struct { - cpu *os.File - mem *os.File -} - -// startProfile initializes the CPU and memory profile, if specified. -func startProfile(cpuprofile, memprofile string) { - if cpuprofile != "" { - f, err := os.Create(cpuprofile) - if err != nil { - log.Fatalf("failed to create CPU profile file at %s: %s", cpuprofile, err.Error()) - } - log.Printf("writing CPU profile to: %s\n", cpuprofile) - prof.cpu = f - pprof.StartCPUProfile(prof.cpu) - } - - if memprofile != "" { - f, err := os.Create(memprofile) - if err != nil { - log.Fatalf("failed to create memory profile file at %s: %s", cpuprofile, err.Error()) - } - log.Printf("writing memory profile to: %s\n", memprofile) - prof.mem = f - runtime.MemProfileRate = 4096 - } -} - -// stopProfile closes the CPU and memory profiles if they are running. -func stopProfile() { - if prof.cpu != nil { - pprof.StopCPUProfile() - prof.cpu.Close() - log.Println("CPU profiling stopped") - } - if prof.mem != nil { - pprof.Lookup("heap").WriteTo(prof.mem, 0) - prof.mem.Close() - log.Println("memory profiling stopped") - } + closer() } diff --git a/cmd/cli/ctx.go b/cmd/cli/ctx.go index 998c470..06812da 100644 --- a/cmd/cli/ctx.go +++ b/cmd/cli/ctx.go @@ -22,6 +22,7 @@ import ( "encoding/json" "fmt" "github.com/c-bata/go-prompt" + "github.com/casbin/casbin-mesh/client/v2" "github.com/jedib0t/go-pretty/v6/table" "github.com/tidwall/pretty" "log" @@ -84,7 +85,7 @@ func updateOperationsRemove(slice [][]CasbinRule, s int) [][]CasbinRule { } type ctx struct { - *client + *client.Client transaction string //can be "g" or "p" sec string @@ -107,9 +108,9 @@ func (c *ctx) LoadNamespaces() error { return nil } -func NewCtx(c *client) *ctx { +func NewCtx(c *client.Client) *ctx { return &ctx{ - client: c, + Client: c, } } @@ -270,7 +271,7 @@ func (c *ctx) Executor(line string) { ptype := c.ptype switch c.transaction { case "add": - policies, err := c.client.AddPolicies(context.TODO(), ns, sec, ptype, c.operations.to2DString()) + policies, err := c.Client.AddPolicies(context.TODO(), ns, sec, ptype, c.operations.to2DString()) if err != nil { fmt.Printf("Commit failed:%s", err.Error()) return @@ -289,7 +290,7 @@ func (c *ctx) Executor(line string) { } case "update": o, n := c.updateOperations.to2DString() - effected, err := c.client.UpdatePolicies(context.TODO(), ns, sec, ptype, o, n) + effected, err := c.Client.UpdatePolicies(context.TODO(), ns, sec, ptype, o, n) if err != nil { fmt.Printf("Commit failed:%s", err.Error()) return @@ -302,7 +303,7 @@ func (c *ctx) Executor(line string) { fmt.Printf("No effected rules! <%s>\n", elapsed) } case "remove": - policies, err := c.client.RemovePolicies(context.TODO(), ns, sec, ptype, c.operations.to2DString()) + policies, err := c.Client.RemovePolicies(context.TODO(), ns, sec, ptype, c.operations.to2DString()) if err != nil { fmt.Printf("Commit failed:%s", err.Error()) return diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 728682d..8e8b49a 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -20,6 +20,7 @@ package main import ( "fmt" "github.com/c-bata/go-prompt" + "github.com/casbin/casbin-mesh/client/v2" ) //func completer(d prompt.Document) []prompt.Suggest { @@ -48,11 +49,11 @@ func main() { name = GetUsername() pwd = GetPWD() } - c := NewClient(options{ - target: host, - authType: Basic, - username: name, - password: pwd, + c := client.NewClient(client.Options{ + Target: host, + AuthType: client.Basic, + Username: name, + Password: pwd, }) ctx := NewCtx(c) p := prompt.New(