Introduce service accounts and bootstrap tokens (#22)

This commit is contained in:
Nikolay Edigaryev
2023-02-21 11:34:12 -05:00
committed by GitHub
parent edb9b3d693
commit 8df31f7c2d
37 changed files with 1245 additions and 40 deletions
+8
View File
@@ -0,0 +1,8 @@
package v1
type ServiceAccount struct {
Token string
Roles []ServiceAccountRole
Meta
}
+45
View File
@@ -0,0 +1,45 @@
package v1
import (
"errors"
"fmt"
)
var ErrUnsupportedServiceAccountRole = errors.New("unsupported service account role")
type ServiceAccountRole string
const (
ServiceAccountRoleWorker ServiceAccountRole = "worker"
ServiceAccountRoleComputeRead ServiceAccountRole = "compute:read"
ServiceAccountRoleComputeWrite ServiceAccountRole = "compute:write"
ServiceAccountRoleAdminRead ServiceAccountRole = "admin:read"
ServiceAccountRoleAdminWrite ServiceAccountRole = "admin:write"
)
func NewServiceAccountRole(name string) (ServiceAccountRole, error) {
switch name {
case string(ServiceAccountRoleWorker):
return ServiceAccountRoleWorker, nil
case string(ServiceAccountRoleComputeRead):
return ServiceAccountRoleComputeRead, nil
case string(ServiceAccountRoleComputeWrite):
return ServiceAccountRoleComputeWrite, nil
case string(ServiceAccountRoleAdminRead):
return ServiceAccountRoleAdminRead, nil
case string(ServiceAccountRoleAdminWrite):
return ServiceAccountRoleAdminWrite, nil
default:
return "", fmt.Errorf("%w: %s", ErrUnsupportedServiceAccountRole, name)
}
}
func AllServiceAccountRoles() []ServiceAccountRole {
return []ServiceAccountRole{
ServiceAccountRoleWorker,
ServiceAccountRoleComputeRead,
ServiceAccountRoleComputeWrite,
ServiceAccountRoleAdminRead,
ServiceAccountRoleAdminWrite,
}
}