You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import opamw "github.com/infobloxopen/atlas-authz-middleware/grpc_opa"// Create Authorizer with example optionsauthzer:=opamw.NewDefaultAuthorizer(
viper.GetString("app.id"),
opamw.WithAddress(opa_client.DefaultAddress),
opamw.WithDecisionInputHandler(&myDecisionInputer{}),
)
// AffirmAuthorization makes an authz request to sidecar-OPA.// If authorization is permitted, error returned is nil,// and a new context is returned, possibly containing obligations.// Caller must further evaluate obligations if required.newCtx, err:=authzer.AffirmAuthorization(ctx, "MyService.MyMethod", nil)
iferr==nil {
// Operation is permitted, fetch and process obligationsifnewCtx!=nil {
obVal:=newCtx.Value(opamw.ObKey)
ifobVal!=nil {
obTree, ok:=obVal.(opamw.ObligationsNode)
ifok&&obTree!=nil&&!obTree.IsShallowEmpty() {
// process any obligations in obTree if required
}
}
}
}
GRPC Unary Interceptor Usage
import opamw "github.com/infobloxopen/atlas-authz-middleware/grpc_opa"// Create unary-interceptor with example optionsauthzOpaInterceptor:=opamw.UnaryServerInterceptor(
viper.GetString("app.id"),
opamw.WithAddress(opa_client.DefaultAddress),
opamw.WithDecisionInputHandler(&myDecisionInputer{}),
)
interceptors=append(interceptors, authzOpaInterceptor)