Skip to content

Commit

Permalink
Add --user (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
dee-kryvenko committed May 15, 2022
1 parent fd319e9 commit 48dc781
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.2] - 2022-05-14

### Added

- Add `--user` options to force it to secure/undo a specific user rather than the entire `KUBECONFIG`

## [0.0.1] - 2022-05-12

### Added
Expand Down
14 changes: 14 additions & 0 deletions cmd/secure.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func FileExists(filename string) (bool, error) {

func init() {
secureCmd.Flags().StringP("kubeconfig", "c", "", "Kubeconfig path")
secureCmd.Flags().StringP("user", "u", "", "Secure specific user instead of all")

rootCmd.AddCommand(secureCmd)
}
Expand All @@ -53,7 +54,20 @@ var secureCmd = &cobra.Command{
log.Fatal(err)
}

specificUser, err := cmd.Flags().GetString("user")
if err != nil {
log.Fatal(err)
}
if specificUser != "" {
fmt.Printf("Looking up for a specific user %s\n", specificUser)
}

for name, user := range cfg.AuthInfos {
if specificUser != "" && specificUser != name {
fmt.Printf("Skip user %s: not a %s\n", name, specificUser)
continue
}

if len(user.ClientCertificateData) == 0 && len(user.ClientKeyData) == 0 && user.Username == "" && user.Password == "" {
fmt.Printf("Skip user %s: nothing to secure\n", name)
continue
Expand Down
14 changes: 14 additions & 0 deletions cmd/undo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

func init() {
undoCmd.Flags().StringP("kubeconfig", "c", "", "Kubeconfig path")
undoCmd.Flags().StringP("user", "u", "", "Secure specific user instead of all")

rootCmd.AddCommand(undoCmd)
}
Expand All @@ -31,7 +32,20 @@ var undoCmd = &cobra.Command{
log.Fatal(err)
}

specificUser, err := cmd.Flags().GetString("user")
if err != nil {
log.Fatal(err)
}
if specificUser != "" {
fmt.Printf("Looking up for a specific user %s\n", specificUser)
}

for name, user := range cfg.AuthInfos {
if specificUser != "" && specificUser != name {
fmt.Printf("Skip user %s: not a %s\n", name, specificUser)
continue
}

fmt.Printf("Found user: %s\n", name)

if user.Exec == nil || !strings.HasSuffix(user.Exec.Command, executable) {
Expand Down

0 comments on commit 48dc781

Please sign in to comment.