forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.go
67 lines (57 loc) · 1.85 KB
/
model.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
56
57
58
59
60
61
62
63
64
65
66
67
package apikey
import (
"errors"
"time"
"github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/services/quota"
"github.com/grafana/grafana/pkg/services/user"
)
var (
ErrNotFound = errors.New("API key not found")
ErrInvalid = errors.New("invalid API key")
ErrInvalidExpiration = errors.New("negative value for SecondsToLive")
ErrDuplicate = errors.New("API key, organization ID and name must be unique")
)
type APIKey struct {
ID int64 `db:"id" xorm:"pk autoincr 'id'"`
OrgID int64 `db:"org_id" xorm:"org_id"`
Name string `db:"name"`
Key string `db:"key"`
Role org.RoleType `db:"role"`
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
LastUsedAt *time.Time `xorm:"last_used_at" db:"last_used_at"`
Expires *int64 `db:"expires"`
ServiceAccountId *int64 `db:"service_account_id"`
IsRevoked *bool `xorm:"is_revoked" db:"is_revoked"`
}
func (k APIKey) TableName() string { return "api_key" }
// swagger:model
type AddCommand struct {
Name string `json:"name" binding:"Required"`
Role org.RoleType `json:"role" binding:"Required"`
OrgID int64 `json:"-" xorm:"org_id"`
Key string `json:"-"`
SecondsToLive int64 `json:"secondsToLive"`
ServiceAccountID *int64 `json:"-"`
}
type DeleteCommand struct {
ID int64 `json:"id"`
OrgID int64 `json:"-"`
}
type GetApiKeysQuery struct {
OrgID int64
IncludeExpired bool
User *user.SignedInUser
}
type GetByNameQuery struct {
KeyName string
OrgID int64
}
type GetByIDQuery struct {
ApiKeyID int64
}
const (
QuotaTargetSrv quota.TargetSrv = "api_key"
QuotaTarget quota.Target = "api_key"
)