Skip to content

Commit

Permalink
added create/delete user logic
Browse files Browse the repository at this point in the history
Signed-off-by: evgkg <[email protected]>
  • Loading branch information
evgkg committed Aug 30, 2023
1 parent 9894000 commit 8ec2803
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dtrack

import (
"context"
"fmt"
"net/http"
"net/url"
)
Expand Down Expand Up @@ -43,3 +44,44 @@ func (us UserService) ForceChangePassword(ctx context.Context, username, passwor
_, err = us.client.doRequest(req, nil)
return
}

type UserDefinitions struct {
Username string `json:"username"`
NewPassword string `json:"newPassword"`
ConfirmPassword string `json:"confirmPassword"`
FullName string `json:"fullname"`
Email string `json:"email"`
Suspended bool `json:"suspended,omitempty"`
ForcePasswordChange bool `json:"forcePasswordChange,omitempty"`
NonExpiryPassword bool `json:"nonExpiryPassword,omitempty"`

//TODO: LastPasswordChange, Teams, Permissions
}

func (us UserService) CreateUser(ctx context.Context, user *UserDefinitions, token string) (err error) {

req, err := us.client.newRequest(ctx, http.MethodPut, "/api/v1/user/managed", withBody(user))
if err != nil {
return
}

req.Header.Set("Accept", "*/*")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))

_, err = us.client.doRequest(req, nil)
return
}

func (us UserService) DeleteUser(ctx context.Context, user *UserDefinitions, token string) (err error) {

req, err := us.client.newRequest(ctx, http.MethodDelete, "/api/v1/user/managed", withBody(user))
if err != nil {
return
}

req.Header.Set("Accept", "*/*")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))

_, err = us.client.doRequest(req, nil)
return
}

0 comments on commit 8ec2803

Please sign in to comment.