diff --git a/cli/cmd/enterprise_channel_assign.go b/cli/cmd/enterprise_channel_assign.go new file mode 100644 index 000000000..f8fc571fe --- /dev/null +++ b/cli/cmd/enterprise_channel_assign.go @@ -0,0 +1,37 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +func (r *runners) InitEnterpriseChannelAssign(parent *cobra.Command) { + cmd := &cobra.Command{ + Use: "assign", + SilenceUsage: true, + Short: "assign a channel to a vendor", + Long: `Assign a channel to a vendor team. + + Example: + replicated enteprise channel assign --channel-id ChannelID --vendor-id VendorID`, + } + parent.AddCommand(cmd) + + cmd.Flags().StringVar(&r.args.enterpriseChannelAssignChannelID, "channel-id", "", "The id of the channel to be assigned") + cmd.Flags().StringVar(&r.args.enterpriseChannelAssignVendorID, "vendor-id", "", "The id of the vendor to assign the channel to") + + cmd.RunE = r.enterpriseChannelAssign +} + +func (r *runners) enterpriseChannelAssign(cmd *cobra.Command, args []string) error { + err := r.enterpriseClient.AssignChannel(r.args.enterpriseChannelAssignChannelID, r.args.enterpriseChannelAssignVendorID) + if err != nil { + return err + } + + fmt.Fprintf(r.w, "Channel successfully assigned\n") + r.w.Flush() + + return nil +} diff --git a/cli/cmd/root.go b/cli/cmd/root.go index e6d9e8bbb..caea4e26f 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -163,6 +163,7 @@ func Execute(rootCmd *cobra.Command, stdin io.Reader, stdout io.Writer, stderr i runCmds.InitEnterpriseChannelCreate(enterpriseChannelCmd) runCmds.InitEnterpriseChannelUpdate(enterpriseChannelCmd) runCmds.InitEnterpriseChannelRM(enterpriseChannelCmd) + runCmds.InitEnterpriseChannelAssign(enterpriseChannelCmd) enterprisePolicyCmd := runCmds.InitEnterprisePolicy(enterpriseCmd) runCmds.InitEnterprisePolicyLS(enterprisePolicyCmd) runCmds.InitEnterprisePolicyCreate(enterprisePolicyCmd) diff --git a/cli/cmd/runner.go b/cli/cmd/runner.go index 9d409ce93..cf1097134 100644 --- a/cli/cmd/runner.go +++ b/cli/cmd/runner.go @@ -105,6 +105,9 @@ type runnerArgs struct { enterpriseChannelRmId string + enterpriseChannelAssignChannelID string + enterpriseChannelAssignVendorID string + enterprisePolicyCreateName string enterprisePolicyCreateDescription string enterprisePolicyCreateFile string diff --git a/pkg/enterpriseclient/channel.go b/pkg/enterpriseclient/channel.go index 1d4f717dc..f5e51f2b8 100644 --- a/pkg/enterpriseclient/channel.go +++ b/pkg/enterpriseclient/channel.go @@ -64,3 +64,12 @@ func (c HTTPClient) RemoveChannel(id string) error { return nil } + +func (c HTTPClient) AssignChannel(channelID string, vendorID string) error { + err := c.doJSON("POST", fmt.Sprintf("/v1/channelvendor/%s/%s", channelID, vendorID), 204, nil, nil) + if err != nil { + return errors.Wrap(err, "failed to assign channel") + } + + return nil +}