Skip to content

Commit

Permalink
Assign an enterprise channel to a vendor (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgalsaleh authored Apr 23, 2020
1 parent f12232b commit 8cc1dfe
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
37 changes: 37 additions & 0 deletions cli/cmd/enterprise_channel_assign.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions cli/cmd/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ type runnerArgs struct {

enterpriseChannelRmId string

enterpriseChannelAssignChannelID string
enterpriseChannelAssignVendorID string

enterprisePolicyCreateName string
enterprisePolicyCreateDescription string
enterprisePolicyCreateFile string
Expand Down
9 changes: 9 additions & 0 deletions pkg/enterpriseclient/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 8cc1dfe

Please sign in to comment.