-
Notifications
You must be signed in to change notification settings - Fork 0
/
accesstokens.go
46 lines (38 loc) · 1004 Bytes
/
accesstokens.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
package api
import (
"context"
log "github.com/sirupsen/logrus"
)
func (a *API) createAccessToken(ctx context.Context, x struct {
ID string `json:"id"`
Type string `json:"type"`
}) Response {
token, err := a.accessTokens.Create(x.ID, x.Type)
if err != nil {
return NewErrorResponse(err)
}
return NewSuccessResponse(token)
}
func (a *API) listAccessTokens(ctx context.Context) Response {
tokens, err := a.accessTokens.List()
if err != nil {
log.Errorf("listAccessTokens: %v", err)
return NewErrorResponse(err)
}
return NewSuccessResponse(tokens)
}
func (a *API) deleteAccessToken(ctx context.Context, x struct {
ID string `json:"id"`
}) Response {
a.accessTokens.Delete(x.ID)
return NewSuccessResponse(nil)
}
func (a *API) checkAccessToken(ctx context.Context, x struct {
ID string `json:"id"`
Secret string `json:"secret"`
}) Response {
if err := a.accessTokens.Check(x.ID, x.Secret); err != nil {
return NewErrorResponse(err)
}
return NewSuccessResponse(nil)
}