-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_admin_user.go
55 lines (44 loc) · 1.42 KB
/
session_admin_user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package cassh
import (
"context"
"net/http"
"net/url"
"strconv"
"time"
"github.com/krostar/httpclient"
)
// User sets the user on which further commands will be applied.
func (s *SessionAdmin) User(username Username) *SessionAdminUser {
return &SessionAdminUser{
api: s.api.Clone(),
serverTimezone: s.serverTimezone,
parentCreateRequestParameters: s.createRequestParameters,
username: username,
}
}
// SessionAdminUser stores attributes useful to make admin requests related to a specific user, to the CASSH server.
type SessionAdminUser struct {
api *httpclient.API
serverTimezone *time.Location
parentCreateRequestParameters func() url.Values
username Username
}
func (s *SessionAdminUser) createRequestParameters() url.Values {
return s.parentCreateRequestParameters()
}
// Status returns the current user status.
func (s *SessionAdminUser) Status(ctx context.Context) (*UserStatus, error) {
requestParameters := s.createRequestParameters()
requestParameters.Set("status", strconv.FormatBool(true))
var response apiUserStatusResponse
if err := s.api.
Do(ctx, s.api.
Post("/admin/{username}").
PathReplacer("{username}", s.username.String()).
SendForm(requestParameters)).
ReceiveJSON(http.StatusOK, &response).
Error(); err != nil {
return nil, err
}
return dtoUserStatusResponse(response, s.serverTimezone)
}