mirror of
https://github.com/openziti/zrok.git
synced 2025-06-20 09:48:07 +02:00
more plumbing and scaffolding (#935)
This commit is contained in:
parent
ada9d7dba6
commit
0d913d1889
40
cmd/zrok/adminUnbootstrap.go
Normal file
40
cmd/zrok/adminUnbootstrap.go
Normal file
@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/michaelquigley/cf"
|
||||
"github.com/openziti/zrok/controller"
|
||||
"github.com/openziti/zrok/controller/config"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
adminCmd.AddCommand(newAdminUnbootstrap().cmd)
|
||||
}
|
||||
|
||||
type adminUnbootstrap struct {
|
||||
cmd *cobra.Command
|
||||
}
|
||||
|
||||
func newAdminUnbootstrap() *adminUnbootstrap {
|
||||
cmd := &cobra.Command{
|
||||
Use: "unbootstrap <configPath>",
|
||||
Short: "Unbootstrap the underlying Ziti network from zrok",
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
command := &adminUnbootstrap{cmd: cmd}
|
||||
cmd.Run = command.run
|
||||
return command
|
||||
}
|
||||
|
||||
func (cmd *adminUnbootstrap) run(_ *cobra.Command, args []string) {
|
||||
cfg, err := config.LoadConfig(args[0])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
logrus.Infof(cf.Dump(cfg, cf.DefaultOptions()))
|
||||
if err := controller.Unbootstrap(cfg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
logrus.Infof("unbootstrap complete!")
|
||||
}
|
@ -1,14 +1,42 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/openziti/edge-api/rest_management_api_client"
|
||||
apiConfig "github.com/openziti/edge-api/rest_management_api_client/config"
|
||||
"github.com/openziti/zrok/controller/config"
|
||||
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func Unbootstrap(cfg *config.Config) error {
|
||||
_, err := zrokEdgeSdk.Client(cfg.Ziti)
|
||||
edge, err := zrokEdgeSdk.Client(cfg.Ziti)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := unbootstrapConfigs(edge); err != nil {
|
||||
logrus.Errorf("error unbootrapping configs: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func unbootstrapConfigs(edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
filter := fmt.Sprintf("tags.zrok != null")
|
||||
limit := int64(100)
|
||||
offset := int64(0)
|
||||
listReq := &apiConfig.ListConfigsParams{
|
||||
Filter: &filter,
|
||||
Limit: &limit,
|
||||
Offset: &offset,
|
||||
Context: context.Background(),
|
||||
}
|
||||
listResp, err := edge.Config.ListConfigs(listReq, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, listCfg := range listResp.Payload.Data {
|
||||
logrus.Infof("found config: %v", *listCfg.ID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user