echoaudit

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Overview

Copyright 2023 Equinix, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2023 Equinix, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2023 Equinix, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	// AuditDataContextKey is the context key for additional audit data.
	AuditDataContextKey = "audit.data"
	// AuditIDContextKey is the context key for the audit ID.
	AuditIDContextKey = "audit.id"
)

Variables

This section is empty.

Functions

func GetOutcomeDefault

func GetOutcomeDefault(c echo.Context) string

GetOutcomeDefault is the default outcome handler that's set in the middleware constructor. It will return `failed` for HTTP response statuses 500 and above, `denied` for requests 400 and above and `succeeded` otherwise.

func GetSubjectDefault

func GetSubjectDefault(c echo.Context) map[string]string

Types

type Middleware

type Middleware struct {
	// contains filtered or unexported fields
}

func NewJSONMiddleware

func NewJSONMiddleware(component string, w io.Writer) *Middleware

NewJSONMiddleware returns a new middleware instance with a default JSON writer.

func NewMiddleware

func NewMiddleware(component string, aew *auditevent.EventWriter) *Middleware

NewMiddleware returns a new instance of audit Middleware.

func (*Middleware) Audit

func (m *Middleware) Audit() echo.MiddlewareFunc

Audit returns a echo middleware that will audit the request. This uses the a pre-registered type for the event (see RegisterEventType). If no type is registered, the event type is the HTTP method and path.

func (*Middleware) AuditWithSkipper

func (m *Middleware) AuditWithSkipper(skipper middleware.Skipper) echo.MiddlewareFunc

AuditWithSkipper is the same as Audit however allows you to provide a skipper.

func (*Middleware) AuditWithType

func (m *Middleware) AuditWithType(t string) echo.MiddlewareFunc

AuditWithType returns a echo middleware that will audit the request. This uses the given type for the event. If the type is empty, the event type will try to use a pre-registered type (see RegisterEventType) and if it doesn't find it, it'll use the HTTP method and path.

func (*Middleware) AuditWithTypeAndSkipper

func (m *Middleware) AuditWithTypeAndSkipper(t string, skipper middleware.Skipper) echo.MiddlewareFunc

AuditWithTypeAndSkipper is the same as AuditWithType however allows you to provide a skipper.

func (*Middleware) RegisterEventType

func (m *Middleware) RegisterEventType(eventType, httpMethod, path string)

RegisterEventType registers an audit event type for a given HTTP method and path.

func (*Middleware) WithOutcomeHandler

func (m *Middleware) WithOutcomeHandler(handler OutcomeHandler) *Middleware

func (*Middleware) WithPrometheusMetrics

func (m *Middleware) WithPrometheusMetrics() *Middleware

WithPrometheusMetrics enables prometheus metrics for this middleware instance using the default prometheus registerer (prometheus.DefaultRegisterer).

func (*Middleware) WithPrometheusMetricsForRegisterer

func (m *Middleware) WithPrometheusMetricsForRegisterer(pr prometheus.Registerer) *Middleware

WithPrometheusMetricsForRegisterer enables prometheus metrics for this middleware instance using the default prometheus registerer (prometheus.DefaultRegisterer).

func (*Middleware) WithSubjectHandler

func (m *Middleware) WithSubjectHandler(handler SubjectHandler) *Middleware

type OutcomeHandler

type OutcomeHandler func(c echo.Context) string

OutcomeHandler is a function that returns the AuditEvent outcome for a given request. This will be called after other middleware; e.g. the given echo context should already contain a result status. It is recommended to return one of the samples defined in `samples.go`.

type SubjectHandler

type SubjectHandler func(c echo.Context) map[string]string

SubjectHandler is a function that returns the AuditEvent subject map for a given request. This will be called after other middleware; e.g. the given gin context should already contain the subject information.

Jump to

Keyboard shortcuts

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