File tree 4 files changed +118
-0
lines changed
4 files changed +118
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Package main implements Cobra commands for management operations on authd.
2
+ package main
3
+
4
+ import (
5
+ "fmt"
6
+ "os"
7
+
8
+ "github.com/spf13/cobra"
9
+ "github.com/ubuntu/authd/cmd/authctl/user"
10
+ )
11
+
12
+ const cmdName = "authctl"
13
+
14
+ var rootCmd = & cobra.Command {
15
+ Use : fmt .Sprintf ("%s COMMAND" , cmdName ),
16
+ Short : "CLI tool to interact with authd" ,
17
+ Long : "authctl is a CLI tool which can be used to interact with authd." ,
18
+ Args : cobra .NoArgs ,
19
+ Run : func (cmd * cobra.Command , args []string ) {},
20
+ }
21
+
22
+ func init () {
23
+ rootCmd .AddCommand (user .UserCmd )
24
+ }
25
+
26
+ func main () {
27
+ if err := rootCmd .Execute (); err != nil {
28
+ fmt .Fprintln (os .Stderr , err .Error ())
29
+ os .Exit (1 )
30
+ }
31
+ }
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
+ // DisableCmd is a command to disable a user.
15
+ var DisableCmd = & cobra.Command {
16
+ Use : "disable" ,
17
+ Short : "Disable a user managed by authd" ,
18
+ Args : cobra .ExactArgs (1 ),
19
+ RunE : func (cmd * cobra.Command , args []string ) error {
20
+ fmt .Printf ("Disabling user %s\n " , args [0 ])
21
+ conn , err := grpc .NewClient ("unix://" + consts .DefaultSocketPath , grpc .WithTransportCredentials (insecure .NewCredentials ()))
22
+ if err != nil {
23
+ return err
24
+ }
25
+
26
+ client := authd .NewNSSClient (conn )
27
+ _ , err = client .DisableUser (context .Background (), & authd.DisableUserRequest {Name : args [0 ]})
28
+ if err != nil {
29
+ return err
30
+ }
31
+
32
+ return nil
33
+ },
34
+ }
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
+ // EnableCmd is a command to enable a user.
15
+ var EnableCmd = & cobra.Command {
16
+ Use : "enable" ,
17
+ Short : "Enable a user managed by authd" ,
18
+ Args : cobra .ExactArgs (1 ),
19
+ RunE : func (cmd * cobra.Command , args []string ) error {
20
+ fmt .Printf ("Enabling user %s\n " , args [0 ])
21
+ conn , err := grpc .NewClient ("unix://" + consts .DefaultSocketPath , grpc .WithTransportCredentials (insecure .NewCredentials ()))
22
+ if err != nil {
23
+ return err
24
+ }
25
+
26
+ client := authd .NewNSSClient (conn )
27
+ _ , err = client .EnableUser (context .Background (), & authd.EnableUserRequest {Name : args [0 ]})
28
+ if err != nil {
29
+ return err
30
+ }
31
+
32
+ return nil
33
+ },
34
+ }
Original file line number Diff line number Diff line change
1
+ // Package user provides utilities for managing user operations.
2
+ package user
3
+
4
+ import (
5
+ "github.com/spf13/cobra"
6
+ )
7
+
8
+ // UserCmd is a command to perform user-related operations.
9
+ var UserCmd = & cobra.Command {
10
+ Use : "user" ,
11
+ Short : "Commands retaled to users" ,
12
+ Args : cobra .NoArgs ,
13
+ Run : func (cmd * cobra.Command , args []string ) {},
14
+ }
15
+
16
+ func init () {
17
+ UserCmd .AddCommand (DisableCmd )
18
+ UserCmd .AddCommand (EnableCmd )
19
+ }
You can’t perform that action at this time.
0 commit comments