wip
parent
5d09d04d14
commit
4f3e5ef64d
@ -1,15 +1,25 @@
|
|||||||
package admin
|
package admin
|
||||||
|
|
||||||
// Type specifies the type of administrator privileges the admin has.
|
import "github.com/smallstep/certificates/authority/status"
|
||||||
|
|
||||||
|
// Type specifies the type of the admin. e.g. SUPER_ADMIN, REGULAR
|
||||||
type Type string
|
type Type string
|
||||||
|
|
||||||
|
var (
|
||||||
|
// TypeSuper superadmin
|
||||||
|
TypeSuper = Type("SUPER_ADMIN")
|
||||||
|
// TypeRegular regular
|
||||||
|
TypeRegular = Type("REGULAR")
|
||||||
|
)
|
||||||
|
|
||||||
// Admin type.
|
// Admin type.
|
||||||
type Admin struct {
|
type Admin struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
AuthorityID string `json:"-"`
|
AuthorityID string `json:"-"`
|
||||||
Subject string `json:"subject"`
|
Subject string `json:"subject"`
|
||||||
ProvisionerName string `json:"provisionerName"`
|
ProvisionerName string `json:"provisionerName"`
|
||||||
ProvisionerType string `json:"provisionerType"`
|
ProvisionerType string `json:"provisionerType"`
|
||||||
ProvisionerID string `json:"provisionerID"`
|
ProvisionerID string `json:"provisionerID"`
|
||||||
Type Type `json:"type"`
|
Type Type `json:"type"`
|
||||||
|
Status status.Type `json:"status"`
|
||||||
}
|
}
|
||||||
|
@ -1,55 +1,23 @@
|
|||||||
package mgmt
|
package mgmt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/smallstep/certificates/authority/admin"
|
"github.com/smallstep/certificates/authority/admin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AdminType specifies the type of the admin. e.g. SUPER_ADMIN, REGULAR
|
// AdminType specifies the type of the admin. e.g. SUPER_ADMIN, REGULAR
|
||||||
type AdminType string
|
type AdminType admin.Type
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// AdminTypeSuper superadmin
|
// AdminTypeSuper superadmin
|
||||||
AdminTypeSuper = AdminType("SUPER_ADMIN")
|
AdminTypeSuper = admin.TypeSuper
|
||||||
// AdminTypeRegular regular
|
// AdminTypeRegular regular
|
||||||
AdminTypeRegular = AdminType("REGULAR")
|
AdminTypeRegular = admin.TypeRegular
|
||||||
)
|
)
|
||||||
|
|
||||||
// Admin type.
|
// Admin type.
|
||||||
type Admin struct {
|
type Admin admin.Admin
|
||||||
ID string `json:"id"`
|
|
||||||
AuthorityID string `json:"-"`
|
|
||||||
ProvisionerID string `json:"provisionerID"`
|
|
||||||
Subject string `json:"subject"`
|
|
||||||
ProvisionerName string `json:"provisionerName"`
|
|
||||||
ProvisionerType string `json:"provisionerType"`
|
|
||||||
Type AdminType `json:"type"`
|
|
||||||
Status StatusType `json:"status"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateAdmin builds and stores an admin type in the DB.
|
|
||||||
func CreateAdmin(ctx context.Context, db DB, provName, sub string, typ AdminType) (*Admin, error) {
|
|
||||||
adm := &Admin{
|
|
||||||
Subject: sub,
|
|
||||||
ProvisionerName: provName,
|
|
||||||
Type: typ,
|
|
||||||
Status: StatusActive,
|
|
||||||
}
|
|
||||||
if err := db.CreateAdmin(ctx, adm); err != nil {
|
|
||||||
return nil, WrapErrorISE(err, "error creating admin")
|
|
||||||
}
|
|
||||||
return adm, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToCertificates converts an Admin to the Admin type expected by the authority.
|
// ToCertificates converts an Admin to the Admin type expected by the authority.
|
||||||
func (adm *Admin) ToCertificates() (*admin.Admin, error) {
|
func (adm *Admin) ToCertificates() (*admin.Admin, error) {
|
||||||
return &admin.Admin{
|
return (*admin.Admin)(adm), nil
|
||||||
ID: adm.ID,
|
|
||||||
Subject: adm.Subject,
|
|
||||||
ProvisionerID: adm.ProvisionerID,
|
|
||||||
ProvisionerName: adm.ProvisionerName,
|
|
||||||
ProvisionerType: adm.ProvisionerType,
|
|
||||||
Type: admin.Type(adm.Type),
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package status
|
||||||
|
|
||||||
|
// Type is the type for status.
|
||||||
|
type Type string
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Active active
|
||||||
|
Active = Type("active")
|
||||||
|
// Deleted deleted
|
||||||
|
Deleted = Type("deleted")
|
||||||
|
)
|
Loading…
Reference in New Issue