repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
open-policy-agent/opa | rego/rego.go | ParsedUnknowns | func ParsedUnknowns(unknowns []*ast.Term) func(r *Rego) {
return func(r *Rego) {
r.parsedUnknowns = unknowns
}
} | go | func ParsedUnknowns(unknowns []*ast.Term) func(r *Rego) {
return func(r *Rego) {
r.parsedUnknowns = unknowns
}
} | [
"func",
"ParsedUnknowns",
"(",
"unknowns",
"[",
"]",
"*",
"ast",
".",
"Term",
")",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"return",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"r",
".",
"parsedUnknowns",
"=",
"unknowns",
"\n",
"}",
"\n",
"}"
] | // ParsedUnknowns returns an argument that sets the values to treat as unknown
// during partial evaluation. | [
"ParsedUnknowns",
"returns",
"an",
"argument",
"that",
"sets",
"the",
"values",
"to",
"treat",
"as",
"unknown",
"during",
"partial",
"evaluation",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L453-L457 | train |
open-policy-agent/opa | rego/rego.go | PartialNamespace | func PartialNamespace(ns string) func(r *Rego) {
return func(r *Rego) {
r.partialNamespace = ns
}
} | go | func PartialNamespace(ns string) func(r *Rego) {
return func(r *Rego) {
r.partialNamespace = ns
}
} | [
"func",
"PartialNamespace",
"(",
"ns",
"string",
")",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"return",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"r",
".",
"partialNamespace",
"=",
"ns",
"\n",
"}",
"\n",
"}"
] | // PartialNamespace returns an argument that sets the namespace to use for
// partial evaluation results. The namespace must be a valid package path
// component. | [
"PartialNamespace",
"returns",
"an",
"argument",
"that",
"sets",
"the",
"namespace",
"to",
"use",
"for",
"partial",
"evaluation",
"results",
".",
"The",
"namespace",
"must",
"be",
"a",
"valid",
"package",
"path",
"component",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L462-L466 | train |
open-policy-agent/opa | rego/rego.go | Module | func Module(filename, input string) func(r *Rego) {
return func(r *Rego) {
r.modules = append(r.modules, rawModule{
filename: filename,
module: input,
})
}
} | go | func Module(filename, input string) func(r *Rego) {
return func(r *Rego) {
r.modules = append(r.modules, rawModule{
filename: filename,
module: input,
})
}
} | [
"func",
"Module",
"(",
"filename",
",",
"input",
"string",
")",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"return",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"r",
".",
"modules",
"=",
"append",
"(",
"r",
".",
"modules",
",",
"rawModule",
"{",
"filename",
":",
"filename",
",",
"module",
":",
"input",
",",
"}",
")",
"\n",
"}",
"\n",
"}"
] | // Module returns an argument that adds a Rego module. | [
"Module",
"returns",
"an",
"argument",
"that",
"adds",
"a",
"Rego",
"module",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L469-L476 | train |
open-policy-agent/opa | rego/rego.go | Compiler | func Compiler(c *ast.Compiler) func(r *Rego) {
return func(r *Rego) {
r.compiler = c
}
} | go | func Compiler(c *ast.Compiler) func(r *Rego) {
return func(r *Rego) {
r.compiler = c
}
} | [
"func",
"Compiler",
"(",
"c",
"*",
"ast",
".",
"Compiler",
")",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"return",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"r",
".",
"compiler",
"=",
"c",
"\n",
"}",
"\n",
"}"
] | // Compiler returns an argument that sets the Rego compiler. | [
"Compiler",
"returns",
"an",
"argument",
"that",
"sets",
"the",
"Rego",
"compiler",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L479-L483 | train |
open-policy-agent/opa | rego/rego.go | Store | func Store(s storage.Store) func(r *Rego) {
return func(r *Rego) {
r.store = s
}
} | go | func Store(s storage.Store) func(r *Rego) {
return func(r *Rego) {
r.store = s
}
} | [
"func",
"Store",
"(",
"s",
"storage",
".",
"Store",
")",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"return",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"r",
".",
"store",
"=",
"s",
"\n",
"}",
"\n",
"}"
] | // Store returns an argument that sets the policy engine's data storage layer. | [
"Store",
"returns",
"an",
"argument",
"that",
"sets",
"the",
"policy",
"engine",
"s",
"data",
"storage",
"layer",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L486-L490 | train |
open-policy-agent/opa | rego/rego.go | Transaction | func Transaction(txn storage.Transaction) func(r *Rego) {
return func(r *Rego) {
r.txn = txn
}
} | go | func Transaction(txn storage.Transaction) func(r *Rego) {
return func(r *Rego) {
r.txn = txn
}
} | [
"func",
"Transaction",
"(",
"txn",
"storage",
".",
"Transaction",
")",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"return",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"r",
".",
"txn",
"=",
"txn",
"\n",
"}",
"\n",
"}"
] | // Transaction returns an argument that sets the transaction to use for storage
// layer operations. | [
"Transaction",
"returns",
"an",
"argument",
"that",
"sets",
"the",
"transaction",
"to",
"use",
"for",
"storage",
"layer",
"operations",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L494-L498 | train |
open-policy-agent/opa | rego/rego.go | Metrics | func Metrics(m metrics.Metrics) func(r *Rego) {
return func(r *Rego) {
r.metrics = m
}
} | go | func Metrics(m metrics.Metrics) func(r *Rego) {
return func(r *Rego) {
r.metrics = m
}
} | [
"func",
"Metrics",
"(",
"m",
"metrics",
".",
"Metrics",
")",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"return",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"r",
".",
"metrics",
"=",
"m",
"\n",
"}",
"\n",
"}"
] | // Metrics returns an argument that sets the metrics collection. | [
"Metrics",
"returns",
"an",
"argument",
"that",
"sets",
"the",
"metrics",
"collection",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L501-L505 | train |
open-policy-agent/opa | rego/rego.go | Instrument | func Instrument(yes bool) func(r *Rego) {
return func(r *Rego) {
r.instrument = yes
}
} | go | func Instrument(yes bool) func(r *Rego) {
return func(r *Rego) {
r.instrument = yes
}
} | [
"func",
"Instrument",
"(",
"yes",
"bool",
")",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"return",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"r",
".",
"instrument",
"=",
"yes",
"\n",
"}",
"\n",
"}"
] | // Instrument returns an argument that enables instrumentation for diagnosing
// performance issues. | [
"Instrument",
"returns",
"an",
"argument",
"that",
"enables",
"instrumentation",
"for",
"diagnosing",
"performance",
"issues",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L509-L513 | train |
open-policy-agent/opa | rego/rego.go | Trace | func Trace(yes bool) func(r *Rego) {
return func(r *Rego) {
r.trace = yes
}
} | go | func Trace(yes bool) func(r *Rego) {
return func(r *Rego) {
r.trace = yes
}
} | [
"func",
"Trace",
"(",
"yes",
"bool",
")",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"return",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"r",
".",
"trace",
"=",
"yes",
"\n",
"}",
"\n",
"}"
] | // Trace returns an argument that enables tracing on r. | [
"Trace",
"returns",
"an",
"argument",
"that",
"enables",
"tracing",
"on",
"r",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L516-L520 | train |
open-policy-agent/opa | rego/rego.go | Tracer | func Tracer(t topdown.Tracer) func(r *Rego) {
return func(r *Rego) {
if t != nil {
r.tracers = append(r.tracers, t)
}
}
} | go | func Tracer(t topdown.Tracer) func(r *Rego) {
return func(r *Rego) {
if t != nil {
r.tracers = append(r.tracers, t)
}
}
} | [
"func",
"Tracer",
"(",
"t",
"topdown",
".",
"Tracer",
")",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"return",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"if",
"t",
"!=",
"nil",
"{",
"r",
".",
"tracers",
"=",
"append",
"(",
"r",
".",
"tracers",
",",
"t",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Tracer returns an argument that adds a query tracer to r. | [
"Tracer",
"returns",
"an",
"argument",
"that",
"adds",
"a",
"query",
"tracer",
"to",
"r",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L523-L529 | train |
open-policy-agent/opa | rego/rego.go | Runtime | func Runtime(term *ast.Term) func(r *Rego) {
return func(r *Rego) {
r.runtime = term
}
} | go | func Runtime(term *ast.Term) func(r *Rego) {
return func(r *Rego) {
r.runtime = term
}
} | [
"func",
"Runtime",
"(",
"term",
"*",
"ast",
".",
"Term",
")",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"return",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"r",
".",
"runtime",
"=",
"term",
"\n",
"}",
"\n",
"}"
] | // Runtime returns an argument that sets the runtime data to provide to the
// evaluation engine. | [
"Runtime",
"returns",
"an",
"argument",
"that",
"sets",
"the",
"runtime",
"data",
"to",
"provide",
"to",
"the",
"evaluation",
"engine",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L533-L537 | train |
open-policy-agent/opa | rego/rego.go | PrintTrace | func PrintTrace(w io.Writer, r *Rego) {
if r == nil || r.tracebuf == nil {
return
}
topdown.PrettyTrace(w, *r.tracebuf)
} | go | func PrintTrace(w io.Writer, r *Rego) {
if r == nil || r.tracebuf == nil {
return
}
topdown.PrettyTrace(w, *r.tracebuf)
} | [
"func",
"PrintTrace",
"(",
"w",
"io",
".",
"Writer",
",",
"r",
"*",
"Rego",
")",
"{",
"if",
"r",
"==",
"nil",
"||",
"r",
".",
"tracebuf",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"topdown",
".",
"PrettyTrace",
"(",
"w",
",",
"*",
"r",
".",
"tracebuf",
")",
"\n",
"}"
] | // PrintTrace is a helper function to write a human-readable version of the
// trace to the writer w. | [
"PrintTrace",
"is",
"a",
"helper",
"function",
"to",
"write",
"a",
"human",
"-",
"readable",
"version",
"of",
"the",
"trace",
"to",
"the",
"writer",
"w",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L541-L546 | train |
open-policy-agent/opa | rego/rego.go | New | func New(options ...func(r *Rego)) *Rego {
r := &Rego{
capture: map[*ast.Expr]ast.Var{},
compiledQueries: map[queryType]compiledQuery{},
}
for _, option := range options {
option(r)
}
if r.compiler == nil {
r.compiler = ast.NewCompiler()
}
if r.store == nil {
r.store = inmem.New()
}
if r.metrics == nil {
r.metrics = metrics.New()
}
if r.instrument {
r.instrumentation = topdown.NewInstrumentation(r.metrics)
}
if r.trace {
r.tracebuf = topdown.NewBufferTracer()
r.tracers = append(r.tracers, r.tracebuf)
}
if r.partialNamespace == "" {
r.partialNamespace = defaultPartialNamespace
}
return r
} | go | func New(options ...func(r *Rego)) *Rego {
r := &Rego{
capture: map[*ast.Expr]ast.Var{},
compiledQueries: map[queryType]compiledQuery{},
}
for _, option := range options {
option(r)
}
if r.compiler == nil {
r.compiler = ast.NewCompiler()
}
if r.store == nil {
r.store = inmem.New()
}
if r.metrics == nil {
r.metrics = metrics.New()
}
if r.instrument {
r.instrumentation = topdown.NewInstrumentation(r.metrics)
}
if r.trace {
r.tracebuf = topdown.NewBufferTracer()
r.tracers = append(r.tracers, r.tracebuf)
}
if r.partialNamespace == "" {
r.partialNamespace = defaultPartialNamespace
}
return r
} | [
"func",
"New",
"(",
"options",
"...",
"func",
"(",
"r",
"*",
"Rego",
")",
")",
"*",
"Rego",
"{",
"r",
":=",
"&",
"Rego",
"{",
"capture",
":",
"map",
"[",
"*",
"ast",
".",
"Expr",
"]",
"ast",
".",
"Var",
"{",
"}",
",",
"compiledQueries",
":",
"map",
"[",
"queryType",
"]",
"compiledQuery",
"{",
"}",
",",
"}",
"\n\n",
"for",
"_",
",",
"option",
":=",
"range",
"options",
"{",
"option",
"(",
"r",
")",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"compiler",
"==",
"nil",
"{",
"r",
".",
"compiler",
"=",
"ast",
".",
"NewCompiler",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"store",
"==",
"nil",
"{",
"r",
".",
"store",
"=",
"inmem",
".",
"New",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"metrics",
"==",
"nil",
"{",
"r",
".",
"metrics",
"=",
"metrics",
".",
"New",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"instrument",
"{",
"r",
".",
"instrumentation",
"=",
"topdown",
".",
"NewInstrumentation",
"(",
"r",
".",
"metrics",
")",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"trace",
"{",
"r",
".",
"tracebuf",
"=",
"topdown",
".",
"NewBufferTracer",
"(",
")",
"\n",
"r",
".",
"tracers",
"=",
"append",
"(",
"r",
".",
"tracers",
",",
"r",
".",
"tracebuf",
")",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"partialNamespace",
"==",
"\"",
"\"",
"{",
"r",
".",
"partialNamespace",
"=",
"defaultPartialNamespace",
"\n",
"}",
"\n\n",
"return",
"r",
"\n",
"}"
] | // New returns a new Rego object. | [
"New",
"returns",
"a",
"new",
"Rego",
"object",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L549-L586 | train |
open-policy-agent/opa | rego/rego.go | Eval | func (r *Rego) Eval(ctx context.Context) (ResultSet, error) {
var err error
if r.txn == nil {
r.txn, err = r.store.NewTransaction(ctx)
if err != nil {
return nil, err
}
defer r.store.Abort(ctx, r.txn)
}
pq, err := r.PrepareForEval(ctx)
if err != nil {
return nil, err
}
return pq.Eval(ctx)
} | go | func (r *Rego) Eval(ctx context.Context) (ResultSet, error) {
var err error
if r.txn == nil {
r.txn, err = r.store.NewTransaction(ctx)
if err != nil {
return nil, err
}
defer r.store.Abort(ctx, r.txn)
}
pq, err := r.PrepareForEval(ctx)
if err != nil {
return nil, err
}
return pq.Eval(ctx)
} | [
"func",
"(",
"r",
"*",
"Rego",
")",
"Eval",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"ResultSet",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"if",
"r",
".",
"txn",
"==",
"nil",
"{",
"r",
".",
"txn",
",",
"err",
"=",
"r",
".",
"store",
".",
"NewTransaction",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"r",
".",
"store",
".",
"Abort",
"(",
"ctx",
",",
"r",
".",
"txn",
")",
"\n",
"}",
"\n\n",
"pq",
",",
"err",
":=",
"r",
".",
"PrepareForEval",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"pq",
".",
"Eval",
"(",
"ctx",
")",
"\n",
"}"
] | // Eval evaluates this Rego object and returns a ResultSet. | [
"Eval",
"evaluates",
"this",
"Rego",
"object",
"and",
"returns",
"a",
"ResultSet",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L589-L605 | train |
open-policy-agent/opa | rego/rego.go | PartialEval | func (r *Rego) PartialEval(ctx context.Context) (PartialResult, error) {
return r.PartialResult(ctx)
} | go | func (r *Rego) PartialEval(ctx context.Context) (PartialResult, error) {
return r.PartialResult(ctx)
} | [
"func",
"(",
"r",
"*",
"Rego",
")",
"PartialEval",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"PartialResult",
",",
"error",
")",
"{",
"return",
"r",
".",
"PartialResult",
"(",
"ctx",
")",
"\n",
"}"
] | // PartialEval has been deprecated and renamed to PartialResult. | [
"PartialEval",
"has",
"been",
"deprecated",
"and",
"renamed",
"to",
"PartialResult",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L608-L610 | train |
open-policy-agent/opa | rego/rego.go | PartialResult | func (r *Rego) PartialResult(ctx context.Context) (PartialResult, error) {
var err error
if r.txn == nil {
r.txn, err = r.store.NewTransaction(ctx)
if err != nil {
return PartialResult{}, err
}
defer r.store.Abort(ctx, r.txn)
}
pq, err := r.PrepareForEval(ctx, WithPartialEval())
if err != nil {
return PartialResult{}, err
}
pr := PartialResult{
compiler: pq.r.compiler,
store: pq.r.store,
body: pq.r.parsedQuery,
}
return pr, nil
} | go | func (r *Rego) PartialResult(ctx context.Context) (PartialResult, error) {
var err error
if r.txn == nil {
r.txn, err = r.store.NewTransaction(ctx)
if err != nil {
return PartialResult{}, err
}
defer r.store.Abort(ctx, r.txn)
}
pq, err := r.PrepareForEval(ctx, WithPartialEval())
if err != nil {
return PartialResult{}, err
}
pr := PartialResult{
compiler: pq.r.compiler,
store: pq.r.store,
body: pq.r.parsedQuery,
}
return pr, nil
} | [
"func",
"(",
"r",
"*",
"Rego",
")",
"PartialResult",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"PartialResult",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"if",
"r",
".",
"txn",
"==",
"nil",
"{",
"r",
".",
"txn",
",",
"err",
"=",
"r",
".",
"store",
".",
"NewTransaction",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"PartialResult",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"defer",
"r",
".",
"store",
".",
"Abort",
"(",
"ctx",
",",
"r",
".",
"txn",
")",
"\n",
"}",
"\n\n",
"pq",
",",
"err",
":=",
"r",
".",
"PrepareForEval",
"(",
"ctx",
",",
"WithPartialEval",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"PartialResult",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"pr",
":=",
"PartialResult",
"{",
"compiler",
":",
"pq",
".",
"r",
".",
"compiler",
",",
"store",
":",
"pq",
".",
"r",
".",
"store",
",",
"body",
":",
"pq",
".",
"r",
".",
"parsedQuery",
",",
"}",
"\n\n",
"return",
"pr",
",",
"nil",
"\n",
"}"
] | // PartialResult partially evaluates this Rego object and returns a PartialResult. | [
"PartialResult",
"partially",
"evaluates",
"this",
"Rego",
"object",
"and",
"returns",
"a",
"PartialResult",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L613-L635 | train |
open-policy-agent/opa | rego/rego.go | Partial | func (r *Rego) Partial(ctx context.Context) (*PartialQueries, error) {
var err error
if r.txn == nil {
r.txn, err = r.store.NewTransaction(ctx)
if err != nil {
return nil, err
}
defer r.store.Abort(ctx, r.txn)
}
pq, err := r.PrepareForPartial(ctx)
if err != nil {
return nil, err
}
return pq.Partial(ctx)
} | go | func (r *Rego) Partial(ctx context.Context) (*PartialQueries, error) {
var err error
if r.txn == nil {
r.txn, err = r.store.NewTransaction(ctx)
if err != nil {
return nil, err
}
defer r.store.Abort(ctx, r.txn)
}
pq, err := r.PrepareForPartial(ctx)
if err != nil {
return nil, err
}
return pq.Partial(ctx)
} | [
"func",
"(",
"r",
"*",
"Rego",
")",
"Partial",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"PartialQueries",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"if",
"r",
".",
"txn",
"==",
"nil",
"{",
"r",
".",
"txn",
",",
"err",
"=",
"r",
".",
"store",
".",
"NewTransaction",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"r",
".",
"store",
".",
"Abort",
"(",
"ctx",
",",
"r",
".",
"txn",
")",
"\n",
"}",
"\n\n",
"pq",
",",
"err",
":=",
"r",
".",
"PrepareForPartial",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"pq",
".",
"Partial",
"(",
"ctx",
")",
"\n",
"}"
] | // Partial runs partial evaluation on r and returns the result. | [
"Partial",
"runs",
"partial",
"evaluation",
"on",
"r",
"and",
"returns",
"the",
"result",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L638-L654 | train |
open-policy-agent/opa | rego/rego.go | Compile | func (r *Rego) Compile(ctx context.Context) (*CompileResult, error) {
pq, err := r.Partial(ctx)
if err != nil {
return nil, err
}
if len(pq.Support) > 0 {
return nil, fmt.Errorf("modules not supported")
}
policy, err := planner.New().WithQueries(pq.Queries).Plan()
if err != nil {
return nil, err
}
if r.dump != nil {
fmt.Fprintln(r.dump, "PLAN:")
fmt.Fprintln(r.dump, "-----")
ir.Pretty(r.dump, policy)
fmt.Fprintln(r.dump)
}
m, err := wasm.New().WithPolicy(policy).Compile()
if err != nil {
return nil, err
}
var out bytes.Buffer
if err := encoding.WriteModule(&out, m); err != nil {
return nil, err
}
result := &CompileResult{
Bytes: out.Bytes(),
}
return result, nil
} | go | func (r *Rego) Compile(ctx context.Context) (*CompileResult, error) {
pq, err := r.Partial(ctx)
if err != nil {
return nil, err
}
if len(pq.Support) > 0 {
return nil, fmt.Errorf("modules not supported")
}
policy, err := planner.New().WithQueries(pq.Queries).Plan()
if err != nil {
return nil, err
}
if r.dump != nil {
fmt.Fprintln(r.dump, "PLAN:")
fmt.Fprintln(r.dump, "-----")
ir.Pretty(r.dump, policy)
fmt.Fprintln(r.dump)
}
m, err := wasm.New().WithPolicy(policy).Compile()
if err != nil {
return nil, err
}
var out bytes.Buffer
if err := encoding.WriteModule(&out, m); err != nil {
return nil, err
}
result := &CompileResult{
Bytes: out.Bytes(),
}
return result, nil
} | [
"func",
"(",
"r",
"*",
"Rego",
")",
"Compile",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"CompileResult",
",",
"error",
")",
"{",
"pq",
",",
"err",
":=",
"r",
".",
"Partial",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"pq",
".",
"Support",
")",
">",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"policy",
",",
"err",
":=",
"planner",
".",
"New",
"(",
")",
".",
"WithQueries",
"(",
"pq",
".",
"Queries",
")",
".",
"Plan",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"dump",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintln",
"(",
"r",
".",
"dump",
",",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Fprintln",
"(",
"r",
".",
"dump",
",",
"\"",
"\"",
")",
"\n",
"ir",
".",
"Pretty",
"(",
"r",
".",
"dump",
",",
"policy",
")",
"\n",
"fmt",
".",
"Fprintln",
"(",
"r",
".",
"dump",
")",
"\n",
"}",
"\n\n",
"m",
",",
"err",
":=",
"wasm",
".",
"New",
"(",
")",
".",
"WithPolicy",
"(",
"policy",
")",
".",
"Compile",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"out",
"bytes",
".",
"Buffer",
"\n\n",
"if",
"err",
":=",
"encoding",
".",
"WriteModule",
"(",
"&",
"out",
",",
"m",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"result",
":=",
"&",
"CompileResult",
"{",
"Bytes",
":",
"out",
".",
"Bytes",
"(",
")",
",",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // Compile returns a compiled policy query. | [
"Compile",
"returns",
"a",
"compiled",
"policy",
"query",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L657-L696 | train |
open-policy-agent/opa | rego/rego.go | PrepareForEval | func (r *Rego) PrepareForEval(ctx context.Context, opts ...PrepareOption) (PreparedEvalQuery, error) {
if !r.hasQuery() {
return PreparedEvalQuery{}, fmt.Errorf("cannot evaluate empty query")
}
pCfg := &PrepareConfig{}
for _, o := range opts {
o(pCfg)
}
txn := r.txn
var err error
if txn == nil {
txn, err = r.store.NewTransaction(ctx)
if err != nil {
return PreparedEvalQuery{}, err
}
defer r.store.Abort(ctx, txn)
}
// If the caller wanted to do partial evaluation as part of preparation
// do it now and use the new Rego object.
if pCfg.doPartialEval {
err := r.prepare(ctx, txn, partialResultQueryType, []extraStage{
{
after: "ResolveRefs",
stage: r.rewriteQueryForPartialEval,
},
})
if err != nil {
return PreparedEvalQuery{}, err
}
ectx := &EvalContext{
parsedInput: r.parsedInput,
metrics: r.metrics,
txn: txn,
partialNamespace: r.partialNamespace,
tracers: r.tracers,
compiledQuery: r.compiledQueries[partialResultQueryType],
}
pr, err := r.partialResult(ctx, ectx, ast.Wildcard)
if err != nil {
return PreparedEvalQuery{}, err
}
// Prepare the new query
return pr.Rego().PrepareForEval(ctx)
}
err = r.prepare(ctx, txn, evalQueryType, []extraStage{
{
after: "ResolveRefs",
stage: r.rewriteQueryToCaptureValue,
},
})
if err != nil {
return PreparedEvalQuery{}, err
}
return PreparedEvalQuery{preparedQuery{r, pCfg}}, err
} | go | func (r *Rego) PrepareForEval(ctx context.Context, opts ...PrepareOption) (PreparedEvalQuery, error) {
if !r.hasQuery() {
return PreparedEvalQuery{}, fmt.Errorf("cannot evaluate empty query")
}
pCfg := &PrepareConfig{}
for _, o := range opts {
o(pCfg)
}
txn := r.txn
var err error
if txn == nil {
txn, err = r.store.NewTransaction(ctx)
if err != nil {
return PreparedEvalQuery{}, err
}
defer r.store.Abort(ctx, txn)
}
// If the caller wanted to do partial evaluation as part of preparation
// do it now and use the new Rego object.
if pCfg.doPartialEval {
err := r.prepare(ctx, txn, partialResultQueryType, []extraStage{
{
after: "ResolveRefs",
stage: r.rewriteQueryForPartialEval,
},
})
if err != nil {
return PreparedEvalQuery{}, err
}
ectx := &EvalContext{
parsedInput: r.parsedInput,
metrics: r.metrics,
txn: txn,
partialNamespace: r.partialNamespace,
tracers: r.tracers,
compiledQuery: r.compiledQueries[partialResultQueryType],
}
pr, err := r.partialResult(ctx, ectx, ast.Wildcard)
if err != nil {
return PreparedEvalQuery{}, err
}
// Prepare the new query
return pr.Rego().PrepareForEval(ctx)
}
err = r.prepare(ctx, txn, evalQueryType, []extraStage{
{
after: "ResolveRefs",
stage: r.rewriteQueryToCaptureValue,
},
})
if err != nil {
return PreparedEvalQuery{}, err
}
return PreparedEvalQuery{preparedQuery{r, pCfg}}, err
} | [
"func",
"(",
"r",
"*",
"Rego",
")",
"PrepareForEval",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"...",
"PrepareOption",
")",
"(",
"PreparedEvalQuery",
",",
"error",
")",
"{",
"if",
"!",
"r",
".",
"hasQuery",
"(",
")",
"{",
"return",
"PreparedEvalQuery",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"pCfg",
":=",
"&",
"PrepareConfig",
"{",
"}",
"\n",
"for",
"_",
",",
"o",
":=",
"range",
"opts",
"{",
"o",
"(",
"pCfg",
")",
"\n",
"}",
"\n\n",
"txn",
":=",
"r",
".",
"txn",
"\n\n",
"var",
"err",
"error",
"\n",
"if",
"txn",
"==",
"nil",
"{",
"txn",
",",
"err",
"=",
"r",
".",
"store",
".",
"NewTransaction",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"PreparedEvalQuery",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"defer",
"r",
".",
"store",
".",
"Abort",
"(",
"ctx",
",",
"txn",
")",
"\n",
"}",
"\n\n",
"// If the caller wanted to do partial evaluation as part of preparation",
"// do it now and use the new Rego object.",
"if",
"pCfg",
".",
"doPartialEval",
"{",
"err",
":=",
"r",
".",
"prepare",
"(",
"ctx",
",",
"txn",
",",
"partialResultQueryType",
",",
"[",
"]",
"extraStage",
"{",
"{",
"after",
":",
"\"",
"\"",
",",
"stage",
":",
"r",
".",
"rewriteQueryForPartialEval",
",",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"PreparedEvalQuery",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"ectx",
":=",
"&",
"EvalContext",
"{",
"parsedInput",
":",
"r",
".",
"parsedInput",
",",
"metrics",
":",
"r",
".",
"metrics",
",",
"txn",
":",
"txn",
",",
"partialNamespace",
":",
"r",
".",
"partialNamespace",
",",
"tracers",
":",
"r",
".",
"tracers",
",",
"compiledQuery",
":",
"r",
".",
"compiledQueries",
"[",
"partialResultQueryType",
"]",
",",
"}",
"\n\n",
"pr",
",",
"err",
":=",
"r",
".",
"partialResult",
"(",
"ctx",
",",
"ectx",
",",
"ast",
".",
"Wildcard",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"PreparedEvalQuery",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"// Prepare the new query",
"return",
"pr",
".",
"Rego",
"(",
")",
".",
"PrepareForEval",
"(",
"ctx",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"r",
".",
"prepare",
"(",
"ctx",
",",
"txn",
",",
"evalQueryType",
",",
"[",
"]",
"extraStage",
"{",
"{",
"after",
":",
"\"",
"\"",
",",
"stage",
":",
"r",
".",
"rewriteQueryToCaptureValue",
",",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"PreparedEvalQuery",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"PreparedEvalQuery",
"{",
"preparedQuery",
"{",
"r",
",",
"pCfg",
"}",
"}",
",",
"err",
"\n",
"}"
] | // PrepareForEval will parse inputs, modules, and query arguments in preparation
// of evaluating them. | [
"PrepareForEval",
"will",
"parse",
"inputs",
"modules",
"and",
"query",
"arguments",
"in",
"preparation",
"of",
"evaluating",
"them",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L719-L781 | train |
open-policy-agent/opa | rego/rego.go | PrepareForPartial | func (r *Rego) PrepareForPartial(ctx context.Context, opts ...PrepareOption) (PreparedPartialQuery, error) {
if !r.hasQuery() {
return PreparedPartialQuery{}, fmt.Errorf("cannot evaluate empty query")
}
pCfg := &PrepareConfig{}
for _, o := range opts {
o(pCfg)
}
txn := r.txn
var err error
if txn == nil {
txn, err = r.store.NewTransaction(ctx)
if err != nil {
return PreparedPartialQuery{}, err
}
defer r.store.Abort(ctx, txn)
}
err = r.prepare(ctx, txn, partialQueryType, []extraStage{
{
after: "CheckSafety",
stage: r.rewriteEqualsForPartialQueryCompile,
},
})
if err != nil {
return PreparedPartialQuery{}, err
}
return PreparedPartialQuery{preparedQuery{r, pCfg}}, err
} | go | func (r *Rego) PrepareForPartial(ctx context.Context, opts ...PrepareOption) (PreparedPartialQuery, error) {
if !r.hasQuery() {
return PreparedPartialQuery{}, fmt.Errorf("cannot evaluate empty query")
}
pCfg := &PrepareConfig{}
for _, o := range opts {
o(pCfg)
}
txn := r.txn
var err error
if txn == nil {
txn, err = r.store.NewTransaction(ctx)
if err != nil {
return PreparedPartialQuery{}, err
}
defer r.store.Abort(ctx, txn)
}
err = r.prepare(ctx, txn, partialQueryType, []extraStage{
{
after: "CheckSafety",
stage: r.rewriteEqualsForPartialQueryCompile,
},
})
if err != nil {
return PreparedPartialQuery{}, err
}
return PreparedPartialQuery{preparedQuery{r, pCfg}}, err
} | [
"func",
"(",
"r",
"*",
"Rego",
")",
"PrepareForPartial",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"...",
"PrepareOption",
")",
"(",
"PreparedPartialQuery",
",",
"error",
")",
"{",
"if",
"!",
"r",
".",
"hasQuery",
"(",
")",
"{",
"return",
"PreparedPartialQuery",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"pCfg",
":=",
"&",
"PrepareConfig",
"{",
"}",
"\n",
"for",
"_",
",",
"o",
":=",
"range",
"opts",
"{",
"o",
"(",
"pCfg",
")",
"\n",
"}",
"\n\n",
"txn",
":=",
"r",
".",
"txn",
"\n\n",
"var",
"err",
"error",
"\n",
"if",
"txn",
"==",
"nil",
"{",
"txn",
",",
"err",
"=",
"r",
".",
"store",
".",
"NewTransaction",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"PreparedPartialQuery",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"defer",
"r",
".",
"store",
".",
"Abort",
"(",
"ctx",
",",
"txn",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"r",
".",
"prepare",
"(",
"ctx",
",",
"txn",
",",
"partialQueryType",
",",
"[",
"]",
"extraStage",
"{",
"{",
"after",
":",
"\"",
"\"",
",",
"stage",
":",
"r",
".",
"rewriteEqualsForPartialQueryCompile",
",",
"}",
",",
"}",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"PreparedPartialQuery",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"PreparedPartialQuery",
"{",
"preparedQuery",
"{",
"r",
",",
"pCfg",
"}",
"}",
",",
"err",
"\n",
"}"
] | // PrepareForPartial will parse inputs, modules, and query arguments in preparation
// of partially evaluating them. | [
"PrepareForPartial",
"will",
"parse",
"inputs",
"modules",
"and",
"query",
"arguments",
"in",
"preparation",
"of",
"partially",
"evaluating",
"them",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L785-L818 | train |
open-policy-agent/opa | rego/rego.go | rewriteEqualsForPartialQueryCompile | func (r *Rego) rewriteEqualsForPartialQueryCompile(_ ast.QueryCompiler, query ast.Body) (ast.Body, error) {
doubleEq := ast.Equal.Ref()
unifyOp := ast.Equality.Ref()
ast.WalkExprs(query, func(x *ast.Expr) bool {
if x.IsCall() {
operator := x.Operator()
if operator.Equal(doubleEq) && len(x.Operands()) == 2 {
x.SetOperator(ast.NewTerm(unifyOp))
}
}
return false
})
return query, nil
} | go | func (r *Rego) rewriteEqualsForPartialQueryCompile(_ ast.QueryCompiler, query ast.Body) (ast.Body, error) {
doubleEq := ast.Equal.Ref()
unifyOp := ast.Equality.Ref()
ast.WalkExprs(query, func(x *ast.Expr) bool {
if x.IsCall() {
operator := x.Operator()
if operator.Equal(doubleEq) && len(x.Operands()) == 2 {
x.SetOperator(ast.NewTerm(unifyOp))
}
}
return false
})
return query, nil
} | [
"func",
"(",
"r",
"*",
"Rego",
")",
"rewriteEqualsForPartialQueryCompile",
"(",
"_",
"ast",
".",
"QueryCompiler",
",",
"query",
"ast",
".",
"Body",
")",
"(",
"ast",
".",
"Body",
",",
"error",
")",
"{",
"doubleEq",
":=",
"ast",
".",
"Equal",
".",
"Ref",
"(",
")",
"\n",
"unifyOp",
":=",
"ast",
".",
"Equality",
".",
"Ref",
"(",
")",
"\n",
"ast",
".",
"WalkExprs",
"(",
"query",
",",
"func",
"(",
"x",
"*",
"ast",
".",
"Expr",
")",
"bool",
"{",
"if",
"x",
".",
"IsCall",
"(",
")",
"{",
"operator",
":=",
"x",
".",
"Operator",
"(",
")",
"\n",
"if",
"operator",
".",
"Equal",
"(",
"doubleEq",
")",
"&&",
"len",
"(",
"x",
".",
"Operands",
"(",
")",
")",
"==",
"2",
"{",
"x",
".",
"SetOperator",
"(",
"ast",
".",
"NewTerm",
"(",
"unifyOp",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
")",
"\n",
"return",
"query",
",",
"nil",
"\n",
"}"
] | // rewriteEqualsForPartialQueryCompile will rewrite == to = in queries. Normally
// this wouldn't be done, except for handling queries with the `Partial` API
// where rewriting them can substantially simplify the result, and it is unlikely
// that the caller would need expression values. | [
"rewriteEqualsForPartialQueryCompile",
"will",
"rewrite",
"==",
"to",
"=",
"in",
"queries",
".",
"Normally",
"this",
"wouldn",
"t",
"be",
"done",
"except",
"for",
"handling",
"queries",
"with",
"the",
"Partial",
"API",
"where",
"rewriting",
"them",
"can",
"substantially",
"simplify",
"the",
"result",
"and",
"it",
"is",
"unlikely",
"that",
"the",
"caller",
"would",
"need",
"expression",
"values",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L1258-L1271 | train |
open-policy-agent/opa | bundle/bundle.go | Init | func (m *Manifest) Init() {
if m.Roots == nil {
defaultRoots := []string{""}
m.Roots = &defaultRoots
}
} | go | func (m *Manifest) Init() {
if m.Roots == nil {
defaultRoots := []string{""}
m.Roots = &defaultRoots
}
} | [
"func",
"(",
"m",
"*",
"Manifest",
")",
"Init",
"(",
")",
"{",
"if",
"m",
".",
"Roots",
"==",
"nil",
"{",
"defaultRoots",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
"\n",
"m",
".",
"Roots",
"=",
"&",
"defaultRoots",
"\n",
"}",
"\n",
"}"
] | // Init initializes the manifest. If you instantiate a manifest
// manually, call Init to ensure that the roots are set properly. | [
"Init",
"initializes",
"the",
"manifest",
".",
"If",
"you",
"instantiate",
"a",
"manifest",
"manually",
"call",
"Init",
"to",
"ensure",
"that",
"the",
"roots",
"are",
"set",
"properly",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/bundle/bundle.go#L52-L57 | train |
open-policy-agent/opa | bundle/bundle.go | IncludeManifestInData | func (r *Reader) IncludeManifestInData(includeManifestInData bool) *Reader {
r.includeManifestInData = includeManifestInData
return r
} | go | func (r *Reader) IncludeManifestInData(includeManifestInData bool) *Reader {
r.includeManifestInData = includeManifestInData
return r
} | [
"func",
"(",
"r",
"*",
"Reader",
")",
"IncludeManifestInData",
"(",
"includeManifestInData",
"bool",
")",
"*",
"Reader",
"{",
"r",
".",
"includeManifestInData",
"=",
"includeManifestInData",
"\n",
"return",
"r",
"\n",
"}"
] | // IncludeManifestInData sets whether the manifest metadata should be
// included in the bundle's data. | [
"IncludeManifestInData",
"sets",
"whether",
"the",
"manifest",
"metadata",
"should",
"be",
"included",
"in",
"the",
"bundle",
"s",
"data",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/bundle/bundle.go#L134-L137 | train |
open-policy-agent/opa | bundle/bundle.go | Write | func Write(w io.Writer, bundle Bundle) error {
gw := gzip.NewWriter(w)
tw := tar.NewWriter(gw)
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(bundle.Data); err != nil {
return err
}
if err := writeFile(tw, "data.json", buf.Bytes()); err != nil {
return err
}
for _, module := range bundle.Modules {
if err := writeFile(tw, module.Path, module.Raw); err != nil {
return err
}
}
if err := writeManifest(tw, bundle); err != nil {
return err
}
if err := tw.Close(); err != nil {
return err
}
return gw.Close()
} | go | func Write(w io.Writer, bundle Bundle) error {
gw := gzip.NewWriter(w)
tw := tar.NewWriter(gw)
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(bundle.Data); err != nil {
return err
}
if err := writeFile(tw, "data.json", buf.Bytes()); err != nil {
return err
}
for _, module := range bundle.Modules {
if err := writeFile(tw, module.Path, module.Raw); err != nil {
return err
}
}
if err := writeManifest(tw, bundle); err != nil {
return err
}
if err := tw.Close(); err != nil {
return err
}
return gw.Close()
} | [
"func",
"Write",
"(",
"w",
"io",
".",
"Writer",
",",
"bundle",
"Bundle",
")",
"error",
"{",
"gw",
":=",
"gzip",
".",
"NewWriter",
"(",
"w",
")",
"\n",
"tw",
":=",
"tar",
".",
"NewWriter",
"(",
"gw",
")",
"\n\n",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n\n",
"if",
"err",
":=",
"json",
".",
"NewEncoder",
"(",
"&",
"buf",
")",
".",
"Encode",
"(",
"bundle",
".",
"Data",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"writeFile",
"(",
"tw",
",",
"\"",
"\"",
",",
"buf",
".",
"Bytes",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"module",
":=",
"range",
"bundle",
".",
"Modules",
"{",
"if",
"err",
":=",
"writeFile",
"(",
"tw",
",",
"module",
".",
"Path",
",",
"module",
".",
"Raw",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"writeManifest",
"(",
"tw",
",",
"bundle",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"tw",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"gw",
".",
"Close",
"(",
")",
"\n",
"}"
] | // Write serializes the Bundle and writes it to w. | [
"Write",
"serializes",
"the",
"Bundle",
"and",
"writes",
"it",
"to",
"w",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/bundle/bundle.go#L241-L270 | train |
open-policy-agent/opa | bundle/bundle.go | Equal | func (b Bundle) Equal(other Bundle) bool {
if !reflect.DeepEqual(b.Data, other.Data) {
return false
}
if len(b.Modules) != len(other.Modules) {
return false
}
for i := range b.Modules {
if b.Modules[i].Path != other.Modules[i].Path {
return false
}
if !b.Modules[i].Parsed.Equal(other.Modules[i].Parsed) {
return false
}
if !bytes.Equal(b.Modules[i].Raw, other.Modules[i].Raw) {
return false
}
}
return true
} | go | func (b Bundle) Equal(other Bundle) bool {
if !reflect.DeepEqual(b.Data, other.Data) {
return false
}
if len(b.Modules) != len(other.Modules) {
return false
}
for i := range b.Modules {
if b.Modules[i].Path != other.Modules[i].Path {
return false
}
if !b.Modules[i].Parsed.Equal(other.Modules[i].Parsed) {
return false
}
if !bytes.Equal(b.Modules[i].Raw, other.Modules[i].Raw) {
return false
}
}
return true
} | [
"func",
"(",
"b",
"Bundle",
")",
"Equal",
"(",
"other",
"Bundle",
")",
"bool",
"{",
"if",
"!",
"reflect",
".",
"DeepEqual",
"(",
"b",
".",
"Data",
",",
"other",
".",
"Data",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"len",
"(",
"b",
".",
"Modules",
")",
"!=",
"len",
"(",
"other",
".",
"Modules",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"b",
".",
"Modules",
"{",
"if",
"b",
".",
"Modules",
"[",
"i",
"]",
".",
"Path",
"!=",
"other",
".",
"Modules",
"[",
"i",
"]",
".",
"Path",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"b",
".",
"Modules",
"[",
"i",
"]",
".",
"Parsed",
".",
"Equal",
"(",
"other",
".",
"Modules",
"[",
"i",
"]",
".",
"Parsed",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"bytes",
".",
"Equal",
"(",
"b",
".",
"Modules",
"[",
"i",
"]",
".",
"Raw",
",",
"other",
".",
"Modules",
"[",
"i",
"]",
".",
"Raw",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // Equal returns true if this bundle's contents equal the other bundle's
// contents. | [
"Equal",
"returns",
"true",
"if",
"this",
"bundle",
"s",
"contents",
"equal",
"the",
"other",
"bundle",
"s",
"contents",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/bundle/bundle.go#L285-L304 | train |
open-policy-agent/opa | ast/transform.go | TransformRefs | func TransformRefs(x interface{}, f func(Ref) (Value, error)) (interface{}, error) {
t := &GenericTransformer{func(x interface{}) (interface{}, error) {
if r, ok := x.(Ref); ok {
return f(r)
}
return x, nil
}}
return Transform(t, x)
} | go | func TransformRefs(x interface{}, f func(Ref) (Value, error)) (interface{}, error) {
t := &GenericTransformer{func(x interface{}) (interface{}, error) {
if r, ok := x.(Ref); ok {
return f(r)
}
return x, nil
}}
return Transform(t, x)
} | [
"func",
"TransformRefs",
"(",
"x",
"interface",
"{",
"}",
",",
"f",
"func",
"(",
"Ref",
")",
"(",
"Value",
",",
"error",
")",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"t",
":=",
"&",
"GenericTransformer",
"{",
"func",
"(",
"x",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"r",
",",
"ok",
":=",
"x",
".",
"(",
"Ref",
")",
";",
"ok",
"{",
"return",
"f",
"(",
"r",
")",
"\n",
"}",
"\n",
"return",
"x",
",",
"nil",
"\n",
"}",
"}",
"\n",
"return",
"Transform",
"(",
"t",
",",
"x",
")",
"\n",
"}"
] | // TransformRefs calls the function f on all references under x. | [
"TransformRefs",
"calls",
"the",
"function",
"f",
"on",
"all",
"references",
"under",
"x",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/transform.go#L248-L256 | train |
open-policy-agent/opa | ast/transform.go | TransformVars | func TransformVars(x interface{}, f func(Var) (Value, error)) (interface{}, error) {
t := &GenericTransformer{func(x interface{}) (interface{}, error) {
if v, ok := x.(Var); ok {
return f(v)
}
return x, nil
}}
return Transform(t, x)
} | go | func TransformVars(x interface{}, f func(Var) (Value, error)) (interface{}, error) {
t := &GenericTransformer{func(x interface{}) (interface{}, error) {
if v, ok := x.(Var); ok {
return f(v)
}
return x, nil
}}
return Transform(t, x)
} | [
"func",
"TransformVars",
"(",
"x",
"interface",
"{",
"}",
",",
"f",
"func",
"(",
"Var",
")",
"(",
"Value",
",",
"error",
")",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"t",
":=",
"&",
"GenericTransformer",
"{",
"func",
"(",
"x",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"v",
",",
"ok",
":=",
"x",
".",
"(",
"Var",
")",
";",
"ok",
"{",
"return",
"f",
"(",
"v",
")",
"\n",
"}",
"\n",
"return",
"x",
",",
"nil",
"\n",
"}",
"}",
"\n",
"return",
"Transform",
"(",
"t",
",",
"x",
")",
"\n",
"}"
] | // TransformVars calls the function f on all vars under x. | [
"TransformVars",
"calls",
"the",
"function",
"f",
"on",
"all",
"vars",
"under",
"x",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/transform.go#L259-L267 | train |
open-policy-agent/opa | ast/transform.go | TransformComprehensions | func TransformComprehensions(x interface{}, f func(interface{}) (Value, error)) (interface{}, error) {
t := &GenericTransformer{func(x interface{}) (interface{}, error) {
switch x := x.(type) {
case *ArrayComprehension:
return f(x)
case *SetComprehension:
return f(x)
case *ObjectComprehension:
return f(x)
}
return x, nil
}}
return Transform(t, x)
} | go | func TransformComprehensions(x interface{}, f func(interface{}) (Value, error)) (interface{}, error) {
t := &GenericTransformer{func(x interface{}) (interface{}, error) {
switch x := x.(type) {
case *ArrayComprehension:
return f(x)
case *SetComprehension:
return f(x)
case *ObjectComprehension:
return f(x)
}
return x, nil
}}
return Transform(t, x)
} | [
"func",
"TransformComprehensions",
"(",
"x",
"interface",
"{",
"}",
",",
"f",
"func",
"(",
"interface",
"{",
"}",
")",
"(",
"Value",
",",
"error",
")",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"t",
":=",
"&",
"GenericTransformer",
"{",
"func",
"(",
"x",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"switch",
"x",
":=",
"x",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ArrayComprehension",
":",
"return",
"f",
"(",
"x",
")",
"\n",
"case",
"*",
"SetComprehension",
":",
"return",
"f",
"(",
"x",
")",
"\n",
"case",
"*",
"ObjectComprehension",
":",
"return",
"f",
"(",
"x",
")",
"\n",
"}",
"\n",
"return",
"x",
",",
"nil",
"\n",
"}",
"}",
"\n",
"return",
"Transform",
"(",
"t",
",",
"x",
")",
"\n",
"}"
] | // TransformComprehensions calls the functio nf on all comprehensions under x. | [
"TransformComprehensions",
"calls",
"the",
"functio",
"nf",
"on",
"all",
"comprehensions",
"under",
"x",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/transform.go#L270-L283 | train |
open-policy-agent/opa | ast/unify.go | Unify | func Unify(safe VarSet, a *Term, b *Term) VarSet {
u := &unifier{
safe: safe,
unified: VarSet{},
unknown: map[Var]VarSet{},
}
u.unify(a, b)
return u.unified
} | go | func Unify(safe VarSet, a *Term, b *Term) VarSet {
u := &unifier{
safe: safe,
unified: VarSet{},
unknown: map[Var]VarSet{},
}
u.unify(a, b)
return u.unified
} | [
"func",
"Unify",
"(",
"safe",
"VarSet",
",",
"a",
"*",
"Term",
",",
"b",
"*",
"Term",
")",
"VarSet",
"{",
"u",
":=",
"&",
"unifier",
"{",
"safe",
":",
"safe",
",",
"unified",
":",
"VarSet",
"{",
"}",
",",
"unknown",
":",
"map",
"[",
"Var",
"]",
"VarSet",
"{",
"}",
",",
"}",
"\n",
"u",
".",
"unify",
"(",
"a",
",",
"b",
")",
"\n",
"return",
"u",
".",
"unified",
"\n",
"}"
] | // Unify returns a set of variables that will be unified when the equality expression defined by
// terms a and b is evaluated. The unifier assumes that variables in the VarSet safe are already
// unified. | [
"Unify",
"returns",
"a",
"set",
"of",
"variables",
"that",
"will",
"be",
"unified",
"when",
"the",
"equality",
"expression",
"defined",
"by",
"terms",
"a",
"and",
"b",
"is",
"evaluated",
".",
"The",
"unifier",
"assumes",
"that",
"variables",
"in",
"the",
"VarSet",
"safe",
"are",
"already",
"unified",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/unify.go#L10-L18 | train |
open-policy-agent/opa | runtime/runtime.go | RegisterPlugin | func RegisterPlugin(name string, factory plugins.Factory) {
registeredPluginsMux.Lock()
defer registeredPluginsMux.Unlock()
registeredPlugins[name] = factory
} | go | func RegisterPlugin(name string, factory plugins.Factory) {
registeredPluginsMux.Lock()
defer registeredPluginsMux.Unlock()
registeredPlugins[name] = factory
} | [
"func",
"RegisterPlugin",
"(",
"name",
"string",
",",
"factory",
"plugins",
".",
"Factory",
")",
"{",
"registeredPluginsMux",
".",
"Lock",
"(",
")",
"\n",
"defer",
"registeredPluginsMux",
".",
"Unlock",
"(",
")",
"\n",
"registeredPlugins",
"[",
"name",
"]",
"=",
"factory",
"\n",
"}"
] | // RegisterPlugin registers a plugin factory with the runtime
// package. When the runtime is created, the factories are used to parse
// plugin configuration and instantiate plugins. If no configuration is
// provided, plugins are not instantiated. This function is idempotent. | [
"RegisterPlugin",
"registers",
"a",
"plugin",
"factory",
"with",
"the",
"runtime",
"package",
".",
"When",
"the",
"runtime",
"is",
"created",
"the",
"factories",
"are",
"used",
"to",
"parse",
"plugin",
"configuration",
"and",
"instantiate",
"plugins",
".",
"If",
"no",
"configuration",
"is",
"provided",
"plugins",
"are",
"not",
"instantiated",
".",
"This",
"function",
"is",
"idempotent",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/runtime/runtime.go#L47-L51 | train |
open-policy-agent/opa | runtime/runtime.go | NewRuntime | func NewRuntime(ctx context.Context, params Params) (*Runtime, error) {
if params.ID == "" {
var err error
params.ID, err = generateInstanceID()
if err != nil {
return nil, err
}
}
loaded, err := loader.Filtered(params.Paths, params.Filter)
if err != nil {
return nil, err
}
store := inmem.New()
txn, err := store.NewTransaction(ctx, storage.WriteParams)
if err != nil {
return nil, err
}
if err := store.Write(ctx, txn, storage.AddOp, storage.Path{}, loaded.Documents); err != nil {
store.Abort(ctx, txn)
return nil, errors.Wrapf(err, "storage error")
}
if err := storedversion.Write(ctx, store, txn); err != nil {
store.Abort(ctx, txn)
return nil, errors.Wrapf(err, "storage error")
}
if err := compileAndStoreInputs(ctx, store, txn, loaded.Modules, params.ErrorLimit); err != nil {
store.Abort(ctx, txn)
return nil, errors.Wrapf(err, "compile error")
}
if err := store.Commit(ctx, txn); err != nil {
return nil, errors.Wrapf(err, "storage error")
}
bs, err := loadConfig(params)
if err != nil {
return nil, errors.Wrapf(err, "config error")
}
info, err := runtime.Term(runtime.Params{Config: bs})
if err != nil {
return nil, err
}
manager, err := plugins.New(bs, params.ID, store, plugins.Info(info))
if err != nil {
return nil, errors.Wrapf(err, "config error")
}
disco, err := discovery.New(manager, discovery.Factories(registeredPlugins))
if err != nil {
return nil, errors.Wrapf(err, "config error")
}
manager.Register("discovery", disco)
rt := &Runtime{
Store: store,
Params: params,
Manager: manager,
info: info,
}
return rt, nil
} | go | func NewRuntime(ctx context.Context, params Params) (*Runtime, error) {
if params.ID == "" {
var err error
params.ID, err = generateInstanceID()
if err != nil {
return nil, err
}
}
loaded, err := loader.Filtered(params.Paths, params.Filter)
if err != nil {
return nil, err
}
store := inmem.New()
txn, err := store.NewTransaction(ctx, storage.WriteParams)
if err != nil {
return nil, err
}
if err := store.Write(ctx, txn, storage.AddOp, storage.Path{}, loaded.Documents); err != nil {
store.Abort(ctx, txn)
return nil, errors.Wrapf(err, "storage error")
}
if err := storedversion.Write(ctx, store, txn); err != nil {
store.Abort(ctx, txn)
return nil, errors.Wrapf(err, "storage error")
}
if err := compileAndStoreInputs(ctx, store, txn, loaded.Modules, params.ErrorLimit); err != nil {
store.Abort(ctx, txn)
return nil, errors.Wrapf(err, "compile error")
}
if err := store.Commit(ctx, txn); err != nil {
return nil, errors.Wrapf(err, "storage error")
}
bs, err := loadConfig(params)
if err != nil {
return nil, errors.Wrapf(err, "config error")
}
info, err := runtime.Term(runtime.Params{Config: bs})
if err != nil {
return nil, err
}
manager, err := plugins.New(bs, params.ID, store, plugins.Info(info))
if err != nil {
return nil, errors.Wrapf(err, "config error")
}
disco, err := discovery.New(manager, discovery.Factories(registeredPlugins))
if err != nil {
return nil, errors.Wrapf(err, "config error")
}
manager.Register("discovery", disco)
rt := &Runtime{
Store: store,
Params: params,
Manager: manager,
info: info,
}
return rt, nil
} | [
"func",
"NewRuntime",
"(",
"ctx",
"context",
".",
"Context",
",",
"params",
"Params",
")",
"(",
"*",
"Runtime",
",",
"error",
")",
"{",
"if",
"params",
".",
"ID",
"==",
"\"",
"\"",
"{",
"var",
"err",
"error",
"\n",
"params",
".",
"ID",
",",
"err",
"=",
"generateInstanceID",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"loaded",
",",
"err",
":=",
"loader",
".",
"Filtered",
"(",
"params",
".",
"Paths",
",",
"params",
".",
"Filter",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"store",
":=",
"inmem",
".",
"New",
"(",
")",
"\n\n",
"txn",
",",
"err",
":=",
"store",
".",
"NewTransaction",
"(",
"ctx",
",",
"storage",
".",
"WriteParams",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"store",
".",
"Write",
"(",
"ctx",
",",
"txn",
",",
"storage",
".",
"AddOp",
",",
"storage",
".",
"Path",
"{",
"}",
",",
"loaded",
".",
"Documents",
")",
";",
"err",
"!=",
"nil",
"{",
"store",
".",
"Abort",
"(",
"ctx",
",",
"txn",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"storedversion",
".",
"Write",
"(",
"ctx",
",",
"store",
",",
"txn",
")",
";",
"err",
"!=",
"nil",
"{",
"store",
".",
"Abort",
"(",
"ctx",
",",
"txn",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"compileAndStoreInputs",
"(",
"ctx",
",",
"store",
",",
"txn",
",",
"loaded",
".",
"Modules",
",",
"params",
".",
"ErrorLimit",
")",
";",
"err",
"!=",
"nil",
"{",
"store",
".",
"Abort",
"(",
"ctx",
",",
"txn",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"store",
".",
"Commit",
"(",
"ctx",
",",
"txn",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"bs",
",",
"err",
":=",
"loadConfig",
"(",
"params",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"info",
",",
"err",
":=",
"runtime",
".",
"Term",
"(",
"runtime",
".",
"Params",
"{",
"Config",
":",
"bs",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"manager",
",",
"err",
":=",
"plugins",
".",
"New",
"(",
"bs",
",",
"params",
".",
"ID",
",",
"store",
",",
"plugins",
".",
"Info",
"(",
"info",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"disco",
",",
"err",
":=",
"discovery",
".",
"New",
"(",
"manager",
",",
"discovery",
".",
"Factories",
"(",
"registeredPlugins",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"manager",
".",
"Register",
"(",
"\"",
"\"",
",",
"disco",
")",
"\n\n",
"rt",
":=",
"&",
"Runtime",
"{",
"Store",
":",
"store",
",",
"Params",
":",
"params",
",",
"Manager",
":",
"manager",
",",
"info",
":",
"info",
",",
"}",
"\n\n",
"return",
"rt",
",",
"nil",
"\n",
"}"
] | // NewRuntime returns a new Runtime object initialized with params. | [
"NewRuntime",
"returns",
"a",
"new",
"Runtime",
"object",
"initialized",
"with",
"params",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/runtime/runtime.go#L165-L236 | train |
open-policy-agent/opa | runtime/runtime.go | StartREPL | func (rt *Runtime) StartREPL(ctx context.Context) {
if err := rt.Manager.Start(ctx); err != nil {
fmt.Fprintln(rt.Params.Output, "error starting plugins:", err)
os.Exit(1)
}
defer rt.Manager.Stop(ctx)
banner := rt.getBanner()
repl := repl.New(rt.Store, rt.Params.HistoryPath, rt.Params.Output, rt.Params.OutputFormat, rt.Params.ErrorLimit, banner).WithRuntime(rt.info)
if rt.Params.Watch {
if err := rt.startWatcher(ctx, rt.Params.Paths, onReloadPrinter(rt.Params.Output)); err != nil {
fmt.Fprintln(rt.Params.Output, "error opening watch:", err)
os.Exit(1)
}
}
repl.Loop(ctx)
} | go | func (rt *Runtime) StartREPL(ctx context.Context) {
if err := rt.Manager.Start(ctx); err != nil {
fmt.Fprintln(rt.Params.Output, "error starting plugins:", err)
os.Exit(1)
}
defer rt.Manager.Stop(ctx)
banner := rt.getBanner()
repl := repl.New(rt.Store, rt.Params.HistoryPath, rt.Params.Output, rt.Params.OutputFormat, rt.Params.ErrorLimit, banner).WithRuntime(rt.info)
if rt.Params.Watch {
if err := rt.startWatcher(ctx, rt.Params.Paths, onReloadPrinter(rt.Params.Output)); err != nil {
fmt.Fprintln(rt.Params.Output, "error opening watch:", err)
os.Exit(1)
}
}
repl.Loop(ctx)
} | [
"func",
"(",
"rt",
"*",
"Runtime",
")",
"StartREPL",
"(",
"ctx",
"context",
".",
"Context",
")",
"{",
"if",
"err",
":=",
"rt",
".",
"Manager",
".",
"Start",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintln",
"(",
"rt",
".",
"Params",
".",
"Output",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"os",
".",
"Exit",
"(",
"1",
")",
"\n",
"}",
"\n\n",
"defer",
"rt",
".",
"Manager",
".",
"Stop",
"(",
"ctx",
")",
"\n\n",
"banner",
":=",
"rt",
".",
"getBanner",
"(",
")",
"\n",
"repl",
":=",
"repl",
".",
"New",
"(",
"rt",
".",
"Store",
",",
"rt",
".",
"Params",
".",
"HistoryPath",
",",
"rt",
".",
"Params",
".",
"Output",
",",
"rt",
".",
"Params",
".",
"OutputFormat",
",",
"rt",
".",
"Params",
".",
"ErrorLimit",
",",
"banner",
")",
".",
"WithRuntime",
"(",
"rt",
".",
"info",
")",
"\n\n",
"if",
"rt",
".",
"Params",
".",
"Watch",
"{",
"if",
"err",
":=",
"rt",
".",
"startWatcher",
"(",
"ctx",
",",
"rt",
".",
"Params",
".",
"Paths",
",",
"onReloadPrinter",
"(",
"rt",
".",
"Params",
".",
"Output",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintln",
"(",
"rt",
".",
"Params",
".",
"Output",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"os",
".",
"Exit",
"(",
"1",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"repl",
".",
"Loop",
"(",
"ctx",
")",
"\n",
"}"
] | // StartREPL starts the runtime in REPL mode. This function will block the calling goroutine. | [
"StartREPL",
"starts",
"the",
"runtime",
"in",
"REPL",
"mode",
".",
"This",
"function",
"will",
"block",
"the",
"calling",
"goroutine",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/runtime/runtime.go#L318-L338 | train |
open-policy-agent/opa | internal/compiler/wasm/wasm.go | New | func New() *Compiler {
c := &Compiler{
code: &module.CodeEntry{},
stringOffset: 2048,
localMax: 2, // assume that locals start at 0..2 then increment monotonically
}
c.stages = []func() error{
c.initModule,
c.compileStrings,
c.emitEntry,
c.compilePlan,
c.emitLocals,
c.emitFunctionSection,
c.emitExportSection,
c.emitCodeSection,
c.emitDataSection,
}
return c
} | go | func New() *Compiler {
c := &Compiler{
code: &module.CodeEntry{},
stringOffset: 2048,
localMax: 2, // assume that locals start at 0..2 then increment monotonically
}
c.stages = []func() error{
c.initModule,
c.compileStrings,
c.emitEntry,
c.compilePlan,
c.emitLocals,
c.emitFunctionSection,
c.emitExportSection,
c.emitCodeSection,
c.emitDataSection,
}
return c
} | [
"func",
"New",
"(",
")",
"*",
"Compiler",
"{",
"c",
":=",
"&",
"Compiler",
"{",
"code",
":",
"&",
"module",
".",
"CodeEntry",
"{",
"}",
",",
"stringOffset",
":",
"2048",
",",
"localMax",
":",
"2",
",",
"// assume that locals start at 0..2 then increment monotonically",
"}",
"\n",
"c",
".",
"stages",
"=",
"[",
"]",
"func",
"(",
")",
"error",
"{",
"c",
".",
"initModule",
",",
"c",
".",
"compileStrings",
",",
"c",
".",
"emitEntry",
",",
"c",
".",
"compilePlan",
",",
"c",
".",
"emitLocals",
",",
"c",
".",
"emitFunctionSection",
",",
"c",
".",
"emitExportSection",
",",
"c",
".",
"emitCodeSection",
",",
"c",
".",
"emitDataSection",
",",
"}",
"\n",
"return",
"c",
"\n",
"}"
] | // New returns a new compiler object. | [
"New",
"returns",
"a",
"new",
"compiler",
"object",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/compiler/wasm/wasm.go#L71-L89 | train |
open-policy-agent/opa | internal/compiler/wasm/wasm.go | WithPolicy | func (c *Compiler) WithPolicy(p *ir.Policy) *Compiler {
c.policy = p
return c
} | go | func (c *Compiler) WithPolicy(p *ir.Policy) *Compiler {
c.policy = p
return c
} | [
"func",
"(",
"c",
"*",
"Compiler",
")",
"WithPolicy",
"(",
"p",
"*",
"ir",
".",
"Policy",
")",
"*",
"Compiler",
"{",
"c",
".",
"policy",
"=",
"p",
"\n",
"return",
"c",
"\n",
"}"
] | // WithPolicy sets the policy to compile. | [
"WithPolicy",
"sets",
"the",
"policy",
"to",
"compile",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/compiler/wasm/wasm.go#L92-L95 | train |
open-policy-agent/opa | internal/compiler/wasm/wasm.go | Compile | func (c *Compiler) Compile() (*module.Module, error) {
for _, stage := range c.stages {
if err := stage(); err != nil {
return nil, err
}
}
return c.module, nil
} | go | func (c *Compiler) Compile() (*module.Module, error) {
for _, stage := range c.stages {
if err := stage(); err != nil {
return nil, err
}
}
return c.module, nil
} | [
"func",
"(",
"c",
"*",
"Compiler",
")",
"Compile",
"(",
")",
"(",
"*",
"module",
".",
"Module",
",",
"error",
")",
"{",
"for",
"_",
",",
"stage",
":=",
"range",
"c",
".",
"stages",
"{",
"if",
"err",
":=",
"stage",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"module",
",",
"nil",
"\n",
"}"
] | // Compile returns a compiled WASM module. | [
"Compile",
"returns",
"a",
"compiled",
"WASM",
"module",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/compiler/wasm/wasm.go#L98-L107 | train |
open-policy-agent/opa | plugins/discovery/discovery.go | Factories | func Factories(fs map[string]plugins.Factory) func(*Discovery) {
return func(d *Discovery) {
d.factories = fs
}
} | go | func Factories(fs map[string]plugins.Factory) func(*Discovery) {
return func(d *Discovery) {
d.factories = fs
}
} | [
"func",
"Factories",
"(",
"fs",
"map",
"[",
"string",
"]",
"plugins",
".",
"Factory",
")",
"func",
"(",
"*",
"Discovery",
")",
"{",
"return",
"func",
"(",
"d",
"*",
"Discovery",
")",
"{",
"d",
".",
"factories",
"=",
"fs",
"\n",
"}",
"\n",
"}"
] | // Factories provides a set of factory functions to use for
// instantiating custom plugins. | [
"Factories",
"provides",
"a",
"set",
"of",
"factory",
"functions",
"to",
"use",
"for",
"instantiating",
"custom",
"plugins",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/plugins/discovery/discovery.go#L40-L44 | train |
open-policy-agent/opa | plugins/discovery/discovery.go | New | func New(manager *plugins.Manager, opts ...func(*Discovery)) (*Discovery, error) {
result := &Discovery{
manager: manager,
}
for _, f := range opts {
f(result)
}
config, err := ParseConfig(manager.Config.Discovery, manager.Services())
if err != nil {
return nil, err
} else if config == nil {
if _, err := getPluginSet(result.factories, manager, manager.Config); err != nil {
return nil, err
}
return result, nil
}
if manager.Config.PluginsEnabled() {
return nil, fmt.Errorf("plugins cannot be specified in the bootstrap configuration when discovery enabled")
}
result.config = config
result.downloader = download.New(config.Config, manager.Client(config.service), config.path).WithCallback(result.oneShot)
result.status = &bundle.Status{
Name: *config.Name,
}
return result, nil
} | go | func New(manager *plugins.Manager, opts ...func(*Discovery)) (*Discovery, error) {
result := &Discovery{
manager: manager,
}
for _, f := range opts {
f(result)
}
config, err := ParseConfig(manager.Config.Discovery, manager.Services())
if err != nil {
return nil, err
} else if config == nil {
if _, err := getPluginSet(result.factories, manager, manager.Config); err != nil {
return nil, err
}
return result, nil
}
if manager.Config.PluginsEnabled() {
return nil, fmt.Errorf("plugins cannot be specified in the bootstrap configuration when discovery enabled")
}
result.config = config
result.downloader = download.New(config.Config, manager.Client(config.service), config.path).WithCallback(result.oneShot)
result.status = &bundle.Status{
Name: *config.Name,
}
return result, nil
} | [
"func",
"New",
"(",
"manager",
"*",
"plugins",
".",
"Manager",
",",
"opts",
"...",
"func",
"(",
"*",
"Discovery",
")",
")",
"(",
"*",
"Discovery",
",",
"error",
")",
"{",
"result",
":=",
"&",
"Discovery",
"{",
"manager",
":",
"manager",
",",
"}",
"\n\n",
"for",
"_",
",",
"f",
":=",
"range",
"opts",
"{",
"f",
"(",
"result",
")",
"\n",
"}",
"\n\n",
"config",
",",
"err",
":=",
"ParseConfig",
"(",
"manager",
".",
"Config",
".",
"Discovery",
",",
"manager",
".",
"Services",
"(",
")",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"else",
"if",
"config",
"==",
"nil",
"{",
"if",
"_",
",",
"err",
":=",
"getPluginSet",
"(",
"result",
".",
"factories",
",",
"manager",
",",
"manager",
".",
"Config",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"manager",
".",
"Config",
".",
"PluginsEnabled",
"(",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"result",
".",
"config",
"=",
"config",
"\n",
"result",
".",
"downloader",
"=",
"download",
".",
"New",
"(",
"config",
".",
"Config",
",",
"manager",
".",
"Client",
"(",
"config",
".",
"service",
")",
",",
"config",
".",
"path",
")",
".",
"WithCallback",
"(",
"result",
".",
"oneShot",
")",
"\n",
"result",
".",
"status",
"=",
"&",
"bundle",
".",
"Status",
"{",
"Name",
":",
"*",
"config",
".",
"Name",
",",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // New returns a new discovery plugin. | [
"New",
"returns",
"a",
"new",
"discovery",
"plugin",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/plugins/discovery/discovery.go#L47-L79 | train |
open-policy-agent/opa | plugins/discovery/discovery.go | Start | func (c *Discovery) Start(ctx context.Context) error {
if c.downloader != nil {
c.downloader.Start(ctx)
}
return nil
} | go | func (c *Discovery) Start(ctx context.Context) error {
if c.downloader != nil {
c.downloader.Start(ctx)
}
return nil
} | [
"func",
"(",
"c",
"*",
"Discovery",
")",
"Start",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"if",
"c",
".",
"downloader",
"!=",
"nil",
"{",
"c",
".",
"downloader",
".",
"Start",
"(",
"ctx",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Start starts the dynamic discovery process if configured. | [
"Start",
"starts",
"the",
"dynamic",
"discovery",
"process",
"if",
"configured",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/plugins/discovery/discovery.go#L82-L87 | train |
open-policy-agent/opa | plugins/discovery/discovery.go | Stop | func (c *Discovery) Stop(ctx context.Context) {
if c.downloader != nil {
c.downloader.Stop(ctx)
}
} | go | func (c *Discovery) Stop(ctx context.Context) {
if c.downloader != nil {
c.downloader.Stop(ctx)
}
} | [
"func",
"(",
"c",
"*",
"Discovery",
")",
"Stop",
"(",
"ctx",
"context",
".",
"Context",
")",
"{",
"if",
"c",
".",
"downloader",
"!=",
"nil",
"{",
"c",
".",
"downloader",
".",
"Stop",
"(",
"ctx",
")",
"\n",
"}",
"\n",
"}"
] | // Stop stops the dynamic discovery process if configured. | [
"Stop",
"stops",
"the",
"dynamic",
"discovery",
"process",
"if",
"configured",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/plugins/discovery/discovery.go#L90-L94 | train |
open-policy-agent/opa | server/identifier/identifier.go | Identity | func Identity(r *http.Request) (string, bool) {
ctx := r.Context()
v, ok := ctx.Value(identity).(string)
if ok {
return v, true
}
return "", false
} | go | func Identity(r *http.Request) (string, bool) {
ctx := r.Context()
v, ok := ctx.Value(identity).(string)
if ok {
return v, true
}
return "", false
} | [
"func",
"Identity",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"string",
",",
"bool",
")",
"{",
"ctx",
":=",
"r",
".",
"Context",
"(",
")",
"\n",
"v",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"identity",
")",
".",
"(",
"string",
")",
"\n",
"if",
"ok",
"{",
"return",
"v",
",",
"true",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}"
] | // Identity returns the identity of the caller associated with ctx. | [
"Identity",
"returns",
"the",
"identity",
"of",
"the",
"caller",
"associated",
"with",
"ctx",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/identifier/identifier.go#L15-L22 | train |
open-policy-agent/opa | server/identifier/identifier.go | SetIdentity | func SetIdentity(r *http.Request, v string) *http.Request {
return r.WithContext(context.WithValue(r.Context(), identity, v))
} | go | func SetIdentity(r *http.Request, v string) *http.Request {
return r.WithContext(context.WithValue(r.Context(), identity, v))
} | [
"func",
"SetIdentity",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"v",
"string",
")",
"*",
"http",
".",
"Request",
"{",
"return",
"r",
".",
"WithContext",
"(",
"context",
".",
"WithValue",
"(",
"r",
".",
"Context",
"(",
")",
",",
"identity",
",",
"v",
")",
")",
"\n",
"}"
] | // SetIdentity returns a new http.Request with the identity set to v. | [
"SetIdentity",
"returns",
"a",
"new",
"http",
".",
"Request",
"with",
"the",
"identity",
"set",
"to",
"v",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/identifier/identifier.go#L25-L27 | train |
open-policy-agent/opa | ast/policy.go | IsKeyword | func IsKeyword(s string) bool {
for _, x := range Keywords {
if x == s {
return true
}
}
return false
} | go | func IsKeyword(s string) bool {
for _, x := range Keywords {
if x == s {
return true
}
}
return false
} | [
"func",
"IsKeyword",
"(",
"s",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"x",
":=",
"range",
"Keywords",
"{",
"if",
"x",
"==",
"s",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsKeyword returns true if s is a language keyword. | [
"IsKeyword",
"returns",
"true",
"if",
"s",
"is",
"a",
"language",
"keyword",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L90-L97 | train |
open-policy-agent/opa | ast/policy.go | Compare | func (mod *Module) Compare(other *Module) int {
if mod == nil {
if other == nil {
return 0
}
return -1
} else if other == nil {
return 1
}
if cmp := mod.Package.Compare(other.Package); cmp != 0 {
return cmp
}
if cmp := importsCompare(mod.Imports, other.Imports); cmp != 0 {
return cmp
}
return rulesCompare(mod.Rules, other.Rules)
} | go | func (mod *Module) Compare(other *Module) int {
if mod == nil {
if other == nil {
return 0
}
return -1
} else if other == nil {
return 1
}
if cmp := mod.Package.Compare(other.Package); cmp != 0 {
return cmp
}
if cmp := importsCompare(mod.Imports, other.Imports); cmp != 0 {
return cmp
}
return rulesCompare(mod.Rules, other.Rules)
} | [
"func",
"(",
"mod",
"*",
"Module",
")",
"Compare",
"(",
"other",
"*",
"Module",
")",
"int",
"{",
"if",
"mod",
"==",
"nil",
"{",
"if",
"other",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"-",
"1",
"\n",
"}",
"else",
"if",
"other",
"==",
"nil",
"{",
"return",
"1",
"\n",
"}",
"\n",
"if",
"cmp",
":=",
"mod",
".",
"Package",
".",
"Compare",
"(",
"other",
".",
"Package",
")",
";",
"cmp",
"!=",
"0",
"{",
"return",
"cmp",
"\n",
"}",
"\n",
"if",
"cmp",
":=",
"importsCompare",
"(",
"mod",
".",
"Imports",
",",
"other",
".",
"Imports",
")",
";",
"cmp",
"!=",
"0",
"{",
"return",
"cmp",
"\n",
"}",
"\n",
"return",
"rulesCompare",
"(",
"mod",
".",
"Rules",
",",
"other",
".",
"Rules",
")",
"\n",
"}"
] | // Compare returns an integer indicating whether mod is less than, equal to,
// or greater than other. | [
"Compare",
"returns",
"an",
"integer",
"indicating",
"whether",
"mod",
"is",
"less",
"than",
"equal",
"to",
"or",
"greater",
"than",
"other",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L199-L215 | train |
open-policy-agent/opa | ast/policy.go | Copy | func (mod *Module) Copy() *Module {
cpy := *mod
cpy.Rules = make([]*Rule, len(mod.Rules))
for i := range mod.Rules {
cpy.Rules[i] = mod.Rules[i].Copy()
}
cpy.Imports = make([]*Import, len(mod.Imports))
for i := range mod.Imports {
cpy.Imports[i] = mod.Imports[i].Copy()
}
cpy.Package = mod.Package.Copy()
return &cpy
} | go | func (mod *Module) Copy() *Module {
cpy := *mod
cpy.Rules = make([]*Rule, len(mod.Rules))
for i := range mod.Rules {
cpy.Rules[i] = mod.Rules[i].Copy()
}
cpy.Imports = make([]*Import, len(mod.Imports))
for i := range mod.Imports {
cpy.Imports[i] = mod.Imports[i].Copy()
}
cpy.Package = mod.Package.Copy()
return &cpy
} | [
"func",
"(",
"mod",
"*",
"Module",
")",
"Copy",
"(",
")",
"*",
"Module",
"{",
"cpy",
":=",
"*",
"mod",
"\n",
"cpy",
".",
"Rules",
"=",
"make",
"(",
"[",
"]",
"*",
"Rule",
",",
"len",
"(",
"mod",
".",
"Rules",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"mod",
".",
"Rules",
"{",
"cpy",
".",
"Rules",
"[",
"i",
"]",
"=",
"mod",
".",
"Rules",
"[",
"i",
"]",
".",
"Copy",
"(",
")",
"\n",
"}",
"\n",
"cpy",
".",
"Imports",
"=",
"make",
"(",
"[",
"]",
"*",
"Import",
",",
"len",
"(",
"mod",
".",
"Imports",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"mod",
".",
"Imports",
"{",
"cpy",
".",
"Imports",
"[",
"i",
"]",
"=",
"mod",
".",
"Imports",
"[",
"i",
"]",
".",
"Copy",
"(",
")",
"\n",
"}",
"\n",
"cpy",
".",
"Package",
"=",
"mod",
".",
"Package",
".",
"Copy",
"(",
")",
"\n",
"return",
"&",
"cpy",
"\n",
"}"
] | // Copy returns a deep copy of mod. | [
"Copy",
"returns",
"a",
"deep",
"copy",
"of",
"mod",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L218-L230 | train |
open-policy-agent/opa | ast/policy.go | RuleSet | func (mod *Module) RuleSet(name Var) RuleSet {
rs := NewRuleSet()
for _, rule := range mod.Rules {
if rule.Head.Name.Equal(name) {
rs.Add(rule)
}
}
return rs
} | go | func (mod *Module) RuleSet(name Var) RuleSet {
rs := NewRuleSet()
for _, rule := range mod.Rules {
if rule.Head.Name.Equal(name) {
rs.Add(rule)
}
}
return rs
} | [
"func",
"(",
"mod",
"*",
"Module",
")",
"RuleSet",
"(",
"name",
"Var",
")",
"RuleSet",
"{",
"rs",
":=",
"NewRuleSet",
"(",
")",
"\n",
"for",
"_",
",",
"rule",
":=",
"range",
"mod",
".",
"Rules",
"{",
"if",
"rule",
".",
"Head",
".",
"Name",
".",
"Equal",
"(",
"name",
")",
"{",
"rs",
".",
"Add",
"(",
"rule",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"rs",
"\n",
"}"
] | // RuleSet returns a RuleSet containing named rules in the mod. | [
"RuleSet",
"returns",
"a",
"RuleSet",
"containing",
"named",
"rules",
"in",
"the",
"mod",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L256-L264 | train |
open-policy-agent/opa | ast/policy.go | Equal | func (c *Comment) Equal(other *Comment) bool {
return c.Location.Equal(other.Location) && bytes.Equal(c.Text, other.Text)
} | go | func (c *Comment) Equal(other *Comment) bool {
return c.Location.Equal(other.Location) && bytes.Equal(c.Text, other.Text)
} | [
"func",
"(",
"c",
"*",
"Comment",
")",
"Equal",
"(",
"other",
"*",
"Comment",
")",
"bool",
"{",
"return",
"c",
".",
"Location",
".",
"Equal",
"(",
"other",
".",
"Location",
")",
"&&",
"bytes",
".",
"Equal",
"(",
"c",
".",
"Text",
",",
"other",
".",
"Text",
")",
"\n",
"}"
] | // Equal returns true if this comment equals the other comment.
// Unlike other equality checks on AST nodes, comment equality
// depends on location. | [
"Equal",
"returns",
"true",
"if",
"this",
"comment",
"equals",
"the",
"other",
"comment",
".",
"Unlike",
"other",
"equality",
"checks",
"on",
"AST",
"nodes",
"comment",
"equality",
"depends",
"on",
"location",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L293-L295 | train |
open-policy-agent/opa | ast/policy.go | Compare | func (pkg *Package) Compare(other *Package) int {
return Compare(pkg.Path, other.Path)
} | go | func (pkg *Package) Compare(other *Package) int {
return Compare(pkg.Path, other.Path)
} | [
"func",
"(",
"pkg",
"*",
"Package",
")",
"Compare",
"(",
"other",
"*",
"Package",
")",
"int",
"{",
"return",
"Compare",
"(",
"pkg",
".",
"Path",
",",
"other",
".",
"Path",
")",
"\n",
"}"
] | // Compare returns an integer indicating whether pkg is less than, equal to,
// or greater than other. | [
"Compare",
"returns",
"an",
"integer",
"indicating",
"whether",
"pkg",
"is",
"less",
"than",
"equal",
"to",
"or",
"greater",
"than",
"other",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L299-L301 | train |
open-policy-agent/opa | ast/policy.go | Copy | func (pkg *Package) Copy() *Package {
cpy := *pkg
cpy.Path = pkg.Path.Copy()
return &cpy
} | go | func (pkg *Package) Copy() *Package {
cpy := *pkg
cpy.Path = pkg.Path.Copy()
return &cpy
} | [
"func",
"(",
"pkg",
"*",
"Package",
")",
"Copy",
"(",
")",
"*",
"Package",
"{",
"cpy",
":=",
"*",
"pkg",
"\n",
"cpy",
".",
"Path",
"=",
"pkg",
".",
"Path",
".",
"Copy",
"(",
")",
"\n",
"return",
"&",
"cpy",
"\n",
"}"
] | // Copy returns a deep copy of pkg. | [
"Copy",
"returns",
"a",
"deep",
"copy",
"of",
"pkg",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L304-L308 | train |
open-policy-agent/opa | ast/policy.go | IsValidImportPath | func IsValidImportPath(v Value) (err error) {
switch v := v.(type) {
case Var:
if !v.Equal(DefaultRootDocument.Value) && !v.Equal(InputRootDocument.Value) {
return fmt.Errorf("invalid path %v: path must begin with input or data", v)
}
case Ref:
if err := IsValidImportPath(v[0].Value); err != nil {
return fmt.Errorf("invalid path %v: path must begin with input or data", v)
}
for _, e := range v[1:] {
if _, ok := e.Value.(String); !ok {
return fmt.Errorf("invalid path %v: path elements must be strings", v)
}
}
default:
return fmt.Errorf("invalid path %v: path must be ref or var", v)
}
return nil
} | go | func IsValidImportPath(v Value) (err error) {
switch v := v.(type) {
case Var:
if !v.Equal(DefaultRootDocument.Value) && !v.Equal(InputRootDocument.Value) {
return fmt.Errorf("invalid path %v: path must begin with input or data", v)
}
case Ref:
if err := IsValidImportPath(v[0].Value); err != nil {
return fmt.Errorf("invalid path %v: path must begin with input or data", v)
}
for _, e := range v[1:] {
if _, ok := e.Value.(String); !ok {
return fmt.Errorf("invalid path %v: path elements must be strings", v)
}
}
default:
return fmt.Errorf("invalid path %v: path must be ref or var", v)
}
return nil
} | [
"func",
"IsValidImportPath",
"(",
"v",
"Value",
")",
"(",
"err",
"error",
")",
"{",
"switch",
"v",
":=",
"v",
".",
"(",
"type",
")",
"{",
"case",
"Var",
":",
"if",
"!",
"v",
".",
"Equal",
"(",
"DefaultRootDocument",
".",
"Value",
")",
"&&",
"!",
"v",
".",
"Equal",
"(",
"InputRootDocument",
".",
"Value",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"}",
"\n",
"case",
"Ref",
":",
"if",
"err",
":=",
"IsValidImportPath",
"(",
"v",
"[",
"0",
"]",
".",
"Value",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"e",
":=",
"range",
"v",
"[",
"1",
":",
"]",
"{",
"if",
"_",
",",
"ok",
":=",
"e",
".",
"Value",
".",
"(",
"String",
")",
";",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"}",
"\n",
"}",
"\n",
"default",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // IsValidImportPath returns an error indicating if the import path is invalid.
// If the import path is invalid, err is nil. | [
"IsValidImportPath",
"returns",
"an",
"error",
"indicating",
"if",
"the",
"import",
"path",
"is",
"invalid",
".",
"If",
"the",
"import",
"path",
"is",
"invalid",
"err",
"is",
"nil",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L343-L362 | train |
open-policy-agent/opa | ast/policy.go | Compare | func (imp *Import) Compare(other *Import) int {
if imp == nil {
if other == nil {
return 0
}
return -1
} else if other == nil {
return 1
}
if cmp := Compare(imp.Path, other.Path); cmp != 0 {
return cmp
}
return Compare(imp.Alias, other.Alias)
} | go | func (imp *Import) Compare(other *Import) int {
if imp == nil {
if other == nil {
return 0
}
return -1
} else if other == nil {
return 1
}
if cmp := Compare(imp.Path, other.Path); cmp != 0 {
return cmp
}
return Compare(imp.Alias, other.Alias)
} | [
"func",
"(",
"imp",
"*",
"Import",
")",
"Compare",
"(",
"other",
"*",
"Import",
")",
"int",
"{",
"if",
"imp",
"==",
"nil",
"{",
"if",
"other",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"-",
"1",
"\n",
"}",
"else",
"if",
"other",
"==",
"nil",
"{",
"return",
"1",
"\n",
"}",
"\n",
"if",
"cmp",
":=",
"Compare",
"(",
"imp",
".",
"Path",
",",
"other",
".",
"Path",
")",
";",
"cmp",
"!=",
"0",
"{",
"return",
"cmp",
"\n",
"}",
"\n",
"return",
"Compare",
"(",
"imp",
".",
"Alias",
",",
"other",
".",
"Alias",
")",
"\n",
"}"
] | // Compare returns an integer indicating whether imp is less than, equal to,
// or greater than other. | [
"Compare",
"returns",
"an",
"integer",
"indicating",
"whether",
"imp",
"is",
"less",
"than",
"equal",
"to",
"or",
"greater",
"than",
"other",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L366-L379 | train |
open-policy-agent/opa | ast/policy.go | Copy | func (imp *Import) Copy() *Import {
cpy := *imp
cpy.Path = imp.Path.Copy()
return &cpy
} | go | func (imp *Import) Copy() *Import {
cpy := *imp
cpy.Path = imp.Path.Copy()
return &cpy
} | [
"func",
"(",
"imp",
"*",
"Import",
")",
"Copy",
"(",
")",
"*",
"Import",
"{",
"cpy",
":=",
"*",
"imp",
"\n",
"cpy",
".",
"Path",
"=",
"imp",
".",
"Path",
".",
"Copy",
"(",
")",
"\n",
"return",
"&",
"cpy",
"\n",
"}"
] | // Copy returns a deep copy of imp. | [
"Copy",
"returns",
"a",
"deep",
"copy",
"of",
"imp",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L382-L386 | train |
open-policy-agent/opa | ast/policy.go | Name | func (imp *Import) Name() Var {
if len(imp.Alias) != 0 {
return imp.Alias
}
switch v := imp.Path.Value.(type) {
case Var:
return v
case Ref:
if len(v) == 1 {
return v[0].Value.(Var)
}
return Var(v[len(v)-1].Value.(String))
}
panic("illegal import")
} | go | func (imp *Import) Name() Var {
if len(imp.Alias) != 0 {
return imp.Alias
}
switch v := imp.Path.Value.(type) {
case Var:
return v
case Ref:
if len(v) == 1 {
return v[0].Value.(Var)
}
return Var(v[len(v)-1].Value.(String))
}
panic("illegal import")
} | [
"func",
"(",
"imp",
"*",
"Import",
")",
"Name",
"(",
")",
"Var",
"{",
"if",
"len",
"(",
"imp",
".",
"Alias",
")",
"!=",
"0",
"{",
"return",
"imp",
".",
"Alias",
"\n",
"}",
"\n",
"switch",
"v",
":=",
"imp",
".",
"Path",
".",
"Value",
".",
"(",
"type",
")",
"{",
"case",
"Var",
":",
"return",
"v",
"\n",
"case",
"Ref",
":",
"if",
"len",
"(",
"v",
")",
"==",
"1",
"{",
"return",
"v",
"[",
"0",
"]",
".",
"Value",
".",
"(",
"Var",
")",
"\n",
"}",
"\n",
"return",
"Var",
"(",
"v",
"[",
"len",
"(",
"v",
")",
"-",
"1",
"]",
".",
"Value",
".",
"(",
"String",
")",
")",
"\n",
"}",
"\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // Name returns the variable that is used to refer to the imported virtual
// document. This is the alias if defined otherwise the last element in the
// path. | [
"Name",
"returns",
"the",
"variable",
"that",
"is",
"used",
"to",
"refer",
"to",
"the",
"imported",
"virtual",
"document",
".",
"This",
"is",
"the",
"alias",
"if",
"defined",
"otherwise",
"the",
"last",
"element",
"in",
"the",
"path",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L409-L423 | train |
open-policy-agent/opa | ast/policy.go | Compare | func (rule *Rule) Compare(other *Rule) int {
if rule == nil {
if other == nil {
return 0
}
return -1
} else if other == nil {
return 1
}
if cmp := rule.Head.Compare(other.Head); cmp != 0 {
return cmp
}
if cmp := util.Compare(rule.Default, other.Default); cmp != 0 {
return cmp
}
if cmp := rule.Body.Compare(other.Body); cmp != 0 {
return cmp
}
return rule.Else.Compare(other.Else)
} | go | func (rule *Rule) Compare(other *Rule) int {
if rule == nil {
if other == nil {
return 0
}
return -1
} else if other == nil {
return 1
}
if cmp := rule.Head.Compare(other.Head); cmp != 0 {
return cmp
}
if cmp := util.Compare(rule.Default, other.Default); cmp != 0 {
return cmp
}
if cmp := rule.Body.Compare(other.Body); cmp != 0 {
return cmp
}
return rule.Else.Compare(other.Else)
} | [
"func",
"(",
"rule",
"*",
"Rule",
")",
"Compare",
"(",
"other",
"*",
"Rule",
")",
"int",
"{",
"if",
"rule",
"==",
"nil",
"{",
"if",
"other",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"-",
"1",
"\n",
"}",
"else",
"if",
"other",
"==",
"nil",
"{",
"return",
"1",
"\n",
"}",
"\n",
"if",
"cmp",
":=",
"rule",
".",
"Head",
".",
"Compare",
"(",
"other",
".",
"Head",
")",
";",
"cmp",
"!=",
"0",
"{",
"return",
"cmp",
"\n",
"}",
"\n",
"if",
"cmp",
":=",
"util",
".",
"Compare",
"(",
"rule",
".",
"Default",
",",
"other",
".",
"Default",
")",
";",
"cmp",
"!=",
"0",
"{",
"return",
"cmp",
"\n",
"}",
"\n",
"if",
"cmp",
":=",
"rule",
".",
"Body",
".",
"Compare",
"(",
"other",
".",
"Body",
")",
";",
"cmp",
"!=",
"0",
"{",
"return",
"cmp",
"\n",
"}",
"\n",
"return",
"rule",
".",
"Else",
".",
"Compare",
"(",
"other",
".",
"Else",
")",
"\n",
"}"
] | // Compare returns an integer indicating whether rule is less than, equal to,
// or greater than other. | [
"Compare",
"returns",
"an",
"integer",
"indicating",
"whether",
"rule",
"is",
"less",
"than",
"equal",
"to",
"or",
"greater",
"than",
"other",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L435-L454 | train |
open-policy-agent/opa | ast/policy.go | Copy | func (rule *Rule) Copy() *Rule {
cpy := *rule
cpy.Head = rule.Head.Copy()
cpy.Body = rule.Body.Copy()
if cpy.Else != nil {
cpy.Else = rule.Else.Copy()
}
return &cpy
} | go | func (rule *Rule) Copy() *Rule {
cpy := *rule
cpy.Head = rule.Head.Copy()
cpy.Body = rule.Body.Copy()
if cpy.Else != nil {
cpy.Else = rule.Else.Copy()
}
return &cpy
} | [
"func",
"(",
"rule",
"*",
"Rule",
")",
"Copy",
"(",
")",
"*",
"Rule",
"{",
"cpy",
":=",
"*",
"rule",
"\n",
"cpy",
".",
"Head",
"=",
"rule",
".",
"Head",
".",
"Copy",
"(",
")",
"\n",
"cpy",
".",
"Body",
"=",
"rule",
".",
"Body",
".",
"Copy",
"(",
")",
"\n",
"if",
"cpy",
".",
"Else",
"!=",
"nil",
"{",
"cpy",
".",
"Else",
"=",
"rule",
".",
"Else",
".",
"Copy",
"(",
")",
"\n",
"}",
"\n",
"return",
"&",
"cpy",
"\n",
"}"
] | // Copy returns a deep copy of rule. | [
"Copy",
"returns",
"a",
"deep",
"copy",
"of",
"rule",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L457-L465 | train |
open-policy-agent/opa | ast/policy.go | Path | func (rule *Rule) Path() Ref {
if rule.Module == nil {
panic("assertion failed")
}
return rule.Module.Package.Path.Append(StringTerm(string(rule.Head.Name)))
} | go | func (rule *Rule) Path() Ref {
if rule.Module == nil {
panic("assertion failed")
}
return rule.Module.Package.Path.Append(StringTerm(string(rule.Head.Name)))
} | [
"func",
"(",
"rule",
"*",
"Rule",
")",
"Path",
"(",
")",
"Ref",
"{",
"if",
"rule",
".",
"Module",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"rule",
".",
"Module",
".",
"Package",
".",
"Path",
".",
"Append",
"(",
"StringTerm",
"(",
"string",
"(",
"rule",
".",
"Head",
".",
"Name",
")",
")",
")",
"\n",
"}"
] | // Path returns a ref referring to the document produced by this rule. If rule
// is not contained in a module, this function panics. | [
"Path",
"returns",
"a",
"ref",
"referring",
"to",
"the",
"document",
"produced",
"by",
"this",
"rule",
".",
"If",
"rule",
"is",
"not",
"contained",
"in",
"a",
"module",
"this",
"function",
"panics",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L487-L492 | train |
open-policy-agent/opa | ast/policy.go | NewHead | func NewHead(name Var, args ...*Term) *Head {
head := &Head{
Name: name,
}
if len(args) == 0 {
return head
}
head.Key = args[0]
if len(args) == 1 {
return head
}
head.Value = args[1]
return head
} | go | func NewHead(name Var, args ...*Term) *Head {
head := &Head{
Name: name,
}
if len(args) == 0 {
return head
}
head.Key = args[0]
if len(args) == 1 {
return head
}
head.Value = args[1]
return head
} | [
"func",
"NewHead",
"(",
"name",
"Var",
",",
"args",
"...",
"*",
"Term",
")",
"*",
"Head",
"{",
"head",
":=",
"&",
"Head",
"{",
"Name",
":",
"name",
",",
"}",
"\n",
"if",
"len",
"(",
"args",
")",
"==",
"0",
"{",
"return",
"head",
"\n",
"}",
"\n",
"head",
".",
"Key",
"=",
"args",
"[",
"0",
"]",
"\n",
"if",
"len",
"(",
"args",
")",
"==",
"1",
"{",
"return",
"head",
"\n",
"}",
"\n",
"head",
".",
"Value",
"=",
"args",
"[",
"1",
"]",
"\n",
"return",
"head",
"\n",
"}"
] | // NewHead returns a new Head object. If args are provided, the first will be
// used for the key and the second will be used for the value. | [
"NewHead",
"returns",
"a",
"new",
"Head",
"object",
".",
"If",
"args",
"are",
"provided",
"the",
"first",
"will",
"be",
"used",
"for",
"the",
"key",
"and",
"the",
"second",
"will",
"be",
"used",
"for",
"the",
"value",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L535-L548 | train |
open-policy-agent/opa | ast/policy.go | DocKind | func (head *Head) DocKind() DocKind {
if head.Key != nil {
if head.Value != nil {
return PartialObjectDoc
}
return PartialSetDoc
}
return CompleteDoc
} | go | func (head *Head) DocKind() DocKind {
if head.Key != nil {
if head.Value != nil {
return PartialObjectDoc
}
return PartialSetDoc
}
return CompleteDoc
} | [
"func",
"(",
"head",
"*",
"Head",
")",
"DocKind",
"(",
")",
"DocKind",
"{",
"if",
"head",
".",
"Key",
"!=",
"nil",
"{",
"if",
"head",
".",
"Value",
"!=",
"nil",
"{",
"return",
"PartialObjectDoc",
"\n",
"}",
"\n",
"return",
"PartialSetDoc",
"\n",
"}",
"\n",
"return",
"CompleteDoc",
"\n",
"}"
] | // DocKind returns the type of document produced by this rule. | [
"DocKind",
"returns",
"the",
"type",
"of",
"document",
"produced",
"by",
"this",
"rule",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L565-L573 | train |
open-policy-agent/opa | ast/policy.go | Compare | func (head *Head) Compare(other *Head) int {
if head == nil {
if other == nil {
return 0
}
return -1
} else if other == nil {
return 1
}
if cmp := Compare(head.Args, other.Args); cmp != 0 {
return cmp
}
if cmp := Compare(head.Name, other.Name); cmp != 0 {
return cmp
}
if cmp := Compare(head.Key, other.Key); cmp != 0 {
return cmp
}
return Compare(head.Value, other.Value)
} | go | func (head *Head) Compare(other *Head) int {
if head == nil {
if other == nil {
return 0
}
return -1
} else if other == nil {
return 1
}
if cmp := Compare(head.Args, other.Args); cmp != 0 {
return cmp
}
if cmp := Compare(head.Name, other.Name); cmp != 0 {
return cmp
}
if cmp := Compare(head.Key, other.Key); cmp != 0 {
return cmp
}
return Compare(head.Value, other.Value)
} | [
"func",
"(",
"head",
"*",
"Head",
")",
"Compare",
"(",
"other",
"*",
"Head",
")",
"int",
"{",
"if",
"head",
"==",
"nil",
"{",
"if",
"other",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"-",
"1",
"\n",
"}",
"else",
"if",
"other",
"==",
"nil",
"{",
"return",
"1",
"\n",
"}",
"\n",
"if",
"cmp",
":=",
"Compare",
"(",
"head",
".",
"Args",
",",
"other",
".",
"Args",
")",
";",
"cmp",
"!=",
"0",
"{",
"return",
"cmp",
"\n",
"}",
"\n",
"if",
"cmp",
":=",
"Compare",
"(",
"head",
".",
"Name",
",",
"other",
".",
"Name",
")",
";",
"cmp",
"!=",
"0",
"{",
"return",
"cmp",
"\n",
"}",
"\n",
"if",
"cmp",
":=",
"Compare",
"(",
"head",
".",
"Key",
",",
"other",
".",
"Key",
")",
";",
"cmp",
"!=",
"0",
"{",
"return",
"cmp",
"\n",
"}",
"\n",
"return",
"Compare",
"(",
"head",
".",
"Value",
",",
"other",
".",
"Value",
")",
"\n",
"}"
] | // Compare returns an integer indicating whether head is less than, equal to,
// or greater than other. | [
"Compare",
"returns",
"an",
"integer",
"indicating",
"whether",
"head",
"is",
"less",
"than",
"equal",
"to",
"or",
"greater",
"than",
"other",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L577-L596 | train |
open-policy-agent/opa | ast/policy.go | Copy | func (head *Head) Copy() *Head {
cpy := *head
cpy.Args = head.Args.Copy()
cpy.Key = head.Key.Copy()
cpy.Value = head.Value.Copy()
return &cpy
} | go | func (head *Head) Copy() *Head {
cpy := *head
cpy.Args = head.Args.Copy()
cpy.Key = head.Key.Copy()
cpy.Value = head.Value.Copy()
return &cpy
} | [
"func",
"(",
"head",
"*",
"Head",
")",
"Copy",
"(",
")",
"*",
"Head",
"{",
"cpy",
":=",
"*",
"head",
"\n",
"cpy",
".",
"Args",
"=",
"head",
".",
"Args",
".",
"Copy",
"(",
")",
"\n",
"cpy",
".",
"Key",
"=",
"head",
".",
"Key",
".",
"Copy",
"(",
")",
"\n",
"cpy",
".",
"Value",
"=",
"head",
".",
"Value",
".",
"Copy",
"(",
")",
"\n",
"return",
"&",
"cpy",
"\n",
"}"
] | // Copy returns a deep copy of head. | [
"Copy",
"returns",
"a",
"deep",
"copy",
"of",
"head",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L599-L605 | train |
open-policy-agent/opa | ast/policy.go | Vars | func (head *Head) Vars() VarSet {
vis := &VarVisitor{vars: VarSet{}}
// TODO: improve test coverage for this.
if head.Args != nil {
Walk(vis, head.Args)
}
if head.Key != nil {
Walk(vis, head.Key)
}
if head.Value != nil {
Walk(vis, head.Value)
}
return vis.vars
} | go | func (head *Head) Vars() VarSet {
vis := &VarVisitor{vars: VarSet{}}
// TODO: improve test coverage for this.
if head.Args != nil {
Walk(vis, head.Args)
}
if head.Key != nil {
Walk(vis, head.Key)
}
if head.Value != nil {
Walk(vis, head.Value)
}
return vis.vars
} | [
"func",
"(",
"head",
"*",
"Head",
")",
"Vars",
"(",
")",
"VarSet",
"{",
"vis",
":=",
"&",
"VarVisitor",
"{",
"vars",
":",
"VarSet",
"{",
"}",
"}",
"\n",
"// TODO: improve test coverage for this.",
"if",
"head",
".",
"Args",
"!=",
"nil",
"{",
"Walk",
"(",
"vis",
",",
"head",
".",
"Args",
")",
"\n",
"}",
"\n",
"if",
"head",
".",
"Key",
"!=",
"nil",
"{",
"Walk",
"(",
"vis",
",",
"head",
".",
"Key",
")",
"\n",
"}",
"\n",
"if",
"head",
".",
"Value",
"!=",
"nil",
"{",
"Walk",
"(",
"vis",
",",
"head",
".",
"Value",
")",
"\n",
"}",
"\n",
"return",
"vis",
".",
"vars",
"\n",
"}"
] | // Vars returns a set of vars found in the head. | [
"Vars",
"returns",
"a",
"set",
"of",
"vars",
"found",
"in",
"the",
"head",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L629-L642 | train |
open-policy-agent/opa | ast/policy.go | Copy | func (a Args) Copy() Args {
cpy := Args{}
for _, t := range a {
cpy = append(cpy, t.Copy())
}
return cpy
} | go | func (a Args) Copy() Args {
cpy := Args{}
for _, t := range a {
cpy = append(cpy, t.Copy())
}
return cpy
} | [
"func",
"(",
"a",
"Args",
")",
"Copy",
"(",
")",
"Args",
"{",
"cpy",
":=",
"Args",
"{",
"}",
"\n",
"for",
"_",
",",
"t",
":=",
"range",
"a",
"{",
"cpy",
"=",
"append",
"(",
"cpy",
",",
"t",
".",
"Copy",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"cpy",
"\n",
"}"
] | // Copy returns a deep copy of a. | [
"Copy",
"returns",
"a",
"deep",
"copy",
"of",
"a",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L658-L664 | train |
open-policy-agent/opa | ast/policy.go | SetLoc | func (a Args) SetLoc(loc *Location) {
if len(a) != 0 {
a[0].SetLocation(loc)
}
} | go | func (a Args) SetLoc(loc *Location) {
if len(a) != 0 {
a[0].SetLocation(loc)
}
} | [
"func",
"(",
"a",
"Args",
")",
"SetLoc",
"(",
"loc",
"*",
"Location",
")",
"{",
"if",
"len",
"(",
"a",
")",
"!=",
"0",
"{",
"a",
"[",
"0",
"]",
".",
"SetLocation",
"(",
"loc",
")",
"\n",
"}",
"\n",
"}"
] | // SetLoc sets the location on a. | [
"SetLoc",
"sets",
"the",
"location",
"on",
"a",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L683-L687 | train |
open-policy-agent/opa | ast/policy.go | Vars | func (a Args) Vars() VarSet {
vis := &VarVisitor{vars: VarSet{}}
Walk(vis, a)
return vis.vars
} | go | func (a Args) Vars() VarSet {
vis := &VarVisitor{vars: VarSet{}}
Walk(vis, a)
return vis.vars
} | [
"func",
"(",
"a",
"Args",
")",
"Vars",
"(",
")",
"VarSet",
"{",
"vis",
":=",
"&",
"VarVisitor",
"{",
"vars",
":",
"VarSet",
"{",
"}",
"}",
"\n",
"Walk",
"(",
"vis",
",",
"a",
")",
"\n",
"return",
"vis",
".",
"vars",
"\n",
"}"
] | // Vars returns a set of vars that appear in a. | [
"Vars",
"returns",
"a",
"set",
"of",
"vars",
"that",
"appear",
"in",
"a",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L690-L694 | train |
open-policy-agent/opa | ast/policy.go | NewBody | func NewBody(exprs ...*Expr) Body {
for i, expr := range exprs {
expr.Index = i
}
return Body(exprs)
} | go | func NewBody(exprs ...*Expr) Body {
for i, expr := range exprs {
expr.Index = i
}
return Body(exprs)
} | [
"func",
"NewBody",
"(",
"exprs",
"...",
"*",
"Expr",
")",
"Body",
"{",
"for",
"i",
",",
"expr",
":=",
"range",
"exprs",
"{",
"expr",
".",
"Index",
"=",
"i",
"\n",
"}",
"\n",
"return",
"Body",
"(",
"exprs",
")",
"\n",
"}"
] | // NewBody returns a new Body containing the given expressions. The indices of
// the immediate expressions will be reset. | [
"NewBody",
"returns",
"a",
"new",
"Body",
"containing",
"the",
"given",
"expressions",
".",
"The",
"indices",
"of",
"the",
"immediate",
"expressions",
"will",
"be",
"reset",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L698-L703 | train |
open-policy-agent/opa | ast/policy.go | MarshalJSON | func (body Body) MarshalJSON() ([]byte, error) {
// Serialize empty Body to empty array. This handles both the empty case and the
// nil case (whereas by default the result would be null if body was nil.)
if len(body) == 0 {
return []byte(`[]`), nil
}
return json.Marshal([]*Expr(body))
} | go | func (body Body) MarshalJSON() ([]byte, error) {
// Serialize empty Body to empty array. This handles both the empty case and the
// nil case (whereas by default the result would be null if body was nil.)
if len(body) == 0 {
return []byte(`[]`), nil
}
return json.Marshal([]*Expr(body))
} | [
"func",
"(",
"body",
"Body",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// Serialize empty Body to empty array. This handles both the empty case and the",
"// nil case (whereas by default the result would be null if body was nil.)",
"if",
"len",
"(",
"body",
")",
"==",
"0",
"{",
"return",
"[",
"]",
"byte",
"(",
"`[]`",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"[",
"]",
"*",
"Expr",
"(",
"body",
")",
")",
"\n",
"}"
] | // MarshalJSON returns JSON encoded bytes representing body. | [
"MarshalJSON",
"returns",
"JSON",
"encoded",
"bytes",
"representing",
"body",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L706-L713 | train |
open-policy-agent/opa | ast/policy.go | Append | func (body *Body) Append(expr *Expr) {
n := len(*body)
expr.Index = n
*body = append(*body, expr)
} | go | func (body *Body) Append(expr *Expr) {
n := len(*body)
expr.Index = n
*body = append(*body, expr)
} | [
"func",
"(",
"body",
"*",
"Body",
")",
"Append",
"(",
"expr",
"*",
"Expr",
")",
"{",
"n",
":=",
"len",
"(",
"*",
"body",
")",
"\n",
"expr",
".",
"Index",
"=",
"n",
"\n",
"*",
"body",
"=",
"append",
"(",
"*",
"body",
",",
"expr",
")",
"\n",
"}"
] | // Append adds the expr to the body and updates the expr's index accordingly. | [
"Append",
"adds",
"the",
"expr",
"to",
"the",
"body",
"and",
"updates",
"the",
"expr",
"s",
"index",
"accordingly",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L716-L720 | train |
open-policy-agent/opa | ast/policy.go | Set | func (body Body) Set(expr *Expr, pos int) {
body[pos] = expr
expr.Index = pos
} | go | func (body Body) Set(expr *Expr, pos int) {
body[pos] = expr
expr.Index = pos
} | [
"func",
"(",
"body",
"Body",
")",
"Set",
"(",
"expr",
"*",
"Expr",
",",
"pos",
"int",
")",
"{",
"body",
"[",
"pos",
"]",
"=",
"expr",
"\n",
"expr",
".",
"Index",
"=",
"pos",
"\n",
"}"
] | // Set sets the expr in the body at the specified position and updates the
// expr's index accordingly. | [
"Set",
"sets",
"the",
"expr",
"in",
"the",
"body",
"at",
"the",
"specified",
"position",
"and",
"updates",
"the",
"expr",
"s",
"index",
"accordingly",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L724-L727 | train |
open-policy-agent/opa | ast/policy.go | Copy | func (body Body) Copy() Body {
cpy := make(Body, len(body))
for i := range body {
cpy[i] = body[i].Copy()
}
return cpy
} | go | func (body Body) Copy() Body {
cpy := make(Body, len(body))
for i := range body {
cpy[i] = body[i].Copy()
}
return cpy
} | [
"func",
"(",
"body",
"Body",
")",
"Copy",
"(",
")",
"Body",
"{",
"cpy",
":=",
"make",
"(",
"Body",
",",
"len",
"(",
"body",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"body",
"{",
"cpy",
"[",
"i",
"]",
"=",
"body",
"[",
"i",
"]",
".",
"Copy",
"(",
")",
"\n",
"}",
"\n",
"return",
"cpy",
"\n",
"}"
] | // Copy returns a deep copy of body. | [
"Copy",
"returns",
"a",
"deep",
"copy",
"of",
"body",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L753-L759 | train |
open-policy-agent/opa | ast/policy.go | Contains | func (body Body) Contains(x *Expr) bool {
for _, e := range body {
if e.Equal(x) {
return true
}
}
return false
} | go | func (body Body) Contains(x *Expr) bool {
for _, e := range body {
if e.Equal(x) {
return true
}
}
return false
} | [
"func",
"(",
"body",
"Body",
")",
"Contains",
"(",
"x",
"*",
"Expr",
")",
"bool",
"{",
"for",
"_",
",",
"e",
":=",
"range",
"body",
"{",
"if",
"e",
".",
"Equal",
"(",
"x",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // Contains returns true if this body contains the given expression. | [
"Contains",
"returns",
"true",
"if",
"this",
"body",
"contains",
"the",
"given",
"expression",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L762-L769 | train |
open-policy-agent/opa | ast/policy.go | Hash | func (body Body) Hash() int {
s := 0
for _, e := range body {
s += e.Hash()
}
return s
} | go | func (body Body) Hash() int {
s := 0
for _, e := range body {
s += e.Hash()
}
return s
} | [
"func",
"(",
"body",
"Body",
")",
"Hash",
"(",
")",
"int",
"{",
"s",
":=",
"0",
"\n",
"for",
"_",
",",
"e",
":=",
"range",
"body",
"{",
"s",
"+=",
"e",
".",
"Hash",
"(",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // Hash returns the hash code for the Body. | [
"Hash",
"returns",
"the",
"hash",
"code",
"for",
"the",
"Body",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L777-L783 | train |
open-policy-agent/opa | ast/policy.go | IsGround | func (body Body) IsGround() bool {
for _, e := range body {
if !e.IsGround() {
return false
}
}
return true
} | go | func (body Body) IsGround() bool {
for _, e := range body {
if !e.IsGround() {
return false
}
}
return true
} | [
"func",
"(",
"body",
"Body",
")",
"IsGround",
"(",
")",
"bool",
"{",
"for",
"_",
",",
"e",
":=",
"range",
"body",
"{",
"if",
"!",
"e",
".",
"IsGround",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // IsGround returns true if all of the expressions in the Body are ground. | [
"IsGround",
"returns",
"true",
"if",
"all",
"of",
"the",
"expressions",
"in",
"the",
"Body",
"are",
"ground",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L786-L793 | train |
open-policy-agent/opa | ast/policy.go | SetLoc | func (body Body) SetLoc(loc *Location) {
if len(body) != 0 {
body[0].SetLocation(loc)
}
} | go | func (body Body) SetLoc(loc *Location) {
if len(body) != 0 {
body[0].SetLocation(loc)
}
} | [
"func",
"(",
"body",
"Body",
")",
"SetLoc",
"(",
"loc",
"*",
"Location",
")",
"{",
"if",
"len",
"(",
"body",
")",
"!=",
"0",
"{",
"body",
"[",
"0",
"]",
".",
"SetLocation",
"(",
"loc",
")",
"\n",
"}",
"\n",
"}"
] | // SetLoc sets the location on body. | [
"SetLoc",
"sets",
"the",
"location",
"on",
"body",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L804-L808 | train |
open-policy-agent/opa | ast/policy.go | Vars | func (body Body) Vars(params VarVisitorParams) VarSet {
vis := NewVarVisitor().WithParams(params)
Walk(vis, body)
return vis.Vars()
} | go | func (body Body) Vars(params VarVisitorParams) VarSet {
vis := NewVarVisitor().WithParams(params)
Walk(vis, body)
return vis.Vars()
} | [
"func",
"(",
"body",
"Body",
")",
"Vars",
"(",
"params",
"VarVisitorParams",
")",
"VarSet",
"{",
"vis",
":=",
"NewVarVisitor",
"(",
")",
".",
"WithParams",
"(",
"params",
")",
"\n",
"Walk",
"(",
"vis",
",",
"body",
")",
"\n",
"return",
"vis",
".",
"Vars",
"(",
")",
"\n",
"}"
] | // Vars returns a VarSet containing variables in body. The params can be set to
// control which vars are included. | [
"Vars",
"returns",
"a",
"VarSet",
"containing",
"variables",
"in",
"body",
".",
"The",
"params",
"can",
"be",
"set",
"to",
"control",
"which",
"vars",
"are",
"included",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L820-L824 | train |
open-policy-agent/opa | ast/policy.go | NewExpr | func NewExpr(terms interface{}) *Expr {
return &Expr{
Negated: false,
Terms: terms,
Index: 0,
With: nil,
}
} | go | func NewExpr(terms interface{}) *Expr {
return &Expr{
Negated: false,
Terms: terms,
Index: 0,
With: nil,
}
} | [
"func",
"NewExpr",
"(",
"terms",
"interface",
"{",
"}",
")",
"*",
"Expr",
"{",
"return",
"&",
"Expr",
"{",
"Negated",
":",
"false",
",",
"Terms",
":",
"terms",
",",
"Index",
":",
"0",
",",
"With",
":",
"nil",
",",
"}",
"\n",
"}"
] | // NewExpr returns a new Expr object. | [
"NewExpr",
"returns",
"a",
"new",
"Expr",
"object",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L827-L834 | train |
open-policy-agent/opa | ast/policy.go | Complement | func (expr *Expr) Complement() *Expr {
cpy := *expr
cpy.Negated = !cpy.Negated
return &cpy
} | go | func (expr *Expr) Complement() *Expr {
cpy := *expr
cpy.Negated = !cpy.Negated
return &cpy
} | [
"func",
"(",
"expr",
"*",
"Expr",
")",
"Complement",
"(",
")",
"*",
"Expr",
"{",
"cpy",
":=",
"*",
"expr",
"\n",
"cpy",
".",
"Negated",
"=",
"!",
"cpy",
".",
"Negated",
"\n",
"return",
"&",
"cpy",
"\n",
"}"
] | // Complement returns a copy of this expression with the negation flag flipped. | [
"Complement",
"returns",
"a",
"copy",
"of",
"this",
"expression",
"with",
"the",
"negation",
"flag",
"flipped",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L837-L841 | train |
open-policy-agent/opa | ast/policy.go | Copy | func (expr *Expr) Copy() *Expr {
cpy := *expr
switch ts := expr.Terms.(type) {
case []*Term:
cpyTs := make([]*Term, len(ts))
for i := range ts {
cpyTs[i] = ts[i].Copy()
}
cpy.Terms = cpyTs
case *Term:
cpy.Terms = ts.Copy()
}
cpy.With = make([]*With, len(expr.With))
for i := range expr.With {
cpy.With[i] = expr.With[i].Copy()
}
return &cpy
} | go | func (expr *Expr) Copy() *Expr {
cpy := *expr
switch ts := expr.Terms.(type) {
case []*Term:
cpyTs := make([]*Term, len(ts))
for i := range ts {
cpyTs[i] = ts[i].Copy()
}
cpy.Terms = cpyTs
case *Term:
cpy.Terms = ts.Copy()
}
cpy.With = make([]*With, len(expr.With))
for i := range expr.With {
cpy.With[i] = expr.With[i].Copy()
}
return &cpy
} | [
"func",
"(",
"expr",
"*",
"Expr",
")",
"Copy",
"(",
")",
"*",
"Expr",
"{",
"cpy",
":=",
"*",
"expr",
"\n\n",
"switch",
"ts",
":=",
"expr",
".",
"Terms",
".",
"(",
"type",
")",
"{",
"case",
"[",
"]",
"*",
"Term",
":",
"cpyTs",
":=",
"make",
"(",
"[",
"]",
"*",
"Term",
",",
"len",
"(",
"ts",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"ts",
"{",
"cpyTs",
"[",
"i",
"]",
"=",
"ts",
"[",
"i",
"]",
".",
"Copy",
"(",
")",
"\n",
"}",
"\n",
"cpy",
".",
"Terms",
"=",
"cpyTs",
"\n",
"case",
"*",
"Term",
":",
"cpy",
".",
"Terms",
"=",
"ts",
".",
"Copy",
"(",
")",
"\n",
"}",
"\n\n",
"cpy",
".",
"With",
"=",
"make",
"(",
"[",
"]",
"*",
"With",
",",
"len",
"(",
"expr",
".",
"With",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"expr",
".",
"With",
"{",
"cpy",
".",
"With",
"[",
"i",
"]",
"=",
"expr",
".",
"With",
"[",
"i",
"]",
".",
"Copy",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"cpy",
"\n",
"}"
] | // Copy returns a deep copy of expr. | [
"Copy",
"returns",
"a",
"deep",
"copy",
"of",
"expr",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L907-L928 | train |
open-policy-agent/opa | ast/policy.go | Hash | func (expr *Expr) Hash() int {
s := expr.Index
switch ts := expr.Terms.(type) {
case []*Term:
for _, t := range ts {
s += t.Value.Hash()
}
case *Term:
s += ts.Value.Hash()
}
if expr.Negated {
s++
}
for _, w := range expr.With {
s += w.Hash()
}
return s
} | go | func (expr *Expr) Hash() int {
s := expr.Index
switch ts := expr.Terms.(type) {
case []*Term:
for _, t := range ts {
s += t.Value.Hash()
}
case *Term:
s += ts.Value.Hash()
}
if expr.Negated {
s++
}
for _, w := range expr.With {
s += w.Hash()
}
return s
} | [
"func",
"(",
"expr",
"*",
"Expr",
")",
"Hash",
"(",
")",
"int",
"{",
"s",
":=",
"expr",
".",
"Index",
"\n",
"switch",
"ts",
":=",
"expr",
".",
"Terms",
".",
"(",
"type",
")",
"{",
"case",
"[",
"]",
"*",
"Term",
":",
"for",
"_",
",",
"t",
":=",
"range",
"ts",
"{",
"s",
"+=",
"t",
".",
"Value",
".",
"Hash",
"(",
")",
"\n",
"}",
"\n",
"case",
"*",
"Term",
":",
"s",
"+=",
"ts",
".",
"Value",
".",
"Hash",
"(",
")",
"\n",
"}",
"\n",
"if",
"expr",
".",
"Negated",
"{",
"s",
"++",
"\n",
"}",
"\n",
"for",
"_",
",",
"w",
":=",
"range",
"expr",
".",
"With",
"{",
"s",
"+=",
"w",
".",
"Hash",
"(",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // Hash returns the hash code of the Expr. | [
"Hash",
"returns",
"the",
"hash",
"code",
"of",
"the",
"Expr",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L931-L948 | train |
open-policy-agent/opa | ast/policy.go | IncludeWith | func (expr *Expr) IncludeWith(target *Term, value *Term) *Expr {
cpy := *expr
cpy.With = append(cpy.With, &With{Target: target, Value: value})
return &cpy
} | go | func (expr *Expr) IncludeWith(target *Term, value *Term) *Expr {
cpy := *expr
cpy.With = append(cpy.With, &With{Target: target, Value: value})
return &cpy
} | [
"func",
"(",
"expr",
"*",
"Expr",
")",
"IncludeWith",
"(",
"target",
"*",
"Term",
",",
"value",
"*",
"Term",
")",
"*",
"Expr",
"{",
"cpy",
":=",
"*",
"expr",
"\n",
"cpy",
".",
"With",
"=",
"append",
"(",
"cpy",
".",
"With",
",",
"&",
"With",
"{",
"Target",
":",
"target",
",",
"Value",
":",
"value",
"}",
")",
"\n",
"return",
"&",
"cpy",
"\n",
"}"
] | // IncludeWith returns a copy of expr with the with modifier appended. | [
"IncludeWith",
"returns",
"a",
"copy",
"of",
"expr",
"with",
"the",
"with",
"modifier",
"appended",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L951-L955 | train |
open-policy-agent/opa | ast/policy.go | IsEquality | func (expr *Expr) IsEquality() bool {
terms, ok := expr.Terms.([]*Term)
if !ok {
return false
}
return terms[0].Value.Compare(Equality.Ref()) == 0
} | go | func (expr *Expr) IsEquality() bool {
terms, ok := expr.Terms.([]*Term)
if !ok {
return false
}
return terms[0].Value.Compare(Equality.Ref()) == 0
} | [
"func",
"(",
"expr",
"*",
"Expr",
")",
"IsEquality",
"(",
")",
"bool",
"{",
"terms",
",",
"ok",
":=",
"expr",
".",
"Terms",
".",
"(",
"[",
"]",
"*",
"Term",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"terms",
"[",
"0",
"]",
".",
"Value",
".",
"Compare",
"(",
"Equality",
".",
"Ref",
"(",
")",
")",
"==",
"0",
"\n",
"}"
] | // IsEquality returns true if this is an equality expression. | [
"IsEquality",
"returns",
"true",
"if",
"this",
"is",
"an",
"equality",
"expression",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L964-L970 | train |
open-policy-agent/opa | ast/policy.go | IsAssignment | func (expr *Expr) IsAssignment() bool {
terms, ok := expr.Terms.([]*Term)
if !ok {
return false
}
return terms[0].Value.Compare(Assign.Ref()) == 0
} | go | func (expr *Expr) IsAssignment() bool {
terms, ok := expr.Terms.([]*Term)
if !ok {
return false
}
return terms[0].Value.Compare(Assign.Ref()) == 0
} | [
"func",
"(",
"expr",
"*",
"Expr",
")",
"IsAssignment",
"(",
")",
"bool",
"{",
"terms",
",",
"ok",
":=",
"expr",
".",
"Terms",
".",
"(",
"[",
"]",
"*",
"Term",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"terms",
"[",
"0",
"]",
".",
"Value",
".",
"Compare",
"(",
"Assign",
".",
"Ref",
"(",
")",
")",
"==",
"0",
"\n",
"}"
] | // IsAssignment returns true if this an assignment expression. | [
"IsAssignment",
"returns",
"true",
"if",
"this",
"an",
"assignment",
"expression",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L973-L979 | train |
open-policy-agent/opa | ast/policy.go | IsCall | func (expr *Expr) IsCall() bool {
_, ok := expr.Terms.([]*Term)
return ok
} | go | func (expr *Expr) IsCall() bool {
_, ok := expr.Terms.([]*Term)
return ok
} | [
"func",
"(",
"expr",
"*",
"Expr",
")",
"IsCall",
"(",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"expr",
".",
"Terms",
".",
"(",
"[",
"]",
"*",
"Term",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // IsCall returns true if this expression calls a function. | [
"IsCall",
"returns",
"true",
"if",
"this",
"expression",
"calls",
"a",
"function",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L982-L985 | train |
open-policy-agent/opa | ast/policy.go | Operator | func (expr *Expr) Operator() Ref {
terms, ok := expr.Terms.([]*Term)
if !ok || len(terms) == 0 {
return nil
}
return terms[0].Value.(Ref)
} | go | func (expr *Expr) Operator() Ref {
terms, ok := expr.Terms.([]*Term)
if !ok || len(terms) == 0 {
return nil
}
return terms[0].Value.(Ref)
} | [
"func",
"(",
"expr",
"*",
"Expr",
")",
"Operator",
"(",
")",
"Ref",
"{",
"terms",
",",
"ok",
":=",
"expr",
".",
"Terms",
".",
"(",
"[",
"]",
"*",
"Term",
")",
"\n",
"if",
"!",
"ok",
"||",
"len",
"(",
"terms",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"terms",
"[",
"0",
"]",
".",
"Value",
".",
"(",
"Ref",
")",
"\n",
"}"
] | // Operator returns the name of the function or built-in this expression refers
// to. If this expression is not a function call, returns nil. | [
"Operator",
"returns",
"the",
"name",
"of",
"the",
"function",
"or",
"built",
"-",
"in",
"this",
"expression",
"refers",
"to",
".",
"If",
"this",
"expression",
"is",
"not",
"a",
"function",
"call",
"returns",
"nil",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L989-L995 | train |
open-policy-agent/opa | ast/policy.go | Operand | func (expr *Expr) Operand(pos int) *Term {
terms, ok := expr.Terms.([]*Term)
if !ok {
return nil
}
idx := pos + 1
if idx < len(terms) {
return terms[idx]
}
return nil
} | go | func (expr *Expr) Operand(pos int) *Term {
terms, ok := expr.Terms.([]*Term)
if !ok {
return nil
}
idx := pos + 1
if idx < len(terms) {
return terms[idx]
}
return nil
} | [
"func",
"(",
"expr",
"*",
"Expr",
")",
"Operand",
"(",
"pos",
"int",
")",
"*",
"Term",
"{",
"terms",
",",
"ok",
":=",
"expr",
".",
"Terms",
".",
"(",
"[",
"]",
"*",
"Term",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"idx",
":=",
"pos",
"+",
"1",
"\n",
"if",
"idx",
"<",
"len",
"(",
"terms",
")",
"{",
"return",
"terms",
"[",
"idx",
"]",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Operand returns the term at the zero-based pos. If the expr does not include
// at least pos+1 terms, this function returns nil. | [
"Operand",
"returns",
"the",
"term",
"at",
"the",
"zero",
"-",
"based",
"pos",
".",
"If",
"the",
"expr",
"does",
"not",
"include",
"at",
"least",
"pos",
"+",
"1",
"terms",
"this",
"function",
"returns",
"nil",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L999-L1009 | train |
open-policy-agent/opa | ast/policy.go | Operands | func (expr *Expr) Operands() []*Term {
terms, ok := expr.Terms.([]*Term)
if !ok {
return nil
}
return terms[1:]
} | go | func (expr *Expr) Operands() []*Term {
terms, ok := expr.Terms.([]*Term)
if !ok {
return nil
}
return terms[1:]
} | [
"func",
"(",
"expr",
"*",
"Expr",
")",
"Operands",
"(",
")",
"[",
"]",
"*",
"Term",
"{",
"terms",
",",
"ok",
":=",
"expr",
".",
"Terms",
".",
"(",
"[",
"]",
"*",
"Term",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"terms",
"[",
"1",
":",
"]",
"\n",
"}"
] | // Operands returns the built-in function operands. | [
"Operands",
"returns",
"the",
"built",
"-",
"in",
"function",
"operands",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L1012-L1018 | train |
open-policy-agent/opa | ast/policy.go | IsGround | func (expr *Expr) IsGround() bool {
switch ts := expr.Terms.(type) {
case []*Term:
for _, t := range ts[1:] {
if !t.IsGround() {
return false
}
}
case *Term:
return ts.IsGround()
}
return true
} | go | func (expr *Expr) IsGround() bool {
switch ts := expr.Terms.(type) {
case []*Term:
for _, t := range ts[1:] {
if !t.IsGround() {
return false
}
}
case *Term:
return ts.IsGround()
}
return true
} | [
"func",
"(",
"expr",
"*",
"Expr",
")",
"IsGround",
"(",
")",
"bool",
"{",
"switch",
"ts",
":=",
"expr",
".",
"Terms",
".",
"(",
"type",
")",
"{",
"case",
"[",
"]",
"*",
"Term",
":",
"for",
"_",
",",
"t",
":=",
"range",
"ts",
"[",
"1",
":",
"]",
"{",
"if",
"!",
"t",
".",
"IsGround",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"*",
"Term",
":",
"return",
"ts",
".",
"IsGround",
"(",
")",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // IsGround returns true if all of the expression terms are ground. | [
"IsGround",
"returns",
"true",
"if",
"all",
"of",
"the",
"expression",
"terms",
"are",
"ground",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L1021-L1033 | train |
open-policy-agent/opa | ast/policy.go | SetOperator | func (expr *Expr) SetOperator(term *Term) *Expr {
expr.Terms.([]*Term)[0] = term
return expr
} | go | func (expr *Expr) SetOperator(term *Term) *Expr {
expr.Terms.([]*Term)[0] = term
return expr
} | [
"func",
"(",
"expr",
"*",
"Expr",
")",
"SetOperator",
"(",
"term",
"*",
"Term",
")",
"*",
"Expr",
"{",
"expr",
".",
"Terms",
".",
"(",
"[",
"]",
"*",
"Term",
")",
"[",
"0",
"]",
"=",
"term",
"\n",
"return",
"expr",
"\n",
"}"
] | // SetOperator sets the expr's operator and returns the expr itself. If expr is
// not a call expr, this function will panic. | [
"SetOperator",
"sets",
"the",
"expr",
"s",
"operator",
"and",
"returns",
"the",
"expr",
"itself",
".",
"If",
"expr",
"is",
"not",
"a",
"call",
"expr",
"this",
"function",
"will",
"panic",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L1037-L1040 | train |
open-policy-agent/opa | ast/policy.go | SetLocation | func (expr *Expr) SetLocation(loc *Location) *Expr {
expr.Location = loc
return expr
} | go | func (expr *Expr) SetLocation(loc *Location) *Expr {
expr.Location = loc
return expr
} | [
"func",
"(",
"expr",
"*",
"Expr",
")",
"SetLocation",
"(",
"loc",
"*",
"Location",
")",
"*",
"Expr",
"{",
"expr",
".",
"Location",
"=",
"loc",
"\n",
"return",
"expr",
"\n",
"}"
] | // SetLocation sets the expr's location and returns the expr itself. | [
"SetLocation",
"sets",
"the",
"expr",
"s",
"location",
"and",
"returns",
"the",
"expr",
"itself",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L1043-L1046 | train |
open-policy-agent/opa | ast/policy.go | UnmarshalJSON | func (expr *Expr) UnmarshalJSON(bs []byte) error {
v := map[string]interface{}{}
if err := util.UnmarshalJSON(bs, &v); err != nil {
return err
}
return unmarshalExpr(expr, v)
} | go | func (expr *Expr) UnmarshalJSON(bs []byte) error {
v := map[string]interface{}{}
if err := util.UnmarshalJSON(bs, &v); err != nil {
return err
}
return unmarshalExpr(expr, v)
} | [
"func",
"(",
"expr",
"*",
"Expr",
")",
"UnmarshalJSON",
"(",
"bs",
"[",
"]",
"byte",
")",
"error",
"{",
"v",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"if",
"err",
":=",
"util",
".",
"UnmarshalJSON",
"(",
"bs",
",",
"&",
"v",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"unmarshalExpr",
"(",
"expr",
",",
"v",
")",
"\n",
"}"
] | // UnmarshalJSON parses the byte array and stores the result in expr. | [
"UnmarshalJSON",
"parses",
"the",
"byte",
"array",
"and",
"stores",
"the",
"result",
"in",
"expr",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L1085-L1091 | train |
open-policy-agent/opa | ast/policy.go | Vars | func (expr *Expr) Vars(params VarVisitorParams) VarSet {
vis := NewVarVisitor().WithParams(params)
Walk(vis, expr)
return vis.Vars()
} | go | func (expr *Expr) Vars(params VarVisitorParams) VarSet {
vis := NewVarVisitor().WithParams(params)
Walk(vis, expr)
return vis.Vars()
} | [
"func",
"(",
"expr",
"*",
"Expr",
")",
"Vars",
"(",
"params",
"VarVisitorParams",
")",
"VarSet",
"{",
"vis",
":=",
"NewVarVisitor",
"(",
")",
".",
"WithParams",
"(",
"params",
")",
"\n",
"Walk",
"(",
"vis",
",",
"expr",
")",
"\n",
"return",
"vis",
".",
"Vars",
"(",
")",
"\n",
"}"
] | // Vars returns a VarSet containing variables in expr. The params can be set to
// control which vars are included. | [
"Vars",
"returns",
"a",
"VarSet",
"containing",
"variables",
"in",
"expr",
".",
"The",
"params",
"can",
"be",
"set",
"to",
"control",
"which",
"vars",
"are",
"included",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L1095-L1099 | train |
open-policy-agent/opa | ast/policy.go | Compare | func (w *With) Compare(other *With) int {
if w == nil {
if other == nil {
return 0
}
return -1
} else if other == nil {
return 1
}
if cmp := Compare(w.Target, other.Target); cmp != 0 {
return cmp
}
return Compare(w.Value, other.Value)
} | go | func (w *With) Compare(other *With) int {
if w == nil {
if other == nil {
return 0
}
return -1
} else if other == nil {
return 1
}
if cmp := Compare(w.Target, other.Target); cmp != 0 {
return cmp
}
return Compare(w.Value, other.Value)
} | [
"func",
"(",
"w",
"*",
"With",
")",
"Compare",
"(",
"other",
"*",
"With",
")",
"int",
"{",
"if",
"w",
"==",
"nil",
"{",
"if",
"other",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"-",
"1",
"\n",
"}",
"else",
"if",
"other",
"==",
"nil",
"{",
"return",
"1",
"\n",
"}",
"\n",
"if",
"cmp",
":=",
"Compare",
"(",
"w",
".",
"Target",
",",
"other",
".",
"Target",
")",
";",
"cmp",
"!=",
"0",
"{",
"return",
"cmp",
"\n",
"}",
"\n",
"return",
"Compare",
"(",
"w",
".",
"Value",
",",
"other",
".",
"Value",
")",
"\n",
"}"
] | // Compare returns an integer indicating whether w is less than, equal to, or
// greater than other. | [
"Compare",
"returns",
"an",
"integer",
"indicating",
"whether",
"w",
"is",
"less",
"than",
"equal",
"to",
"or",
"greater",
"than",
"other",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L1118-L1131 | train |
open-policy-agent/opa | ast/policy.go | Copy | func (w *With) Copy() *With {
cpy := *w
cpy.Value = w.Value.Copy()
cpy.Target = w.Target.Copy()
return &cpy
} | go | func (w *With) Copy() *With {
cpy := *w
cpy.Value = w.Value.Copy()
cpy.Target = w.Target.Copy()
return &cpy
} | [
"func",
"(",
"w",
"*",
"With",
")",
"Copy",
"(",
")",
"*",
"With",
"{",
"cpy",
":=",
"*",
"w",
"\n",
"cpy",
".",
"Value",
"=",
"w",
".",
"Value",
".",
"Copy",
"(",
")",
"\n",
"cpy",
".",
"Target",
"=",
"w",
".",
"Target",
".",
"Copy",
"(",
")",
"\n",
"return",
"&",
"cpy",
"\n",
"}"
] | // Copy returns a deep copy of w. | [
"Copy",
"returns",
"a",
"deep",
"copy",
"of",
"w",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L1134-L1139 | train |
open-policy-agent/opa | ast/policy.go | Hash | func (w With) Hash() int {
return w.Target.Hash() + w.Value.Hash()
} | go | func (w With) Hash() int {
return w.Target.Hash() + w.Value.Hash()
} | [
"func",
"(",
"w",
"With",
")",
"Hash",
"(",
")",
"int",
"{",
"return",
"w",
".",
"Target",
".",
"Hash",
"(",
")",
"+",
"w",
".",
"Value",
".",
"Hash",
"(",
")",
"\n",
"}"
] | // Hash returns the hash code of the With. | [
"Hash",
"returns",
"the",
"hash",
"code",
"of",
"the",
"With",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L1142-L1144 | train |
open-policy-agent/opa | ast/policy.go | SetLocation | func (w *With) SetLocation(loc *Location) *With {
w.Location = loc
return w
} | go | func (w *With) SetLocation(loc *Location) *With {
w.Location = loc
return w
} | [
"func",
"(",
"w",
"*",
"With",
")",
"SetLocation",
"(",
"loc",
"*",
"Location",
")",
"*",
"With",
"{",
"w",
".",
"Location",
"=",
"loc",
"\n",
"return",
"w",
"\n",
"}"
] | // SetLocation sets the location on w. | [
"SetLocation",
"sets",
"the",
"location",
"on",
"w",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L1147-L1150 | train |
open-policy-agent/opa | ast/policy.go | NewRuleSet | func NewRuleSet(rules ...*Rule) RuleSet {
rs := make(RuleSet, 0, len(rules))
for _, rule := range rules {
rs.Add(rule)
}
return rs
} | go | func NewRuleSet(rules ...*Rule) RuleSet {
rs := make(RuleSet, 0, len(rules))
for _, rule := range rules {
rs.Add(rule)
}
return rs
} | [
"func",
"NewRuleSet",
"(",
"rules",
"...",
"*",
"Rule",
")",
"RuleSet",
"{",
"rs",
":=",
"make",
"(",
"RuleSet",
",",
"0",
",",
"len",
"(",
"rules",
")",
")",
"\n",
"for",
"_",
",",
"rule",
":=",
"range",
"rules",
"{",
"rs",
".",
"Add",
"(",
"rule",
")",
"\n",
"}",
"\n",
"return",
"rs",
"\n",
"}"
] | // NewRuleSet returns a new RuleSet containing the given rules. | [
"NewRuleSet",
"returns",
"a",
"new",
"RuleSet",
"containing",
"the",
"given",
"rules",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L1169-L1175 | train |
open-policy-agent/opa | ast/policy.go | Add | func (rs *RuleSet) Add(rule *Rule) {
for _, exist := range *rs {
if exist.Equal(rule) {
return
}
}
*rs = append(*rs, rule)
} | go | func (rs *RuleSet) Add(rule *Rule) {
for _, exist := range *rs {
if exist.Equal(rule) {
return
}
}
*rs = append(*rs, rule)
} | [
"func",
"(",
"rs",
"*",
"RuleSet",
")",
"Add",
"(",
"rule",
"*",
"Rule",
")",
"{",
"for",
"_",
",",
"exist",
":=",
"range",
"*",
"rs",
"{",
"if",
"exist",
".",
"Equal",
"(",
"rule",
")",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"*",
"rs",
"=",
"append",
"(",
"*",
"rs",
",",
"rule",
")",
"\n",
"}"
] | // Add inserts the rule into rs. | [
"Add",
"inserts",
"the",
"rule",
"into",
"rs",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L1178-L1185 | train |
open-policy-agent/opa | ast/policy.go | Contains | func (rs RuleSet) Contains(rule *Rule) bool {
for i := range rs {
if rs[i].Equal(rule) {
return true
}
}
return false
} | go | func (rs RuleSet) Contains(rule *Rule) bool {
for i := range rs {
if rs[i].Equal(rule) {
return true
}
}
return false
} | [
"func",
"(",
"rs",
"RuleSet",
")",
"Contains",
"(",
"rule",
"*",
"Rule",
")",
"bool",
"{",
"for",
"i",
":=",
"range",
"rs",
"{",
"if",
"rs",
"[",
"i",
"]",
".",
"Equal",
"(",
"rule",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // Contains returns true if rs contains rule. | [
"Contains",
"returns",
"true",
"if",
"rs",
"contains",
"rule",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L1188-L1195 | train |
open-policy-agent/opa | ast/policy.go | Diff | func (rs RuleSet) Diff(other RuleSet) RuleSet {
result := NewRuleSet()
for i := range rs {
if !other.Contains(rs[i]) {
result.Add(rs[i])
}
}
return result
} | go | func (rs RuleSet) Diff(other RuleSet) RuleSet {
result := NewRuleSet()
for i := range rs {
if !other.Contains(rs[i]) {
result.Add(rs[i])
}
}
return result
} | [
"func",
"(",
"rs",
"RuleSet",
")",
"Diff",
"(",
"other",
"RuleSet",
")",
"RuleSet",
"{",
"result",
":=",
"NewRuleSet",
"(",
")",
"\n",
"for",
"i",
":=",
"range",
"rs",
"{",
"if",
"!",
"other",
".",
"Contains",
"(",
"rs",
"[",
"i",
"]",
")",
"{",
"result",
".",
"Add",
"(",
"rs",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // Diff returns a new RuleSet containing rules in rs that are not in other. | [
"Diff",
"returns",
"a",
"new",
"RuleSet",
"containing",
"rules",
"in",
"rs",
"that",
"are",
"not",
"in",
"other",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L1198-L1206 | train |
open-policy-agent/opa | ast/policy.go | Equal | func (rs RuleSet) Equal(other RuleSet) bool {
return len(rs.Diff(other)) == 0 && len(other.Diff(rs)) == 0
} | go | func (rs RuleSet) Equal(other RuleSet) bool {
return len(rs.Diff(other)) == 0 && len(other.Diff(rs)) == 0
} | [
"func",
"(",
"rs",
"RuleSet",
")",
"Equal",
"(",
"other",
"RuleSet",
")",
"bool",
"{",
"return",
"len",
"(",
"rs",
".",
"Diff",
"(",
"other",
")",
")",
"==",
"0",
"&&",
"len",
"(",
"other",
".",
"Diff",
"(",
"rs",
")",
")",
"==",
"0",
"\n",
"}"
] | // Equal returns true if rs equals other. | [
"Equal",
"returns",
"true",
"if",
"rs",
"equals",
"other",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L1209-L1211 | train |
open-policy-agent/opa | ast/policy.go | Merge | func (rs RuleSet) Merge(other RuleSet) RuleSet {
result := NewRuleSet()
for i := range rs {
result.Add(rs[i])
}
for i := range other {
result.Add(other[i])
}
return result
} | go | func (rs RuleSet) Merge(other RuleSet) RuleSet {
result := NewRuleSet()
for i := range rs {
result.Add(rs[i])
}
for i := range other {
result.Add(other[i])
}
return result
} | [
"func",
"(",
"rs",
"RuleSet",
")",
"Merge",
"(",
"other",
"RuleSet",
")",
"RuleSet",
"{",
"result",
":=",
"NewRuleSet",
"(",
")",
"\n",
"for",
"i",
":=",
"range",
"rs",
"{",
"result",
".",
"Add",
"(",
"rs",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"other",
"{",
"result",
".",
"Add",
"(",
"other",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // Merge returns a ruleset containing the union of rules from rs an other. | [
"Merge",
"returns",
"a",
"ruleset",
"containing",
"the",
"union",
"of",
"rules",
"from",
"rs",
"an",
"other",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/policy.go#L1214-L1223 | train |
open-policy-agent/opa | server/authorizer/authorizer.go | Runtime | func Runtime(term *ast.Term) func(*Basic) {
return func(b *Basic) {
b.runtime = term
}
} | go | func Runtime(term *ast.Term) func(*Basic) {
return func(b *Basic) {
b.runtime = term
}
} | [
"func",
"Runtime",
"(",
"term",
"*",
"ast",
".",
"Term",
")",
"func",
"(",
"*",
"Basic",
")",
"{",
"return",
"func",
"(",
"b",
"*",
"Basic",
")",
"{",
"b",
".",
"runtime",
"=",
"term",
"\n",
"}",
"\n",
"}"
] | // Runtime returns an argument that sets the runtime on the authorizer. | [
"Runtime",
"returns",
"an",
"argument",
"that",
"sets",
"the",
"runtime",
"on",
"the",
"authorizer",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/authorizer/authorizer.go#L31-L35 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.