This repository has been archived by the owner on May 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 382
Add flags to svcat register broker command #2208
Merged
k8s-ci-robot
merged 1 commit into
kubernetes-retired:master
from
jberkhahn:svcat_register_flags
Aug 14, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,23 +18,43 @@ package broker | |
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
"github.com/kubernetes-incubator/service-catalog/cmd/svcat/command" | ||
"github.com/kubernetes-incubator/service-catalog/cmd/svcat/output" | ||
"github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1" | ||
servicecatalog "github.com/kubernetes-incubator/service-catalog/pkg/svcat/service-catalog" | ||
"github.com/spf13/cobra" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// RegisterCmd contains the information needed to register a broker | ||
type RegisterCmd struct { | ||
BrokerName string | ||
Context *command.Context | ||
URL string | ||
*command.Namespaced | ||
*command.Waitable | ||
|
||
Context *command.Context | ||
|
||
BasicSecret string | ||
BearerSecret string | ||
BrokerName string | ||
CAFile string | ||
ClassRestrictions []string | ||
PlanRestrictions []string | ||
SkipTLS bool | ||
RelistBehavior string | ||
RelistDuration time.Duration | ||
URL string | ||
} | ||
|
||
// NewRegisterCmd builds a "svcat register" command | ||
func NewRegisterCmd(cxt *command.Context) *cobra.Command { | ||
registerCmd := &RegisterCmd{ | ||
Context: cxt, | ||
Context: cxt, | ||
Namespaced: command.NewNamespaced(cxt), | ||
Waitable: command.NewWaitable(), | ||
} | ||
cmd := &cobra.Command{ | ||
Use: "register NAME --url URL", | ||
|
@@ -48,27 +68,73 @@ func NewRegisterCmd(cxt *command.Context) *cobra.Command { | |
cmd.Flags().StringVar(®isterCmd.URL, "url", "", | ||
"The broker URL (Required)") | ||
cmd.MarkFlagRequired("url") | ||
cmd.Flags().StringVar(®isterCmd.BasicSecret, "basic-secret", "", | ||
"A secret containing basic auth (username/password) information to connect to the broker") | ||
cmd.Flags().StringVar(®isterCmd.BearerSecret, "bearer-secret", "", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't follow that convention for flags that indicate secrets for other commands - both provision and bind just use |
||
"A secret containing a bearer token to connect to the broker") | ||
cmd.Flags().StringVar(®isterCmd.CAFile, "ca", "", | ||
"A file containing the CA certificate to connect to the broker") | ||
cmd.Flags().StringSliceVar(®isterCmd.ClassRestrictions, "class-restrictions", []string{}, | ||
"A list of restrictions to apply to the classes allowed from the broker") | ||
cmd.Flags().StringSliceVar(®isterCmd.PlanRestrictions, "plan-restrictions", []string{}, | ||
"A list of restrictions to apply to the plans allowed from the broker") | ||
cmd.Flags().StringVar(®isterCmd.RelistBehavior, "relist-behavior", "", | ||
"Behavior for relisting the broker's catalog. Valid options are manual or duration. Defaults to duration with an interval of 15m.") | ||
cmd.Flags().DurationVar(®isterCmd.RelistDuration, "relist-duration", 0*time.Second, | ||
"Interval to refetch broker catalog when relist-behavior is set to duration, specified in human readable format: 30s, 1m, 1h") | ||
cmd.Flags().BoolVar(®isterCmd.SkipTLS, "skip-tls", false, | ||
"Disables TLS certificate verification when communicating with this broker. This is strongly discouraged. You should use --ca instead.") | ||
registerCmd.AddNamespaceFlags(cmd.Flags(), false) | ||
registerCmd.AddWaitFlags(cmd) | ||
|
||
return cmd | ||
} | ||
|
||
// Validate checks that the required arguements have been provided | ||
func (c *RegisterCmd) Validate(args []string) error { | ||
if len(args) == 0 { | ||
if len(args) < 1 { | ||
return fmt.Errorf("a broker name is required") | ||
} | ||
c.BrokerName = args[0] | ||
|
||
if c.BasicSecret != "" && c.BearerSecret != "" { | ||
return fmt.Errorf("cannot use both basic auth and bearer auth") | ||
} | ||
|
||
if c.CAFile != "" { | ||
_, err := os.Stat(c.CAFile) | ||
if err != nil { | ||
return fmt.Errorf("error finding CA file: %v", err.Error()) | ||
} | ||
} | ||
if c.RelistBehavior != "" { | ||
c.RelistBehavior = strings.ToLower(c.RelistBehavior) | ||
if c.RelistBehavior != "duration" && c.RelistBehavior != "manual" { | ||
return fmt.Errorf("invalid --relist-duration value, allowed values are: duration, manual") | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// Run runs the command | ||
// Run creates the broker and then displays the broker details | ||
func (c *RegisterCmd) Run() error { | ||
return c.Register() | ||
} | ||
opts := &servicecatalog.RegisterOptions{ | ||
BasicSecret: c.BasicSecret, | ||
BearerSecret: c.BearerSecret, | ||
CAFile: c.CAFile, | ||
ClassRestrictions: c.ClassRestrictions, | ||
Namespace: c.Namespace, | ||
PlanRestrictions: c.PlanRestrictions, | ||
SkipTLS: c.SkipTLS, | ||
} | ||
if c.RelistBehavior == "duration" { | ||
opts.RelistBehavior = v1beta1.ServiceBrokerRelistBehaviorDuration | ||
opts.RelistDuration = &metav1.Duration{Duration: c.RelistDuration} | ||
} else if c.RelistBehavior == "manual" { | ||
opts.RelistBehavior = v1beta1.ServiceBrokerRelistBehaviorManual | ||
} | ||
|
||
// Register calls out to the pkg lib to create the broker and displays the output | ||
func (c *RegisterCmd) Register() error { | ||
broker, err := c.Context.App.Register(c.BrokerName, c.URL) | ||
broker, err := c.Context.App.Register(c.BrokerName, c.URL, opts) | ||
if err != nil { | ||
return err | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm always confused by what a create should look like with a manual relistduration. Should we pass a null duration or does the api server just ignore whatever is sent for the duration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sends a time.Duration of 0, which the apiserver drops on the floor. It never gets set in the spec at all.