2015-01-27 01:26:11 -06:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2021-04-28 06:30:09 -05:00
|
|
|
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")
|
|
|
|
)
|
2015-01-27 01:26:11 -06:00
|
|
|
|
|
|
|
type ApiKey struct {
|
2015-02-23 13:07:49 -06:00
|
|
|
Id int64
|
|
|
|
OrgId int64
|
|
|
|
Name string
|
|
|
|
Key string
|
|
|
|
Role RoleType
|
|
|
|
Created time.Time
|
|
|
|
Updated time.Time
|
2019-06-26 01:47:03 -05:00
|
|
|
Expires *int64
|
2015-01-27 01:26:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------
|
|
|
|
// COMMANDS
|
|
|
|
type AddApiKeyCommand struct {
|
2019-06-26 01:47:03 -05:00
|
|
|
Name string `json:"name" binding:"Required"`
|
|
|
|
Role RoleType `json:"role" binding:"Required"`
|
|
|
|
OrgId int64 `json:"-"`
|
|
|
|
Key string `json:"-"`
|
|
|
|
SecondsToLive int64 `json:"secondsToLive"`
|
2015-01-27 01:26:11 -06:00
|
|
|
|
|
|
|
Result *ApiKey `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type DeleteApiKeyCommand struct {
|
2015-02-23 13:07:49 -06:00
|
|
|
Id int64 `json:"id"`
|
|
|
|
OrgId int64 `json:"-"`
|
2015-01-27 01:26:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------
|
|
|
|
// QUERIES
|
|
|
|
|
|
|
|
type GetApiKeysQuery struct {
|
2019-06-26 01:47:03 -05:00
|
|
|
OrgId int64
|
2019-11-20 05:14:57 -06:00
|
|
|
IncludeExpired bool
|
2019-06-26 01:47:03 -05:00
|
|
|
Result []*ApiKey
|
2015-01-27 01:26:11 -06:00
|
|
|
}
|
|
|
|
|
2015-02-26 10:23:28 -06:00
|
|
|
type GetApiKeyByNameQuery struct {
|
|
|
|
KeyName string
|
|
|
|
OrgId int64
|
|
|
|
Result *ApiKey
|
2015-01-27 01:26:11 -06:00
|
|
|
}
|
|
|
|
|
2015-04-08 01:59:12 -05:00
|
|
|
type GetApiKeyByIdQuery struct {
|
|
|
|
ApiKeyId int64
|
|
|
|
Result *ApiKey
|
|
|
|
}
|
|
|
|
|
2015-01-27 01:26:11 -06:00
|
|
|
// ------------------------
|
|
|
|
// DTO & Projections
|
|
|
|
|
|
|
|
type ApiKeyDTO struct {
|
2019-06-26 01:47:03 -05:00
|
|
|
Id int64 `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Role RoleType `json:"role"`
|
|
|
|
Expiration *time.Time `json:"expiration,omitempty"`
|
2015-01-27 01:26:11 -06:00
|
|
|
}
|