query services (#75)

This commit is contained in:
Michael Quigley 2022-10-06 13:52:19 -04:00
parent abe8d3e153
commit 637f27d9f4
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
6 changed files with 87 additions and 46 deletions

View File

@ -26,7 +26,7 @@ func newGcCmd() *gcCmd {
return c
}
func (c *gcCmd) run(_ *cobra.Command, args []string) {
func (gc *gcCmd) run(_ *cobra.Command, args []string) {
cfg, err := controller.LoadConfig(args[0])
if err != nil {
panic(err)

View File

@ -2,14 +2,12 @@ package controller
import (
"github.com/go-openapi/loads"
"github.com/go-openapi/runtime/middleware"
"github.com/openziti-test-kitchen/zrok/controller/store"
"github.com/openziti-test-kitchen/zrok/rest_server_zrok"
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations"
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/identity"
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/metadata"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
var str *store.Store
@ -55,21 +53,3 @@ func Run(cfg *Config) error {
}
return nil
}
func GC(cfg *Config) error {
if v, err := store.Open(cfg.Store); err == nil {
str = v
} else {
return errors.Wrap(err, "error opening store")
}
defer func() {
if err := str.Close(); err != nil {
logrus.Errorf("error closing store: %v", err)
}
}()
return nil
}
func versionHandler(_ metadata.VersionParams) middleware.Responder {
return metadata.NewVersionOK().WithPayload(version)
}

50
controller/gc.go Normal file
View File

@ -0,0 +1,50 @@
package controller
import (
"context"
"github.com/openziti-test-kitchen/zrok/controller/store"
"github.com/openziti/edge/rest_management_api_client/service"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"time"
)
func GC(cfg *Config) error {
if v, err := store.Open(cfg.Store); err == nil {
str = v
} else {
return errors.Wrap(err, "error opening store")
}
defer func() {
if err := str.Close(); err != nil {
logrus.Errorf("error closing store: %v", err)
}
}()
if err := gcServices(cfg, str); err != nil {
return errors.Wrap(err, "error garbage collecting services")
}
return nil
}
func gcServices(cfg *Config, str *store.Store) error {
edge, err := edgeClient(cfg.Ziti)
if err != nil {
return err
}
filter := "tags.zrok != null"
limit := int64(0)
offset := int64(0)
listReq := &service.ListServicesParams{
Filter: &filter,
Limit: &limit,
Offset: &offset,
Context: context.Background(),
}
listReq.SetTimeout(30 * time.Second)
if listResp, err := edge.Service.ListServices(listReq, nil); err == nil {
for _, svc := range listResp.Payload.Data {
logrus.Infof("found svcId='%v', name='%v'", *svc.ID, *svc.Name)
}
}
return nil
}

10
controller/version.go Normal file
View File

@ -0,0 +1,10 @@
package controller
import (
"github.com/go-openapi/runtime/middleware"
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/metadata"
)
func versionHandler(_ metadata.VersionParams) middleware.Responder {
return metadata.NewVersionOK().WithPayload(version)
}

18
go.mod
View File

@ -23,12 +23,13 @@ require (
github.com/opentracing/opentracing-go v1.2.0
github.com/openziti/edge v0.22.39
github.com/openziti/foundation/v2 v2.0.4
github.com/openziti/sdk-golang v0.16.123
github.com/openziti/sdk-golang v0.16.125
github.com/pkg/errors v0.9.1
github.com/rubenv/sql-migrate v1.1.2
github.com/shirou/gopsutil/v3 v3.22.8
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.5.0
github.com/spf13/pflag v1.0.5
github.com/wneessen/go-mail v0.2.7
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4
)
@ -39,7 +40,7 @@ require (
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa // indirect
github.com/go-gorp/gorp/v3 v3.0.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
@ -65,25 +66,24 @@ require (
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0 // indirect
github.com/netfoundry/secretstream v0.1.2 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/openziti/channel v1.0.3 // indirect
github.com/openziti/identity v1.0.12 // indirect
github.com/openziti/channel/v2 v2.0.1 // indirect
github.com/openziti/identity v1.0.13 // indirect
github.com/openziti/metrics v1.1.0 // indirect
github.com/openziti/transport/v2 v2.0.29 // indirect
github.com/openziti/transport/v2 v2.0.30 // indirect
github.com/orcaman/concurrent-map/v2 v2.0.0 // indirect
github.com/parallaxsecond/parsec-client-go v0.0.0-20220111122524-cb78842db373 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/speps/go-hashids v2.0.0+incompatible // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.mongodb.org/mongo-driver v1.10.0 // indirect
go.mozilla.org/pkcs7 v0.0.0-20200128120323-432b2356ecb1 // indirect
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 // indirect
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be // indirect
golang.org/x/sys v0.0.0-20220926163933-8cfa568d3c25 // indirect
golang.org/x/term v0.0.0-20220919170432-7a66f970e087 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect

33
go.sum
View File

@ -90,8 +90,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI=
github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa h1:RDBNVkRviHZtvDvId8XSGPu3rmpmSe+wKRcEWNgsfWU=
github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa/go.mod h1:KnogPXtdwXqoenmZCw6S+25EAm2MkxbG0deNDu4cbSA=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
@ -405,20 +405,20 @@ github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7
github.com/onsi/gomega v1.13.0 h1:7lLHu94wT9Ij0o6EWWclhu0aOh32VxhkwEJvzuWPeak=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/openziti/channel v1.0.3 h1:WlM3DYTWxfGslct1jnUUgOHbm0wYS1LRCVwdfx8mBzU=
github.com/openziti/channel v1.0.3/go.mod h1:/te3/V0rq3r9hM0JIAlL8dlg+SynzkVE7uL6ntaYlik=
github.com/openziti/channel/v2 v2.0.1 h1:Y+4BQ+AbrUKO7WLLwnhHmdOKTFf7auNcsGiaco3SfEE=
github.com/openziti/channel/v2 v2.0.1/go.mod h1:uD5oDrP/iuOnawxeVUqcJ25zMHAd2+gH5VfF+F+XWhc=
github.com/openziti/edge v0.22.39 h1:vxILPpjf4pk2Ha1ga3vlbvYrDFgoA71lc46z8fQIwGs=
github.com/openziti/edge v0.22.39/go.mod h1:0jSUt6SdibB9zYhYsCF8+NGpKyUwihm7N+tr05V7DPk=
github.com/openziti/foundation/v2 v2.0.4 h1:QnpbNgRzPTnbu/QIqdNhYJl4nrhxrX7VXiIF5yIqQhc=
github.com/openziti/foundation/v2 v2.0.4/go.mod h1:L75kwCC5WTUPqxuAd3G+WMBompaElMb/nYlJjR1sJ9Q=
github.com/openziti/identity v1.0.12 h1:Y6adirthFBpMSI0fyWWGR/fUFtaMOIWQIvyr2yTeIcM=
github.com/openziti/identity v1.0.12/go.mod h1:ScEYhB5F5FfBmTEHmfATBlbzMIpMJwDF8CcJbNuO5ic=
github.com/openziti/identity v1.0.13 h1:hpEXZo/xwED6jSXhpS6wJwQ+7o1YKKrIXs3TKHe2HPI=
github.com/openziti/identity v1.0.13/go.mod h1:ScEYhB5F5FfBmTEHmfATBlbzMIpMJwDF8CcJbNuO5ic=
github.com/openziti/metrics v1.1.0 h1:V3stVSxGz0Rq3GXxQz+ahMH8D3jR8yVT+IrJZNWdFxA=
github.com/openziti/metrics v1.1.0/go.mod h1:N3ffH3Vp7czCpyDSk1hFE3DZ3bTEUSiubHWHZFUuP2g=
github.com/openziti/sdk-golang v0.16.123 h1:9/XFMTOzprDrcLQi6DgyFF1rl7cfWN5dzYsGIiWCfvA=
github.com/openziti/sdk-golang v0.16.123/go.mod h1:cdv9FOrj3XuOQR/B54OrUwaAvrd1Wwpbl1KxwJvTC2k=
github.com/openziti/transport/v2 v2.0.29 h1:lT9FyDUF3bxkMYjFACW909LSc7sonLK86ghRDXN05Ug=
github.com/openziti/transport/v2 v2.0.29/go.mod h1:vYXp00wBXxq3s5ffSJEfkscOBH2+/d29FK1l7yMid4g=
github.com/openziti/sdk-golang v0.16.125 h1:4ZTV+YyaztsmYUxkQgztRtfRDEISpKZzw3vuvv51l4M=
github.com/openziti/sdk-golang v0.16.125/go.mod h1:nd6m4FYbBvEFg9Mgy9lNeqecN5sCmyqkaXK6+7DdS8k=
github.com/openziti/transport/v2 v2.0.30 h1:g8qM6ZN2PXsig73I8nYV8S+7i//YolCd5uAPJ3dWPOI=
github.com/openziti/transport/v2 v2.0.30/go.mod h1:VABFew9Ls3/3ITFgpAK6s/l9JvKVc+jFMyFTnsmkTWw=
github.com/orcaman/concurrent-map/v2 v2.0.0 h1:iSMwuBQvQ1nX5i9gYuGMiSy0fjWHmazdjF+NdSO9JzI=
github.com/orcaman/concurrent-map/v2 v2.0.0/go.mod h1:9Eq3TG2oBe5FirmYWQfYO5iH1q0Jv47PLaNK++uCdOM=
github.com/parallaxsecond/parsec-client-go v0.0.0-20220111122524-cb78842db373 h1:CUvH4JL/8OVy023LMER3dB/MerNQ6OIz4QV3E/JQ3UY=
@ -553,8 +553,8 @@ golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 h1:Y/gsMcFOcR+6S6f3YeMKl5g+dZMEWqcz5Czj/GWYbkM=
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be h1:fmw3UbQh+nxngCAHrDCCztao/kbYFnWjoqop8dHx05A=
golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@ -720,16 +720,17 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 h1:v6hYoSR9T5oet+pMXwUWkbiVqx/63mlHjefrHmxwfeY=
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220926163933-8cfa568d3c25 h1:nwzwVf0l2Y/lkov/+IYgMMbFyI+QypZDds9RxlSmsFQ=
golang.org/x/sys v0.0.0-20220926163933-8cfa568d3c25/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220919170432-7a66f970e087 h1:tPwmk4vmvVCMdr98VgL4JH+qZxPL8fqlUOHnyOM8N3w=
golang.org/x/term v0.0.0-20220919170432-7a66f970e087/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=