admin

package
v0.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2024 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// DefaultAuthorityID is the default AuthorityID. This will be the ID
	// of the first Authority created, as well as the default AuthorityID
	// if one is not specified in the configuration.
	DefaultAuthorityID = "00000000-0000-0000-0000-000000000000"
)

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is an error that should be used by the authority.DB interface to indicate that an entity does not exist.

Functions

func NewContext added in v0.20.0

func NewContext(ctx context.Context, db DB) context.Context

NewContext adds the given admin database to the context.

func UnmarshalProvisionerDetails

func UnmarshalProvisionerDetails(typ linkedca.Provisioner_Type, data []byte) (*linkedca.ProvisionerDetails, error)

UnmarshalProvisionerDetails unmarshals details type to the specific provisioner details.

Types

type DB

type DB interface {
	CreateProvisioner(ctx context.Context, prov *linkedca.Provisioner) error
	GetProvisioner(ctx context.Context, id string) (*linkedca.Provisioner, error)
	GetProvisioners(ctx context.Context) ([]*linkedca.Provisioner, error)
	UpdateProvisioner(ctx context.Context, prov *linkedca.Provisioner) error
	DeleteProvisioner(ctx context.Context, id string) error

	CreateAdmin(ctx context.Context, admin *linkedca.Admin) error
	GetAdmin(ctx context.Context, id string) (*linkedca.Admin, error)
	GetAdmins(ctx context.Context) ([]*linkedca.Admin, error)
	UpdateAdmin(ctx context.Context, admin *linkedca.Admin) error
	DeleteAdmin(ctx context.Context, id string) error

	CreateAuthorityPolicy(ctx context.Context, policy *linkedca.Policy) error
	GetAuthorityPolicy(ctx context.Context) (*linkedca.Policy, error)
	UpdateAuthorityPolicy(ctx context.Context, policy *linkedca.Policy) error
	DeleteAuthorityPolicy(ctx context.Context) error
}

DB is the DB interface expected by the step-ca Admin API.

func FromContext added in v0.20.0

func FromContext(ctx context.Context) (db DB, ok bool)

FromContext returns the current admin database from the given context.

func MustFromContext added in v0.20.0

func MustFromContext(ctx context.Context) DB

MustFromContext returns the current admin database from the given context. It will panic if it's not in the context.

type Error

type Error struct {
	Type    string `json:"type"`
	Detail  string `json:"detail"`
	Message string `json:"message"`
	Err     error  `json:"-"`
	Status  int    `json:"-"`
}

Error represents an Admin error

func NewError

func NewError(pt ProblemType, msg string, args ...interface{}) *Error

NewError creates a new Error type.

func NewErrorISE

func NewErrorISE(msg string, args ...interface{}) *Error

NewErrorISE creates a new ErrorServerInternalType Error.

func WrapError

func WrapError(typ ProblemType, err error, msg string, args ...interface{}) *Error

WrapError attempts to wrap the internal error.

func WrapErrorISE

func WrapErrorISE(err error, msg string, args ...interface{}) *Error

WrapErrorISE shortcut to wrap an internal server error type.

func (*Error) Cause

func (e *Error) Cause() error

Cause returns the internal error and implements the Causer interface.

func (*Error) Error

func (e *Error) Error() string

Error allows AError to implement the error interface.

func (*Error) IsType

func (e *Error) IsType(pt ProblemType) bool

IsType returns true if the error type matches the input type.

func (*Error) Render added in v0.19.0

func (e *Error) Render(w http.ResponseWriter)

Render implements render.RenderableError for Error.

func (*Error) StatusCode

func (e *Error) StatusCode() int

StatusCode returns the status code and implements the StatusCoder interface.

func (*Error) ToLog

func (e *Error) ToLog() (interface{}, error)

ToLog implements the EnableLogger interface.

type MockDB

