Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var GetHeaderDecl = &ast.Builtin{ Name: "get_header", Decl: types.NewFunction( types.Args( types.S, types.A, ), types.S, ), }
GetHeader returns the first value corresponding (in case-insensitive mode) to the headerKey in the headers of the request, otherwise return an empty string if does not exist.
View Source
var GetHeaderFunction = rego.Function2( ®o.Function{ Name: GetHeaderDecl.Name, Decl: GetHeaderDecl.Decl, }, func(_ rego.BuiltinContext, a, b *ast.Term) (*ast.Term, error) { var headerKey string var headers http.Header if err := ast.As(a.Value, &headerKey); err != nil { return nil, err } if err := ast.As(b.Value, &headers); err != nil { return nil, err } return ast.StringTerm(headers.Get(headerKey)), nil }, )
View Source
var MongoFindMany = rego.Function2( ®o.Function{ Name: MongoFindManyDecl.Name, Decl: MongoFindManyDecl.Decl, }, func(ctx rego.BuiltinContext, collectionNameTerm, queryTerm *ast.Term) (*ast.Term, error) { mongoClient, err := GetMongoClientFromContext(ctx.Context) if err != nil { return nil, err } if mongoClient == nil { return nil, fmt.Errorf("mongo client not set") } var collectionName string if err := ast.As(collectionNameTerm.Value, &collectionName); err != nil { return nil, err } query := make(map[string]interface{}) if err := ast.As(queryTerm.Value, &query); err != nil { return nil, err } result, err := mongoClient.FindMany(ctx.Context, collectionName, query) if err != nil { return nil, err } t, err := ast.InterfaceToValue(result) if err != nil { return nil, err } return ast.NewTerm(t), nil }, )
View Source
var MongoFindManyDecl = &ast.Builtin{ Name: "find_many", Decl: types.NewFunction( types.Args( types.S, types.A, ), types.A, ), }
View Source
var MongoFindOne = rego.Function2( ®o.Function{ Name: MongoFindOneDecl.Name, Decl: MongoFindOneDecl.Decl, }, func(ctx rego.BuiltinContext, collectionNameTerm, queryTerm *ast.Term) (*ast.Term, error) { mongoClient, err := GetMongoClientFromContext(ctx.Context) if err != nil { return nil, err } if mongoClient == nil { return nil, fmt.Errorf("mongo client not set") } var collectionName string if err := ast.As(collectionNameTerm.Value, &collectionName); err != nil { return nil, err } query := make(map[string]interface{}) if err := ast.As(queryTerm.Value, &query); err != nil { return nil, err } result, err := mongoClient.FindOne(ctx.Context, collectionName, query) if err != nil { return nil, err } t, err := ast.InterfaceToValue(result) if err != nil { return nil, err } return ast.NewTerm(t), nil }, )
Functions ¶
func WithMongoClient ¶ added in v1.10.0
func WithMongoClient(ctx context.Context, mongoClient IMongoClient) context.Context
Types ¶
type IMongoClient ¶ added in v1.10.0
type IMongoClient interface { FindOne(ctx context.Context, collectionName string, query map[string]interface{}) (interface{}, error) FindMany(ctx context.Context, collectionName string, query map[string]interface{}) ([]interface{}, error) }
func GetMongoClientFromContext ¶ added in v1.10.0
func GetMongoClientFromContext(ctx context.Context) (IMongoClient, error)
func NewMongoClient ¶ added in v1.10.0
func NewMongoClient(logger logging.Logger, mongoClient types.MongoClient) (IMongoClient, error)
type MongoClient ¶ added in v1.10.0
type MongoClient struct {
// contains filtered or unexported fields
}
Click to show internal directories.
Click to hide internal directories.