From 0bf1ee5564c6c46f9f918819eec76b9dcd10cede Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Mon, 23 May 2022 07:45:18 +1000 Subject: [PATCH] feat: add a function to generate and return all routes --- cmd/identify_ingress.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cmd/identify_ingress.go b/cmd/identify_ingress.go index 1a69b64c..6c97a7d3 100644 --- a/cmd/identify_ingress.go +++ b/cmd/identify_ingress.go @@ -1,12 +1,19 @@ package cmd import ( + "encoding/json" "fmt" "github.com/spf13/cobra" "github.com/uselagoon/build-deploy-tool/internal/lagoon" ) +type ingressIdentifyJSON struct { + primary string `json:"primary"` + secondary []string `json:"secondary"` + autogenerated []string `json:"autogenerated"` +} + var primaryIngressIdentify = &cobra.Command{ Use: "primary-ingress", Aliases: []string{"pi"}, @@ -21,6 +28,26 @@ var primaryIngressIdentify = &cobra.Command{ }, } +var ingressIdentify = &cobra.Command{ + Use: "ingress", + Aliases: []string{"i"}, + Short: "Identify all ingress for a specific environment", + RunE: func(cmd *cobra.Command, args []string) error { + primary, secondary, autogen, err := IdentifyPrimaryIngress(false) + if err != nil { + return err + } + ret := ingressIdentifyJSON{ + primary: primary, + secondary: secondary, + autogenerated: autogen, + } + retJSON, _ := json.Marshal(ret) + fmt.Println(string(retJSON)) + return nil + }, +} + // IdentifyPrimaryIngress . func IdentifyPrimaryIngress(debug bool) (string, []string, []string, error) { activeEnv := false @@ -126,4 +153,5 @@ func generateRoutes(lagoonEnvVars []lagoon.EnvironmentVariable, func init() { identifyCmd.AddCommand(primaryIngressIdentify) + identifyCmd.AddCommand(ingressIdentify) }