-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
group commands for users and servers
- Loading branch information
Sam Ban
committed
Sep 4, 2021
1 parent
faa0e5e
commit c429ab0
Showing
10 changed files
with
203 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Develop Test | ||
|
||
on: | ||
push: | ||
branches-ignore: | ||
- wip | ||
|
||
jobs: | ||
Test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Checkout submodules | ||
uses: textbook/git-checkout-submodule-action@master | ||
with: | ||
remote: true | ||
- name: Install Go | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: '1.17.x' | ||
- name: Checkout code | ||
uses: actions/checkout@v1 | ||
- name: Tests | ||
run: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// groupsCmd represents the groups command | ||
var groupsCmd = &cobra.Command{ | ||
Use: "groups", | ||
Short: "Modify user or server groups", | ||
Long: `Modify user's groups, or remove groups from user to allow global access: | ||
$ ./sshman groups user email@server.com group1 group2 | ||
Modify server groups or remove from all groups: | ||
$ ./sshman groups server serveralias group1 group2 | ||
`, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(groupsCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cmd | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/shoobyban/sshman/backend" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// groupsServerCmd represents the user group editing command | ||
var groupsServerCmd = &cobra.Command{ | ||
Use: "server", | ||
Short: "Modify group assignments for a server", | ||
Long: `Modify server groups or remove from all groups: | ||
$ ./sshman groups server serveralias group1 group2 | ||
`, | ||
Run: func(_ *cobra.Command, args []string) { | ||
cfg := backend.ReadConfig(backend.NewSFTP()) | ||
if len(args) < 1 { | ||
return | ||
} | ||
email := args[0] | ||
groups := args[1:] | ||
if host, ok := cfg.Hosts[args[0]]; ok { | ||
oldgroups := host.Groups | ||
host.Groups = groups | ||
cfg.Hosts[args[0]] = host | ||
cfg.Write() | ||
log.Printf("Groups for %s edited: %v\n", email, host.Groups) | ||
host.UpdateGroups(cfg, oldgroups) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
groupsCmd.AddCommand(groupsServerCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cmd | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/shoobyban/sshman/backend" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// groupsUserCmd represents the user group editing command | ||
var groupsUserCmd = &cobra.Command{ | ||
Use: "user", | ||
Short: "Modify group assignments of a user", | ||
Long: `Modify user's groups, or remove groups from user to allow global access: | ||
$ ./sshman groups user email@server.com group1 group2 | ||
`, | ||
Run: func(_ *cobra.Command, args []string) { | ||
cfg := backend.ReadConfig(backend.NewSFTP()) | ||
if len(args) < 1 { | ||
return | ||
} | ||
email := args[0] | ||
groups := args[1:] | ||
key, user := cfg.GetUserByEmail(email) | ||
if user != nil { | ||
oldgroups := user.Groups | ||
user.Groups = groups | ||
cfg.Users[key] = *user | ||
cfg.Write() | ||
log.Printf("Groups for %s edited: %v\n", email, groups) | ||
user.UpdateGroups(cfg, oldgroups) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
groupsCmd.AddCommand(groupsUserCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters