auth_context

package
v0.0.0-...-4da4744 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: Apache-2.0 Imports: 5 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Must match authz-service/../constants.go#AllProjectsExternalID
	AllProjectsKey = "*"
)
View Source
var (
	ErrParseAuthContext = errors.New("could not parse auth context")
)

Functions

func AllProjectsRequested

func AllProjectsRequested(projectsFilter []string) bool

AllProjectsRequested takes in the project filter list and returns true if the list is a single entry of *.

func ContextWithoutProjects

func ContextWithoutProjects(ctx context.Context) context.Context

ContextWithoutProjects removes any projects from the incoming GRPC metadata attached to the context. Following attempts to read projects from incoming metadata will yield nothing -- so this can be used in handlers that should not do projects filtering, but would do that if the key was present.

func FromIncomingMetadata

func FromIncomingMetadata(ctx context.Context) context.Context

FromIncomingMetadata translates auth info provided by GRPC metadata into auth_context's representation, to be retrieved via auth_context.FromContext.

func NewContext

func NewContext(ctx context.Context, subs []string, projects []string,
	res, act string) context.Context

NewContext returns a new `context.Context` that holds a reference to the provided properties

func NewOutgoingContext

func NewOutgoingContext(ctx context.Context) context.Context

NewOutgoingContext translates previously injected auth_context info into GRPC metadata, to be consumed by the downstream service.

func NewOutgoingProjectsContext

func NewOutgoingProjectsContext(ctx context.Context) context.Context

NewOutgoingProjectsContext translates previously injected auth_context info into GRPC metadata, to be consumed by the downstream service, but only for projects.

func NewOutgoingRequestorInfoContext

func NewOutgoingRequestorInfoContext(ctx context.Context) context.Context

func NewRequestorContext

func NewRequestorContext(ctx context.Context, requestorID string) context.Context

func ProjectsFromIncomingContext

func ProjectsFromIncomingContext(ctx context.Context) ([]string, error)

ProjectsFromIncomingContext parses the projects from the incoming request context. It throws an error if there is an issue parsing the context.

func ProjectsFromMetadata

func ProjectsFromMetadata(md metadata.MD) []string

ProjectsFromMetadata extracts the requested projects from (incoming) metadata as provided by grpc-gateway (so, it's expecting, and removing, grpc-gateway's key prefixes).

func RequestorFromIncomingContext

func RequestorFromIncomingContext(ctx context.Context) (string, error)

func Subjects

func Subjects(ctx context.Context) (subs []string)

Subjects returns the auth subjects associated with `ctx`, or `nil` if it could not be found.

Types

type Properties

type Properties struct {
	Subjects    []string
	Projects    []string
	Resource    string
	Action      string
	RequestorID string
}

Properties is a container for metadata available from the context.

func FromContext

func FromContext(ctx context.Context) *Properties

FromContext returns the auth data previously associated with `ctx`, or `nil` or "" if a piece of the information could not be found.

Jump to

Keyboard shortcuts

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