fleet/server/contexts/authz/authz.go
Tomas Touceda 5859db36bb
Move logger up to the HTTP layer and make it generic (#1439)
* Add basic idea

* Implement the new logging strategy everywhere

* Remove unused const

* Add tests and fix error cases

* Fix logging in osquery service

* If there are extras, log info unless force debug

* Change to info

* Fix test

* Make logging context more chainable and force info for sessions
2021-08-02 19:06:27 -03:00

27 lines
868 B
Go

// Package authz defines the "authorization context", used to check that a
// request has had an authorization check performed before returning results.
package authz
import "context"
type key int
const authzKey key = 0
// NewContext creates a new context.Context with an AuthorizationContext.
func NewContext(ctx context.Context, authz *AuthorizationContext) context.Context {
return context.WithValue(ctx, authzKey, authz)
}
// FromContext returns a pointer to the AuthorizationContext.
func FromContext(ctx context.Context) (*AuthorizationContext, bool) {
v, ok := ctx.Value(authzKey).(*AuthorizationContext)
return v, ok
}
// AuthorizationContext contains the context information used for the
// authorization check.
type AuthorizationContext struct {
// Checked indicates whether a call was made to check authorization for the request.
Checked bool
}