type MockDB struct {
	MockCreateProvisioner func(ctx context.Context, prov *linkedca.Provisioner) error
	MockGetProvisioner    func(ctx context.Context, id string) (*linkedca.Provisioner, error)
	MockGetProvisioners   func(ctx context.Context) ([]*linkedca.Provisioner, error)
	MockUpdateProvisioner func(ctx context.Context, prov *linkedca.Provisioner) error
	MockDeleteProvisioner func(ctx context.Context, id string) error

	MockCreateAdmin func(ctx context.Context, adm *linkedca.Admin) error
	MockGetAdmin    func(ctx context.Context, id string) (*linkedca.Admin, error)
	MockGetAdmins   func(ctx context.Context) ([]*linkedca.Admin, error)
	MockUpdateAdmin func(ctx context.Context, adm *linkedca.Admin) error
	MockDeleteAdmin func(ctx context.Context, id string) error

	MockCreateAuthorityPolicy func(ctx context.Context, policy *linkedca.Policy) error
	MockGetAuthorityPolicy    func(ctx context.Context) (*linkedca.Policy, error)
	MockUpdateAuthorityPolicy func(ctx context.Context, policy *linkedca.Policy) error
	MockDeleteAuthorityPolicy func(ctx context.Context) error

	MockError error
	MockRet1  interface{}
}

MockDB is an implementation of the DB interface that should only be used as a mock in tests.

func (*MockDB) CreateAdmin

func (m *MockDB) CreateAdmin(ctx context.Context, admin *linkedca.Admin) error

CreateAdmin mock

func (*MockDB) CreateAuthorityPolicy added in v0.20.0

func (m *MockDB) CreateAuthorityPolicy(ctx context.Context, policy *linkedca.Policy) error

CreateAuthorityPolicy mock

func (*MockDB) CreateProvisioner

func (m *MockDB) CreateProvisioner(ctx context.Context, prov *linkedca.Provisioner) error

CreateProvisioner mock.

func (*MockDB) DeleteAdmin

func (m *MockDB) DeleteAdmin(ctx context.Context, id string) error

DeleteAdmin mock

func (*MockDB) DeleteAuthorityPolicy added in v0.20.0

func (m *MockDB) DeleteAuthorityPolicy(ctx context.Context) error

DeleteAuthorityPolicy mock

func (*MockDB) DeleteProvisioner

func (m *MockDB) DeleteProvisioner(ctx context.Context, id string) error

DeleteProvisioner mock

func (*MockDB) GetAdmin

func (m *MockDB) GetAdmin(ctx context.Context, id string) (*linkedca.Admin, error)

GetAdmin mock.

func (*MockDB) GetAdmins

func (m *MockDB) GetAdmins(ctx context.Context) ([]*linkedca.Admin, error)

GetAdmins mock

func (*MockDB) GetAuthorityPolicy added in v0.20.0

func (m *MockDB) GetAuthorityPolicy(ctx context.Context) (*linkedca.Policy, error)

GetAuthorityPolicy mock

func (*MockDB) GetProvisioner

func (m *MockDB) GetProvisioner(ctx context.Context, id string) (*linkedca.Provisioner, error)

GetProvisioner mock.

func (*MockDB) GetProvisioners

func (m *MockDB) GetProvisioners(ctx context.Context) ([]*linkedca.Provisioner, error)

GetProvisioners mock

func (*MockDB) UpdateAdmin

func (m *MockDB) UpdateAdmin(ctx context.Context, adm *linkedca.Admin) error

UpdateAdmin mock

func (*MockDB) UpdateAuthorityPolicy added in v0.20.0

func (m *MockDB) UpdateAuthorityPolicy(ctx context.Context, policy *linkedca.Policy) error

UpdateAuthorityPolicy mock

func (*MockDB) UpdateProvisioner

func (m *MockDB) UpdateProvisioner(ctx context.Context, prov *linkedca.Provisioner) error

UpdateProvisioner mock

type ProblemType

type ProblemType int

ProblemType is the type of the Admin problem.

const (
	// ErrorNotFoundType resource not found.
	ErrorNotFoundType ProblemType = iota
	// ErrorAuthorityMismatchType resource Authority ID does not match the
	// context Authority ID.
	ErrorAuthorityMismatchType
	// ErrorDeletedType resource has been deleted.
	ErrorDeletedType
	// ErrorBadRequestType bad request.
	ErrorBadRequestType
	// ErrorNotImplementedType not implemented.
	ErrorNotImplementedType
	// ErrorUnauthorizedType unauthorized.
	ErrorUnauthorizedType
	// ErrorServerInternalType internal server error.
	ErrorServerInternalType
	// ErrorConflictType conflict.
	ErrorConflictType
)

func (ProblemType) String

func (ap ProblemType) String() string

String returns the string representation of the admin problem type, fulfilling the Stringer interface.

Directories

Path Synopsis
db

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL