Skip to content

Commit 8ec2803

Browse files
committed
added create/delete user logic
Signed-off-by: evgkg <gureev.e.98@mail.ru>
1 parent 9894000 commit 8ec2803

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

user.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dtrack
22

33
import (
44
"context"
5+
"fmt"
56
"net/http"
67
"net/url"
78
)
@@ -43,3 +44,44 @@ func (us UserService) ForceChangePassword(ctx context.Context, username, passwor
4344
_, err = us.client.doRequest(req, nil)
4445
return
4546
}
47+
48+
type UserDefinitions struct {
49+
Username string `json:"username"`
50+
NewPassword string `json:"newPassword"`
51+
ConfirmPassword string `json:"confirmPassword"`
52+
FullName string `json:"fullname"`
53+
Email string `json:"email"`
54+
Suspended bool `json:"suspended,omitempty"`
55+
ForcePasswordChange bool `json:"forcePasswordChange,omitempty"`
56+
NonExpiryPassword bool `json:"nonExpiryPassword,omitempty"`
57+
58+
//TODO: LastPasswordChange, Teams, Permissions
59+
}
60+
61+
func (us UserService) CreateUser(ctx context.Context, user *UserDefinitions, token string) (err error) {
62+
63+
req, err := us.client.newRequest(ctx, http.MethodPut, "/api/v1/user/managed", withBody(user))
64+
if err != nil {
65+
return
66+
}
67+
68+
req.Header.Set("Accept", "*/*")
69+
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
70+
71+
_, err = us.client.doRequest(req, nil)
72+
return
73+
}
74+
75+
func (us UserService) DeleteUser(ctx context.Context, user *UserDefinitions, token string) (err error) {
76+
77+
req, err := us.client.newRequest(ctx, http.MethodDelete, "/api/v1/user/managed", withBody(user))
78+
if err != nil {
79+
return
80+
}
81+
82+
req.Header.Set("Accept", "*/*")
83+
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
84+
85+
_, err = us.client.doRequest(req, nil)
86+
return
87+
}

0 commit comments

Comments
 (0)