Skip to content

Commit

Permalink
allow importer/exporter to login in one command by adding --controlle…
Browse files Browse the repository at this point in the history
…r-url flag (#2665)
  • Loading branch information
dovholuknf authored Jan 21, 2025
1 parent 8f2b85a commit 60f62f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ziti/cmd/ascode/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Exporter struct {
configTypeCache map[string]any
authPolicyCache map[string]any
externalJwtCache map[string]any
controllerUrl string
}

var output Output
Expand Down Expand Up @@ -95,6 +96,7 @@ func NewExportCmd(out io.Writer, errOut io.Writer) *cobra.Command {
cmd.Flags().SetInterspersed(true)
cmd.Flags().BoolVar(&exporter.ofJson, "json", true, "Output in JSON")
cmd.Flags().BoolVar(&exporter.ofYaml, "yaml", false, "Output in YAML")
cmd.Flags().StringVar(&exporter.controllerUrl, "controller-url", "", "The url of the controller")
cmd.MarkFlagsMutuallyExclusive("json", "yaml")

cmd.Flags().StringVarP(&exporter.filename, "output-file", "o", "", "Write output to local file")
Expand All @@ -118,6 +120,9 @@ func (exporter *Exporter) Init(out io.Writer) error {

client, err := mgmt.NewClient()
if err != nil {
if exporter.controllerUrl != "" {
exporter.loginOpts.Args = []string{exporter.controllerUrl}
}
loginErr := exporter.loginOpts.Run()
if loginErr != nil {
log.Fatal(err)
Expand Down
5 changes: 5 additions & 0 deletions ziti/cmd/ascode/importer/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Importer struct {
authPolicyCache map[string]any
extJwtSignersCache map[string]any
identityCache map[string]any
controllerUrl string
}

func NewImportCmd(out io.Writer, errOut io.Writer) *cobra.Command {
Expand Down Expand Up @@ -102,6 +103,7 @@ func NewImportCmd(out io.Writer, errOut io.Writer) *cobra.Command {
cmd.Flags().SetInterspersed(true)
cmd.Flags().BoolVar(&importer.ofJson, "json", true, "Input parsed as JSON")
cmd.Flags().BoolVar(&importer.ofYaml, "yaml", false, "Input parsed as YAML")
cmd.Flags().StringVar(&importer.controllerUrl, "controller-url", "", "The url of the controller")
cmd.MarkFlagsMutuallyExclusive("json", "yaml")

edge.AddLoginFlags(cmd, &importer.loginOpts)
Expand All @@ -123,6 +125,9 @@ func (importer *Importer) Init() {

client, err := mgmt.NewClient()
if err != nil {
if importer.controllerUrl != "" {
importer.loginOpts.Args = []string{importer.controllerUrl}
}
loginErr := importer.loginOpts.Run()
if loginErr != nil {
log.Fatal(err)
Expand Down

0 comments on commit 60f62f0

Please sign in to comment.