Skip to content

Commit 509acd3

Browse files
committed
first user modify functionality
1 parent cf23edd commit 509acd3

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
_obj
88
_test
99

10+
# Configurations
11+
*.conf
12+
1013
# Architecture specific extensions/prefixes
1114
*.[568vq]
1215
[568vq].out

securepassctl.go

+41
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,43 @@ func (s *SecurePass) UserAdd(user *UserDescriptor) (*UserAddResponse, error) {
495495
return &obj, err
496496
}
497497

498+
// Modify a user in SecurePass
499+
func (s *SecurePass) UserMod(username string, user *UserDescriptor) (*Response, error) {
500+
var obj Response
501+
502+
data := url.Values{}
503+
data.Set("USERNAME", user.Username)
504+
505+
if user.Name != "" {
506+
data.Set("NAME", user.Name)
507+
}
508+
if user.Surname != "" {
509+
data.Set("SURNAME", user.Surname)
510+
}
511+
if user.Email != "" {
512+
data.Set("EMAIL", user.Email)
513+
}
514+
if user.Mobile != "" {
515+
data.Set("MOBILE", user.Mobile)
516+
}
517+
if user.Nin != "" {
518+
data.Set("NIN", user.Nin)
519+
}
520+
if user.Rfid != "" {
521+
data.Set("RFID", user.Rfid)
522+
}
523+
if user.Manager != "" {
524+
data.Set("MANAGER", user.Manager)
525+
}
526+
527+
req, err := s.NewRequest("POST", "/api/v1/users/modify", &data)
528+
if err != nil {
529+
return nil, err
530+
}
531+
err = s.DoRequest(req, &obj, 200)
532+
return &obj, err
533+
}
534+
498535
// UserDel deletes a user from SecurePass
499536
func (s *SecurePass) UserDel(username string) (*Response, error) {
500537
var obj Response
@@ -638,6 +675,10 @@ func (s *SecurePass) UserXattrsSet(username, attribute, value string) (*Response
638675
return &obj, err
639676
}
640677

678+
/*
679+
* Radius operations
680+
*/
681+
641682
// RadiusAdd adds a RADIUS to SecurePass RADIUS
642683
func (s *SecurePass) RadiusAdd(radius *RadiusDescriptor) (*Response, error) {
643684
var obj Response

spctl/cmd/user/mod.go

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package user
2+
3+
import (
4+
"log"
5+
6+
"github.com/codegangsta/cli"
7+
"github.com/garlsecurity/securepassctl"
8+
"github.com/garlsecurity/securepassctl/spctl/service"
9+
)
10+
11+
func init() {
12+
Command.Subcommands = append(Command.Subcommands,
13+
cli.Command{
14+
Name: "mod",
15+
Usage: "modify user",
16+
ArgsUsage: "USERNAME",
17+
Description: "Modify user information.",
18+
Action: ActionMod,
19+
Flags: []cli.Flag{
20+
cli.StringFlag{
21+
Name: "name, n",
22+
Usage: "First name",
23+
},
24+
cli.StringFlag{
25+
Name: "surname, s",
26+
Usage: "Last name",
27+
},
28+
cli.StringFlag{
29+
Name: "email, e",
30+
Usage: "E-mail",
31+
},
32+
cli.StringFlag{
33+
Name: "mobile, m",
34+
Usage: "Mobile number",
35+
},
36+
cli.StringFlag{
37+
Name: "nin",
38+
Usage: "National Identification Number (optional)",
39+
},
40+
cli.StringFlag{
41+
Name: "rfid",
42+
Usage: "RFID tag (optional)",
43+
},
44+
cli.StringFlag{
45+
Name: "manager",
46+
Usage: "Manager user id (optional)",
47+
},
48+
},
49+
})
50+
}
51+
52+
// ActionMod provides the radius mod command
53+
func ActionMod(c *cli.Context) {
54+
if len(c.Args()) != 1 {
55+
log.Fatal("error: must specify a username")
56+
}
57+
username := c.Args()[0]
58+
securepassctl.DebugLogger.Printf("Modifying user %q", username)
59+
60+
61+
_, err := service.Service.UserMod(username, &securepassctl.UserDescriptor{
62+
Username: username,
63+
Name: c.String("name"),
64+
Surname: c.String("surname"),
65+
Email: c.String("email"),
66+
Mobile: c.String("mobile"),
67+
Nin: c.String("nin"),
68+
Rfid: c.String("rfid"),
69+
Manager: c.String("manager"),
70+
})
71+
72+
if err != nil {
73+
log.Fatalf("error: %v", err)
74+
}
75+
76+
}

0 commit comments

Comments
 (0)