-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_admin.go
40 lines (34 loc) · 1.06 KB
/
session_admin.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
package cassh
import (
"context"
"net/url"
"time"
"github.com/krostar/httpclient"
)
// SessionAdmin exposes all admin related methods.
func (c *Client) SessionAdmin(opts ...SessionAdminOption) *SessionAdmin {
o := sessionAdminOptionsDefaults()
for _, opt := range opts {
opt(o)
}
return &SessionAdmin{
api: c.api.Clone(),
serverTimezone: c.serverTimezone,
authMechanism: o.authMechanism,
}
}
// SessionAdmin stores attributes useful to make admin related requests to the CASSH server.
type SessionAdmin struct {
api *httpclient.API
serverTimezone *time.Location
authMechanism SessionAuth
}
func (s *SessionAdmin) createRequestParameters() url.Values {
parameters := make(url.Values)
s.authMechanism.ExtendRequestParameters(parameters)
return parameters
}
// CheckAuthentication checks whenever the provided admin authentication mechanism is valid and authorized.
func (s *SessionAdmin) CheckAuthentication(ctx context.Context) error {
return s.api.Execute(ctx, s.api.Post("/test_auth").SendForm(s.createRequestParameters()))
}