Skip to content

Commit 48dc781

Browse files
authored
Add --user (#2)
1 parent fd319e9 commit 48dc781

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.0.2] - 2022-05-14
11+
12+
### Added
13+
14+
- Add `--user` options to force it to secure/undo a specific user rather than the entire `KUBECONFIG`
15+
1016
## [0.0.1] - 2022-05-12
1117

1218
### Added

cmd/secure.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func FileExists(filename string) (bool, error) {
3737

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

4142
rootCmd.AddCommand(secureCmd)
4243
}
@@ -53,7 +54,20 @@ var secureCmd = &cobra.Command{
5354
log.Fatal(err)
5455
}
5556

57+
specificUser, err := cmd.Flags().GetString("user")
58+
if err != nil {
59+
log.Fatal(err)
60+
}
61+
if specificUser != "" {
62+
fmt.Printf("Looking up for a specific user %s\n", specificUser)
63+
}
64+
5665
for name, user := range cfg.AuthInfos {
66+
if specificUser != "" && specificUser != name {
67+
fmt.Printf("Skip user %s: not a %s\n", name, specificUser)
68+
continue
69+
}
70+
5771
if len(user.ClientCertificateData) == 0 && len(user.ClientKeyData) == 0 && user.Username == "" && user.Password == "" {
5872
fmt.Printf("Skip user %s: nothing to secure\n", name)
5973
continue

cmd/undo.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

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

1920
rootCmd.AddCommand(undoCmd)
2021
}
@@ -31,7 +32,20 @@ var undoCmd = &cobra.Command{
3132
log.Fatal(err)
3233
}
3334

35+
specificUser, err := cmd.Flags().GetString("user")
36+
if err != nil {
37+
log.Fatal(err)
38+
}
39+
if specificUser != "" {
40+
fmt.Printf("Looking up for a specific user %s\n", specificUser)
41+
}
42+
3443
for name, user := range cfg.AuthInfos {
44+
if specificUser != "" && specificUser != name {
45+
fmt.Printf("Skip user %s: not a %s\n", name, specificUser)
46+
continue
47+
}
48+
3549
fmt.Printf("Found user: %s\n", name)
3650

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

0 commit comments

Comments
 (0)