File tree Expand file tree Collapse file tree 4 files changed +117
-0
lines changed
Expand file tree Collapse file tree 4 files changed +117
-0
lines changed Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "fmt"
5+ "os"
6+
7+ "github.com/spf13/cobra"
8+ "github.com/ubuntu/authd/cmd/authctl/user"
9+ )
10+
11+ const cmdName = "authctl"
12+
13+ var rootCmd = & cobra.Command {
14+ Use : fmt .Sprintf ("%s COMMAND" , cmdName ),
15+ Short : "CLI tool to interact with authd services" ,
16+ Long : "authctl is a CLI tool which can be used to interact with various authd services." ,
17+ Args : cobra .NoArgs ,
18+ Run : func (cmd * cobra.Command , args []string ) {},
19+ }
20+
21+ func init () {
22+ rootCmd .AddCommand (user .UserCmd )
23+ }
24+
25+ func main () {
26+ if err := rootCmd .Execute (); err != nil {
27+ fmt .Fprintf (os .Stderr , "Error while executing authctl '%s'\n " , err )
28+ os .Exit (1 )
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ package user
2+
3+ import (
4+ "context"
5+ "fmt"
6+
7+ "github.com/spf13/cobra"
8+ "github.com/ubuntu/authd/internal/consts"
9+ "github.com/ubuntu/authd/internal/proto/authd"
10+ "google.golang.org/grpc"
11+ "google.golang.org/grpc/credentials/insecure"
12+ )
13+
14+ var DisableCmd = & cobra.Command {
15+ Use : "disable" ,
16+ Short : "Disable a user to log in" ,
17+ Args : cobra .ExactArgs (1 ),
18+ RunE : func (cmd * cobra.Command , args []string ) error {
19+ fmt .Printf ("Disabling user %s\n " , args [0 ])
20+ conn , err := grpc .NewClient ("unix://" + consts .DefaultSocketPath , grpc .WithTransportCredentials (insecure .NewCredentials ()))
21+
22+ if err != nil {
23+ return err
24+ }
25+
26+ client := authd .NewNSSClient (conn )
27+ _ , err = client .EnablePasswd (context .Background (), & authd.EnablePasswdRequest {Name : args [0 ]})
28+
29+ if err != nil {
30+ return err
31+ }
32+
33+ return nil
34+ },
35+ }
Original file line number Diff line number Diff line change 1+ package user
2+
3+ import (
4+ "context"
5+ "fmt"
6+
7+ "github.com/spf13/cobra"
8+ "github.com/ubuntu/authd/internal/consts"
9+ "github.com/ubuntu/authd/internal/proto/authd"
10+ "google.golang.org/grpc"
11+ "google.golang.org/grpc/credentials/insecure"
12+ )
13+
14+ var EnableCmd = & cobra.Command {
15+ Use : "enable" ,
16+ Short : "Enable a user to log in" ,
17+ Args : cobra .ExactArgs (1 ),
18+ RunE : func (cmd * cobra.Command , args []string ) error {
19+ fmt .Printf ("Enabling user %s\n " , args [0 ])
20+ conn , err := grpc .NewClient ("unix://" + consts .DefaultSocketPath , grpc .WithTransportCredentials (insecure .NewCredentials ()))
21+
22+ if err != nil {
23+ return err
24+ }
25+
26+ client := authd .NewNSSClient (conn )
27+ _ , err = client .EnablePasswd (context .Background (), & authd.EnablePasswdRequest {Name : args [0 ]})
28+
29+ if err != nil {
30+ return err
31+ }
32+
33+ return nil
34+ },
35+ }
Original file line number Diff line number Diff line change 1+ package user
2+
3+ import (
4+ "github.com/spf13/cobra"
5+ )
6+
7+ var UserCmd = & cobra.Command {
8+ Use : "user" ,
9+ Short : "Commands retaled to working with users" ,
10+ Args : cobra .NoArgs ,
11+ Run : func (cmd * cobra.Command , args []string ) {},
12+ }
13+
14+ func init () {
15+ UserCmd .AddCommand (DisableCmd )
16+ UserCmd .AddCommand (EnableCmd )
17+ }
You can’t perform that action at this time.
0 commit comments