Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
Add option to specify secret name
Browse files Browse the repository at this point in the history
  • Loading branch information
rancher-max committed Feb 19, 2020
1 parent 9e32adb commit a146fde
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
10 changes: 8 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ assignees: ''

---

<!--
Note: Please add dashboard specific bugs to the dashboard repo: https://github.com/rancher/dashboard/issues
-->

**Describe the bug**
A clear and concise description of what the bug is.
<!--A clear and concise description of what the bug is.-->



**To Reproduce**
Steps to reproduce the behavior:
<!--Steps to reproduce the behavior:-->
1.


Expand All @@ -36,3 +40,5 @@ output:
```
```
<!--Please provide any additional information that may be helpful in debugging.
For example: `rio logs taskrun/demo-v0jhl5r-ccd11-cd2cf` for a failed build-->
50 changes: 43 additions & 7 deletions cli/cmd/secrets/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
)

type Create struct {
N_Name string `desc:"Assign a name to the secret. Use format [namespace:]name"`
T_Type string `desc:"Create type" default:"Opaque"`
F_FromFile []string `desc:"Creating secrets from files"`
D_Data []string `desc:"Creating secrets from key-pair data"`
Expand All @@ -30,6 +31,13 @@ const (
)

func (s *Create) Run(ctx *clicontext.CLIContext) error {
name := s.N_Name
if name != "" {
r := ctx.ParseID(fmt.Sprintf("secret/%s", name))
if _, err := ctx.Core.Secrets(r.Namespace).Get(r.Name, metav1.GetOptions{}); err == nil {
fmt.Printf("Warning: %s already exists\n", r)
}
}
if s.GithubWebhook {
var err error
var accessToken, ns string
Expand All @@ -38,11 +46,18 @@ func (s *Create) Run(ctx *clicontext.CLIContext) error {
return err
}

secret, err := ctx.Core.Secrets(ns).Get(constants.DefaultGithubCrendential, metav1.GetOptions{})
if name == "" {
name, err = questions.Prompt(fmt.Sprintf("Name[%s]: ", constants.DefaultGithubCrendential), constants.DefaultGithubCrendential)
if err != nil {
return err
}
}

secret, err := ctx.Core.Secrets(ns).Get(name, metav1.GetOptions{})
if err == nil {
accessToken = string(secret.Data["accessToken"])
} else {
secret = constructors.NewSecret(ns, constants.DefaultGithubCrendential, v1.Secret{})
secret = constructors.NewSecret(ns, name, v1.Secret{})
}
setDefaults(secret, v1.SecretTypeOpaque)

Expand All @@ -62,6 +77,13 @@ func (s *Create) Run(ctx *clicontext.CLIContext) error {
return err
}

if name == "" {
name, err = questions.Prompt(fmt.Sprintf("Name[%s]: ", constants.DefaultDockerCrendential), constants.DefaultDockerCrendential)
if err != nil {
return err
}
}

url, err = questions.Prompt(fmt.Sprintf("Registry URL[%s]: ", defaultDockerRegistry), defaultDockerRegistry)
if err != nil {
return err
Expand All @@ -78,7 +100,7 @@ func (s *Create) Run(ctx *clicontext.CLIContext) error {
}

generator := generateversioned.SecretForDockerRegistryGeneratorV1{
Name: constants.DefaultDockerCrendential,
Name: name,
Username: username,
Password: password,
Server: url,
Expand All @@ -104,13 +126,20 @@ func (s *Create) Run(ctx *clicontext.CLIContext) error {
return err
}

secret, err := ctx.Core.Secrets(ns).Get(constants.DefaultGitCrendential, metav1.GetOptions{})
if name == "" {
name, err = questions.Prompt(fmt.Sprintf("Name[%s]: ", constants.DefaultGitCrendential), constants.DefaultGitCrendential)
if err != nil {
return err
}
}

secret, err := ctx.Core.Secrets(ns).Get(name, metav1.GetOptions{})
if err == nil {
url = secret.Annotations["tekton.dev/git-0"]
username = string(secret.Data["username"])
password = string(secret.Data["password"])
} else {
secret = constructors.NewSecret(ns, constants.DefaultGitCrendential, v1.Secret{})
secret = constructors.NewSecret(ns, name, v1.Secret{})
}
setDefaults(secret, v1.SecretTypeBasicAuth)

Expand Down Expand Up @@ -143,11 +172,18 @@ func (s *Create) Run(ctx *clicontext.CLIContext) error {
return err
}

secret, err := ctx.Core.Secrets(ns).Get(constants.DefaultGitCrendentialSSH, metav1.GetOptions{})
if name == "" {
name, err = questions.Prompt(fmt.Sprintf("Name[%s]: ", constants.DefaultGitCrendentialSSH), constants.DefaultGitCrendentialSSH)
if err != nil {
return err
}
}

secret, err := ctx.Core.Secrets(ns).Get(name, metav1.GetOptions{})
if err == nil {
url = secret.Annotations["tekton.dev/git-0"]
} else {
secret = constructors.NewSecret(ns, constants.DefaultGitCrendentialSSH, v1.Secret{})
secret = constructors.NewSecret(ns, name, v1.Secret{})
secret.Type = v1.SecretTypeSSHAuth
}
setDefaults(secret, v1.SecretTypeSSHAuth)
Expand Down

0 comments on commit a146fde

Please sign in to comment.