Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Command = cli.Command{ Name: "targetgroup", Description: "Manage Target Groups", Usage: "Manage Target Groups", Subcommands: []*cli.Command{ &CreateCommand, &LinkCommand, &UnlinkCommand, &ListCommand, &DeleteCommand, &RoutesCommand, }, }
View Source
var CreateCommand = cli.Command{ Name: "create", Description: "Create a target group", Usage: "Create a target group", Flags: []cli.Flag{ &cli.StringFlag{Name: "id", Required: true}, &cli.StringFlag{Name: "schema-from", Required: true, Usage: "publisher/name@version/kind"}, &cli.BoolFlag{Name: "ok-if-exists", Value: false}, }, Action: func(c *cli.Context) error { ctx := c.Context id := c.String("id") schemaFrom := c.String("schema-from") cfg, err := config.Load() if err != nil { return err } cf, err := client.FromConfig(ctx, cfg) if err != nil { return err } res, err := cf.AdminCreateTargetGroupWithResponse(ctx, types.AdminCreateTargetGroupJSONRequestBody{ Id: id, TargetSchema: schemaFrom, }) if err != nil { return err } switch res.StatusCode() { case http.StatusCreated: clio.Successf("Successfully created the targetgroup: %s", id) case http.StatusConflict: if c.Bool("ok-if-exists") { clio.Infof("Targetgroup with that ID already exists: '%s'", id) return nil } return clierr.New(fmt.Sprintf("Duplicate targetgroup ID provided. Targetgroup with that ID '%s' already exist", id)) case http.StatusUnauthorized: return errors.New(res.JSON401.Error) case http.StatusInternalServerError: return errors.New(res.JSON500.Error) default: return clierr.New("Unhandled response from the Common Fate API", clierr.Infof("Status Code: %d", res.StatusCode()), clierr.Error(string(res.Body))) } return nil }, }
View Source
var DeleteCommand = cli.Command{ Name: "delete", Description: "Delete a target group", Usage: "Delete a target group", Flags: []cli.Flag{ &cli.StringFlag{Name: "id", Required: true}, }, Action: func(c *cli.Context) error { ctx := c.Context cfg, err := config.Load() if err != nil { return err } id := c.String("id") cf, err := client.FromConfig(ctx, cfg) if err != nil { return err } _, err = cf.AdminDeleteTargetGroupWithResponse(ctx, id) if err != nil { return err } clio.Successf("Deleted target group %s", id) return nil }, }
View Source
var LinkCommand = cli.Command{ Name: "link", Description: "Link a handler to a target group", Usage: "Link a handler to a target group", Flags: []cli.Flag{ &cli.StringFlag{Name: "target-group", Required: true}, &cli.StringFlag{Name: "handler", Required: true}, &cli.StringFlag{Name: "kind", Required: true}, &cli.IntFlag{Name: "priority", Value: 100}, }, Action: func(c *cli.Context) error { ctx := c.Context cfg, err := config.Load() if err != nil { return err } cf, err := client.FromConfig(ctx, cfg) if err != nil { return err } _, err = cf.AdminCreateTargetGroupLinkWithResponse(ctx, c.String("target-group"), types.AdminCreateTargetGroupLinkJSONRequestBody{ DeploymentId: c.String("handler"), Priority: c.Int("priority"), Kind: c.String("kind"), }) if err != nil { return err } clio.Successf("Successfully linked the handler '%s' with target group '%s' using kind: '%s'", c.String("handler"), c.String("target-group"), c.String("kind")) return nil }, }
View Source
var ListCommand = cli.Command{ Name: "list", Aliases: []string{"ls"}, Description: "List target groups", Usage: "List target groups", Action: cli.ActionFunc(func(c *cli.Context) error { ctx := c.Context cfg, err := config.Load() if err != nil { return err } cf, err := client.FromConfig(ctx, cfg) if err != nil { return err } res, err := cf.AdminListTargetGroupsWithResponse(ctx) if err != nil { return err } table := tablewriter.NewWriter(os.Stdout) table.SetHeader([]string{"ID", "Target Schema"}) table.SetAutoWrapText(false) table.SetAutoFormatHeaders(true) table.SetHeaderAlignment(tablewriter.ALIGN_LEFT) table.SetAlignment(tablewriter.ALIGN_LEFT) table.SetCenterSeparator("") table.SetColumnSeparator("") table.SetRowSeparator("") table.SetHeaderLine(false) table.SetBorder(false) for _, d := range res.JSON200.TargetGroups { table.Append([]string{ d.Id, d.TargetSchema.From, }) } table.Render() return nil }), }
View Source
var ListRoutesCommand = cli.Command{ Name: "list", Aliases: []string{"ls"}, Description: "List target group routes", Usage: "List target group routes", Flags: []cli.Flag{ &cli.StringFlag{Name: "id", Required: true}, }, Action: cli.ActionFunc(func(c *cli.Context) error { ctx := c.Context cfg, err := config.Load() if err != nil { return err } cf, err := client.FromConfig(ctx, cfg) if err != nil { return err } res, err := cf.AdminListTargetRoutesWithResponse(ctx, c.String("id")) if err != nil { return err } table := tablewriter.NewWriter(os.Stdout) table.SetHeader([]string{"Target Group Id", "Handler Id", "Kind", "Priority", "Valid", "Diagnostics"}) table.SetAutoWrapText(false) table.SetAutoFormatHeaders(true) table.SetHeaderAlignment(tablewriter.ALIGN_LEFT) table.SetAlignment(tablewriter.ALIGN_LEFT) table.SetCenterSeparator("") table.SetColumnSeparator("") table.SetRowSeparator("") table.SetHeaderLine(false) table.SetBorder(false) for _, d := range res.JSON200.Routes { table.Append([]string{ d.TargetGroupId, d.HandlerId, d.Kind, strconv.Itoa(d.Priority), strconv.FormatBool(d.Valid), fmt.Sprintf("%v", d.Diagnostics), }) } table.Render() return nil }), }
View Source
var RoutesCommand = cli.Command{ Name: "routes", Description: "Manage Target Groups Routes", Usage: "Manage Target Groups Routes", Subcommands: []*cli.Command{ &ListRoutesCommand, }, }
View Source
var UnlinkCommand = cli.Command{ Name: "unlink", Description: "Unlink a deployment from a target group", Usage: "Unlink a deployment from a target group", Flags: []cli.Flag{ &cli.StringFlag{Name: "deployment", Required: true}, &cli.StringFlag{Name: "target-group", Required: true}, }, Action: func(c *cli.Context) error { ctx := c.Context cfg, err := config.Load() if err != nil { return err } cf, err := client.FromConfig(ctx, cfg) if err != nil { return err } _, err = cf.AdminRemoveTargetGroupLinkWithResponse(ctx, c.String("target-group"), &types.AdminRemoveTargetGroupLinkParams{ DeploymentId: c.String("deployment"), }) if err != nil { return err } clio.Successf("Unlinked deployment %s from group %s", c.String("deployment"), c.String("target-group")) return nil }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.