mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 12:44:10 -06:00
5cb03d6e62
* ServiceAccounts: Fix token-apikey cross deletion * ServiceAccounts: separate API key store and service account token store * ServiceAccounts: hide service account tokens from API Keys page * ServiceAccounts: uppercase statement * ServiceAccounts: fix and add new tests for SAT store * ServiceAccounts: remove service account ID from add API key * ServiceAccounts: clear up errors
72 lines
1.5 KiB
Go
72 lines
1.5 KiB
Go
package models
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
ErrApiKeyNotFound = errors.New("API key not found")
|
|
ErrInvalidApiKey = errors.New("invalid API key")
|
|
ErrInvalidApiKeyExpiration = errors.New("negative value for SecondsToLive")
|
|
ErrDuplicateApiKey = errors.New("API key, organization ID and name must be unique")
|
|
)
|
|
|
|
type ApiKey struct {
|
|
Id int64
|
|
OrgId int64
|
|
Name string
|
|
Key string
|
|
Role RoleType
|
|
Created time.Time
|
|
Updated time.Time
|
|
Expires *int64
|
|
ServiceAccountId *int64
|
|
}
|
|
|
|
// ---------------------
|
|
// COMMANDS
|
|
type AddApiKeyCommand struct {
|
|
Name string `json:"name" binding:"Required"`
|
|
Role RoleType `json:"role" binding:"Required"`
|
|
OrgId int64 `json:"-"`
|
|
Key string `json:"-"`
|
|
SecondsToLive int64 `json:"secondsToLive"`
|
|
Result *ApiKey `json:"-"`
|
|
}
|
|
|
|
type DeleteApiKeyCommand struct {
|
|
Id int64 `json:"id"`
|
|
OrgId int64 `json:"-"`
|
|
}
|
|
|
|
// ----------------------
|
|
// QUERIES
|
|
|
|
type GetApiKeysQuery struct {
|
|
OrgId int64
|
|
IncludeExpired bool
|
|
Result []*ApiKey
|
|
}
|
|
|
|
type GetApiKeyByNameQuery struct {
|
|
KeyName string
|
|
OrgId int64
|
|
Result *ApiKey
|
|
}
|
|
|
|
type GetApiKeyByIdQuery struct {
|
|
ApiKeyId int64
|
|
Result *ApiKey
|
|
}
|
|
|
|
// ------------------------
|
|
// DTO & Projections
|
|
|
|
type ApiKeyDTO struct {
|
|
Id int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
Role RoleType `json:"role"`
|
|
Expiration *time.Time `json:"expiration,omitempty"`
|
|
}
|