Skip to content

Commit

Permalink
feat: added support for an interactive editor to edit kube secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
Karim-W committed Aug 14, 2024
1 parent bb81138 commit ee6ac72
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 56 deletions.
40 changes: 31 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,58 @@
# ksec

KSec is a command line tool to manage secrets in Kubernetes with the following functionallities:

- [x] Create a secret from an env file
- [x] Append a secret to an existing secret
- [x] Get a secret from Kubernetes secrets
- [x] Get a secret from Kubernetes secrets
- [x] Delete a secret from Kubernetes secrets
- [x] List all secrets in a namespace
- [x] Fill a file with a secret from Kubernetes secrets
- [x] Modify a secret in Kubernetes secrets using an editor

## Installation

to install Ksec use the following command:
` go install github.com/karim-w/ksec `
`go install github.com/karim-w/ksec`

## Usage

### Create a secret from an env file
` ksec -e <.env file path> -n <namespace> -s <secret name> `

`ksec -e <.env file path> -n <namespace> -s <secret name>`
this command will :

- create a secret from the env file and will add it to the kubernetes secrets
- create a yaml file with the env config map
- create a yaml file with the env config map

### Append a secret to an existing secret
` ksec -w <.env file path> -n <namespace> -s <secret name> -a `

`ksec -w <.env file path> -n <namespace> -s <secret name> -a`
this commmand will add a secret to a existing secret in kubernetes secrets

### List all secrets in a Kubernetes secret
` ksec -l -n <namespace> -s <secret name> `

`ksec -l -n <namespace> -s <secret name>`
this command will retrieve the secrets embedde in a kubernetes secrets

### Get a secret from Kubernetes secrets
` ksec -g -n <namespace> -s <secret name> -k <key> `

`ksec -g -n <namespace> -s <secret name> -k <key>`
this command will retrieve a the value of secret within an existing kubernetes secret

### Delete a secret from Kubernetes secrets
` ksec -d -n <namespace> -s <secret name> -k <key> `

`ksec -d -n <namespace> -s <secret name> -k <key>`
this command will delete a secret from an existing kubernetes secret

### Fill a file with secrets from Kubernetes secrets
` ksec -f <file path> -n <namespace> -s <secret name> `

`ksec -f <file path> -n <namespace> -s <secret name>`

### Modify a secret in Kubernetes secrets using an editor

`ksec -m -n <namespace> -s <secret name>`

### Specify the file format

`ksec -m -n <namespace> -s <secret name> -F <file format: json/yaml>`
33 changes: 20 additions & 13 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,28 @@ var RootCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
// Do Stuff Here
c := &models.Secrets{
Namespace: cmd.Flag("namespace").Value.String(),
Secret: cmd.Flag("secret").Value.String(),
Set: cmd.Flag("set").Value.String() == "true",
Key: cmd.Flag("key").Value.String(),
Value: cmd.Flag("value").Value.String(),
Get: cmd.Flag("get").Value.String() == "true",
Delete: cmd.Flag("delete").Value.String() == "true",
List: cmd.Flag("list").Value.String() == "true",
All: cmd.Flag("all").Value.String() == "true",
EnvPath: cmd.Flag("env").Value.String(),
FillPath: cmd.Flag("fill").Value.String(),
Namespace: cmd.Flag("namespace").Value.String(),
Secret: cmd.Flag("secret").Value.String(),
Set: cmd.Flag("set").Value.String() == "true",
Key: cmd.Flag("key").Value.String(),
Value: cmd.Flag("value").Value.String(),
Get: cmd.Flag("get").Value.String() == "true",
Delete: cmd.Flag("delete").Value.String() == "true",
List: cmd.Flag("list").Value.String() == "true",
All: cmd.Flag("all").Value.String() == "true",
EnvPath: cmd.Flag("env").Value.String(),
FillPath: cmd.Flag("fill").Value.String(),
Modify: cmd.Flag("modify").Value.String() == "true",
FileFormat: cmd.Flag("file-format").Value.String(),
}
service.KubectlSecretsSvc(c)
},
}
var Verbose bool
var Source string

var (
Verbose bool
Source string
)

func Execute() {
err := RootCmd.Execute()
Expand All @@ -57,4 +62,6 @@ func init() {
RootCmd.PersistentFlags().BoolP("all", "a", false, "list all secrets")
RootCmd.PersistentFlags().StringP("env", "e", "", "Create from a .env file")
RootCmd.PersistentFlags().StringP("fill", "f", "", "Fill a file with secrets")
RootCmd.PersistentFlags().BoolP("modify", "m", false, "Modify a secret in an interactive mode")
RootCmd.PersistentFlags().StringP("file-format", "F", "yaml", "File format")
}
31 changes: 19 additions & 12 deletions models/secrets.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package models

type Secrets struct {
Namespace string
Secret string
Set bool
Key string
Value string
Get bool
Delete bool
List bool
All bool
Operation string
EnvPath string
FillPath string
Namespace string
Secret string
Set bool
Key string
Value string
Get bool
Delete bool
List bool
All bool
Operation string
EnvPath string
FillPath string
Modify bool
FileFormat string
}

var SupportedFormats = map[string]struct{}{
"yaml": {},
"json": {},
}
Loading

0 comments on commit ee6ac72

Please sign in to comment.