Skip to content

Commit

Permalink
Deprecate oc secrets subcomands
Browse files Browse the repository at this point in the history
  • Loading branch information
soltysh committed Jan 15, 2018
1 parent 00c6589 commit 5046e19
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 23 deletions.
10 changes: 9 additions & 1 deletion pkg/oc/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func NewCommandCLI(name, fullName string, in io.Reader, out, errout io.Writer) *
f := clientcmd.New(cmds.PersistentFlags())

loginCmd := login.NewCmdLogin(fullName, f, in, out, errout)
secretcmds := secrets.NewCmdSecrets(secrets.SecretsRecommendedName, fullName+" "+secrets.SecretsRecommendedName, f, in, out, errout, fullName+" edit")
secretcmds := secrets.NewCmdSecrets(secrets.SecretsRecommendedName, fullName+" "+secrets.SecretsRecommendedName, f, out, errout)

groups := ktemplates.CommandGroups{
{
Expand Down Expand Up @@ -185,6 +185,10 @@ func NewCommandCLI(name, fullName string, in io.Reader, out, errout io.Writer) *
}
groups.Add(cmds)

ocEditFullName := fullName + " edit"
ocSecretsFullName := fullName + " " + secrets.SecretsRecommendedName
ocSecretsNewFullName := ocSecretsFullName + " " + secrets.NewSecretRecommendedCommandName

filters := []string{
"options",
"deploy",
Expand All @@ -193,6 +197,10 @@ func NewCommandCLI(name, fullName string, in io.Reader, out, errout io.Writer) *
moved(fullName, "set volume", cmds, set.NewCmdVolume(fullName, f, out, errout)),
moved(fullName, "logs", cmds, cmd.NewCmdBuildLogs(fullName, f, out)),
moved(fullName, "secrets link", secretcmds, secrets.NewCmdLinkSecret("add", fullName, f, out)),
moved(fullName, "create secret", secretcmds, secrets.NewCmdCreateSecret(secrets.NewSecretRecommendedCommandName, fullName, f, out)),
moved(fullName, "create secret", secretcmds, secrets.NewCmdCreateDockerConfigSecret(secrets.CreateDockerConfigSecretRecommendedName, fullName, f, out, ocSecretsNewFullName, ocEditFullName)),
moved(fullName, "create secret", secretcmds, secrets.NewCmdCreateBasicAuthSecret(secrets.CreateBasicAuthSecretRecommendedCommandName, fullName, f, in, out, ocSecretsNewFullName, ocEditFullName)),
moved(fullName, "create secret", secretcmds, secrets.NewCmdCreateSSHAuthSecret(secrets.CreateSSHAuthSecretRecommendedCommandName, fullName, f, out, ocSecretsNewFullName, ocEditFullName)),
}

changeSharedFlagDefaults(cmds)
Expand Down
9 changes: 5 additions & 4 deletions pkg/oc/cli/secrets/basicauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ func NewCmdCreateBasicAuthSecret(name, fullName string, f kcmdutil.Factory, read
}

cmd := &cobra.Command{
Use: fmt.Sprintf("%s SECRET --username=USERNAME --password=PASSWORD [--ca-cert=FILENAME] [--gitconfig=FILENAME]", name),
Short: "Create a new secret for basic authentication",
Long: createBasicAuthSecretLong,
Example: fmt.Sprintf(createBasicAuthSecretExample, fullName, newSecretFullName, ocEditFullName),
Use: fmt.Sprintf("%s SECRET --username=USERNAME --password=PASSWORD [--ca-cert=FILENAME] [--gitconfig=FILENAME]", name),
Short: "Create a new secret for basic authentication",
Long: createBasicAuthSecretLong,
Example: fmt.Sprintf(createBasicAuthSecretExample, fullName, newSecretFullName, ocEditFullName),
Deprecated: "use oc create secret",
Run: func(c *cobra.Command, args []string) {
if err := o.Complete(f, args); err != nil {
kcmdutil.CheckErr(kcmdutil.UsageErrorf(c, err.Error()))
Expand Down
9 changes: 5 additions & 4 deletions pkg/oc/cli/secrets/dockercfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ func NewCmdCreateDockerConfigSecret(name, fullName string, f kcmdutil.Factory, o
o := &CreateDockerConfigOptions{Out: out}

cmd := &cobra.Command{
Use: fmt.Sprintf("%s SECRET --docker-server=DOCKER_REGISTRY_SERVER --docker-username=DOCKER_USER --docker-password=DOCKER_PASSWORD --docker-email=DOCKER_EMAIL", name),
Short: "Create a new dockercfg secret",
Long: createDockercfgLong,
Example: fmt.Sprintf(createDockercfgExample, fullName, newSecretFullName, ocEditFullName),
Use: fmt.Sprintf("%s SECRET --docker-server=DOCKER_REGISTRY_SERVER --docker-username=DOCKER_USER --docker-password=DOCKER_PASSWORD --docker-email=DOCKER_EMAIL", name),
Short: "Create a new dockercfg secret",
Long: createDockercfgLong,
Example: fmt.Sprintf(createDockercfgExample, fullName, newSecretFullName, ocEditFullName),
Deprecated: "use oc create secret",
Run: func(c *cobra.Command, args []string) {
if err := o.Complete(f, args); err != nil {
kcmdutil.CheckErr(kcmdutil.UsageErrorf(c, err.Error()))
Expand Down
10 changes: 10 additions & 0 deletions pkg/oc/cli/secrets/link_secret_to_obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"io"
"os"
"strings"

kapi "k8s.io/kubernetes/pkg/apis/core"
Expand Down Expand Up @@ -51,6 +52,11 @@ func NewCmdLinkSecret(name, fullName string, f kcmdutil.Factory, out io.Writer)
Short: "Link secrets to a ServiceAccount",
Long: linkSecretLong,
Example: fmt.Sprintf(linkSecretExample, fullName),
PreRun: func(cmd *cobra.Command, args []string) {
if len(os.Args) > 1 && os.Args[1] == "add" {
printDeprecationWarning("secrets add", "secrets link")
}
},
Run: func(c *cobra.Command, args []string) {
if err := o.Complete(f, args); err != nil {
kcmdutil.CheckErr(kcmdutil.UsageErrorf(c, err.Error()))
Expand Down Expand Up @@ -160,3 +166,7 @@ func (o LinkSecretOptions) linkSecretsToServiceAccount(serviceaccount *kapi.Serv

return nil
}

func printDeprecationWarning(command, alias string) {
fmt.Fprintf(os.Stderr, "%s is DEPRECATED and will be removed in a future version. Use %s instead.\n", alias, command)
}
9 changes: 5 additions & 4 deletions pkg/oc/cli/secrets/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ func NewCmdCreateSecret(name, fullName string, f *clientcmd.Factory, out io.Writ
options.Out = out

cmd := &cobra.Command{
Use: fmt.Sprintf("%s NAME [KEY=]SOURCE ...", name),
Short: "Create a new secret based on a key file or on files within a directory",
Long: newLong,
Example: fmt.Sprintf(newExample, fullName),
Use: fmt.Sprintf("%s NAME [KEY=]SOURCE ...", name),
Short: "Create a new secret based on a key file or on files within a directory",
Long: newLong,
Example: fmt.Sprintf(newExample, fullName),
Deprecated: "use oc create secret",
Run: func(c *cobra.Command, args []string) {
if err := options.Complete(args, f); err != nil {
kcmdutil.CheckErr(kcmdutil.UsageErrorf(c, err.Error()))
Expand Down
9 changes: 5 additions & 4 deletions pkg/oc/cli/secrets/sshauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ func NewCmdCreateSSHAuthSecret(name, fullName string, f kcmdutil.Factory, out io
}

cmd := &cobra.Command{
Use: fmt.Sprintf("%s SECRET --ssh-privatekey=FILENAME [--ca-cert=FILENAME] [--gitconfig=FILENAME]", name),
Short: "Create a new secret for SSH authentication",
Long: createSSHAuthSecretLong,
Example: fmt.Sprintf(createSSHAuthSecretExample, fullName, newSecretFullName, ocEditFullName),
Use: fmt.Sprintf("%s SECRET --ssh-privatekey=FILENAME [--ca-cert=FILENAME] [--gitconfig=FILENAME]", name),
Short: "Create a new secret for SSH authentication",
Long: createSSHAuthSecretLong,
Example: fmt.Sprintf(createSSHAuthSecretExample, fullName, newSecretFullName, ocEditFullName),
Deprecated: "use oc create secret",
Run: func(c *cobra.Command, args []string) {
if err := o.Complete(f, args); err != nil {
kcmdutil.CheckErr(kcmdutil.UsageErrorf(c, err.Error()))
Expand Down
7 changes: 1 addition & 6 deletions pkg/oc/cli/secrets/subcommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (
Docker registries.`)
)

func NewCmdSecrets(name, fullName string, f *clientcmd.Factory, reader io.Reader, out, errOut io.Writer, ocEditFullName string) *cobra.Command {
func NewCmdSecrets(name, fullName string, f *clientcmd.Factory, out, errOut io.Writer) *cobra.Command {
// Parent command to which all subcommands are added.
cmds := &cobra.Command{
Use: name,
Expand All @@ -44,11 +44,6 @@ func NewCmdSecrets(name, fullName string, f *clientcmd.Factory, reader io.Reader
Run: cmdutil.DefaultSubCommandRun(errOut),
}

newSecretFullName := fullName + " " + NewSecretRecommendedCommandName
cmds.AddCommand(NewCmdCreateSecret(NewSecretRecommendedCommandName, newSecretFullName, f, out))
cmds.AddCommand(NewCmdCreateDockerConfigSecret(CreateDockerConfigSecretRecommendedName, fullName+" "+CreateDockerConfigSecretRecommendedName, f, out, newSecretFullName, ocEditFullName))
cmds.AddCommand(NewCmdCreateBasicAuthSecret(CreateBasicAuthSecretRecommendedCommandName, fullName+" "+CreateBasicAuthSecretRecommendedCommandName, f, reader, out, newSecretFullName, ocEditFullName))
cmds.AddCommand(NewCmdCreateSSHAuthSecret(CreateSSHAuthSecretRecommendedCommandName, fullName+" "+CreateSSHAuthSecretRecommendedCommandName, f, out, newSecretFullName, ocEditFullName))
cmds.AddCommand(NewCmdLinkSecret(LinkSecretRecommendedName, fullName+" "+LinkSecretRecommendedName, f, out))
cmds.AddCommand(NewCmdUnlinkSecret(UnlinkSecretRecommendedName, fullName+" "+UnlinkSecretRecommendedName, f, out))

Expand Down

0 comments on commit 5046e19

Please sign in to comment.