Documentation
¶
Overview ¶
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var AddCmd = &cobra.Command{ Use: "add", Short: "Adds a new target group", Long: `Adds target group. Example: echo "test2" | acucli targetGroup add : add a target group named "test2" cat targetGroups.txt | acucli targetGroup add : Add multiple target groups `, Run: func(cmd *cobra.Command, args []string) { input := filehelper.ReadStdin() if input != nil { for _, targetGroupName := range input { postBody := PostBody{Name: targetGroupName} requestJson, _ := json.Marshal(postBody) req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", viper.GetString("URL"), "/target_groups"), bytes.NewBuffer(requestJson)) if err != nil { fmt.Println("Error creating request:", err) return } req.Header.Set("Content-Type", "application/json") resp, err := httpclient.MyHTTPClient.Do(req) if err != nil { fmt.Println("Error making request:", err) return } defer resp.Body.Close() if resp.StatusCode == http.StatusCreated { var responseBody ResponseBody decoder := json.NewDecoder(resp.Body) if err := decoder.Decode(&responseBody); err != nil { fmt.Println("Error decoding response body:", err) return } fmt.Println(chalk.Green, chalk.Bold.TextStyle(responseBody.Name+" "+responseBody.GroupID), chalk.Reset) } } } else { fmt.Println("Please provide input") } }, }
addCmd represents the add command
View Source
var AddTargetsCmd = &cobra.Command{ Use: "addTargets", Short: "Add targets to a target group", Long: `Add targets from stdin and the target group via id flag. Example: echo targets.txt| acucli targetGroup addTargets --id 0637a8b0-900d-44e8-9a04-edef6ac25e23 : Add targets from file adds the defined target group id `, Run: func(cmd *cobra.Command, args []string) { id, _ = cmd.Flags().GetString("id") input := filehelper.ReadStdin() if input != nil { pBody := postBody{} pBody.Add = input pBody.Remove = []string{} addTargets(pBody, id) } }, }
addTargetsCmd represents the addTargets command
View Source
var ListCmd = &cobra.Command{ Use: "list", Short: "List all the target groups", Long: `Lists all the target groups with their name and their corresponding id to use it for other commands`, Run: func(cmd *cobra.Command, args []string) { req, err := http.NewRequest("GET", fmt.Sprintf("%s%s", viper.GetString("URL"), "/target_groups"), nil) if err != nil { fmt.Println("Error creating request:", err) return } resp, err := httpclient.MyHTTPClient.Do(req) if err != nil { fmt.Println("Error making request:", err) return } defer resp.Body.Close() body, _ := io.ReadAll(resp.Body) var responseBody responseBody err = json.Unmarshal(body, &responseBody) if err != nil { fmt.Println("Error parsing JSON:", err) return } for _, targetGroup := range responseBody.TargetGroups { fmt.Printf("'%s'\t%s\n", targetGroup.Name, targetGroup.GroupID) } }, }
listCmd represents the list command
View Source
var RemoveCmd = &cobra.Command{ Use: "remove", Short: "Remove a target group", Long: `Takes id input from stdin, removes it without deleting the targets inside. Example: echo "39468242-2706-43ce-8278-3edf30ed1889" | acucli targetGroup remove : Removes a single target group cat toremove.txt | acucli targetGroup remove : Removes multiple `, Run: func(cmd *cobra.Command, args []string) { input := filehelper.ReadStdin() if input != nil { makeDeleteRequest(input) } }, }
RemoveCmd represents the remove command
View Source
var TargetGroupCmd = &cobra.Command{ Use: "targetGroup", Short: "Get targets from target group id", Long: `Takes id of the target group and prints the targets with their id. Example: acucli targetGroup --id=cd3db1f4-6275-478c-8830-8d96d37120f3 : Prints the targets of the target group `, Run: func(cmd *cobra.Command, args []string) { id, _ := cmd.Flags().GetString("id") responseCode, respBody := GetTargetGroupRequest(id) if responseCode == 200 { for _, targetID := range respBody.TargetIDList { _, target := target.GetTargetRequest(targetID) fmt.Printf("%s\t%s\n", target.Address, targetID) } } else { fmt.Fprintf(os.Stderr, "%sTargetGroup not found%s\n", chalk.Red, chalk.Reset) } }, }
targetGroupCmd represents the targetGroup command
Functions ¶
func GetTargetGroupRequest ¶
Types ¶
type RemovePostBody ¶
type RemovePostBody struct {
TargetGroupIDList []string `json:"group_id_list"`
}
type ResponseBody ¶
Click to show internal directories.
Click to hide internal directories.