2021-11-11 09:10:24 -06:00
|
|
|
package serviceaccounts
|
|
|
|
|
2022-02-08 07:31:34 -06:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
2022-08-04 07:19:09 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/apikey"
|
2022-08-10 04:56:48 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/org"
|
2022-02-08 07:31:34 -06:00
|
|
|
)
|
2021-11-11 09:10:24 -06:00
|
|
|
|
|
|
|
var (
|
|
|
|
ScopeAll = "serviceaccounts:*"
|
2022-02-07 07:51:54 -06:00
|
|
|
ScopeID = accesscontrol.Scope("serviceaccounts", "id", accesscontrol.Parameter(":serviceAccountId"))
|
2021-11-11 09:10:24 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2022-07-08 04:53:18 -05:00
|
|
|
ActionRead = "serviceaccounts:read"
|
|
|
|
ActionWrite = "serviceaccounts:write"
|
|
|
|
ActionCreate = "serviceaccounts:create"
|
|
|
|
ActionDelete = "serviceaccounts:delete"
|
|
|
|
ActionPermissionsRead = "serviceaccounts.permissions:read"
|
|
|
|
ActionPermissionsWrite = "serviceaccounts.permissions:write"
|
2021-11-11 09:10:24 -06:00
|
|
|
)
|
2021-12-14 07:39:25 -06:00
|
|
|
|
|
|
|
type ServiceAccount struct {
|
|
|
|
Id int64
|
|
|
|
}
|
|
|
|
|
2022-07-19 04:52:51 -05:00
|
|
|
// swagger:model
|
2022-06-16 09:02:03 -05:00
|
|
|
type CreateServiceAccountForm struct {
|
2022-07-19 04:52:51 -05:00
|
|
|
// example: grafana
|
|
|
|
Name string `json:"name" binding:"Required"`
|
|
|
|
// example: Admin
|
2022-08-10 04:56:48 -05:00
|
|
|
Role *org.RoleType `json:"role"`
|
2022-07-19 04:52:51 -05:00
|
|
|
// example: false
|
|
|
|
IsDisabled *bool `json:"isDisabled"`
|
2022-06-16 09:02:03 -05:00
|
|
|
}
|
|
|
|
|
2022-07-19 04:52:51 -05:00
|
|
|
// swagger:model
|
2022-02-17 06:19:58 -06:00
|
|
|
type UpdateServiceAccountForm struct {
|
2022-08-10 04:56:48 -05:00
|
|
|
Name *string `json:"name"`
|
|
|
|
Role *org.RoleType `json:"role"`
|
|
|
|
IsDisabled *bool `json:"isDisabled"`
|
2022-02-17 06:19:58 -06:00
|
|
|
}
|
|
|
|
|
2022-07-19 04:52:51 -05:00
|
|
|
// swagger: model
|
2022-02-08 07:31:34 -06:00
|
|
|
type ServiceAccountDTO struct {
|
2022-07-19 04:52:51 -05:00
|
|
|
Id int64 `json:"id" xorm:"user_id"`
|
|
|
|
// example: grafana
|
|
|
|
Name string `json:"name" xorm:"name"`
|
|
|
|
// example: sa-grafana
|
|
|
|
Login string `json:"login" xorm:"login"`
|
|
|
|
// example: 1
|
|
|
|
OrgId int64 `json:"orgId" xorm:"org_id"`
|
|
|
|
// example: false
|
|
|
|
IsDisabled bool `json:"isDisabled" xorm:"is_disabled"`
|
|
|
|
// example: Viewer
|
|
|
|
Role string `json:"role" xorm:"role"`
|
|
|
|
// example: 0
|
|
|
|
Tokens int64 `json:"tokens"`
|
|
|
|
// example: /avatar/85ec38023d90823d3e5b43ef35646af9
|
|
|
|
AvatarUrl string `json:"avatarUrl"`
|
|
|
|
// example: {"serviceaccounts:delete": true, "serviceaccounts:read": true, "serviceaccounts:write": true}
|
2022-02-08 13:19:22 -06:00
|
|
|
AccessControl map[string]bool `json:"accessControl,omitempty"`
|
2022-02-08 07:31:34 -06:00
|
|
|
}
|
2022-04-13 11:11:03 -05:00
|
|
|
|
2022-08-18 09:54:39 -05:00
|
|
|
type GetSATokensQuery struct {
|
|
|
|
OrgID *int64 // optional filtering by org ID
|
|
|
|
ServiceAccountID *int64 // optional filtering by service account ID
|
|
|
|
}
|
|
|
|
|
2022-04-13 11:11:03 -05:00
|
|
|
type AddServiceAccountTokenCommand struct {
|
|
|
|
Name string `json:"name" binding:"Required"`
|
|
|
|
OrgId int64 `json:"-"`
|
|
|
|
Key string `json:"-"`
|
|
|
|
SecondsToLive int64 `json:"secondsToLive"`
|
2022-08-04 07:19:09 -05:00
|
|
|
Result *apikey.APIKey `json:"-"`
|
2022-04-13 11:11:03 -05:00
|
|
|
}
|
|
|
|
|
2022-07-19 04:52:51 -05:00
|
|
|
// swagger: model
|
2022-03-14 12:24:07 -05:00
|
|
|
type SearchServiceAccountsResult struct {
|
2022-07-19 04:52:51 -05:00
|
|
|
// It can be used for pagination of the user list
|
|
|
|
// E.g. if totalCount is equal to 100 users and
|
|
|
|
// the perpage parameter is set to 10 then there are 10 pages of users.
|
2022-03-14 12:24:07 -05:00
|
|
|
TotalCount int64 `json:"totalCount"`
|
|
|
|
ServiceAccounts []*ServiceAccountDTO `json:"serviceAccounts"`
|
|
|
|
Page int `json:"page"`
|
|
|
|
PerPage int `json:"perPage"`
|
|
|
|
}
|
2022-02-08 07:31:34 -06:00
|
|
|
|
2022-07-19 04:52:51 -05:00
|
|
|
// swagger:model
|
2022-02-08 07:31:34 -06:00
|
|
|
type ServiceAccountProfileDTO struct {
|
2022-07-19 04:52:51 -05:00
|
|
|
// example: 2
|
|
|
|
Id int64 `json:"id" xorm:"user_id"`
|
|
|
|
// example: test
|
|
|
|
Name string `json:"name" xorm:"name"`
|
|
|
|
// example: sa-grafana
|
|
|
|
Login string `json:"login" xorm:"login"`
|
|
|
|
// example: 1
|
|
|
|
OrgId int64 `json:"orgId" xorm:"org_id"`
|
|
|
|
// example: false
|
|
|
|
IsDisabled bool `json:"isDisabled" xorm:"is_disabled"`
|
|
|
|
// example: 2022-03-21T14:35:33Z
|
|
|
|
Created time.Time `json:"createdAt" xorm:"created"`
|
|
|
|
// example: 2022-03-21T14:35:33Z
|
|
|
|
Updated time.Time `json:"updatedAt" xorm:"updated"`
|
|
|
|
// example: /avatar/8ea890a677d6a223c591a1beea6ea9d2
|
|
|
|
AvatarUrl string `json:"avatarUrl" xorm:"-"`
|
|
|
|
// example: Editor
|
|
|
|
Role string `json:"role" xorm:"role"`
|
|
|
|
// example: []
|
2022-03-01 02:21:55 -06:00
|
|
|
Teams []string `json:"teams" xorm:"-"`
|
2022-06-01 02:35:16 -05:00
|
|
|
Tokens int64 `json:"tokens,omitempty"`
|
2022-03-01 02:21:55 -06:00
|
|
|
AccessControl map[string]bool `json:"accessControl,omitempty" xorm:"-"`
|
2022-02-08 07:31:34 -06:00
|
|
|
}
|
2022-03-18 09:50:34 -05:00
|
|
|
|
|
|
|
type ServiceAccountFilter string // used for filtering
|
|
|
|
|
2022-06-15 07:59:40 -05:00
|
|
|
type APIKeysMigrationStatus struct {
|
|
|
|
Migrated bool `json:"migrated"`
|
|
|
|
}
|
|
|
|
|
2022-03-18 09:50:34 -05:00
|
|
|
const (
|
|
|
|
FilterOnlyExpiredTokens ServiceAccountFilter = "expiredTokens"
|
2022-06-01 02:35:16 -05:00
|
|
|
FilterOnlyDisabled ServiceAccountFilter = "disabled"
|
2022-03-18 09:50:34 -05:00
|
|
|
FilterIncludeAll ServiceAccountFilter = "all"
|
|
|
|
)
|