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 | plugins/bundle/plugin.go | Unregister | func (p *Plugin) Unregister(name interface{}) {
p.mtx.Lock()
defer p.mtx.Unlock()
delete(p.listeners, name)
} | go | func (p *Plugin) Unregister(name interface{}) {
p.mtx.Lock()
defer p.mtx.Unlock()
delete(p.listeners, name)
} | [
"func",
"(",
"p",
"*",
"Plugin",
")",
"Unregister",
"(",
"name",
"interface",
"{",
"}",
")",
"{",
"p",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"delete",
"(",
"p",
".",
"listeners",
",",
"name",
")",
"\n",
"}"
] | // Unregister a listener to stop receiving status updates. | [
"Unregister",
"a",
"listener",
"to",
"stop",
"receiving",
"status",
"updates",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/plugins/bundle/plugin.go#L109-L114 | train |
open-policy-agent/opa | server/types/types.go | NewErrorV1 | func NewErrorV1(code, f string, a ...interface{}) *ErrorV1 {
return &ErrorV1{
Code: code,
Message: fmt.Sprintf(f, a...),
}
} | go | func NewErrorV1(code, f string, a ...interface{}) *ErrorV1 {
return &ErrorV1{
Code: code,
Message: fmt.Sprintf(f, a...),
}
} | [
"func",
"NewErrorV1",
"(",
"code",
",",
"f",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"ErrorV1",
"{",
"return",
"&",
"ErrorV1",
"{",
"Code",
":",
"code",
",",
"Message",
":",
"fmt",
".",
"Sprintf",
"(",
"f",
",",
"a",
"...",
")",
",",
"}",
"\n",
"}"
] | // NewErrorV1 returns a new ErrorV1 object. | [
"NewErrorV1",
"returns",
"a",
"new",
"ErrorV1",
"object",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/types/types.go#L39-L44 | train |
open-policy-agent/opa | server/types/types.go | WithError | func (e *ErrorV1) WithError(err error) *ErrorV1 {
e.Errors = append(e.Errors, err)
return e
} | go | func (e *ErrorV1) WithError(err error) *ErrorV1 {
e.Errors = append(e.Errors, err)
return e
} | [
"func",
"(",
"e",
"*",
"ErrorV1",
")",
"WithError",
"(",
"err",
"error",
")",
"*",
"ErrorV1",
"{",
"e",
".",
"Errors",
"=",
"append",
"(",
"e",
".",
"Errors",
",",
"err",
")",
"\n",
"return",
"e",
"\n",
"}"
] | // WithError updates e to include a detailed error. | [
"WithError",
"updates",
"e",
"to",
"include",
"a",
"detailed",
"error",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/types/types.go#L47-L50 | train |
open-policy-agent/opa | server/types/types.go | WithASTErrors | func (e *ErrorV1) WithASTErrors(errors []*ast.Error) *ErrorV1 {
e.Errors = make([]error, len(errors))
for i := range e.Errors {
e.Errors[i] = errors[i]
}
return e
} | go | func (e *ErrorV1) WithASTErrors(errors []*ast.Error) *ErrorV1 {
e.Errors = make([]error, len(errors))
for i := range e.Errors {
e.Errors[i] = errors[i]
}
return e
} | [
"func",
"(",
"e",
"*",
"ErrorV1",
")",
"WithASTErrors",
"(",
"errors",
"[",
"]",
"*",
"ast",
".",
"Error",
")",
"*",
"ErrorV1",
"{",
"e",
".",
"Errors",
"=",
"make",
"(",
"[",
"]",
"error",
",",
"len",
"(",
"errors",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"e",
".",
"Errors",
"{",
"e",
".",
"Errors",
"[",
"i",
"]",
"=",
"errors",
"[",
"i",
"]",
"\n",
"}",
"\n",
"return",
"e",
"\n",
"}"
] | // WithASTErrors updates e to include detailed AST errors. | [
"WithASTErrors",
"updates",
"e",
"to",
"include",
"detailed",
"AST",
"errors",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/types/types.go#L53-L59 | train |
open-policy-agent/opa | server/types/types.go | Bytes | func (e *ErrorV1) Bytes() []byte {
if bs, err := json.MarshalIndent(e, "", " "); err == nil {
return bs
}
return nil
} | go | func (e *ErrorV1) Bytes() []byte {
if bs, err := json.MarshalIndent(e, "", " "); err == nil {
return bs
}
return nil
} | [
"func",
"(",
"e",
"*",
"ErrorV1",
")",
"Bytes",
"(",
")",
"[",
"]",
"byte",
"{",
"if",
"bs",
",",
"err",
":=",
"json",
".",
"MarshalIndent",
"(",
"e",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"bs",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Bytes marshals e with indentation for readability. | [
"Bytes",
"marshals",
"e",
"with",
"indentation",
"for",
"readability",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/types/types.go#L62-L67 | train |
open-policy-agent/opa | server/types/types.go | Equal | func (p PolicyV1) Equal(other PolicyV1) bool {
return p.ID == other.ID && p.Raw == other.Raw && p.AST.Equal(other.AST)
} | go | func (p PolicyV1) Equal(other PolicyV1) bool {
return p.ID == other.ID && p.Raw == other.Raw && p.AST.Equal(other.AST)
} | [
"func",
"(",
"p",
"PolicyV1",
")",
"Equal",
"(",
"other",
"PolicyV1",
")",
"bool",
"{",
"return",
"p",
".",
"ID",
"==",
"other",
".",
"ID",
"&&",
"p",
".",
"Raw",
"==",
"other",
".",
"Raw",
"&&",
"p",
".",
"AST",
".",
"Equal",
"(",
"other",
".",
"AST",
")",
"\n",
"}"
] | // Equal returns true if p is equal to other. | [
"Equal",
"returns",
"true",
"if",
"p",
"is",
"equal",
"to",
"other",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/types/types.go#L117-L119 | train |
open-policy-agent/opa | server/types/types.go | UnmarshalJSON | func (t *TraceV1) UnmarshalJSON(b []byte) error {
*t = TraceV1(b[:])
return nil
} | go | func (t *TraceV1) UnmarshalJSON(b []byte) error {
*t = TraceV1(b[:])
return nil
} | [
"func",
"(",
"t",
"*",
"TraceV1",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"*",
"t",
"=",
"TraceV1",
"(",
"b",
"[",
":",
"]",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON unmarshals the TraceV1 from a JSON representation. | [
"UnmarshalJSON",
"unmarshals",
"the",
"TraceV1",
"from",
"a",
"JSON",
"representation",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/types/types.go#L208-L211 | train |
open-policy-agent/opa | server/types/types.go | UnmarshalJSON | func (t *TraceV1Raw) UnmarshalJSON(b []byte) error {
var trace []TraceEventV1
if err := json.Unmarshal(b, &trace); err != nil {
return err
}
*t = TraceV1Raw(trace)
return nil
} | go | func (t *TraceV1Raw) UnmarshalJSON(b []byte) error {
var trace []TraceEventV1
if err := json.Unmarshal(b, &trace); err != nil {
return err
}
*t = TraceV1Raw(trace)
return nil
} | [
"func",
"(",
"t",
"*",
"TraceV1Raw",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"trace",
"[",
"]",
"TraceEventV1",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"trace",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"*",
"t",
"=",
"TraceV1Raw",
"(",
"trace",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON unmarshals the TraceV1Raw from a JSON representation. | [
"UnmarshalJSON",
"unmarshals",
"the",
"TraceV1Raw",
"from",
"a",
"JSON",
"representation",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/types/types.go#L219-L226 | train |
open-policy-agent/opa | server/types/types.go | UnmarshalJSON | func (t *TraceV1Pretty) UnmarshalJSON(b []byte) error {
var s []string
if err := json.Unmarshal(b, &s); err != nil {
return err
}
*t = TraceV1Pretty(s)
return nil
} | go | func (t *TraceV1Pretty) UnmarshalJSON(b []byte) error {
var s []string
if err := json.Unmarshal(b, &s); err != nil {
return err
}
*t = TraceV1Pretty(s)
return nil
} | [
"func",
"(",
"t",
"*",
"TraceV1Pretty",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"s",
"[",
"]",
"string",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"s",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"*",
"t",
"=",
"TraceV1Pretty",
"(",
"s",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON unmarshals the TraceV1Pretty from a JSON representation. | [
"UnmarshalJSON",
"unmarshals",
"the",
"TraceV1Pretty",
"from",
"a",
"JSON",
"representation",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/types/types.go#L234-L241 | train |
open-policy-agent/opa | server/types/types.go | NewTraceV1 | func NewTraceV1(trace []*topdown.Event, pretty bool) (result TraceV1, err error) {
if pretty {
return newPrettyTraceV1(trace)
}
return newRawTraceV1(trace)
} | go | func NewTraceV1(trace []*topdown.Event, pretty bool) (result TraceV1, err error) {
if pretty {
return newPrettyTraceV1(trace)
}
return newRawTraceV1(trace)
} | [
"func",
"NewTraceV1",
"(",
"trace",
"[",
"]",
"*",
"topdown",
".",
"Event",
",",
"pretty",
"bool",
")",
"(",
"result",
"TraceV1",
",",
"err",
"error",
")",
"{",
"if",
"pretty",
"{",
"return",
"newPrettyTraceV1",
"(",
"trace",
")",
"\n",
"}",
"\n",
"return",
"newRawTraceV1",
"(",
"trace",
")",
"\n",
"}"
] | // NewTraceV1 returns a new TraceV1 object. | [
"NewTraceV1",
"returns",
"a",
"new",
"TraceV1",
"object",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/types/types.go#L244-L249 | train |
open-policy-agent/opa | server/types/types.go | UnmarshalJSON | func (te *TraceEventV1) UnmarshalJSON(bs []byte) error {
keys := map[string]json.RawMessage{}
if err := util.UnmarshalJSON(bs, &keys); err != nil {
return err
}
if err := util.UnmarshalJSON(keys["type"], &te.Type); err != nil {
return err
}
if err := util.UnmarshalJSON(keys["op"], &te.Op); err != nil {
return err
}
if err := util.UnmarshalJSON(keys["query_id"], &te.QueryID); err != nil {
return err
}
if err := util.UnmarshalJSON(keys["parent_id"], &te.ParentID); err != nil {
return err
}
switch te.Type {
case "body":
var body ast.Body
if err := util.UnmarshalJSON(keys["node"], &body); err != nil {
return err
}
te.Node = body
case "expr":
var expr ast.Expr
if err := util.UnmarshalJSON(keys["node"], &expr); err != nil {
return err
}
te.Node = &expr
case "rule":
var rule ast.Rule
if err := util.UnmarshalJSON(keys["node"], &rule); err != nil {
return err
}
te.Node = &rule
}
return util.UnmarshalJSON(keys["locals"], &te.Locals)
} | go | func (te *TraceEventV1) UnmarshalJSON(bs []byte) error {
keys := map[string]json.RawMessage{}
if err := util.UnmarshalJSON(bs, &keys); err != nil {
return err
}
if err := util.UnmarshalJSON(keys["type"], &te.Type); err != nil {
return err
}
if err := util.UnmarshalJSON(keys["op"], &te.Op); err != nil {
return err
}
if err := util.UnmarshalJSON(keys["query_id"], &te.QueryID); err != nil {
return err
}
if err := util.UnmarshalJSON(keys["parent_id"], &te.ParentID); err != nil {
return err
}
switch te.Type {
case "body":
var body ast.Body
if err := util.UnmarshalJSON(keys["node"], &body); err != nil {
return err
}
te.Node = body
case "expr":
var expr ast.Expr
if err := util.UnmarshalJSON(keys["node"], &expr); err != nil {
return err
}
te.Node = &expr
case "rule":
var rule ast.Rule
if err := util.UnmarshalJSON(keys["node"], &rule); err != nil {
return err
}
te.Node = &rule
}
return util.UnmarshalJSON(keys["locals"], &te.Locals)
} | [
"func",
"(",
"te",
"*",
"TraceEventV1",
")",
"UnmarshalJSON",
"(",
"bs",
"[",
"]",
"byte",
")",
"error",
"{",
"keys",
":=",
"map",
"[",
"string",
"]",
"json",
".",
"RawMessage",
"{",
"}",
"\n\n",
"if",
"err",
":=",
"util",
".",
"UnmarshalJSON",
"(",
"bs",
",",
"&",
"keys",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"util",
".",
"UnmarshalJSON",
"(",
"keys",
"[",
"\"",
"\"",
"]",
",",
"&",
"te",
".",
"Type",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"util",
".",
"UnmarshalJSON",
"(",
"keys",
"[",
"\"",
"\"",
"]",
",",
"&",
"te",
".",
"Op",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"util",
".",
"UnmarshalJSON",
"(",
"keys",
"[",
"\"",
"\"",
"]",
",",
"&",
"te",
".",
"QueryID",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"util",
".",
"UnmarshalJSON",
"(",
"keys",
"[",
"\"",
"\"",
"]",
",",
"&",
"te",
".",
"ParentID",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"switch",
"te",
".",
"Type",
"{",
"case",
"\"",
"\"",
":",
"var",
"body",
"ast",
".",
"Body",
"\n",
"if",
"err",
":=",
"util",
".",
"UnmarshalJSON",
"(",
"keys",
"[",
"\"",
"\"",
"]",
",",
"&",
"body",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"te",
".",
"Node",
"=",
"body",
"\n",
"case",
"\"",
"\"",
":",
"var",
"expr",
"ast",
".",
"Expr",
"\n",
"if",
"err",
":=",
"util",
".",
"UnmarshalJSON",
"(",
"keys",
"[",
"\"",
"\"",
"]",
",",
"&",
"expr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"te",
".",
"Node",
"=",
"&",
"expr",
"\n",
"case",
"\"",
"\"",
":",
"var",
"rule",
"ast",
".",
"Rule",
"\n",
"if",
"err",
":=",
"util",
".",
"UnmarshalJSON",
"(",
"keys",
"[",
"\"",
"\"",
"]",
",",
"&",
"rule",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"te",
".",
"Node",
"=",
"&",
"rule",
"\n",
"}",
"\n\n",
"return",
"util",
".",
"UnmarshalJSON",
"(",
"keys",
"[",
"\"",
"\"",
"]",
",",
"&",
"te",
".",
"Locals",
")",
"\n",
"}"
] | // UnmarshalJSON deserializes a TraceEventV1 object. The Node field is
// deserialized based on the type hint from the type property in the JSON
// object. | [
"UnmarshalJSON",
"deserializes",
"a",
"TraceEventV1",
"object",
".",
"The",
"Node",
"field",
"is",
"deserialized",
"based",
"on",
"the",
"type",
"hint",
"from",
"the",
"type",
"property",
"in",
"the",
"JSON",
"object",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/types/types.go#L300-L346 | train |
open-policy-agent/opa | server/types/types.go | NewBindingsV1 | func NewBindingsV1(locals *ast.ValueMap) (result []*BindingV1) {
result = make([]*BindingV1, 0, locals.Len())
locals.Iter(func(key, value ast.Value) bool {
result = append(result, &BindingV1{
Key: &ast.Term{Value: key},
Value: &ast.Term{Value: value},
})
return false
})
return result
} | go | func NewBindingsV1(locals *ast.ValueMap) (result []*BindingV1) {
result = make([]*BindingV1, 0, locals.Len())
locals.Iter(func(key, value ast.Value) bool {
result = append(result, &BindingV1{
Key: &ast.Term{Value: key},
Value: &ast.Term{Value: value},
})
return false
})
return result
} | [
"func",
"NewBindingsV1",
"(",
"locals",
"*",
"ast",
".",
"ValueMap",
")",
"(",
"result",
"[",
"]",
"*",
"BindingV1",
")",
"{",
"result",
"=",
"make",
"(",
"[",
"]",
"*",
"BindingV1",
",",
"0",
",",
"locals",
".",
"Len",
"(",
")",
")",
"\n",
"locals",
".",
"Iter",
"(",
"func",
"(",
"key",
",",
"value",
"ast",
".",
"Value",
")",
"bool",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"&",
"BindingV1",
"{",
"Key",
":",
"&",
"ast",
".",
"Term",
"{",
"Value",
":",
"key",
"}",
",",
"Value",
":",
"&",
"ast",
".",
"Term",
"{",
"Value",
":",
"value",
"}",
",",
"}",
")",
"\n",
"return",
"false",
"\n",
"}",
")",
"\n",
"return",
"result",
"\n",
"}"
] | // NewBindingsV1 returns a new BindingsV1 object. | [
"NewBindingsV1",
"returns",
"a",
"new",
"BindingsV1",
"object",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/types/types.go#L358-L368 | train |
open-policy-agent/opa | ast/errors.go | IsError | func IsError(code string, err error) bool {
if err, ok := err.(*Error); ok {
return err.Code == code
}
return false
} | go | func IsError(code string, err error) bool {
if err, ok := err.(*Error); ok {
return err.Code == code
}
return false
} | [
"func",
"IsError",
"(",
"code",
"string",
",",
"err",
"error",
")",
"bool",
"{",
"if",
"err",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"Error",
")",
";",
"ok",
"{",
"return",
"err",
".",
"Code",
"==",
"code",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsError returns true if err is an AST error with code. | [
"IsError",
"returns",
"true",
"if",
"err",
"is",
"an",
"AST",
"error",
"with",
"code",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/errors.go#L52-L57 | train |
open-policy-agent/opa | ast/errors.go | NewError | func NewError(code string, loc *Location, f string, a ...interface{}) *Error {
return &Error{
Code: code,
Location: loc,
Message: fmt.Sprintf(f, a...),
}
} | go | func NewError(code string, loc *Location, f string, a ...interface{}) *Error {
return &Error{
Code: code,
Location: loc,
Message: fmt.Sprintf(f, a...),
}
} | [
"func",
"NewError",
"(",
"code",
"string",
",",
"loc",
"*",
"Location",
",",
"f",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"*",
"Error",
"{",
"return",
"&",
"Error",
"{",
"Code",
":",
"code",
",",
"Location",
":",
"loc",
",",
"Message",
":",
"fmt",
".",
"Sprintf",
"(",
"f",
",",
"a",
"...",
")",
",",
"}",
"\n",
"}"
] | // NewError returns a new Error object. | [
"NewError",
"returns",
"a",
"new",
"Error",
"object",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/errors.go#L101-L107 | train |
open-policy-agent/opa | dependencies/deps.go | All | func All(x interface{}) (resolved []ast.Ref, err error) {
var rawResolved []ast.Ref
switch x := x.(type) {
case *ast.Module, *ast.Package, *ast.Import, *ast.Rule, *ast.Head, ast.Body, *ast.Expr, *ast.With, *ast.Term, ast.Ref, ast.Object, ast.Array, ast.Set, *ast.ArrayComprehension:
default:
return nil, fmt.Errorf("not an ast element: %v", x)
}
visitor := ast.NewGenericVisitor(func(x interface{}) bool {
switch x := x.(type) {
case *ast.Package, *ast.Import:
return true
case *ast.Module, *ast.Head, *ast.Expr, *ast.With, *ast.Term, ast.Object, ast.Array, *ast.Set, *ast.ArrayComprehension:
case *ast.Rule:
rawResolved = append(rawResolved, ruleDeps(x)...)
return true
case ast.Body:
vars := ast.NewVarVisitor()
ast.Walk(vars, x)
var arr ast.Array
for v := range vars.Vars() {
if v.IsWildcard() {
continue
}
arr = append(arr, ast.NewTerm(v))
}
// The analysis will discard variables that are not used in
// direct comparisons or in the output. Since lone Bodies are
// often queries, we want all the variables to be in the output.
r := &ast.Rule{
Head: &ast.Head{Name: ast.Var("_"), Value: ast.NewTerm(arr)},
Body: x,
}
rawResolved = append(rawResolved, ruleDeps(r)...)
return true
case ast.Ref:
rawResolved = append(rawResolved, x)
}
return false
})
ast.Walk(visitor, x)
if len(rawResolved) == 0 {
return nil, nil
}
return dedup(rawResolved), nil
} | go | func All(x interface{}) (resolved []ast.Ref, err error) {
var rawResolved []ast.Ref
switch x := x.(type) {
case *ast.Module, *ast.Package, *ast.Import, *ast.Rule, *ast.Head, ast.Body, *ast.Expr, *ast.With, *ast.Term, ast.Ref, ast.Object, ast.Array, ast.Set, *ast.ArrayComprehension:
default:
return nil, fmt.Errorf("not an ast element: %v", x)
}
visitor := ast.NewGenericVisitor(func(x interface{}) bool {
switch x := x.(type) {
case *ast.Package, *ast.Import:
return true
case *ast.Module, *ast.Head, *ast.Expr, *ast.With, *ast.Term, ast.Object, ast.Array, *ast.Set, *ast.ArrayComprehension:
case *ast.Rule:
rawResolved = append(rawResolved, ruleDeps(x)...)
return true
case ast.Body:
vars := ast.NewVarVisitor()
ast.Walk(vars, x)
var arr ast.Array
for v := range vars.Vars() {
if v.IsWildcard() {
continue
}
arr = append(arr, ast.NewTerm(v))
}
// The analysis will discard variables that are not used in
// direct comparisons or in the output. Since lone Bodies are
// often queries, we want all the variables to be in the output.
r := &ast.Rule{
Head: &ast.Head{Name: ast.Var("_"), Value: ast.NewTerm(arr)},
Body: x,
}
rawResolved = append(rawResolved, ruleDeps(r)...)
return true
case ast.Ref:
rawResolved = append(rawResolved, x)
}
return false
})
ast.Walk(visitor, x)
if len(rawResolved) == 0 {
return nil, nil
}
return dedup(rawResolved), nil
} | [
"func",
"All",
"(",
"x",
"interface",
"{",
"}",
")",
"(",
"resolved",
"[",
"]",
"ast",
".",
"Ref",
",",
"err",
"error",
")",
"{",
"var",
"rawResolved",
"[",
"]",
"ast",
".",
"Ref",
"\n",
"switch",
"x",
":=",
"x",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ast",
".",
"Module",
",",
"*",
"ast",
".",
"Package",
",",
"*",
"ast",
".",
"Import",
",",
"*",
"ast",
".",
"Rule",
",",
"*",
"ast",
".",
"Head",
",",
"ast",
".",
"Body",
",",
"*",
"ast",
".",
"Expr",
",",
"*",
"ast",
".",
"With",
",",
"*",
"ast",
".",
"Term",
",",
"ast",
".",
"Ref",
",",
"ast",
".",
"Object",
",",
"ast",
".",
"Array",
",",
"ast",
".",
"Set",
",",
"*",
"ast",
".",
"ArrayComprehension",
":",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"x",
")",
"\n",
"}",
"\n\n",
"visitor",
":=",
"ast",
".",
"NewGenericVisitor",
"(",
"func",
"(",
"x",
"interface",
"{",
"}",
")",
"bool",
"{",
"switch",
"x",
":=",
"x",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ast",
".",
"Package",
",",
"*",
"ast",
".",
"Import",
":",
"return",
"true",
"\n",
"case",
"*",
"ast",
".",
"Module",
",",
"*",
"ast",
".",
"Head",
",",
"*",
"ast",
".",
"Expr",
",",
"*",
"ast",
".",
"With",
",",
"*",
"ast",
".",
"Term",
",",
"ast",
".",
"Object",
",",
"ast",
".",
"Array",
",",
"*",
"ast",
".",
"Set",
",",
"*",
"ast",
".",
"ArrayComprehension",
":",
"case",
"*",
"ast",
".",
"Rule",
":",
"rawResolved",
"=",
"append",
"(",
"rawResolved",
",",
"ruleDeps",
"(",
"x",
")",
"...",
")",
"\n",
"return",
"true",
"\n",
"case",
"ast",
".",
"Body",
":",
"vars",
":=",
"ast",
".",
"NewVarVisitor",
"(",
")",
"\n",
"ast",
".",
"Walk",
"(",
"vars",
",",
"x",
")",
"\n\n",
"var",
"arr",
"ast",
".",
"Array",
"\n",
"for",
"v",
":=",
"range",
"vars",
".",
"Vars",
"(",
")",
"{",
"if",
"v",
".",
"IsWildcard",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n",
"arr",
"=",
"append",
"(",
"arr",
",",
"ast",
".",
"NewTerm",
"(",
"v",
")",
")",
"\n",
"}",
"\n\n",
"// The analysis will discard variables that are not used in",
"// direct comparisons or in the output. Since lone Bodies are",
"// often queries, we want all the variables to be in the output.",
"r",
":=",
"&",
"ast",
".",
"Rule",
"{",
"Head",
":",
"&",
"ast",
".",
"Head",
"{",
"Name",
":",
"ast",
".",
"Var",
"(",
"\"",
"\"",
")",
",",
"Value",
":",
"ast",
".",
"NewTerm",
"(",
"arr",
")",
"}",
",",
"Body",
":",
"x",
",",
"}",
"\n",
"rawResolved",
"=",
"append",
"(",
"rawResolved",
",",
"ruleDeps",
"(",
"r",
")",
"...",
")",
"\n",
"return",
"true",
"\n",
"case",
"ast",
".",
"Ref",
":",
"rawResolved",
"=",
"append",
"(",
"rawResolved",
",",
"x",
")",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
")",
"\n",
"ast",
".",
"Walk",
"(",
"visitor",
",",
"x",
")",
"\n",
"if",
"len",
"(",
"rawResolved",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"dedup",
"(",
"rawResolved",
")",
",",
"nil",
"\n",
"}"
] | // All returns the list of data ast.Refs that the given AST element depends on. | [
"All",
"returns",
"the",
"list",
"of",
"data",
"ast",
".",
"Refs",
"that",
"the",
"given",
"AST",
"element",
"depends",
"on",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/dependencies/deps.go#L16-L64 | train |
open-policy-agent/opa | dependencies/deps.go | Minimal | func Minimal(x interface{}) (resolved []ast.Ref, err error) {
rawResolved, err := All(x)
if err != nil {
return nil, err
}
if len(rawResolved) == 0 {
return nil, nil
}
return filter(rawResolved, func(a, b ast.Ref) bool {
return b.HasPrefix(a)
}), nil
} | go | func Minimal(x interface{}) (resolved []ast.Ref, err error) {
rawResolved, err := All(x)
if err != nil {
return nil, err
}
if len(rawResolved) == 0 {
return nil, nil
}
return filter(rawResolved, func(a, b ast.Ref) bool {
return b.HasPrefix(a)
}), nil
} | [
"func",
"Minimal",
"(",
"x",
"interface",
"{",
"}",
")",
"(",
"resolved",
"[",
"]",
"ast",
".",
"Ref",
",",
"err",
"error",
")",
"{",
"rawResolved",
",",
"err",
":=",
"All",
"(",
"x",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"rawResolved",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"filter",
"(",
"rawResolved",
",",
"func",
"(",
"a",
",",
"b",
"ast",
".",
"Ref",
")",
"bool",
"{",
"return",
"b",
".",
"HasPrefix",
"(",
"a",
")",
"\n",
"}",
")",
",",
"nil",
"\n",
"}"
] | // Minimal returns the list of data ast.Refs that the given AST element depends on.
// If an AST element depends on a ast.Ref that is a prefix of another dependency, the
// ast.Ref that is the prefix of the other will be the only one in the returned list.
//
// As an example, if an element depends on data.x and data.x.y, only data.x will
// be in the returned list. | [
"Minimal",
"returns",
"the",
"list",
"of",
"data",
"ast",
".",
"Refs",
"that",
"the",
"given",
"AST",
"element",
"depends",
"on",
".",
"If",
"an",
"AST",
"element",
"depends",
"on",
"a",
"ast",
".",
"Ref",
"that",
"is",
"a",
"prefix",
"of",
"another",
"dependency",
"the",
"ast",
".",
"Ref",
"that",
"is",
"the",
"prefix",
"of",
"the",
"other",
"will",
"be",
"the",
"only",
"one",
"in",
"the",
"returned",
"list",
".",
"As",
"an",
"example",
"if",
"an",
"element",
"depends",
"on",
"data",
".",
"x",
"and",
"data",
".",
"x",
".",
"y",
"only",
"data",
".",
"x",
"will",
"be",
"in",
"the",
"returned",
"list",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/dependencies/deps.go#L72-L85 | train |
open-policy-agent/opa | dependencies/deps.go | filter | func filter(rs []ast.Ref, pred func(ast.Ref, ast.Ref) bool) (filtered []ast.Ref) {
if len(rs) == 0 {
return nil
}
last := rs[0]
filtered = append(filtered, last)
for i := 1; i < len(rs); i++ {
cur := rs[i]
if pred(last, cur) {
continue
}
filtered = append(filtered, cur)
last = cur
}
return filtered
} | go | func filter(rs []ast.Ref, pred func(ast.Ref, ast.Ref) bool) (filtered []ast.Ref) {
if len(rs) == 0 {
return nil
}
last := rs[0]
filtered = append(filtered, last)
for i := 1; i < len(rs); i++ {
cur := rs[i]
if pred(last, cur) {
continue
}
filtered = append(filtered, cur)
last = cur
}
return filtered
} | [
"func",
"filter",
"(",
"rs",
"[",
"]",
"ast",
".",
"Ref",
",",
"pred",
"func",
"(",
"ast",
".",
"Ref",
",",
"ast",
".",
"Ref",
")",
"bool",
")",
"(",
"filtered",
"[",
"]",
"ast",
".",
"Ref",
")",
"{",
"if",
"len",
"(",
"rs",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"last",
":=",
"rs",
"[",
"0",
"]",
"\n",
"filtered",
"=",
"append",
"(",
"filtered",
",",
"last",
")",
"\n",
"for",
"i",
":=",
"1",
";",
"i",
"<",
"len",
"(",
"rs",
")",
";",
"i",
"++",
"{",
"cur",
":=",
"rs",
"[",
"i",
"]",
"\n",
"if",
"pred",
"(",
"last",
",",
"cur",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"filtered",
"=",
"append",
"(",
"filtered",
",",
"cur",
")",
"\n",
"last",
"=",
"cur",
"\n",
"}",
"\n\n",
"return",
"filtered",
"\n",
"}"
] | // filter removes all items from the list that cause pref to return true. It is
// called on adjacent pairs of elements, and the one passed as the second argument
// to pref is considered the current one being examined. The first argument will
// be the element immediately preceding it. | [
"filter",
"removes",
"all",
"items",
"from",
"the",
"list",
"that",
"cause",
"pref",
"to",
"return",
"true",
".",
"It",
"is",
"called",
"on",
"adjacent",
"pairs",
"of",
"elements",
"and",
"the",
"one",
"passed",
"as",
"the",
"second",
"argument",
"to",
"pref",
"is",
"considered",
"the",
"current",
"one",
"being",
"examined",
".",
"The",
"first",
"argument",
"will",
"be",
"the",
"element",
"immediately",
"preceding",
"it",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/dependencies/deps.go#L179-L197 | train |
open-policy-agent/opa | dependencies/deps.go | extractEq | func extractEq(exprs ast.Body) (vars map[ast.Var][]ast.Ref, others []*ast.Expr) {
vars = map[ast.Var][]ast.Ref{}
for v := range exprs.Vars(ast.VarVisitorParams{}) {
vars[v] = nil
}
for _, expr := range exprs {
if !expr.IsEquality() {
others = append(others, expr)
continue
}
terms := expr.Terms.([]*ast.Term)
left, right := terms[1], terms[2]
if l, ok := left.Value.(ast.Var); ok {
if r, ok := right.Value.(ast.Ref); ok {
vars[l] = append(vars[l], r)
continue
}
} else if r, ok := right.Value.(ast.Var); ok {
if l, ok := left.Value.(ast.Ref); ok {
vars[r] = append(vars[r], l)
continue
}
}
others = append(others, expr)
}
return vars, others
} | go | func extractEq(exprs ast.Body) (vars map[ast.Var][]ast.Ref, others []*ast.Expr) {
vars = map[ast.Var][]ast.Ref{}
for v := range exprs.Vars(ast.VarVisitorParams{}) {
vars[v] = nil
}
for _, expr := range exprs {
if !expr.IsEquality() {
others = append(others, expr)
continue
}
terms := expr.Terms.([]*ast.Term)
left, right := terms[1], terms[2]
if l, ok := left.Value.(ast.Var); ok {
if r, ok := right.Value.(ast.Ref); ok {
vars[l] = append(vars[l], r)
continue
}
} else if r, ok := right.Value.(ast.Var); ok {
if l, ok := left.Value.(ast.Ref); ok {
vars[r] = append(vars[r], l)
continue
}
}
others = append(others, expr)
}
return vars, others
} | [
"func",
"extractEq",
"(",
"exprs",
"ast",
".",
"Body",
")",
"(",
"vars",
"map",
"[",
"ast",
".",
"Var",
"]",
"[",
"]",
"ast",
".",
"Ref",
",",
"others",
"[",
"]",
"*",
"ast",
".",
"Expr",
")",
"{",
"vars",
"=",
"map",
"[",
"ast",
".",
"Var",
"]",
"[",
"]",
"ast",
".",
"Ref",
"{",
"}",
"\n",
"for",
"v",
":=",
"range",
"exprs",
".",
"Vars",
"(",
"ast",
".",
"VarVisitorParams",
"{",
"}",
")",
"{",
"vars",
"[",
"v",
"]",
"=",
"nil",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"expr",
":=",
"range",
"exprs",
"{",
"if",
"!",
"expr",
".",
"IsEquality",
"(",
")",
"{",
"others",
"=",
"append",
"(",
"others",
",",
"expr",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"terms",
":=",
"expr",
".",
"Terms",
".",
"(",
"[",
"]",
"*",
"ast",
".",
"Term",
")",
"\n",
"left",
",",
"right",
":=",
"terms",
"[",
"1",
"]",
",",
"terms",
"[",
"2",
"]",
"\n",
"if",
"l",
",",
"ok",
":=",
"left",
".",
"Value",
".",
"(",
"ast",
".",
"Var",
")",
";",
"ok",
"{",
"if",
"r",
",",
"ok",
":=",
"right",
".",
"Value",
".",
"(",
"ast",
".",
"Ref",
")",
";",
"ok",
"{",
"vars",
"[",
"l",
"]",
"=",
"append",
"(",
"vars",
"[",
"l",
"]",
",",
"r",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"}",
"else",
"if",
"r",
",",
"ok",
":=",
"right",
".",
"Value",
".",
"(",
"ast",
".",
"Var",
")",
";",
"ok",
"{",
"if",
"l",
",",
"ok",
":=",
"left",
".",
"Value",
".",
"(",
"ast",
".",
"Ref",
")",
";",
"ok",
"{",
"vars",
"[",
"r",
"]",
"=",
"append",
"(",
"vars",
"[",
"r",
"]",
",",
"l",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"}",
"\n\n",
"others",
"=",
"append",
"(",
"others",
",",
"expr",
")",
"\n",
"}",
"\n",
"return",
"vars",
",",
"others",
"\n",
"}"
] | // Extract the equality expressions from each rule, they contain
// the potential split references. In order to be considered for
// joining, an equality must have a variable on one side and a
// reference on the other. Any other construct is thrown into
// the others list to be resolved later. | [
"Extract",
"the",
"equality",
"expressions",
"from",
"each",
"rule",
"they",
"contain",
"the",
"potential",
"split",
"references",
".",
"In",
"order",
"to",
"be",
"considered",
"for",
"joining",
"an",
"equality",
"must",
"have",
"a",
"variable",
"on",
"one",
"side",
"and",
"a",
"reference",
"on",
"the",
"other",
".",
"Any",
"other",
"construct",
"is",
"thrown",
"into",
"the",
"others",
"list",
"to",
"be",
"resolved",
"later",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/dependencies/deps.go#L256-L285 | train |
open-policy-agent/opa | internal/leb128/leb128.go | MustReadVarInt32 | func MustReadVarInt32(r io.Reader) int32 {
i32, err := ReadVarInt32(r)
if err != nil {
panic(err)
}
return i32
} | go | func MustReadVarInt32(r io.Reader) int32 {
i32, err := ReadVarInt32(r)
if err != nil {
panic(err)
}
return i32
} | [
"func",
"MustReadVarInt32",
"(",
"r",
"io",
".",
"Reader",
")",
"int32",
"{",
"i32",
",",
"err",
":=",
"ReadVarInt32",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"i32",
"\n",
"}"
] | // MustReadVarInt32 returns an int32 from r or panics. | [
"MustReadVarInt32",
"returns",
"an",
"int32",
"from",
"r",
"or",
"panics",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/leb128/leb128.go#L13-L19 | train |
open-policy-agent/opa | internal/leb128/leb128.go | MustReadVarInt64 | func MustReadVarInt64(r io.Reader) int64 {
i64, err := ReadVarInt64(r)
if err != nil {
panic(err)
}
return i64
} | go | func MustReadVarInt64(r io.Reader) int64 {
i64, err := ReadVarInt64(r)
if err != nil {
panic(err)
}
return i64
} | [
"func",
"MustReadVarInt64",
"(",
"r",
"io",
".",
"Reader",
")",
"int64",
"{",
"i64",
",",
"err",
":=",
"ReadVarInt64",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"i64",
"\n",
"}"
] | // MustReadVarInt64 returns an int64 from r or panics. | [
"MustReadVarInt64",
"returns",
"an",
"int64",
"from",
"r",
"or",
"panics",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/leb128/leb128.go#L22-L28 | train |
open-policy-agent/opa | internal/leb128/leb128.go | MustReadVarUint32 | func MustReadVarUint32(r io.Reader) uint32 {
u32, err := ReadVarUint32(r)
if err != nil {
panic(err)
}
return u32
} | go | func MustReadVarUint32(r io.Reader) uint32 {
u32, err := ReadVarUint32(r)
if err != nil {
panic(err)
}
return u32
} | [
"func",
"MustReadVarUint32",
"(",
"r",
"io",
".",
"Reader",
")",
"uint32",
"{",
"u32",
",",
"err",
":=",
"ReadVarUint32",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"u32",
"\n",
"}"
] | // MustReadVarUint32 returns an uint32 from r or panics. | [
"MustReadVarUint32",
"returns",
"an",
"uint32",
"from",
"r",
"or",
"panics",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/leb128/leb128.go#L31-L37 | train |
open-policy-agent/opa | internal/leb128/leb128.go | MustReadVarUint64 | func MustReadVarUint64(r io.Reader) uint64 {
u64, err := ReadVarUint64(r)
if err != nil {
panic(err)
}
return u64
} | go | func MustReadVarUint64(r io.Reader) uint64 {
u64, err := ReadVarUint64(r)
if err != nil {
panic(err)
}
return u64
} | [
"func",
"MustReadVarUint64",
"(",
"r",
"io",
".",
"Reader",
")",
"uint64",
"{",
"u64",
",",
"err",
":=",
"ReadVarUint64",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"u64",
"\n",
"}"
] | // MustReadVarUint64 returns an uint64 from r or panics. | [
"MustReadVarUint64",
"returns",
"an",
"uint64",
"from",
"r",
"or",
"panics",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/leb128/leb128.go#L40-L46 | train |
open-policy-agent/opa | internal/leb128/leb128.go | ReadVarUint64 | func ReadVarUint64(r io.Reader) (uint64, error) {
var result uint64
var shift uint64
buf := make([]byte, 1)
for {
if _, err := r.Read(buf); err != nil {
return 0, err
}
v := uint64(buf[0])
result |= (v & 0x7F) << shift
if v&0x80 == 0 {
return result, nil
}
shift += 7
}
} | go | func ReadVarUint64(r io.Reader) (uint64, error) {
var result uint64
var shift uint64
buf := make([]byte, 1)
for {
if _, err := r.Read(buf); err != nil {
return 0, err
}
v := uint64(buf[0])
result |= (v & 0x7F) << shift
if v&0x80 == 0 {
return result, nil
}
shift += 7
}
} | [
"func",
"ReadVarUint64",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"var",
"result",
"uint64",
"\n",
"var",
"shift",
"uint64",
"\n",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"1",
")",
"\n",
"for",
"{",
"if",
"_",
",",
"err",
":=",
"r",
".",
"Read",
"(",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"v",
":=",
"uint64",
"(",
"buf",
"[",
"0",
"]",
")",
"\n",
"result",
"|=",
"(",
"v",
"&",
"0x7F",
")",
"<<",
"shift",
"\n",
"if",
"v",
"&",
"0x80",
"==",
"0",
"{",
"return",
"result",
",",
"nil",
"\n",
"}",
"\n",
"shift",
"+=",
"7",
"\n",
"}",
"\n\n",
"}"
] | // ReadVarUint64 tries to read a uint64 from r. | [
"ReadVarUint64",
"tries",
"to",
"read",
"a",
"uint64",
"from",
"r",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/leb128/leb128.go#L60-L76 | train |
open-policy-agent/opa | internal/leb128/leb128.go | ReadVarInt32 | func ReadVarInt32(r io.Reader) (int32, error) {
i64, err := ReadVarInt64(r)
if err != nil {
return 0, err
}
return int32(i64), nil
} | go | func ReadVarInt32(r io.Reader) (int32, error) {
i64, err := ReadVarInt64(r)
if err != nil {
return 0, err
}
return int32(i64), nil
} | [
"func",
"ReadVarInt32",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"int32",
",",
"error",
")",
"{",
"i64",
",",
"err",
":=",
"ReadVarInt64",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"int32",
"(",
"i64",
")",
",",
"nil",
"\n",
"}"
] | // ReadVarInt32 tries to read a int32 from r. | [
"ReadVarInt32",
"tries",
"to",
"read",
"a",
"int32",
"from",
"r",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/leb128/leb128.go#L79-L85 | train |
open-policy-agent/opa | internal/leb128/leb128.go | ReadVarInt64 | func ReadVarInt64(r io.Reader) (int64, error) {
var result int64
var shift uint64
size := uint64(32)
buf := make([]byte, 1)
for {
if _, err := r.Read(buf); err != nil {
return 0, err
}
v := int64(buf[0])
result |= (v & 0x7F) << shift
shift += 7
if v&0x80 == 0 {
if (shift < size) && (v&0x40 != 0) {
result |= (^0 << shift)
}
return result, nil
}
}
} | go | func ReadVarInt64(r io.Reader) (int64, error) {
var result int64
var shift uint64
size := uint64(32)
buf := make([]byte, 1)
for {
if _, err := r.Read(buf); err != nil {
return 0, err
}
v := int64(buf[0])
result |= (v & 0x7F) << shift
shift += 7
if v&0x80 == 0 {
if (shift < size) && (v&0x40 != 0) {
result |= (^0 << shift)
}
return result, nil
}
}
} | [
"func",
"ReadVarInt64",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"int64",
",",
"error",
")",
"{",
"var",
"result",
"int64",
"\n",
"var",
"shift",
"uint64",
"\n",
"size",
":=",
"uint64",
"(",
"32",
")",
"\n",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"1",
")",
"\n",
"for",
"{",
"if",
"_",
",",
"err",
":=",
"r",
".",
"Read",
"(",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"v",
":=",
"int64",
"(",
"buf",
"[",
"0",
"]",
")",
"\n",
"result",
"|=",
"(",
"v",
"&",
"0x7F",
")",
"<<",
"shift",
"\n",
"shift",
"+=",
"7",
"\n",
"if",
"v",
"&",
"0x80",
"==",
"0",
"{",
"if",
"(",
"shift",
"<",
"size",
")",
"&&",
"(",
"v",
"&",
"0x40",
"!=",
"0",
")",
"{",
"result",
"|=",
"(",
"^",
"0",
"<<",
"shift",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // ReadVarInt64 tries to read a int64 from r. | [
"ReadVarInt64",
"tries",
"to",
"read",
"a",
"int64",
"from",
"r",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/leb128/leb128.go#L88-L107 | train |
open-policy-agent/opa | internal/leb128/leb128.go | WriteVarUint32 | func WriteVarUint32(w io.Writer, u uint32) error {
var b []byte
_, err := w.Write(appendUleb128(b, uint64(u)))
return err
} | go | func WriteVarUint32(w io.Writer, u uint32) error {
var b []byte
_, err := w.Write(appendUleb128(b, uint64(u)))
return err
} | [
"func",
"WriteVarUint32",
"(",
"w",
"io",
".",
"Writer",
",",
"u",
"uint32",
")",
"error",
"{",
"var",
"b",
"[",
"]",
"byte",
"\n",
"_",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"appendUleb128",
"(",
"b",
",",
"uint64",
"(",
"u",
")",
")",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // WriteVarUint32 writes u to w. | [
"WriteVarUint32",
"writes",
"u",
"to",
"w",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/leb128/leb128.go#L110-L114 | train |
open-policy-agent/opa | internal/leb128/leb128.go | WriteVarInt64 | func WriteVarInt64(w io.Writer, i int64) error {
var b []byte
_, err := w.Write(appendSleb128(b, i))
return err
} | go | func WriteVarInt64(w io.Writer, i int64) error {
var b []byte
_, err := w.Write(appendSleb128(b, i))
return err
} | [
"func",
"WriteVarInt64",
"(",
"w",
"io",
".",
"Writer",
",",
"i",
"int64",
")",
"error",
"{",
"var",
"b",
"[",
"]",
"byte",
"\n",
"_",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"appendSleb128",
"(",
"b",
",",
"i",
")",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // WriteVarInt64 writes u to w. | [
"WriteVarInt64",
"writes",
"u",
"to",
"w",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/leb128/leb128.go#L131-L135 | train |
open-policy-agent/opa | internal/leb128/leb128.go | appendSleb128 | func appendSleb128(b []byte, v int64) []byte {
for {
c := uint8(v & 0x7f)
s := uint8(v & 0x40)
v >>= 7
if (v != -1 || s == 0) && (v != 0 || s != 0) {
c |= 0x80
}
b = append(b, c)
if c&0x80 == 0 {
break
}
}
return b
} | go | func appendSleb128(b []byte, v int64) []byte {
for {
c := uint8(v & 0x7f)
s := uint8(v & 0x40)
v >>= 7
if (v != -1 || s == 0) && (v != 0 || s != 0) {
c |= 0x80
}
b = append(b, c)
if c&0x80 == 0 {
break
}
}
return b
} | [
"func",
"appendSleb128",
"(",
"b",
"[",
"]",
"byte",
",",
"v",
"int64",
")",
"[",
"]",
"byte",
"{",
"for",
"{",
"c",
":=",
"uint8",
"(",
"v",
"&",
"0x7f",
")",
"\n",
"s",
":=",
"uint8",
"(",
"v",
"&",
"0x40",
")",
"\n",
"v",
">>=",
"7",
"\n",
"if",
"(",
"v",
"!=",
"-",
"1",
"||",
"s",
"==",
"0",
")",
"&&",
"(",
"v",
"!=",
"0",
"||",
"s",
"!=",
"0",
")",
"{",
"c",
"|=",
"0x80",
"\n",
"}",
"\n",
"b",
"=",
"append",
"(",
"b",
",",
"c",
")",
"\n",
"if",
"c",
"&",
"0x80",
"==",
"0",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"b",
"\n",
"}"
] | // appendSleb128 appends v to b using DWARF's signed LEB128 encoding. | [
"appendSleb128",
"appends",
"v",
"to",
"b",
"using",
"DWARF",
"s",
"signed",
"LEB128",
"encoding",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/leb128/leb128.go#L156-L170 | train |
open-policy-agent/opa | util/close.go | Close | func Close(resp *http.Response) {
if resp != nil {
if _, err := io.Copy(ioutil.Discard, resp.Body); err != nil {
return
}
resp.Body.Close()
}
} | go | func Close(resp *http.Response) {
if resp != nil {
if _, err := io.Copy(ioutil.Discard, resp.Body); err != nil {
return
}
resp.Body.Close()
}
} | [
"func",
"Close",
"(",
"resp",
"*",
"http",
".",
"Response",
")",
"{",
"if",
"resp",
"!=",
"nil",
"{",
"if",
"_",
",",
"err",
":=",
"io",
".",
"Copy",
"(",
"ioutil",
".",
"Discard",
",",
"resp",
".",
"Body",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Close reads the remaining bytes from the response and then closes it to
// ensure that the connection is freed. If the body is not read and closed, a
// leak can occur. | [
"Close",
"reads",
"the",
"remaining",
"bytes",
"from",
"the",
"response",
"and",
"then",
"closes",
"it",
"to",
"ensure",
"that",
"the",
"connection",
"is",
"freed",
".",
"If",
"the",
"body",
"is",
"not",
"read",
"and",
"closed",
"a",
"leak",
"can",
"occur",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/close.go#L16-L23 | train |
open-policy-agent/opa | ast/check.go | newTypeChecker | func newTypeChecker() *typeChecker {
tc := &typeChecker{}
tc.exprCheckers = map[string]exprChecker{
"eq": tc.checkExprEq,
}
return tc
} | go | func newTypeChecker() *typeChecker {
tc := &typeChecker{}
tc.exprCheckers = map[string]exprChecker{
"eq": tc.checkExprEq,
}
return tc
} | [
"func",
"newTypeChecker",
"(",
")",
"*",
"typeChecker",
"{",
"tc",
":=",
"&",
"typeChecker",
"{",
"}",
"\n",
"tc",
".",
"exprCheckers",
"=",
"map",
"[",
"string",
"]",
"exprChecker",
"{",
"\"",
"\"",
":",
"tc",
".",
"checkExprEq",
",",
"}",
"\n",
"return",
"tc",
"\n",
"}"
] | // newTypeChecker returns a new typeChecker object that has no errors. | [
"newTypeChecker",
"returns",
"a",
"new",
"typeChecker",
"object",
"that",
"has",
"no",
"errors",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/check.go#L30-L36 | train |
open-policy-agent/opa | ast/check.go | CheckBody | func (tc *typeChecker) CheckBody(env *TypeEnv, body Body) (*TypeEnv, Errors) {
if env == nil {
env = NewTypeEnv()
} else {
env = env.wrap()
}
WalkExprs(body, func(expr *Expr) bool {
closureErrs := tc.checkClosures(env, expr)
for _, err := range closureErrs {
tc.err(err)
}
hasClosureErrors := len(closureErrs) > 0
vis := newRefChecker(env)
Walk(vis, expr)
for _, err := range vis.errs {
tc.err(err)
}
hasRefErrors := len(vis.errs) > 0
if err := tc.checkExpr(env, expr); err != nil {
// Suppress this error if a more actionable one has occurred. In
// this case, if an error occurred in a ref or closure contained in
// this expression, and the error is due to a nil type, then it's
// likely to be the result of the more specific error.
skip := (hasClosureErrors || hasRefErrors) && causedByNilType(err)
if !skip {
tc.err(err)
}
}
return true
})
return env, tc.errs
} | go | func (tc *typeChecker) CheckBody(env *TypeEnv, body Body) (*TypeEnv, Errors) {
if env == nil {
env = NewTypeEnv()
} else {
env = env.wrap()
}
WalkExprs(body, func(expr *Expr) bool {
closureErrs := tc.checkClosures(env, expr)
for _, err := range closureErrs {
tc.err(err)
}
hasClosureErrors := len(closureErrs) > 0
vis := newRefChecker(env)
Walk(vis, expr)
for _, err := range vis.errs {
tc.err(err)
}
hasRefErrors := len(vis.errs) > 0
if err := tc.checkExpr(env, expr); err != nil {
// Suppress this error if a more actionable one has occurred. In
// this case, if an error occurred in a ref or closure contained in
// this expression, and the error is due to a nil type, then it's
// likely to be the result of the more specific error.
skip := (hasClosureErrors || hasRefErrors) && causedByNilType(err)
if !skip {
tc.err(err)
}
}
return true
})
return env, tc.errs
} | [
"func",
"(",
"tc",
"*",
"typeChecker",
")",
"CheckBody",
"(",
"env",
"*",
"TypeEnv",
",",
"body",
"Body",
")",
"(",
"*",
"TypeEnv",
",",
"Errors",
")",
"{",
"if",
"env",
"==",
"nil",
"{",
"env",
"=",
"NewTypeEnv",
"(",
")",
"\n",
"}",
"else",
"{",
"env",
"=",
"env",
".",
"wrap",
"(",
")",
"\n",
"}",
"\n\n",
"WalkExprs",
"(",
"body",
",",
"func",
"(",
"expr",
"*",
"Expr",
")",
"bool",
"{",
"closureErrs",
":=",
"tc",
".",
"checkClosures",
"(",
"env",
",",
"expr",
")",
"\n",
"for",
"_",
",",
"err",
":=",
"range",
"closureErrs",
"{",
"tc",
".",
"err",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"hasClosureErrors",
":=",
"len",
"(",
"closureErrs",
")",
">",
"0",
"\n\n",
"vis",
":=",
"newRefChecker",
"(",
"env",
")",
"\n",
"Walk",
"(",
"vis",
",",
"expr",
")",
"\n",
"for",
"_",
",",
"err",
":=",
"range",
"vis",
".",
"errs",
"{",
"tc",
".",
"err",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"hasRefErrors",
":=",
"len",
"(",
"vis",
".",
"errs",
")",
">",
"0",
"\n\n",
"if",
"err",
":=",
"tc",
".",
"checkExpr",
"(",
"env",
",",
"expr",
")",
";",
"err",
"!=",
"nil",
"{",
"// Suppress this error if a more actionable one has occurred. In",
"// this case, if an error occurred in a ref or closure contained in",
"// this expression, and the error is due to a nil type, then it's",
"// likely to be the result of the more specific error.",
"skip",
":=",
"(",
"hasClosureErrors",
"||",
"hasRefErrors",
")",
"&&",
"causedByNilType",
"(",
"err",
")",
"\n",
"if",
"!",
"skip",
"{",
"tc",
".",
"err",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}",
")",
"\n\n",
"return",
"env",
",",
"tc",
".",
"errs",
"\n",
"}"
] | // CheckBody runs type checking on the body and returns a TypeEnv if no errors
// are found. The resulting TypeEnv wraps the provided one. The resulting
// TypeEnv will be able to resolve types of vars contained in the body. | [
"CheckBody",
"runs",
"type",
"checking",
"on",
"the",
"body",
"and",
"returns",
"a",
"TypeEnv",
"if",
"no",
"errors",
"are",
"found",
".",
"The",
"resulting",
"TypeEnv",
"wraps",
"the",
"provided",
"one",
".",
"The",
"resulting",
"TypeEnv",
"will",
"be",
"able",
"to",
"resolve",
"types",
"of",
"vars",
"contained",
"in",
"the",
"body",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/check.go#L41-L81 | train |
open-policy-agent/opa | ast/check.go | CheckTypes | func (tc *typeChecker) CheckTypes(env *TypeEnv, sorted []util.T) (*TypeEnv, Errors) {
if env == nil {
env = NewTypeEnv()
} else {
env = env.wrap()
}
for _, s := range sorted {
tc.checkRule(env, s.(*Rule))
}
return env, tc.errs
} | go | func (tc *typeChecker) CheckTypes(env *TypeEnv, sorted []util.T) (*TypeEnv, Errors) {
if env == nil {
env = NewTypeEnv()
} else {
env = env.wrap()
}
for _, s := range sorted {
tc.checkRule(env, s.(*Rule))
}
return env, tc.errs
} | [
"func",
"(",
"tc",
"*",
"typeChecker",
")",
"CheckTypes",
"(",
"env",
"*",
"TypeEnv",
",",
"sorted",
"[",
"]",
"util",
".",
"T",
")",
"(",
"*",
"TypeEnv",
",",
"Errors",
")",
"{",
"if",
"env",
"==",
"nil",
"{",
"env",
"=",
"NewTypeEnv",
"(",
")",
"\n",
"}",
"else",
"{",
"env",
"=",
"env",
".",
"wrap",
"(",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"sorted",
"{",
"tc",
".",
"checkRule",
"(",
"env",
",",
"s",
".",
"(",
"*",
"Rule",
")",
")",
"\n",
"}",
"\n",
"return",
"env",
",",
"tc",
".",
"errs",
"\n",
"}"
] | // CheckTypes runs type checking on the rules returns a TypeEnv if no errors
// are found. The resulting TypeEnv wraps the provided one. The resulting
// TypeEnv will be able to resolve types of refs that refer to rules. | [
"CheckTypes",
"runs",
"type",
"checking",
"on",
"the",
"rules",
"returns",
"a",
"TypeEnv",
"if",
"no",
"errors",
"are",
"found",
".",
"The",
"resulting",
"TypeEnv",
"wraps",
"the",
"provided",
"one",
".",
"The",
"resulting",
"TypeEnv",
"will",
"be",
"able",
"to",
"resolve",
"types",
"of",
"refs",
"that",
"refer",
"to",
"rules",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/check.go#L86-L96 | train |
open-policy-agent/opa | internal/runtime/runtime.go | Term | func Term(params Params) (*ast.Term, error) {
obj := ast.NewObject()
if params.Config != nil {
var x interface{}
if err := util.Unmarshal(params.Config, &x); err != nil {
return nil, err
}
v, err := ast.InterfaceToValue(x)
if err != nil {
return nil, err
}
obj.Insert(ast.StringTerm("config"), ast.NewTerm(v))
}
env := ast.NewObject()
for _, s := range os.Environ() {
parts := strings.SplitN(s, "=", 2)
if len(parts) == 1 {
env.Insert(ast.StringTerm(parts[0]), ast.NullTerm())
} else if len(parts) > 1 {
env.Insert(ast.StringTerm(parts[0]), ast.StringTerm(parts[1]))
}
}
obj.Insert(ast.StringTerm("env"), ast.NewTerm(env))
return ast.NewTerm(obj), nil
} | go | func Term(params Params) (*ast.Term, error) {
obj := ast.NewObject()
if params.Config != nil {
var x interface{}
if err := util.Unmarshal(params.Config, &x); err != nil {
return nil, err
}
v, err := ast.InterfaceToValue(x)
if err != nil {
return nil, err
}
obj.Insert(ast.StringTerm("config"), ast.NewTerm(v))
}
env := ast.NewObject()
for _, s := range os.Environ() {
parts := strings.SplitN(s, "=", 2)
if len(parts) == 1 {
env.Insert(ast.StringTerm(parts[0]), ast.NullTerm())
} else if len(parts) > 1 {
env.Insert(ast.StringTerm(parts[0]), ast.StringTerm(parts[1]))
}
}
obj.Insert(ast.StringTerm("env"), ast.NewTerm(env))
return ast.NewTerm(obj), nil
} | [
"func",
"Term",
"(",
"params",
"Params",
")",
"(",
"*",
"ast",
".",
"Term",
",",
"error",
")",
"{",
"obj",
":=",
"ast",
".",
"NewObject",
"(",
")",
"\n\n",
"if",
"params",
".",
"Config",
"!=",
"nil",
"{",
"var",
"x",
"interface",
"{",
"}",
"\n",
"if",
"err",
":=",
"util",
".",
"Unmarshal",
"(",
"params",
".",
"Config",
",",
"&",
"x",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"v",
",",
"err",
":=",
"ast",
".",
"InterfaceToValue",
"(",
"x",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"obj",
".",
"Insert",
"(",
"ast",
".",
"StringTerm",
"(",
"\"",
"\"",
")",
",",
"ast",
".",
"NewTerm",
"(",
"v",
")",
")",
"\n",
"}",
"\n\n",
"env",
":=",
"ast",
".",
"NewObject",
"(",
")",
"\n\n",
"for",
"_",
",",
"s",
":=",
"range",
"os",
".",
"Environ",
"(",
")",
"{",
"parts",
":=",
"strings",
".",
"SplitN",
"(",
"s",
",",
"\"",
"\"",
",",
"2",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
"==",
"1",
"{",
"env",
".",
"Insert",
"(",
"ast",
".",
"StringTerm",
"(",
"parts",
"[",
"0",
"]",
")",
",",
"ast",
".",
"NullTerm",
"(",
")",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"parts",
")",
">",
"1",
"{",
"env",
".",
"Insert",
"(",
"ast",
".",
"StringTerm",
"(",
"parts",
"[",
"0",
"]",
")",
",",
"ast",
".",
"StringTerm",
"(",
"parts",
"[",
"1",
"]",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"obj",
".",
"Insert",
"(",
"ast",
".",
"StringTerm",
"(",
"\"",
"\"",
")",
",",
"ast",
".",
"NewTerm",
"(",
"env",
")",
")",
"\n\n",
"return",
"ast",
".",
"NewTerm",
"(",
"obj",
")",
",",
"nil",
"\n",
"}"
] | // Term returns the runtime information as an ast.Term object. | [
"Term",
"returns",
"the",
"runtime",
"information",
"as",
"an",
"ast",
".",
"Term",
"object",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/runtime/runtime.go#L22-L55 | train |
open-policy-agent/opa | util/queue.go | NewLIFO | func NewLIFO(ts ...T) *LIFO {
s := &LIFO{}
for i := range ts {
s.Push(ts[i])
}
return s
} | go | func NewLIFO(ts ...T) *LIFO {
s := &LIFO{}
for i := range ts {
s.Push(ts[i])
}
return s
} | [
"func",
"NewLIFO",
"(",
"ts",
"...",
"T",
")",
"*",
"LIFO",
"{",
"s",
":=",
"&",
"LIFO",
"{",
"}",
"\n",
"for",
"i",
":=",
"range",
"ts",
"{",
"s",
".",
"Push",
"(",
"ts",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // NewLIFO returns a new LIFO queue containing elements ts starting with the
// left-most argument at the bottom. | [
"NewLIFO",
"returns",
"a",
"new",
"LIFO",
"queue",
"containing",
"elements",
"ts",
"starting",
"with",
"the",
"left",
"-",
"most",
"argument",
"at",
"the",
"bottom",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/queue.go#L20-L26 | train |
open-policy-agent/opa | util/queue.go | NewFIFO | func NewFIFO(ts ...T) *FIFO {
s := &FIFO{}
for i := range ts {
s.Push(ts[i])
}
return s
} | go | func NewFIFO(ts ...T) *FIFO {
s := &FIFO{}
for i := range ts {
s.Push(ts[i])
}
return s
} | [
"func",
"NewFIFO",
"(",
"ts",
"...",
"T",
")",
"*",
"FIFO",
"{",
"s",
":=",
"&",
"FIFO",
"{",
"}",
"\n",
"for",
"i",
":=",
"range",
"ts",
"{",
"s",
".",
"Push",
"(",
"ts",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // NewFIFO returns a new FIFO queue containing elements ts starting with the
// left-most argument at the front. | [
"NewFIFO",
"returns",
"a",
"new",
"FIFO",
"queue",
"containing",
"elements",
"ts",
"starting",
"with",
"the",
"left",
"-",
"most",
"argument",
"at",
"the",
"front",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/queue.go#L69-L75 | train |
open-policy-agent/opa | plugins/rest/rest.go | Name | func Name(s string) func(*Client) {
return func(c *Client) {
c.config.Name = s
}
} | go | func Name(s string) func(*Client) {
return func(c *Client) {
c.config.Name = s
}
} | [
"func",
"Name",
"(",
"s",
"string",
")",
"func",
"(",
"*",
"Client",
")",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"{",
"c",
".",
"config",
".",
"Name",
"=",
"s",
"\n",
"}",
"\n",
"}"
] | // Name returns an option that overrides the service name on the client. | [
"Name",
"returns",
"an",
"option",
"that",
"overrides",
"the",
"service",
"name",
"on",
"the",
"client",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/plugins/rest/rest.go#L146-L150 | train |
open-policy-agent/opa | plugins/rest/rest.go | New | func New(config []byte, opts ...func(*Client)) (Client, error) {
var parsedConfig Config
if err := util.Unmarshal(config, &parsedConfig); err != nil {
return Client{}, err
}
tlsConfig, err := parsedConfig.validateAndInjectDefaults()
if err != nil {
return Client{}, err
}
// Ensure we use a http.Transport with proper settings: the zero values are not
// a good choice, as they cause leaking connections:
// https://github.com/golang/go/issues/19620
//
// Also, there's no simple way to copy the values from http.DefaultTransport,
// see https://github.com/golang/go/issues/26013. Hence, we copy the settings
// used in the golang sources,
// https://github.com/golang/go/blob/5fae09b7386de26db59a1184f62fc7b22ec7667b/src/net/http/transport.go#L42-L53
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
var tr http.RoundTripper = &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
TLSClientConfig: tlsConfig,
}
// copy, we don't want to alter the default client's Transport
c := *http.DefaultClient
c.Transport = tr
client := Client{
config: parsedConfig,
Client: c,
}
for _, f := range opts {
f(&client)
}
return client, nil
} | go | func New(config []byte, opts ...func(*Client)) (Client, error) {
var parsedConfig Config
if err := util.Unmarshal(config, &parsedConfig); err != nil {
return Client{}, err
}
tlsConfig, err := parsedConfig.validateAndInjectDefaults()
if err != nil {
return Client{}, err
}
// Ensure we use a http.Transport with proper settings: the zero values are not
// a good choice, as they cause leaking connections:
// https://github.com/golang/go/issues/19620
//
// Also, there's no simple way to copy the values from http.DefaultTransport,
// see https://github.com/golang/go/issues/26013. Hence, we copy the settings
// used in the golang sources,
// https://github.com/golang/go/blob/5fae09b7386de26db59a1184f62fc7b22ec7667b/src/net/http/transport.go#L42-L53
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
var tr http.RoundTripper = &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
TLSClientConfig: tlsConfig,
}
// copy, we don't want to alter the default client's Transport
c := *http.DefaultClient
c.Transport = tr
client := Client{
config: parsedConfig,
Client: c,
}
for _, f := range opts {
f(&client)
}
return client, nil
} | [
"func",
"New",
"(",
"config",
"[",
"]",
"byte",
",",
"opts",
"...",
"func",
"(",
"*",
"Client",
")",
")",
"(",
"Client",
",",
"error",
")",
"{",
"var",
"parsedConfig",
"Config",
"\n\n",
"if",
"err",
":=",
"util",
".",
"Unmarshal",
"(",
"config",
",",
"&",
"parsedConfig",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"Client",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"tlsConfig",
",",
"err",
":=",
"parsedConfig",
".",
"validateAndInjectDefaults",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Client",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"// Ensure we use a http.Transport with proper settings: the zero values are not",
"// a good choice, as they cause leaking connections:",
"// https://github.com/golang/go/issues/19620",
"//",
"// Also, there's no simple way to copy the values from http.DefaultTransport,",
"// see https://github.com/golang/go/issues/26013. Hence, we copy the settings",
"// used in the golang sources,",
"// https://github.com/golang/go/blob/5fae09b7386de26db59a1184f62fc7b22ec7667b/src/net/http/transport.go#L42-L53",
"// Copyright 2011 The Go Authors. All rights reserved.",
"// Use of this source code is governed by a BSD-style",
"// license that can be found in the LICENSE file.",
"var",
"tr",
"http",
".",
"RoundTripper",
"=",
"&",
"http",
".",
"Transport",
"{",
"Proxy",
":",
"http",
".",
"ProxyFromEnvironment",
",",
"DialContext",
":",
"(",
"&",
"net",
".",
"Dialer",
"{",
"Timeout",
":",
"30",
"*",
"time",
".",
"Second",
",",
"KeepAlive",
":",
"30",
"*",
"time",
".",
"Second",
",",
"DualStack",
":",
"true",
",",
"}",
")",
".",
"DialContext",
",",
"MaxIdleConns",
":",
"100",
",",
"IdleConnTimeout",
":",
"90",
"*",
"time",
".",
"Second",
",",
"TLSHandshakeTimeout",
":",
"10",
"*",
"time",
".",
"Second",
",",
"ExpectContinueTimeout",
":",
"1",
"*",
"time",
".",
"Second",
",",
"TLSClientConfig",
":",
"tlsConfig",
",",
"}",
"\n\n",
"// copy, we don't want to alter the default client's Transport",
"c",
":=",
"*",
"http",
".",
"DefaultClient",
"\n",
"c",
".",
"Transport",
"=",
"tr",
"\n\n",
"client",
":=",
"Client",
"{",
"config",
":",
"parsedConfig",
",",
"Client",
":",
"c",
",",
"}",
"\n\n",
"for",
"_",
",",
"f",
":=",
"range",
"opts",
"{",
"f",
"(",
"&",
"client",
")",
"\n",
"}",
"\n\n",
"return",
"client",
",",
"nil",
"\n",
"}"
] | // New returns a new Client for config. | [
"New",
"returns",
"a",
"new",
"Client",
"for",
"config",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/plugins/rest/rest.go#L153-L204 | train |
open-policy-agent/opa | plugins/rest/rest.go | WithHeader | func (c Client) WithHeader(k, v string) Client {
if v == "" {
return c
}
if c.headers == nil {
c.headers = map[string]string{}
}
c.headers[k] = v
return c
} | go | func (c Client) WithHeader(k, v string) Client {
if v == "" {
return c
}
if c.headers == nil {
c.headers = map[string]string{}
}
c.headers[k] = v
return c
} | [
"func",
"(",
"c",
"Client",
")",
"WithHeader",
"(",
"k",
",",
"v",
"string",
")",
"Client",
"{",
"if",
"v",
"==",
"\"",
"\"",
"{",
"return",
"c",
"\n",
"}",
"\n",
"if",
"c",
".",
"headers",
"==",
"nil",
"{",
"c",
".",
"headers",
"=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n",
"}",
"\n",
"c",
".",
"headers",
"[",
"k",
"]",
"=",
"v",
"\n",
"return",
"c",
"\n",
"}"
] | // WithHeader returns a shallow copy of the client with a header to include the
// requests. | [
"WithHeader",
"returns",
"a",
"shallow",
"copy",
"of",
"the",
"client",
"with",
"a",
"header",
"to",
"include",
"the",
"requests",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/plugins/rest/rest.go#L213-L222 | train |
open-policy-agent/opa | plugins/rest/rest.go | WithJSON | func (c Client) WithJSON(body interface{}) Client {
c = c.WithHeader("Content-Type", "application/json")
c.json = &body
return c
} | go | func (c Client) WithJSON(body interface{}) Client {
c = c.WithHeader("Content-Type", "application/json")
c.json = &body
return c
} | [
"func",
"(",
"c",
"Client",
")",
"WithJSON",
"(",
"body",
"interface",
"{",
"}",
")",
"Client",
"{",
"c",
"=",
"c",
".",
"WithHeader",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"c",
".",
"json",
"=",
"&",
"body",
"\n",
"return",
"c",
"\n",
"}"
] | // WithJSON returns a shallow copy of the client with the JSON value set as the
// message body to include the requests. This function sets the Content-Type
// header. | [
"WithJSON",
"returns",
"a",
"shallow",
"copy",
"of",
"the",
"client",
"with",
"the",
"JSON",
"value",
"set",
"as",
"the",
"message",
"body",
"to",
"include",
"the",
"requests",
".",
"This",
"function",
"sets",
"the",
"Content",
"-",
"Type",
"header",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/plugins/rest/rest.go#L227-L231 | train |
open-policy-agent/opa | plugins/rest/rest.go | WithBytes | func (c Client) WithBytes(body []byte) Client {
c.bytes = &body
return c
} | go | func (c Client) WithBytes(body []byte) Client {
c.bytes = &body
return c
} | [
"func",
"(",
"c",
"Client",
")",
"WithBytes",
"(",
"body",
"[",
"]",
"byte",
")",
"Client",
"{",
"c",
".",
"bytes",
"=",
"&",
"body",
"\n",
"return",
"c",
"\n",
"}"
] | // WithBytes returns a shallow copy of the client with the bytes set as the
// message body to include in the requests. | [
"WithBytes",
"returns",
"a",
"shallow",
"copy",
"of",
"the",
"client",
"with",
"the",
"bytes",
"set",
"as",
"the",
"message",
"body",
"to",
"include",
"in",
"the",
"requests",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/plugins/rest/rest.go#L235-L238 | train |
open-policy-agent/opa | plugins/rest/rest.go | Do | func (c Client) Do(ctx context.Context, method, path string) (*http.Response, error) {
path = strings.Trim(path, "/")
var body io.Reader
if c.bytes != nil {
buf := bytes.NewBuffer(*c.bytes)
body = buf
} else if c.json != nil {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(*c.json); err != nil {
return nil, err
}
body = &buf
}
url := c.config.URL + "/" + path
req, err := http.NewRequest(method, url, body)
if err != nil {
return nil, err
}
headers := map[string]string{}
// Set authorization header for credentials.
if c.config.Credentials.Bearer != nil {
req.Header.Add("Authorization", fmt.Sprintf("%v %v", c.config.Credentials.Bearer.Scheme, c.config.Credentials.Bearer.Token))
}
// Copy custom headers from config.
for key, value := range c.config.Headers {
headers[key] = value
}
// Overwrite with headers set directly on client.
for key, value := range c.headers {
headers[key] = value
}
for key, value := range headers {
req.Header.Add(key, value)
}
req = req.WithContext(ctx)
logrus.WithFields(logrus.Fields{
"method": method,
"url": url,
"headers": req.Header,
}).Debug("Sending request.")
resp, err := c.Client.Do(req)
if resp != nil {
// Only log for debug purposes. If an error occurred, the caller should handle
// that. In the non-error case, the caller may not do anything.
logrus.WithFields(logrus.Fields{
"method": method,
"url": url,
"status": resp.Status,
"headers": resp.Header,
}).Debug("Received response.")
}
return resp, err
} | go | func (c Client) Do(ctx context.Context, method, path string) (*http.Response, error) {
path = strings.Trim(path, "/")
var body io.Reader
if c.bytes != nil {
buf := bytes.NewBuffer(*c.bytes)
body = buf
} else if c.json != nil {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(*c.json); err != nil {
return nil, err
}
body = &buf
}
url := c.config.URL + "/" + path
req, err := http.NewRequest(method, url, body)
if err != nil {
return nil, err
}
headers := map[string]string{}
// Set authorization header for credentials.
if c.config.Credentials.Bearer != nil {
req.Header.Add("Authorization", fmt.Sprintf("%v %v", c.config.Credentials.Bearer.Scheme, c.config.Credentials.Bearer.Token))
}
// Copy custom headers from config.
for key, value := range c.config.Headers {
headers[key] = value
}
// Overwrite with headers set directly on client.
for key, value := range c.headers {
headers[key] = value
}
for key, value := range headers {
req.Header.Add(key, value)
}
req = req.WithContext(ctx)
logrus.WithFields(logrus.Fields{
"method": method,
"url": url,
"headers": req.Header,
}).Debug("Sending request.")
resp, err := c.Client.Do(req)
if resp != nil {
// Only log for debug purposes. If an error occurred, the caller should handle
// that. In the non-error case, the caller may not do anything.
logrus.WithFields(logrus.Fields{
"method": method,
"url": url,
"status": resp.Status,
"headers": resp.Header,
}).Debug("Received response.")
}
return resp, err
} | [
"func",
"(",
"c",
"Client",
")",
"Do",
"(",
"ctx",
"context",
".",
"Context",
",",
"method",
",",
"path",
"string",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"path",
"=",
"strings",
".",
"Trim",
"(",
"path",
",",
"\"",
"\"",
")",
"\n\n",
"var",
"body",
"io",
".",
"Reader",
"\n\n",
"if",
"c",
".",
"bytes",
"!=",
"nil",
"{",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"*",
"c",
".",
"bytes",
")",
"\n",
"body",
"=",
"buf",
"\n",
"}",
"else",
"if",
"c",
".",
"json",
"!=",
"nil",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"if",
"err",
":=",
"json",
".",
"NewEncoder",
"(",
"&",
"buf",
")",
".",
"Encode",
"(",
"*",
"c",
".",
"json",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"body",
"=",
"&",
"buf",
"\n",
"}",
"\n\n",
"url",
":=",
"c",
".",
"config",
".",
"URL",
"+",
"\"",
"\"",
"+",
"path",
"\n",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"method",
",",
"url",
",",
"body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"headers",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n\n",
"// Set authorization header for credentials.",
"if",
"c",
".",
"config",
".",
"Credentials",
".",
"Bearer",
"!=",
"nil",
"{",
"req",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"config",
".",
"Credentials",
".",
"Bearer",
".",
"Scheme",
",",
"c",
".",
"config",
".",
"Credentials",
".",
"Bearer",
".",
"Token",
")",
")",
"\n",
"}",
"\n\n",
"// Copy custom headers from config.",
"for",
"key",
",",
"value",
":=",
"range",
"c",
".",
"config",
".",
"Headers",
"{",
"headers",
"[",
"key",
"]",
"=",
"value",
"\n",
"}",
"\n\n",
"// Overwrite with headers set directly on client.",
"for",
"key",
",",
"value",
":=",
"range",
"c",
".",
"headers",
"{",
"headers",
"[",
"key",
"]",
"=",
"value",
"\n",
"}",
"\n\n",
"for",
"key",
",",
"value",
":=",
"range",
"headers",
"{",
"req",
".",
"Header",
".",
"Add",
"(",
"key",
",",
"value",
")",
"\n",
"}",
"\n\n",
"req",
"=",
"req",
".",
"WithContext",
"(",
"ctx",
")",
"\n\n",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"method",
",",
"\"",
"\"",
":",
"url",
",",
"\"",
"\"",
":",
"req",
".",
"Header",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"resp",
",",
"err",
":=",
"c",
".",
"Client",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"resp",
"!=",
"nil",
"{",
"// Only log for debug purposes. If an error occurred, the caller should handle",
"// that. In the non-error case, the caller may not do anything.",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"method",
",",
"\"",
"\"",
":",
"url",
",",
"\"",
"\"",
":",
"resp",
".",
"Status",
",",
"\"",
"\"",
":",
"resp",
".",
"Header",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"resp",
",",
"err",
"\n",
"}"
] | // Do executes a request using the client. | [
"Do",
"executes",
"a",
"request",
"using",
"the",
"client",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/plugins/rest/rest.go#L241-L306 | train |
open-policy-agent/opa | format/format.go | Bytes | func Bytes(src []byte) ([]byte, error) {
astElem, err := ast.Parse("", src, ast.CommentsOption())
if err != nil {
return nil, err
}
return Ast(astElem)
} | go | func Bytes(src []byte) ([]byte, error) {
astElem, err := ast.Parse("", src, ast.CommentsOption())
if err != nil {
return nil, err
}
return Ast(astElem)
} | [
"func",
"Bytes",
"(",
"src",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"astElem",
",",
"err",
":=",
"ast",
".",
"Parse",
"(",
"\"",
"\"",
",",
"src",
",",
"ast",
".",
"CommentsOption",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"Ast",
"(",
"astElem",
")",
"\n",
"}"
] | // Bytes formats Rego source code. The bytes provided do not have to be an entire
// source file, but they must be parse-able. If the bytes are not parse-able, Bytes
// will return an error resulting from the attempt to parse them. | [
"Bytes",
"formats",
"Rego",
"source",
"code",
".",
"The",
"bytes",
"provided",
"do",
"not",
"have",
"to",
"be",
"an",
"entire",
"source",
"file",
"but",
"they",
"must",
"be",
"parse",
"-",
"able",
".",
"If",
"the",
"bytes",
"are",
"not",
"parse",
"-",
"able",
"Bytes",
"will",
"return",
"an",
"error",
"resulting",
"from",
"the",
"attempt",
"to",
"parse",
"them",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/format/format.go#L19-L25 | train |
open-policy-agent/opa | format/format.go | Source | func Source(filename string, src []byte) ([]byte, error) {
module, err := ast.ParseModule(filename, string(src))
if err != nil {
return nil, err
}
formatted, err := Ast(module)
if err != nil {
return nil, fmt.Errorf("%s: %v", filename, err)
}
return formatted, nil
} | go | func Source(filename string, src []byte) ([]byte, error) {
module, err := ast.ParseModule(filename, string(src))
if err != nil {
return nil, err
}
formatted, err := Ast(module)
if err != nil {
return nil, fmt.Errorf("%s: %v", filename, err)
}
return formatted, nil
} | [
"func",
"Source",
"(",
"filename",
"string",
",",
"src",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"module",
",",
"err",
":=",
"ast",
".",
"ParseModule",
"(",
"filename",
",",
"string",
"(",
"src",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"formatted",
",",
"err",
":=",
"Ast",
"(",
"module",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"filename",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"formatted",
",",
"nil",
"\n",
"}"
] | // Source formats a Rego source file. The bytes provided must describe a complete
// Rego module. If they don't, Source will return an error resulting from the attempt
// to parse the bytes. | [
"Source",
"formats",
"a",
"Rego",
"source",
"file",
".",
"The",
"bytes",
"provided",
"must",
"describe",
"a",
"complete",
"Rego",
"module",
".",
"If",
"they",
"don",
"t",
"Source",
"will",
"return",
"an",
"error",
"resulting",
"from",
"the",
"attempt",
"to",
"parse",
"the",
"bytes",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/format/format.go#L30-L40 | train |
open-policy-agent/opa | format/format.go | MustAst | func MustAst(x interface{}) []byte {
bs, err := Ast(x)
if err != nil {
panic(err)
}
return bs
} | go | func MustAst(x interface{}) []byte {
bs, err := Ast(x)
if err != nil {
panic(err)
}
return bs
} | [
"func",
"MustAst",
"(",
"x",
"interface",
"{",
"}",
")",
"[",
"]",
"byte",
"{",
"bs",
",",
"err",
":=",
"Ast",
"(",
"x",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"bs",
"\n",
"}"
] | // MustAst is a helper function to format a Rego AST element. If any errors
// occurs this function will panic. This is mostly used for test | [
"MustAst",
"is",
"a",
"helper",
"function",
"to",
"format",
"a",
"Rego",
"AST",
"element",
".",
"If",
"any",
"errors",
"occurs",
"this",
"function",
"will",
"panic",
".",
"This",
"is",
"mostly",
"used",
"for",
"test"
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/format/format.go#L44-L50 | train |
open-policy-agent/opa | format/format.go | Ast | func Ast(x interface{}) (formatted []byte, err error) {
ast.WalkNodes(x, func(x ast.Node) bool {
if b, ok := x.(ast.Body); ok {
if len(b) == 0 {
return false
}
}
if x.Loc() == nil {
x.SetLoc(defaultLocation(x))
}
return false
})
w := &writer{indent: "\t"}
switch x := x.(type) {
case *ast.Module:
w.writeModule(x)
case *ast.Package:
w.writePackage(x, nil)
case *ast.Import:
w.writeImports([]*ast.Import{x}, nil)
case *ast.Rule:
w.writeRule(x, false, nil)
case *ast.Head:
w.writeHead(x, false, nil)
case ast.Body:
w.writeBody(x, nil)
case *ast.Expr:
w.writeExpr(x, nil)
case *ast.With:
w.writeWith(x, nil)
case *ast.Term:
w.writeTerm(x, nil)
case ast.Value:
w.writeTerm(&ast.Term{Value: x, Location: &ast.Location{}}, nil)
case *ast.Comment:
w.writeComments([]*ast.Comment{x})
default:
return nil, fmt.Errorf("not an ast element: %v", x)
}
return squashTrailingNewlines(w.buf.Bytes()), nil
} | go | func Ast(x interface{}) (formatted []byte, err error) {
ast.WalkNodes(x, func(x ast.Node) bool {
if b, ok := x.(ast.Body); ok {
if len(b) == 0 {
return false
}
}
if x.Loc() == nil {
x.SetLoc(defaultLocation(x))
}
return false
})
w := &writer{indent: "\t"}
switch x := x.(type) {
case *ast.Module:
w.writeModule(x)
case *ast.Package:
w.writePackage(x, nil)
case *ast.Import:
w.writeImports([]*ast.Import{x}, nil)
case *ast.Rule:
w.writeRule(x, false, nil)
case *ast.Head:
w.writeHead(x, false, nil)
case ast.Body:
w.writeBody(x, nil)
case *ast.Expr:
w.writeExpr(x, nil)
case *ast.With:
w.writeWith(x, nil)
case *ast.Term:
w.writeTerm(x, nil)
case ast.Value:
w.writeTerm(&ast.Term{Value: x, Location: &ast.Location{}}, nil)
case *ast.Comment:
w.writeComments([]*ast.Comment{x})
default:
return nil, fmt.Errorf("not an ast element: %v", x)
}
return squashTrailingNewlines(w.buf.Bytes()), nil
} | [
"func",
"Ast",
"(",
"x",
"interface",
"{",
"}",
")",
"(",
"formatted",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"ast",
".",
"WalkNodes",
"(",
"x",
",",
"func",
"(",
"x",
"ast",
".",
"Node",
")",
"bool",
"{",
"if",
"b",
",",
"ok",
":=",
"x",
".",
"(",
"ast",
".",
"Body",
")",
";",
"ok",
"{",
"if",
"len",
"(",
"b",
")",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"x",
".",
"Loc",
"(",
")",
"==",
"nil",
"{",
"x",
".",
"SetLoc",
"(",
"defaultLocation",
"(",
"x",
")",
")",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
")",
"\n\n",
"w",
":=",
"&",
"writer",
"{",
"indent",
":",
"\"",
"\\t",
"\"",
"}",
"\n",
"switch",
"x",
":=",
"x",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ast",
".",
"Module",
":",
"w",
".",
"writeModule",
"(",
"x",
")",
"\n",
"case",
"*",
"ast",
".",
"Package",
":",
"w",
".",
"writePackage",
"(",
"x",
",",
"nil",
")",
"\n",
"case",
"*",
"ast",
".",
"Import",
":",
"w",
".",
"writeImports",
"(",
"[",
"]",
"*",
"ast",
".",
"Import",
"{",
"x",
"}",
",",
"nil",
")",
"\n",
"case",
"*",
"ast",
".",
"Rule",
":",
"w",
".",
"writeRule",
"(",
"x",
",",
"false",
",",
"nil",
")",
"\n",
"case",
"*",
"ast",
".",
"Head",
":",
"w",
".",
"writeHead",
"(",
"x",
",",
"false",
",",
"nil",
")",
"\n",
"case",
"ast",
".",
"Body",
":",
"w",
".",
"writeBody",
"(",
"x",
",",
"nil",
")",
"\n",
"case",
"*",
"ast",
".",
"Expr",
":",
"w",
".",
"writeExpr",
"(",
"x",
",",
"nil",
")",
"\n",
"case",
"*",
"ast",
".",
"With",
":",
"w",
".",
"writeWith",
"(",
"x",
",",
"nil",
")",
"\n",
"case",
"*",
"ast",
".",
"Term",
":",
"w",
".",
"writeTerm",
"(",
"x",
",",
"nil",
")",
"\n",
"case",
"ast",
".",
"Value",
":",
"w",
".",
"writeTerm",
"(",
"&",
"ast",
".",
"Term",
"{",
"Value",
":",
"x",
",",
"Location",
":",
"&",
"ast",
".",
"Location",
"{",
"}",
"}",
",",
"nil",
")",
"\n",
"case",
"*",
"ast",
".",
"Comment",
":",
"w",
".",
"writeComments",
"(",
"[",
"]",
"*",
"ast",
".",
"Comment",
"{",
"x",
"}",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"x",
")",
"\n",
"}",
"\n\n",
"return",
"squashTrailingNewlines",
"(",
"w",
".",
"buf",
".",
"Bytes",
"(",
")",
")",
",",
"nil",
"\n",
"}"
] | // Ast formats a Rego AST element. If the passed value is not a valid AST
// element, Ast returns nil and an error. Ast relies on all AST elements having
// non-nil Location values. If an AST element with a nil Location value is
// encountered, a default location will be set on the AST node. | [
"Ast",
"formats",
"a",
"Rego",
"AST",
"element",
".",
"If",
"the",
"passed",
"value",
"is",
"not",
"a",
"valid",
"AST",
"element",
"Ast",
"returns",
"nil",
"and",
"an",
"error",
".",
"Ast",
"relies",
"on",
"all",
"AST",
"elements",
"having",
"non",
"-",
"nil",
"Location",
"values",
".",
"If",
"an",
"AST",
"element",
"with",
"a",
"nil",
"Location",
"value",
"is",
"encountered",
"a",
"default",
"location",
"will",
"be",
"set",
"on",
"the",
"AST",
"node",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/format/format.go#L56-L99 | train |
open-policy-agent/opa | format/format.go | startLine | func (w *writer) startLine() {
if w.inline {
panic("currently in a line")
}
w.inline = true
for i := 0; i < w.level; i++ {
w.write(w.indent)
}
} | go | func (w *writer) startLine() {
if w.inline {
panic("currently in a line")
}
w.inline = true
for i := 0; i < w.level; i++ {
w.write(w.indent)
}
} | [
"func",
"(",
"w",
"*",
"writer",
")",
"startLine",
"(",
")",
"{",
"if",
"w",
".",
"inline",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"w",
".",
"inline",
"=",
"true",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"w",
".",
"level",
";",
"i",
"++",
"{",
"w",
".",
"write",
"(",
"w",
".",
"indent",
")",
"\n",
"}",
"\n",
"}"
] | // startLine begins a line with the current indentation level. | [
"startLine",
"begins",
"a",
"line",
"with",
"the",
"current",
"indentation",
"level",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/format/format.go#L858-L866 | train |
open-policy-agent/opa | format/format.go | endLine | func (w *writer) endLine() {
if !w.inline {
panic("not in a line")
}
w.inline = false
if w.beforeEnd != nil && !w.delay {
w.write(" " + w.beforeEnd.String())
w.beforeEnd = nil
}
w.delay = false
w.write("\n")
} | go | func (w *writer) endLine() {
if !w.inline {
panic("not in a line")
}
w.inline = false
if w.beforeEnd != nil && !w.delay {
w.write(" " + w.beforeEnd.String())
w.beforeEnd = nil
}
w.delay = false
w.write("\n")
} | [
"func",
"(",
"w",
"*",
"writer",
")",
"endLine",
"(",
")",
"{",
"if",
"!",
"w",
".",
"inline",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"w",
".",
"inline",
"=",
"false",
"\n",
"if",
"w",
".",
"beforeEnd",
"!=",
"nil",
"&&",
"!",
"w",
".",
"delay",
"{",
"w",
".",
"write",
"(",
"\"",
"\"",
"+",
"w",
".",
"beforeEnd",
".",
"String",
"(",
")",
")",
"\n",
"w",
".",
"beforeEnd",
"=",
"nil",
"\n",
"}",
"\n",
"w",
".",
"delay",
"=",
"false",
"\n",
"w",
".",
"write",
"(",
"\"",
"\\n",
"\"",
")",
"\n",
"}"
] | // endLine ends a line with a newline. | [
"endLine",
"ends",
"a",
"line",
"with",
"a",
"newline",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/format/format.go#L869-L880 | train |
open-policy-agent/opa | format/format.go | beforeLineEnd | func (w *writer) beforeLineEnd(c *ast.Comment) {
if w.beforeEnd != nil {
if c == nil {
return
}
panic("overwriting non-nil beforeEnd")
}
w.beforeEnd = c
} | go | func (w *writer) beforeLineEnd(c *ast.Comment) {
if w.beforeEnd != nil {
if c == nil {
return
}
panic("overwriting non-nil beforeEnd")
}
w.beforeEnd = c
} | [
"func",
"(",
"w",
"*",
"writer",
")",
"beforeLineEnd",
"(",
"c",
"*",
"ast",
".",
"Comment",
")",
"{",
"if",
"w",
".",
"beforeEnd",
"!=",
"nil",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"w",
".",
"beforeEnd",
"=",
"c",
"\n",
"}"
] | // beforeLineEnd registers a comment to be printed at the end of the current line. | [
"beforeLineEnd",
"registers",
"a",
"comment",
"to",
"be",
"printed",
"at",
"the",
"end",
"of",
"the",
"current",
"line",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/format/format.go#L883-L891 | train |
open-policy-agent/opa | format/format.go | writeLine | func (w *writer) writeLine(s string) {
if !w.inline {
w.startLine()
}
w.write(s)
w.endLine()
} | go | func (w *writer) writeLine(s string) {
if !w.inline {
w.startLine()
}
w.write(s)
w.endLine()
} | [
"func",
"(",
"w",
"*",
"writer",
")",
"writeLine",
"(",
"s",
"string",
")",
"{",
"if",
"!",
"w",
".",
"inline",
"{",
"w",
".",
"startLine",
"(",
")",
"\n",
"}",
"\n",
"w",
".",
"write",
"(",
"s",
")",
"\n",
"w",
".",
"endLine",
"(",
")",
"\n",
"}"
] | // writeLine writes the string on a newly started line, then terminate the line. | [
"writeLine",
"writes",
"the",
"string",
"on",
"a",
"newly",
"started",
"line",
"then",
"terminate",
"the",
"line",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/format/format.go#L912-L918 | train |
open-policy-agent/opa | util/json.go | UnmarshalJSON | func UnmarshalJSON(bs []byte, x interface{}) (err error) {
buf := bytes.NewBuffer(bs)
decoder := NewJSONDecoder(buf)
return decoder.Decode(x)
} | go | func UnmarshalJSON(bs []byte, x interface{}) (err error) {
buf := bytes.NewBuffer(bs)
decoder := NewJSONDecoder(buf)
return decoder.Decode(x)
} | [
"func",
"UnmarshalJSON",
"(",
"bs",
"[",
"]",
"byte",
",",
"x",
"interface",
"{",
"}",
")",
"(",
"err",
"error",
")",
"{",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"bs",
")",
"\n",
"decoder",
":=",
"NewJSONDecoder",
"(",
"buf",
")",
"\n",
"return",
"decoder",
".",
"Decode",
"(",
"x",
")",
"\n",
"}"
] | // UnmarshalJSON parses the JSON encoded data and stores the result in the value
// pointed to by x.
//
// This function is intended to be used in place of the standard json.Marshal
// function when json.Number is required. | [
"UnmarshalJSON",
"parses",
"the",
"JSON",
"encoded",
"data",
"and",
"stores",
"the",
"result",
"in",
"the",
"value",
"pointed",
"to",
"by",
"x",
".",
"This",
"function",
"is",
"intended",
"to",
"be",
"used",
"in",
"place",
"of",
"the",
"standard",
"json",
".",
"Marshal",
"function",
"when",
"json",
".",
"Number",
"is",
"required",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/json.go#L21-L25 | train |
open-policy-agent/opa | util/json.go | NewJSONDecoder | func NewJSONDecoder(r io.Reader) *json.Decoder {
decoder := json.NewDecoder(r)
decoder.UseNumber()
return decoder
} | go | func NewJSONDecoder(r io.Reader) *json.Decoder {
decoder := json.NewDecoder(r)
decoder.UseNumber()
return decoder
} | [
"func",
"NewJSONDecoder",
"(",
"r",
"io",
".",
"Reader",
")",
"*",
"json",
".",
"Decoder",
"{",
"decoder",
":=",
"json",
".",
"NewDecoder",
"(",
"r",
")",
"\n",
"decoder",
".",
"UseNumber",
"(",
")",
"\n",
"return",
"decoder",
"\n",
"}"
] | // NewJSONDecoder returns a new decoder that reads from r.
//
// This function is intended to be used in place of the standard json.NewDecoder
// when json.Number is required. | [
"NewJSONDecoder",
"returns",
"a",
"new",
"decoder",
"that",
"reads",
"from",
"r",
".",
"This",
"function",
"is",
"intended",
"to",
"be",
"used",
"in",
"place",
"of",
"the",
"standard",
"json",
".",
"NewDecoder",
"when",
"json",
".",
"Number",
"is",
"required",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/json.go#L31-L35 | train |
open-policy-agent/opa | util/json.go | MustUnmarshalJSON | func MustUnmarshalJSON(bs []byte) interface{} {
var x interface{}
if err := UnmarshalJSON(bs, &x); err != nil {
panic(err)
}
return x
} | go | func MustUnmarshalJSON(bs []byte) interface{} {
var x interface{}
if err := UnmarshalJSON(bs, &x); err != nil {
panic(err)
}
return x
} | [
"func",
"MustUnmarshalJSON",
"(",
"bs",
"[",
"]",
"byte",
")",
"interface",
"{",
"}",
"{",
"var",
"x",
"interface",
"{",
"}",
"\n",
"if",
"err",
":=",
"UnmarshalJSON",
"(",
"bs",
",",
"&",
"x",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"x",
"\n",
"}"
] | // MustUnmarshalJSON parse the JSON encoded data and returns the result.
//
// If the data cannot be decoded, this function will panic. This function is for
// test purposes. | [
"MustUnmarshalJSON",
"parse",
"the",
"JSON",
"encoded",
"data",
"and",
"returns",
"the",
"result",
".",
"If",
"the",
"data",
"cannot",
"be",
"decoded",
"this",
"function",
"will",
"panic",
".",
"This",
"function",
"is",
"for",
"test",
"purposes",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/json.go#L41-L47 | train |
open-policy-agent/opa | util/json.go | MustMarshalJSON | func MustMarshalJSON(x interface{}) []byte {
bs, err := json.Marshal(x)
if err != nil {
panic(err)
}
return bs
} | go | func MustMarshalJSON(x interface{}) []byte {
bs, err := json.Marshal(x)
if err != nil {
panic(err)
}
return bs
} | [
"func",
"MustMarshalJSON",
"(",
"x",
"interface",
"{",
"}",
")",
"[",
"]",
"byte",
"{",
"bs",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"x",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"bs",
"\n",
"}"
] | // MustMarshalJSON returns the JSON encoding of x
//
// If the data cannot be encoded, this function will panic. This function is for
// test purposes. | [
"MustMarshalJSON",
"returns",
"the",
"JSON",
"encoding",
"of",
"x",
"If",
"the",
"data",
"cannot",
"be",
"encoded",
"this",
"function",
"will",
"panic",
".",
"This",
"function",
"is",
"for",
"test",
"purposes",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/json.go#L53-L59 | train |
open-policy-agent/opa | util/json.go | RoundTrip | func RoundTrip(x *interface{}) error {
bs, err := json.Marshal(x)
if err != nil {
return err
}
return UnmarshalJSON(bs, x)
} | go | func RoundTrip(x *interface{}) error {
bs, err := json.Marshal(x)
if err != nil {
return err
}
return UnmarshalJSON(bs, x)
} | [
"func",
"RoundTrip",
"(",
"x",
"*",
"interface",
"{",
"}",
")",
"error",
"{",
"bs",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"x",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"UnmarshalJSON",
"(",
"bs",
",",
"x",
")",
"\n",
"}"
] | // RoundTrip encodes to JSON, and decodes the result again.
//
// Thereby, it is converting its argument to the representation expected by
// rego.Input and inmem's Write operations. Works with both references and
// values. | [
"RoundTrip",
"encodes",
"to",
"JSON",
"and",
"decodes",
"the",
"result",
"again",
".",
"Thereby",
"it",
"is",
"converting",
"its",
"argument",
"to",
"the",
"representation",
"expected",
"by",
"rego",
".",
"Input",
"and",
"inmem",
"s",
"Write",
"operations",
".",
"Works",
"with",
"both",
"references",
"and",
"values",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/json.go#L66-L72 | train |
open-policy-agent/opa | util/json.go | Unmarshal | func Unmarshal(bs []byte, v interface{}) error {
bs, err := yaml.YAMLToJSON(bs)
if err != nil {
return err
}
return UnmarshalJSON(bs, v)
} | go | func Unmarshal(bs []byte, v interface{}) error {
bs, err := yaml.YAMLToJSON(bs)
if err != nil {
return err
}
return UnmarshalJSON(bs, v)
} | [
"func",
"Unmarshal",
"(",
"bs",
"[",
"]",
"byte",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"bs",
",",
"err",
":=",
"yaml",
".",
"YAMLToJSON",
"(",
"bs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"UnmarshalJSON",
"(",
"bs",
",",
"v",
")",
"\n",
"}"
] | // Unmarshal decodes a YAML or JSON value into the specified type. | [
"Unmarshal",
"decodes",
"a",
"YAML",
"or",
"JSON",
"value",
"into",
"the",
"specified",
"type",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/json.go#L93-L99 | train |
open-policy-agent/opa | storage/errors.go | IsNotFound | func IsNotFound(err error) bool {
switch err := err.(type) {
case *Error:
return err.Code == NotFoundErr
}
return false
} | go | func IsNotFound(err error) bool {
switch err := err.(type) {
case *Error:
return err.Code == NotFoundErr
}
return false
} | [
"func",
"IsNotFound",
"(",
"err",
"error",
")",
"bool",
"{",
"switch",
"err",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"*",
"Error",
":",
"return",
"err",
".",
"Code",
"==",
"NotFoundErr",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsNotFound returns true if this error is a NotFoundErr. | [
"IsNotFound",
"returns",
"true",
"if",
"this",
"error",
"is",
"a",
"NotFoundErr",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/errors.go#L62-L68 | train |
open-policy-agent/opa | storage/errors.go | IsWriteConflictError | func IsWriteConflictError(err error) bool {
switch err := err.(type) {
case *Error:
return err.Code == WriteConflictErr
}
return false
} | go | func IsWriteConflictError(err error) bool {
switch err := err.(type) {
case *Error:
return err.Code == WriteConflictErr
}
return false
} | [
"func",
"IsWriteConflictError",
"(",
"err",
"error",
")",
"bool",
"{",
"switch",
"err",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"*",
"Error",
":",
"return",
"err",
".",
"Code",
"==",
"WriteConflictErr",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsWriteConflictError returns true if this error a WriteConflictErr. | [
"IsWriteConflictError",
"returns",
"true",
"if",
"this",
"error",
"a",
"WriteConflictErr",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/errors.go#L71-L77 | train |
open-policy-agent/opa | storage/errors.go | IsInvalidPatch | func IsInvalidPatch(err error) bool {
switch err := err.(type) {
case *Error:
return err.Code == InvalidPatchErr
}
return false
} | go | func IsInvalidPatch(err error) bool {
switch err := err.(type) {
case *Error:
return err.Code == InvalidPatchErr
}
return false
} | [
"func",
"IsInvalidPatch",
"(",
"err",
"error",
")",
"bool",
"{",
"switch",
"err",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"*",
"Error",
":",
"return",
"err",
".",
"Code",
"==",
"InvalidPatchErr",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsInvalidPatch returns true if this error is a InvalidPatchErr. | [
"IsInvalidPatch",
"returns",
"true",
"if",
"this",
"error",
"is",
"a",
"InvalidPatchErr",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/errors.go#L80-L86 | train |
open-policy-agent/opa | storage/errors.go | IsInvalidTransaction | func IsInvalidTransaction(err error) bool {
switch err := err.(type) {
case *Error:
return err.Code == InvalidTransactionErr
}
return false
} | go | func IsInvalidTransaction(err error) bool {
switch err := err.(type) {
case *Error:
return err.Code == InvalidTransactionErr
}
return false
} | [
"func",
"IsInvalidTransaction",
"(",
"err",
"error",
")",
"bool",
"{",
"switch",
"err",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"*",
"Error",
":",
"return",
"err",
".",
"Code",
"==",
"InvalidTransactionErr",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsInvalidTransaction returns true if this error is a InvalidTransactionErr. | [
"IsInvalidTransaction",
"returns",
"true",
"if",
"this",
"error",
"is",
"a",
"InvalidTransactionErr",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/errors.go#L89-L95 | train |
open-policy-agent/opa | storage/errors.go | IsIndexingNotSupported | func IsIndexingNotSupported(err error) bool {
switch err := err.(type) {
case *Error:
return err.Code == IndexingNotSupportedErr
}
return false
} | go | func IsIndexingNotSupported(err error) bool {
switch err := err.(type) {
case *Error:
return err.Code == IndexingNotSupportedErr
}
return false
} | [
"func",
"IsIndexingNotSupported",
"(",
"err",
"error",
")",
"bool",
"{",
"switch",
"err",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"*",
"Error",
":",
"return",
"err",
".",
"Code",
"==",
"IndexingNotSupportedErr",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsIndexingNotSupported returns true if this error is a IndexingNotSupportedErr. | [
"IsIndexingNotSupported",
"returns",
"true",
"if",
"this",
"error",
"is",
"a",
"IndexingNotSupportedErr",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/errors.go#L98-L104 | train |
open-policy-agent/opa | ast/map.go | NewValueMap | func NewValueMap() *ValueMap {
vs := &ValueMap{
hashMap: util.NewHashMap(valueEq, valueHash),
}
return vs
} | go | func NewValueMap() *ValueMap {
vs := &ValueMap{
hashMap: util.NewHashMap(valueEq, valueHash),
}
return vs
} | [
"func",
"NewValueMap",
"(",
")",
"*",
"ValueMap",
"{",
"vs",
":=",
"&",
"ValueMap",
"{",
"hashMap",
":",
"util",
".",
"NewHashMap",
"(",
"valueEq",
",",
"valueHash",
")",
",",
"}",
"\n",
"return",
"vs",
"\n",
"}"
] | // NewValueMap returns a new ValueMap. | [
"NewValueMap",
"returns",
"a",
"new",
"ValueMap",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/map.go#L16-L21 | train |
open-policy-agent/opa | ast/map.go | Copy | func (vs *ValueMap) Copy() *ValueMap {
if vs == nil {
return nil
}
cpy := NewValueMap()
cpy.hashMap = vs.hashMap.Copy()
return cpy
} | go | func (vs *ValueMap) Copy() *ValueMap {
if vs == nil {
return nil
}
cpy := NewValueMap()
cpy.hashMap = vs.hashMap.Copy()
return cpy
} | [
"func",
"(",
"vs",
"*",
"ValueMap",
")",
"Copy",
"(",
")",
"*",
"ValueMap",
"{",
"if",
"vs",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"cpy",
":=",
"NewValueMap",
"(",
")",
"\n",
"cpy",
".",
"hashMap",
"=",
"vs",
".",
"hashMap",
".",
"Copy",
"(",
")",
"\n",
"return",
"cpy",
"\n",
"}"
] | // Copy returns a shallow copy of the ValueMap. | [
"Copy",
"returns",
"a",
"shallow",
"copy",
"of",
"the",
"ValueMap",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/map.go#L24-L31 | train |
open-policy-agent/opa | ast/map.go | Equal | func (vs *ValueMap) Equal(other *ValueMap) bool {
if vs == nil {
return other == nil || other.Len() == 0
}
if other == nil {
return vs == nil || vs.Len() == 0
}
return vs.hashMap.Equal(other.hashMap)
} | go | func (vs *ValueMap) Equal(other *ValueMap) bool {
if vs == nil {
return other == nil || other.Len() == 0
}
if other == nil {
return vs == nil || vs.Len() == 0
}
return vs.hashMap.Equal(other.hashMap)
} | [
"func",
"(",
"vs",
"*",
"ValueMap",
")",
"Equal",
"(",
"other",
"*",
"ValueMap",
")",
"bool",
"{",
"if",
"vs",
"==",
"nil",
"{",
"return",
"other",
"==",
"nil",
"||",
"other",
".",
"Len",
"(",
")",
"==",
"0",
"\n",
"}",
"\n",
"if",
"other",
"==",
"nil",
"{",
"return",
"vs",
"==",
"nil",
"||",
"vs",
".",
"Len",
"(",
")",
"==",
"0",
"\n",
"}",
"\n",
"return",
"vs",
".",
"hashMap",
".",
"Equal",
"(",
"other",
".",
"hashMap",
")",
"\n",
"}"
] | // Equal returns true if this ValueMap equals the other. | [
"Equal",
"returns",
"true",
"if",
"this",
"ValueMap",
"equals",
"the",
"other",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/map.go#L34-L42 | train |
open-policy-agent/opa | ast/map.go | Get | func (vs *ValueMap) Get(k Value) Value {
if vs != nil {
if v, ok := vs.hashMap.Get(k); ok {
return v.(Value)
}
}
return nil
} | go | func (vs *ValueMap) Get(k Value) Value {
if vs != nil {
if v, ok := vs.hashMap.Get(k); ok {
return v.(Value)
}
}
return nil
} | [
"func",
"(",
"vs",
"*",
"ValueMap",
")",
"Get",
"(",
"k",
"Value",
")",
"Value",
"{",
"if",
"vs",
"!=",
"nil",
"{",
"if",
"v",
",",
"ok",
":=",
"vs",
".",
"hashMap",
".",
"Get",
"(",
"k",
")",
";",
"ok",
"{",
"return",
"v",
".",
"(",
"Value",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Get returns the value in the map for k. | [
"Get",
"returns",
"the",
"value",
"in",
"the",
"map",
"for",
"k",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/map.go#L53-L60 | train |
open-policy-agent/opa | ast/map.go | Put | func (vs *ValueMap) Put(k, v Value) {
if vs == nil {
panic("put on nil value map")
}
vs.hashMap.Put(k, v)
} | go | func (vs *ValueMap) Put(k, v Value) {
if vs == nil {
panic("put on nil value map")
}
vs.hashMap.Put(k, v)
} | [
"func",
"(",
"vs",
"*",
"ValueMap",
")",
"Put",
"(",
"k",
",",
"v",
"Value",
")",
"{",
"if",
"vs",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"vs",
".",
"hashMap",
".",
"Put",
"(",
"k",
",",
"v",
")",
"\n",
"}"
] | // Put inserts a key k into the map with value v. | [
"Put",
"inserts",
"a",
"key",
"k",
"into",
"the",
"map",
"with",
"value",
"v",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/map.go#L84-L89 | train |
open-policy-agent/opa | ast/map.go | Delete | func (vs *ValueMap) Delete(k Value) {
if vs == nil {
return
}
vs.hashMap.Delete(k)
} | go | func (vs *ValueMap) Delete(k Value) {
if vs == nil {
return
}
vs.hashMap.Delete(k)
} | [
"func",
"(",
"vs",
"*",
"ValueMap",
")",
"Delete",
"(",
"k",
"Value",
")",
"{",
"if",
"vs",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"vs",
".",
"hashMap",
".",
"Delete",
"(",
"k",
")",
"\n",
"}"
] | // Delete removes a key k from the map. | [
"Delete",
"removes",
"a",
"key",
"k",
"from",
"the",
"map",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/map.go#L92-L97 | train |
open-policy-agent/opa | topdown/eval.go | mergeObjects | func mergeObjects(objA, objB ast.Object) (result ast.Object, ok bool) {
result = ast.NewObject()
stop := objA.Until(func(k, v *ast.Term) bool {
if v2 := objB.Get(k); v2 == nil {
result.Insert(k, v)
} else {
obj1, ok1 := v.Value.(ast.Object)
obj2, ok2 := v2.Value.(ast.Object)
if !ok1 || !ok2 {
result.Insert(k, v)
return false
}
obj3, ok := mergeObjects(obj1, obj2)
if !ok {
return true
}
result.Insert(k, ast.NewTerm(obj3))
}
return false
})
if stop {
return nil, false
}
objB.Foreach(func(k, v *ast.Term) {
if v2 := objA.Get(k); v2 == nil {
result.Insert(k, v)
}
})
return result, true
} | go | func mergeObjects(objA, objB ast.Object) (result ast.Object, ok bool) {
result = ast.NewObject()
stop := objA.Until(func(k, v *ast.Term) bool {
if v2 := objB.Get(k); v2 == nil {
result.Insert(k, v)
} else {
obj1, ok1 := v.Value.(ast.Object)
obj2, ok2 := v2.Value.(ast.Object)
if !ok1 || !ok2 {
result.Insert(k, v)
return false
}
obj3, ok := mergeObjects(obj1, obj2)
if !ok {
return true
}
result.Insert(k, ast.NewTerm(obj3))
}
return false
})
if stop {
return nil, false
}
objB.Foreach(func(k, v *ast.Term) {
if v2 := objA.Get(k); v2 == nil {
result.Insert(k, v)
}
})
return result, true
} | [
"func",
"mergeObjects",
"(",
"objA",
",",
"objB",
"ast",
".",
"Object",
")",
"(",
"result",
"ast",
".",
"Object",
",",
"ok",
"bool",
")",
"{",
"result",
"=",
"ast",
".",
"NewObject",
"(",
")",
"\n",
"stop",
":=",
"objA",
".",
"Until",
"(",
"func",
"(",
"k",
",",
"v",
"*",
"ast",
".",
"Term",
")",
"bool",
"{",
"if",
"v2",
":=",
"objB",
".",
"Get",
"(",
"k",
")",
";",
"v2",
"==",
"nil",
"{",
"result",
".",
"Insert",
"(",
"k",
",",
"v",
")",
"\n",
"}",
"else",
"{",
"obj1",
",",
"ok1",
":=",
"v",
".",
"Value",
".",
"(",
"ast",
".",
"Object",
")",
"\n",
"obj2",
",",
"ok2",
":=",
"v2",
".",
"Value",
".",
"(",
"ast",
".",
"Object",
")",
"\n\n",
"if",
"!",
"ok1",
"||",
"!",
"ok2",
"{",
"result",
".",
"Insert",
"(",
"k",
",",
"v",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"obj3",
",",
"ok",
":=",
"mergeObjects",
"(",
"obj1",
",",
"obj2",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"true",
"\n",
"}",
"\n",
"result",
".",
"Insert",
"(",
"k",
",",
"ast",
".",
"NewTerm",
"(",
"obj3",
")",
")",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
")",
"\n",
"if",
"stop",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"objB",
".",
"Foreach",
"(",
"func",
"(",
"k",
",",
"v",
"*",
"ast",
".",
"Term",
")",
"{",
"if",
"v2",
":=",
"objA",
".",
"Get",
"(",
"k",
")",
";",
"v2",
"==",
"nil",
"{",
"result",
".",
"Insert",
"(",
"k",
",",
"v",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"return",
"result",
",",
"true",
"\n",
"}"
] | // mergeObjects returns a new Object containing the non-overlapping keys of
// the objA and objB. If there are overlapping keys between objA and objB,
// the values of associated with the keys are merged. Only
// objects can be merged with other objects. If the values cannot be merged,
// objB value will be overwritten by objA value. | [
"mergeObjects",
"returns",
"a",
"new",
"Object",
"containing",
"the",
"non",
"-",
"overlapping",
"keys",
"of",
"the",
"objA",
"and",
"objB",
".",
"If",
"there",
"are",
"overlapping",
"keys",
"between",
"objA",
"and",
"objB",
"the",
"values",
"of",
"associated",
"with",
"the",
"keys",
"are",
"merged",
".",
"Only",
"objects",
"can",
"be",
"merged",
"with",
"other",
"objects",
".",
"If",
"the",
"values",
"cannot",
"be",
"merged",
"objB",
"value",
"will",
"be",
"overwritten",
"by",
"objA",
"value",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/eval.go#L2127-L2157 | train |
open-policy-agent/opa | topdown/query.go | NewQuery | func NewQuery(query ast.Body) *Query {
return &Query{
query: query,
genvarprefix: ast.WildcardPrefix,
}
} | go | func NewQuery(query ast.Body) *Query {
return &Query{
query: query,
genvarprefix: ast.WildcardPrefix,
}
} | [
"func",
"NewQuery",
"(",
"query",
"ast",
".",
"Body",
")",
"*",
"Query",
"{",
"return",
"&",
"Query",
"{",
"query",
":",
"query",
",",
"genvarprefix",
":",
"ast",
".",
"WildcardPrefix",
",",
"}",
"\n",
"}"
] | // NewQuery returns a new Query object that can be run. | [
"NewQuery",
"returns",
"a",
"new",
"Query",
"object",
"that",
"can",
"be",
"run",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/query.go#L39-L44 | train |
open-policy-agent/opa | topdown/query.go | WithCompiler | func (q *Query) WithCompiler(compiler *ast.Compiler) *Query {
q.compiler = compiler
return q
} | go | func (q *Query) WithCompiler(compiler *ast.Compiler) *Query {
q.compiler = compiler
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"WithCompiler",
"(",
"compiler",
"*",
"ast",
".",
"Compiler",
")",
"*",
"Query",
"{",
"q",
".",
"compiler",
"=",
"compiler",
"\n",
"return",
"q",
"\n",
"}"
] | // WithCompiler sets the compiler to use for the query. | [
"WithCompiler",
"sets",
"the",
"compiler",
"to",
"use",
"for",
"the",
"query",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/query.go#L47-L50 | train |
open-policy-agent/opa | topdown/query.go | WithStore | func (q *Query) WithStore(store storage.Store) *Query {
q.store = store
return q
} | go | func (q *Query) WithStore(store storage.Store) *Query {
q.store = store
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"WithStore",
"(",
"store",
"storage",
".",
"Store",
")",
"*",
"Query",
"{",
"q",
".",
"store",
"=",
"store",
"\n",
"return",
"q",
"\n",
"}"
] | // WithStore sets the store to use for the query. | [
"WithStore",
"sets",
"the",
"store",
"to",
"use",
"for",
"the",
"query",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/query.go#L53-L56 | train |
open-policy-agent/opa | topdown/query.go | WithTransaction | func (q *Query) WithTransaction(txn storage.Transaction) *Query {
q.txn = txn
return q
} | go | func (q *Query) WithTransaction(txn storage.Transaction) *Query {
q.txn = txn
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"WithTransaction",
"(",
"txn",
"storage",
".",
"Transaction",
")",
"*",
"Query",
"{",
"q",
".",
"txn",
"=",
"txn",
"\n",
"return",
"q",
"\n",
"}"
] | // WithTransaction sets the transaction to use for the query. All queries
// should be performed over a consistent snapshot of the storage layer. | [
"WithTransaction",
"sets",
"the",
"transaction",
"to",
"use",
"for",
"the",
"query",
".",
"All",
"queries",
"should",
"be",
"performed",
"over",
"a",
"consistent",
"snapshot",
"of",
"the",
"storage",
"layer",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/query.go#L60-L63 | train |
open-policy-agent/opa | topdown/query.go | WithCancel | func (q *Query) WithCancel(cancel Cancel) *Query {
q.cancel = cancel
return q
} | go | func (q *Query) WithCancel(cancel Cancel) *Query {
q.cancel = cancel
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"WithCancel",
"(",
"cancel",
"Cancel",
")",
"*",
"Query",
"{",
"q",
".",
"cancel",
"=",
"cancel",
"\n",
"return",
"q",
"\n",
"}"
] | // WithCancel sets the cancellation object to use for the query. Set this if
// you need to abort queries based on a deadline. This is optional. | [
"WithCancel",
"sets",
"the",
"cancellation",
"object",
"to",
"use",
"for",
"the",
"query",
".",
"Set",
"this",
"if",
"you",
"need",
"to",
"abort",
"queries",
"based",
"on",
"a",
"deadline",
".",
"This",
"is",
"optional",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/query.go#L67-L70 | train |
open-policy-agent/opa | topdown/query.go | WithInput | func (q *Query) WithInput(input *ast.Term) *Query {
q.input = input
return q
} | go | func (q *Query) WithInput(input *ast.Term) *Query {
q.input = input
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"WithInput",
"(",
"input",
"*",
"ast",
".",
"Term",
")",
"*",
"Query",
"{",
"q",
".",
"input",
"=",
"input",
"\n",
"return",
"q",
"\n",
"}"
] | // WithInput sets the input object to use for the query. References rooted at
// input will be evaluated against this value. This is optional. | [
"WithInput",
"sets",
"the",
"input",
"object",
"to",
"use",
"for",
"the",
"query",
".",
"References",
"rooted",
"at",
"input",
"will",
"be",
"evaluated",
"against",
"this",
"value",
".",
"This",
"is",
"optional",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/query.go#L74-L77 | train |
open-policy-agent/opa | topdown/query.go | WithTracer | func (q *Query) WithTracer(tracer Tracer) *Query {
q.tracers = append(q.tracers, tracer)
return q
} | go | func (q *Query) WithTracer(tracer Tracer) *Query {
q.tracers = append(q.tracers, tracer)
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"WithTracer",
"(",
"tracer",
"Tracer",
")",
"*",
"Query",
"{",
"q",
".",
"tracers",
"=",
"append",
"(",
"q",
".",
"tracers",
",",
"tracer",
")",
"\n",
"return",
"q",
"\n",
"}"
] | // WithTracer adds a query tracer to use during evaluation. This is optional. | [
"WithTracer",
"adds",
"a",
"query",
"tracer",
"to",
"use",
"during",
"evaluation",
".",
"This",
"is",
"optional",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/query.go#L80-L83 | train |
open-policy-agent/opa | topdown/query.go | WithMetrics | func (q *Query) WithMetrics(m metrics.Metrics) *Query {
q.metrics = m
return q
} | go | func (q *Query) WithMetrics(m metrics.Metrics) *Query {
q.metrics = m
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"WithMetrics",
"(",
"m",
"metrics",
".",
"Metrics",
")",
"*",
"Query",
"{",
"q",
".",
"metrics",
"=",
"m",
"\n",
"return",
"q",
"\n",
"}"
] | // WithMetrics sets the metrics collection to add evaluation metrics to. This
// is optional. | [
"WithMetrics",
"sets",
"the",
"metrics",
"collection",
"to",
"add",
"evaluation",
"metrics",
"to",
".",
"This",
"is",
"optional",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/query.go#L87-L90 | train |
open-policy-agent/opa | topdown/query.go | WithInstrumentation | func (q *Query) WithInstrumentation(instr *Instrumentation) *Query {
q.instr = instr
return q
} | go | func (q *Query) WithInstrumentation(instr *Instrumentation) *Query {
q.instr = instr
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"WithInstrumentation",
"(",
"instr",
"*",
"Instrumentation",
")",
"*",
"Query",
"{",
"q",
".",
"instr",
"=",
"instr",
"\n",
"return",
"q",
"\n",
"}"
] | // WithInstrumentation sets the instrumentation configuration to enable on the
// evaluation process. By default, instrumentation is turned off. | [
"WithInstrumentation",
"sets",
"the",
"instrumentation",
"configuration",
"to",
"enable",
"on",
"the",
"evaluation",
"process",
".",
"By",
"default",
"instrumentation",
"is",
"turned",
"off",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/query.go#L94-L97 | train |
open-policy-agent/opa | topdown/query.go | WithUnknowns | func (q *Query) WithUnknowns(terms []*ast.Term) *Query {
q.unknowns = terms
return q
} | go | func (q *Query) WithUnknowns(terms []*ast.Term) *Query {
q.unknowns = terms
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"WithUnknowns",
"(",
"terms",
"[",
"]",
"*",
"ast",
".",
"Term",
")",
"*",
"Query",
"{",
"q",
".",
"unknowns",
"=",
"terms",
"\n",
"return",
"q",
"\n",
"}"
] | // WithUnknowns sets the initial set of variables or references to treat as
// unknown during query evaluation. This is required for partial evaluation. | [
"WithUnknowns",
"sets",
"the",
"initial",
"set",
"of",
"variables",
"or",
"references",
"to",
"treat",
"as",
"unknown",
"during",
"query",
"evaluation",
".",
"This",
"is",
"required",
"for",
"partial",
"evaluation",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/query.go#L101-L104 | train |
open-policy-agent/opa | topdown/query.go | WithPartialNamespace | func (q *Query) WithPartialNamespace(ns string) *Query {
q.partialNamespace = ns
return q
} | go | func (q *Query) WithPartialNamespace(ns string) *Query {
q.partialNamespace = ns
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"WithPartialNamespace",
"(",
"ns",
"string",
")",
"*",
"Query",
"{",
"q",
".",
"partialNamespace",
"=",
"ns",
"\n",
"return",
"q",
"\n",
"}"
] | // WithPartialNamespace sets the namespace to use for supporting rules
// generated as part of the partial evaluation process. The ns value must be a
// valid package path component. | [
"WithPartialNamespace",
"sets",
"the",
"namespace",
"to",
"use",
"for",
"supporting",
"rules",
"generated",
"as",
"part",
"of",
"the",
"partial",
"evaluation",
"process",
".",
"The",
"ns",
"value",
"must",
"be",
"a",
"valid",
"package",
"path",
"component",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/query.go#L109-L112 | train |
open-policy-agent/opa | topdown/query.go | WithRuntime | func (q *Query) WithRuntime(runtime *ast.Term) *Query {
q.runtime = runtime
return q
} | go | func (q *Query) WithRuntime(runtime *ast.Term) *Query {
q.runtime = runtime
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"WithRuntime",
"(",
"runtime",
"*",
"ast",
".",
"Term",
")",
"*",
"Query",
"{",
"q",
".",
"runtime",
"=",
"runtime",
"\n",
"return",
"q",
"\n",
"}"
] | // WithRuntime sets the runtime data to execute the query with. The runtime data
// can be returned by the `opa.runtime` built-in function. | [
"WithRuntime",
"sets",
"the",
"runtime",
"data",
"to",
"execute",
"the",
"query",
"with",
".",
"The",
"runtime",
"data",
"can",
"be",
"returned",
"by",
"the",
"opa",
".",
"runtime",
"built",
"-",
"in",
"function",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/query.go#L116-L119 | train |
open-policy-agent/opa | topdown/query.go | PartialRun | func (q *Query) PartialRun(ctx context.Context) (partials []ast.Body, support []*ast.Module, err error) {
if q.partialNamespace == "" {
q.partialNamespace = "partial" // lazily initialize partial namespace
}
f := &queryIDFactory{}
b := newBindings(0, q.instr)
e := &eval{
ctx: ctx,
cancel: q.cancel,
query: q.query,
queryIDFact: f,
queryID: f.Next(),
bindings: b,
compiler: q.compiler,
store: q.store,
baseCache: newBaseCache(),
targetStack: newRefStack(),
txn: q.txn,
input: q.input,
tracers: q.tracers,
instr: q.instr,
builtinCache: builtins.Cache{},
virtualCache: newVirtualCache(),
saveSet: newSaveSet(q.unknowns, b),
saveStack: newSaveStack(),
saveSupport: newSaveSupport(),
saveNamespace: ast.StringTerm(q.partialNamespace),
genvarprefix: q.genvarprefix,
runtime: q.runtime,
}
q.startTimer(metrics.RegoPartialEval)
defer q.stopTimer(metrics.RegoPartialEval)
livevars := ast.NewVarSet()
ast.WalkVars(q.query, func(x ast.Var) bool {
if !x.IsGenerated() {
livevars.Add(x)
}
return false
})
p := copypropagation.New(livevars)
err = e.Run(func(e *eval) error {
// Build output from saved expressions.
body := ast.NewBody()
for _, elem := range e.saveStack.Stack[len(e.saveStack.Stack)-1] {
body.Append(elem.Plug(e.bindings))
}
// Include bindings as exprs so that when caller evals the result, they
// can obtain values for the vars in their query.
bindingExprs := []*ast.Expr{}
e.bindings.Iter(e.bindings, func(a, b *ast.Term) error {
bindingExprs = append(bindingExprs, ast.Equality.Expr(a, b))
return nil
})
// Sort binding expressions so that results are deterministic.
sort.Slice(bindingExprs, func(i, j int) bool {
return bindingExprs[i].Compare(bindingExprs[j]) < 0
})
for i := range bindingExprs {
body.Append(bindingExprs[i])
}
body = p.Apply(body)
partials = append(partials, body)
return nil
})
support = e.saveSupport.List()
return partials, support, err
} | go | func (q *Query) PartialRun(ctx context.Context) (partials []ast.Body, support []*ast.Module, err error) {
if q.partialNamespace == "" {
q.partialNamespace = "partial" // lazily initialize partial namespace
}
f := &queryIDFactory{}
b := newBindings(0, q.instr)
e := &eval{
ctx: ctx,
cancel: q.cancel,
query: q.query,
queryIDFact: f,
queryID: f.Next(),
bindings: b,
compiler: q.compiler,
store: q.store,
baseCache: newBaseCache(),
targetStack: newRefStack(),
txn: q.txn,
input: q.input,
tracers: q.tracers,
instr: q.instr,
builtinCache: builtins.Cache{},
virtualCache: newVirtualCache(),
saveSet: newSaveSet(q.unknowns, b),
saveStack: newSaveStack(),
saveSupport: newSaveSupport(),
saveNamespace: ast.StringTerm(q.partialNamespace),
genvarprefix: q.genvarprefix,
runtime: q.runtime,
}
q.startTimer(metrics.RegoPartialEval)
defer q.stopTimer(metrics.RegoPartialEval)
livevars := ast.NewVarSet()
ast.WalkVars(q.query, func(x ast.Var) bool {
if !x.IsGenerated() {
livevars.Add(x)
}
return false
})
p := copypropagation.New(livevars)
err = e.Run(func(e *eval) error {
// Build output from saved expressions.
body := ast.NewBody()
for _, elem := range e.saveStack.Stack[len(e.saveStack.Stack)-1] {
body.Append(elem.Plug(e.bindings))
}
// Include bindings as exprs so that when caller evals the result, they
// can obtain values for the vars in their query.
bindingExprs := []*ast.Expr{}
e.bindings.Iter(e.bindings, func(a, b *ast.Term) error {
bindingExprs = append(bindingExprs, ast.Equality.Expr(a, b))
return nil
})
// Sort binding expressions so that results are deterministic.
sort.Slice(bindingExprs, func(i, j int) bool {
return bindingExprs[i].Compare(bindingExprs[j]) < 0
})
for i := range bindingExprs {
body.Append(bindingExprs[i])
}
body = p.Apply(body)
partials = append(partials, body)
return nil
})
support = e.saveSupport.List()
return partials, support, err
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"PartialRun",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"partials",
"[",
"]",
"ast",
".",
"Body",
",",
"support",
"[",
"]",
"*",
"ast",
".",
"Module",
",",
"err",
"error",
")",
"{",
"if",
"q",
".",
"partialNamespace",
"==",
"\"",
"\"",
"{",
"q",
".",
"partialNamespace",
"=",
"\"",
"\"",
"// lazily initialize partial namespace",
"\n",
"}",
"\n",
"f",
":=",
"&",
"queryIDFactory",
"{",
"}",
"\n",
"b",
":=",
"newBindings",
"(",
"0",
",",
"q",
".",
"instr",
")",
"\n",
"e",
":=",
"&",
"eval",
"{",
"ctx",
":",
"ctx",
",",
"cancel",
":",
"q",
".",
"cancel",
",",
"query",
":",
"q",
".",
"query",
",",
"queryIDFact",
":",
"f",
",",
"queryID",
":",
"f",
".",
"Next",
"(",
")",
",",
"bindings",
":",
"b",
",",
"compiler",
":",
"q",
".",
"compiler",
",",
"store",
":",
"q",
".",
"store",
",",
"baseCache",
":",
"newBaseCache",
"(",
")",
",",
"targetStack",
":",
"newRefStack",
"(",
")",
",",
"txn",
":",
"q",
".",
"txn",
",",
"input",
":",
"q",
".",
"input",
",",
"tracers",
":",
"q",
".",
"tracers",
",",
"instr",
":",
"q",
".",
"instr",
",",
"builtinCache",
":",
"builtins",
".",
"Cache",
"{",
"}",
",",
"virtualCache",
":",
"newVirtualCache",
"(",
")",
",",
"saveSet",
":",
"newSaveSet",
"(",
"q",
".",
"unknowns",
",",
"b",
")",
",",
"saveStack",
":",
"newSaveStack",
"(",
")",
",",
"saveSupport",
":",
"newSaveSupport",
"(",
")",
",",
"saveNamespace",
":",
"ast",
".",
"StringTerm",
"(",
"q",
".",
"partialNamespace",
")",
",",
"genvarprefix",
":",
"q",
".",
"genvarprefix",
",",
"runtime",
":",
"q",
".",
"runtime",
",",
"}",
"\n",
"q",
".",
"startTimer",
"(",
"metrics",
".",
"RegoPartialEval",
")",
"\n",
"defer",
"q",
".",
"stopTimer",
"(",
"metrics",
".",
"RegoPartialEval",
")",
"\n\n",
"livevars",
":=",
"ast",
".",
"NewVarSet",
"(",
")",
"\n\n",
"ast",
".",
"WalkVars",
"(",
"q",
".",
"query",
",",
"func",
"(",
"x",
"ast",
".",
"Var",
")",
"bool",
"{",
"if",
"!",
"x",
".",
"IsGenerated",
"(",
")",
"{",
"livevars",
".",
"Add",
"(",
"x",
")",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
")",
"\n\n",
"p",
":=",
"copypropagation",
".",
"New",
"(",
"livevars",
")",
"\n\n",
"err",
"=",
"e",
".",
"Run",
"(",
"func",
"(",
"e",
"*",
"eval",
")",
"error",
"{",
"// Build output from saved expressions.",
"body",
":=",
"ast",
".",
"NewBody",
"(",
")",
"\n\n",
"for",
"_",
",",
"elem",
":=",
"range",
"e",
".",
"saveStack",
".",
"Stack",
"[",
"len",
"(",
"e",
".",
"saveStack",
".",
"Stack",
")",
"-",
"1",
"]",
"{",
"body",
".",
"Append",
"(",
"elem",
".",
"Plug",
"(",
"e",
".",
"bindings",
")",
")",
"\n",
"}",
"\n\n",
"// Include bindings as exprs so that when caller evals the result, they",
"// can obtain values for the vars in their query.",
"bindingExprs",
":=",
"[",
"]",
"*",
"ast",
".",
"Expr",
"{",
"}",
"\n",
"e",
".",
"bindings",
".",
"Iter",
"(",
"e",
".",
"bindings",
",",
"func",
"(",
"a",
",",
"b",
"*",
"ast",
".",
"Term",
")",
"error",
"{",
"bindingExprs",
"=",
"append",
"(",
"bindingExprs",
",",
"ast",
".",
"Equality",
".",
"Expr",
"(",
"a",
",",
"b",
")",
")",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n\n",
"// Sort binding expressions so that results are deterministic.",
"sort",
".",
"Slice",
"(",
"bindingExprs",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"bindingExprs",
"[",
"i",
"]",
".",
"Compare",
"(",
"bindingExprs",
"[",
"j",
"]",
")",
"<",
"0",
"\n",
"}",
")",
"\n\n",
"for",
"i",
":=",
"range",
"bindingExprs",
"{",
"body",
".",
"Append",
"(",
"bindingExprs",
"[",
"i",
"]",
")",
"\n",
"}",
"\n\n",
"body",
"=",
"p",
".",
"Apply",
"(",
"body",
")",
"\n",
"partials",
"=",
"append",
"(",
"partials",
",",
"body",
")",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n\n",
"support",
"=",
"e",
".",
"saveSupport",
".",
"List",
"(",
")",
"\n\n",
"return",
"partials",
",",
"support",
",",
"err",
"\n",
"}"
] | // PartialRun executes partial evaluation on the query with respect to unknown
// values. Partial evaluation attempts to evaluate as much of the query as
// possible without requiring values for the unknowns set on the query. The
// result of partial evaluation is a new set of queries that can be evaluated
// once the unknown value is known. In addition to new queries, partial
// evaluation may produce additional support modules that should be used in
// conjunction with the partially evaluated queries. | [
"PartialRun",
"executes",
"partial",
"evaluation",
"on",
"the",
"query",
"with",
"respect",
"to",
"unknown",
"values",
".",
"Partial",
"evaluation",
"attempts",
"to",
"evaluate",
"as",
"much",
"of",
"the",
"query",
"as",
"possible",
"without",
"requiring",
"values",
"for",
"the",
"unknowns",
"set",
"on",
"the",
"query",
".",
"The",
"result",
"of",
"partial",
"evaluation",
"is",
"a",
"new",
"set",
"of",
"queries",
"that",
"can",
"be",
"evaluated",
"once",
"the",
"unknown",
"value",
"is",
"known",
".",
"In",
"addition",
"to",
"new",
"queries",
"partial",
"evaluation",
"may",
"produce",
"additional",
"support",
"modules",
"that",
"should",
"be",
"used",
"in",
"conjunction",
"with",
"the",
"partially",
"evaluated",
"queries",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/query.go#L128-L205 | train |
open-policy-agent/opa | topdown/query.go | Run | func (q *Query) Run(ctx context.Context) (QueryResultSet, error) {
qrs := QueryResultSet{}
return qrs, q.Iter(ctx, func(qr QueryResult) error {
qrs = append(qrs, qr)
return nil
})
} | go | func (q *Query) Run(ctx context.Context) (QueryResultSet, error) {
qrs := QueryResultSet{}
return qrs, q.Iter(ctx, func(qr QueryResult) error {
qrs = append(qrs, qr)
return nil
})
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Run",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"QueryResultSet",
",",
"error",
")",
"{",
"qrs",
":=",
"QueryResultSet",
"{",
"}",
"\n",
"return",
"qrs",
",",
"q",
".",
"Iter",
"(",
"ctx",
",",
"func",
"(",
"qr",
"QueryResult",
")",
"error",
"{",
"qrs",
"=",
"append",
"(",
"qrs",
",",
"qr",
")",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"}"
] | // Run is a wrapper around Iter that accumulates query results and returns them
// in one shot. | [
"Run",
"is",
"a",
"wrapper",
"around",
"Iter",
"that",
"accumulates",
"query",
"results",
"and",
"returns",
"them",
"in",
"one",
"shot",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/query.go#L209-L215 | train |
open-policy-agent/opa | topdown/query.go | Iter | func (q *Query) Iter(ctx context.Context, iter func(QueryResult) error) error {
f := &queryIDFactory{}
e := &eval{
ctx: ctx,
cancel: q.cancel,
query: q.query,
queryIDFact: f,
queryID: f.Next(),
bindings: newBindings(0, q.instr),
compiler: q.compiler,
store: q.store,
baseCache: newBaseCache(),
targetStack: newRefStack(),
txn: q.txn,
input: q.input,
tracers: q.tracers,
instr: q.instr,
builtinCache: builtins.Cache{},
virtualCache: newVirtualCache(),
genvarprefix: q.genvarprefix,
runtime: q.runtime,
}
q.startTimer(metrics.RegoQueryEval)
defer q.stopTimer(metrics.RegoQueryEval)
return e.Run(func(e *eval) error {
qr := QueryResult{}
e.bindings.Iter(nil, func(k, v *ast.Term) error {
qr[k.Value.(ast.Var)] = v
return nil
})
return iter(qr)
})
} | go | func (q *Query) Iter(ctx context.Context, iter func(QueryResult) error) error {
f := &queryIDFactory{}
e := &eval{
ctx: ctx,
cancel: q.cancel,
query: q.query,
queryIDFact: f,
queryID: f.Next(),
bindings: newBindings(0, q.instr),
compiler: q.compiler,
store: q.store,
baseCache: newBaseCache(),
targetStack: newRefStack(),
txn: q.txn,
input: q.input,
tracers: q.tracers,
instr: q.instr,
builtinCache: builtins.Cache{},
virtualCache: newVirtualCache(),
genvarprefix: q.genvarprefix,
runtime: q.runtime,
}
q.startTimer(metrics.RegoQueryEval)
defer q.stopTimer(metrics.RegoQueryEval)
return e.Run(func(e *eval) error {
qr := QueryResult{}
e.bindings.Iter(nil, func(k, v *ast.Term) error {
qr[k.Value.(ast.Var)] = v
return nil
})
return iter(qr)
})
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Iter",
"(",
"ctx",
"context",
".",
"Context",
",",
"iter",
"func",
"(",
"QueryResult",
")",
"error",
")",
"error",
"{",
"f",
":=",
"&",
"queryIDFactory",
"{",
"}",
"\n",
"e",
":=",
"&",
"eval",
"{",
"ctx",
":",
"ctx",
",",
"cancel",
":",
"q",
".",
"cancel",
",",
"query",
":",
"q",
".",
"query",
",",
"queryIDFact",
":",
"f",
",",
"queryID",
":",
"f",
".",
"Next",
"(",
")",
",",
"bindings",
":",
"newBindings",
"(",
"0",
",",
"q",
".",
"instr",
")",
",",
"compiler",
":",
"q",
".",
"compiler",
",",
"store",
":",
"q",
".",
"store",
",",
"baseCache",
":",
"newBaseCache",
"(",
")",
",",
"targetStack",
":",
"newRefStack",
"(",
")",
",",
"txn",
":",
"q",
".",
"txn",
",",
"input",
":",
"q",
".",
"input",
",",
"tracers",
":",
"q",
".",
"tracers",
",",
"instr",
":",
"q",
".",
"instr",
",",
"builtinCache",
":",
"builtins",
".",
"Cache",
"{",
"}",
",",
"virtualCache",
":",
"newVirtualCache",
"(",
")",
",",
"genvarprefix",
":",
"q",
".",
"genvarprefix",
",",
"runtime",
":",
"q",
".",
"runtime",
",",
"}",
"\n",
"q",
".",
"startTimer",
"(",
"metrics",
".",
"RegoQueryEval",
")",
"\n",
"defer",
"q",
".",
"stopTimer",
"(",
"metrics",
".",
"RegoQueryEval",
")",
"\n",
"return",
"e",
".",
"Run",
"(",
"func",
"(",
"e",
"*",
"eval",
")",
"error",
"{",
"qr",
":=",
"QueryResult",
"{",
"}",
"\n",
"e",
".",
"bindings",
".",
"Iter",
"(",
"nil",
",",
"func",
"(",
"k",
",",
"v",
"*",
"ast",
".",
"Term",
")",
"error",
"{",
"qr",
"[",
"k",
".",
"Value",
".",
"(",
"ast",
".",
"Var",
")",
"]",
"=",
"v",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"return",
"iter",
"(",
"qr",
")",
"\n",
"}",
")",
"\n",
"}"
] | // Iter executes the query and invokes the iter function with query results
// produced by evaluating the query. | [
"Iter",
"executes",
"the",
"query",
"and",
"invokes",
"the",
"iter",
"function",
"with",
"query",
"results",
"produced",
"by",
"evaluating",
"the",
"query",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/query.go#L219-L251 | train |
open-policy-agent/opa | rego/rego.go | EvalInput | func EvalInput(input interface{}) EvalOption {
return func(e *EvalContext) {
e.rawInput = &input
e.hasInput = true
}
} | go | func EvalInput(input interface{}) EvalOption {
return func(e *EvalContext) {
e.rawInput = &input
e.hasInput = true
}
} | [
"func",
"EvalInput",
"(",
"input",
"interface",
"{",
"}",
")",
"EvalOption",
"{",
"return",
"func",
"(",
"e",
"*",
"EvalContext",
")",
"{",
"e",
".",
"rawInput",
"=",
"&",
"input",
"\n",
"e",
".",
"hasInput",
"=",
"true",
"\n",
"}",
"\n",
"}"
] | // EvalInput configures the input for a Prepared Query's evaluation | [
"EvalInput",
"configures",
"the",
"input",
"for",
"a",
"Prepared",
"Query",
"s",
"evaluation"
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L90-L95 | train |
open-policy-agent/opa | rego/rego.go | EvalParsedInput | func EvalParsedInput(input ast.Value) EvalOption {
return func(e *EvalContext) {
e.parsedInput = input
e.hasInput = true
}
} | go | func EvalParsedInput(input ast.Value) EvalOption {
return func(e *EvalContext) {
e.parsedInput = input
e.hasInput = true
}
} | [
"func",
"EvalParsedInput",
"(",
"input",
"ast",
".",
"Value",
")",
"EvalOption",
"{",
"return",
"func",
"(",
"e",
"*",
"EvalContext",
")",
"{",
"e",
".",
"parsedInput",
"=",
"input",
"\n",
"e",
".",
"hasInput",
"=",
"true",
"\n",
"}",
"\n",
"}"
] | // EvalParsedInput configures the input for a Prepared Query's evaluation | [
"EvalParsedInput",
"configures",
"the",
"input",
"for",
"a",
"Prepared",
"Query",
"s",
"evaluation"
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L98-L103 | train |
open-policy-agent/opa | rego/rego.go | EvalMetrics | func EvalMetrics(metric metrics.Metrics) EvalOption {
return func(e *EvalContext) {
e.metrics = metric
}
} | go | func EvalMetrics(metric metrics.Metrics) EvalOption {
return func(e *EvalContext) {
e.metrics = metric
}
} | [
"func",
"EvalMetrics",
"(",
"metric",
"metrics",
".",
"Metrics",
")",
"EvalOption",
"{",
"return",
"func",
"(",
"e",
"*",
"EvalContext",
")",
"{",
"e",
".",
"metrics",
"=",
"metric",
"\n",
"}",
"\n",
"}"
] | // EvalMetrics configures the metrics for a Prepared Query's evaluation | [
"EvalMetrics",
"configures",
"the",
"metrics",
"for",
"a",
"Prepared",
"Query",
"s",
"evaluation"
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L106-L110 | train |
open-policy-agent/opa | rego/rego.go | EvalTransaction | func EvalTransaction(txn storage.Transaction) EvalOption {
return func(e *EvalContext) {
e.txn = txn
}
} | go | func EvalTransaction(txn storage.Transaction) EvalOption {
return func(e *EvalContext) {
e.txn = txn
}
} | [
"func",
"EvalTransaction",
"(",
"txn",
"storage",
".",
"Transaction",
")",
"EvalOption",
"{",
"return",
"func",
"(",
"e",
"*",
"EvalContext",
")",
"{",
"e",
".",
"txn",
"=",
"txn",
"\n",
"}",
"\n",
"}"
] | // EvalTransaction configures the Transaction for a Prepared Query's evaluation | [
"EvalTransaction",
"configures",
"the",
"Transaction",
"for",
"a",
"Prepared",
"Query",
"s",
"evaluation"
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L113-L117 | train |
open-policy-agent/opa | rego/rego.go | EvalTracer | func EvalTracer(tracer topdown.Tracer) EvalOption {
return func(e *EvalContext) {
if tracer != nil {
e.tracers = append(e.tracers, tracer)
}
}
} | go | func EvalTracer(tracer topdown.Tracer) EvalOption {
return func(e *EvalContext) {
if tracer != nil {
e.tracers = append(e.tracers, tracer)
}
}
} | [
"func",
"EvalTracer",
"(",
"tracer",
"topdown",
".",
"Tracer",
")",
"EvalOption",
"{",
"return",
"func",
"(",
"e",
"*",
"EvalContext",
")",
"{",
"if",
"tracer",
"!=",
"nil",
"{",
"e",
".",
"tracers",
"=",
"append",
"(",
"e",
".",
"tracers",
",",
"tracer",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // EvalTracer configures a tracer for a Prepared Query's evaluation | [
"EvalTracer",
"configures",
"a",
"tracer",
"for",
"a",
"Prepared",
"Query",
"s",
"evaluation"
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L127-L133 | train |
open-policy-agent/opa | rego/rego.go | EvalParsedUnknowns | func EvalParsedUnknowns(unknowns []*ast.Term) EvalOption {
return func(e *EvalContext) {
e.parsedUnknowns = unknowns
}
} | go | func EvalParsedUnknowns(unknowns []*ast.Term) EvalOption {
return func(e *EvalContext) {
e.parsedUnknowns = unknowns
}
} | [
"func",
"EvalParsedUnknowns",
"(",
"unknowns",
"[",
"]",
"*",
"ast",
".",
"Term",
")",
"EvalOption",
"{",
"return",
"func",
"(",
"e",
"*",
"EvalContext",
")",
"{",
"e",
".",
"parsedUnknowns",
"=",
"unknowns",
"\n",
"}",
"\n",
"}"
] | // EvalParsedUnknowns returns an argument that sets the values to treat
// as unknown during partial evaluation. | [
"EvalParsedUnknowns",
"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#L154-L158 | train |
open-policy-agent/opa | rego/rego.go | Eval | func (pq PreparedEvalQuery) Eval(ctx context.Context, options ...EvalOption) (ResultSet, error) {
ectx, err := pq.newEvalContext(ctx, options)
if err != nil {
return nil, err
}
ectx.compiledQuery = pq.r.compiledQueries[evalQueryType]
return pq.r.eval(ctx, ectx)
} | go | func (pq PreparedEvalQuery) Eval(ctx context.Context, options ...EvalOption) (ResultSet, error) {
ectx, err := pq.newEvalContext(ctx, options)
if err != nil {
return nil, err
}
ectx.compiledQuery = pq.r.compiledQueries[evalQueryType]
return pq.r.eval(ctx, ectx)
} | [
"func",
"(",
"pq",
"PreparedEvalQuery",
")",
"Eval",
"(",
"ctx",
"context",
".",
"Context",
",",
"options",
"...",
"EvalOption",
")",
"(",
"ResultSet",
",",
"error",
")",
"{",
"ectx",
",",
"err",
":=",
"pq",
".",
"newEvalContext",
"(",
"ctx",
",",
"options",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"ectx",
".",
"compiledQuery",
"=",
"pq",
".",
"r",
".",
"compiledQueries",
"[",
"evalQueryType",
"]",
"\n\n",
"return",
"pq",
".",
"r",
".",
"eval",
"(",
"ctx",
",",
"ectx",
")",
"\n",
"}"
] | // Eval evaluates this PartialResult's Rego object with additional eval options
// and returns a ResultSet.
// If options are provided they will override the original Rego options respective value. | [
"Eval",
"evaluates",
"this",
"PartialResult",
"s",
"Rego",
"object",
"with",
"additional",
"eval",
"options",
"and",
"returns",
"a",
"ResultSet",
".",
"If",
"options",
"are",
"provided",
"they",
"will",
"override",
"the",
"original",
"Rego",
"options",
"respective",
"value",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L224-L233 | train |
open-policy-agent/opa | rego/rego.go | Partial | func (pq PreparedPartialQuery) Partial(ctx context.Context, options ...EvalOption) (*PartialQueries, error) {
ectx, err := pq.newEvalContext(ctx, options)
if err != nil {
return nil, err
}
ectx.compiledQuery = pq.r.compiledQueries[partialQueryType]
return pq.r.partial(ctx, ectx)
} | go | func (pq PreparedPartialQuery) Partial(ctx context.Context, options ...EvalOption) (*PartialQueries, error) {
ectx, err := pq.newEvalContext(ctx, options)
if err != nil {
return nil, err
}
ectx.compiledQuery = pq.r.compiledQueries[partialQueryType]
return pq.r.partial(ctx, ectx)
} | [
"func",
"(",
"pq",
"PreparedPartialQuery",
")",
"Partial",
"(",
"ctx",
"context",
".",
"Context",
",",
"options",
"...",
"EvalOption",
")",
"(",
"*",
"PartialQueries",
",",
"error",
")",
"{",
"ectx",
",",
"err",
":=",
"pq",
".",
"newEvalContext",
"(",
"ctx",
",",
"options",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"ectx",
".",
"compiledQuery",
"=",
"pq",
".",
"r",
".",
"compiledQueries",
"[",
"partialQueryType",
"]",
"\n\n",
"return",
"pq",
".",
"r",
".",
"partial",
"(",
"ctx",
",",
"ectx",
")",
"\n",
"}"
] | // Partial runs partial evaluation on the prepared query and returns the result. | [
"Partial",
"runs",
"partial",
"evaluation",
"on",
"the",
"prepared",
"query",
"and",
"returns",
"the",
"result",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L242-L251 | train |
open-policy-agent/opa | rego/rego.go | WithoutWildcards | func (v Vars) WithoutWildcards() Vars {
n := Vars{}
for k, v := range v {
if ast.Var(k).IsWildcard() || ast.Var(k).IsGenerated() {
continue
}
n[k] = v
}
return n
} | go | func (v Vars) WithoutWildcards() Vars {
n := Vars{}
for k, v := range v {
if ast.Var(k).IsWildcard() || ast.Var(k).IsGenerated() {
continue
}
n[k] = v
}
return n
} | [
"func",
"(",
"v",
"Vars",
")",
"WithoutWildcards",
"(",
")",
"Vars",
"{",
"n",
":=",
"Vars",
"{",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"v",
"{",
"if",
"ast",
".",
"Var",
"(",
"k",
")",
".",
"IsWildcard",
"(",
")",
"||",
"ast",
".",
"Var",
"(",
"k",
")",
".",
"IsGenerated",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n",
"n",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"return",
"n",
"\n",
"}"
] | // WithoutWildcards returns a copy of v with wildcard variables removed. | [
"WithoutWildcards",
"returns",
"a",
"copy",
"of",
"v",
"with",
"wildcard",
"variables",
"removed",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L302-L311 | train |
open-policy-agent/opa | rego/rego.go | Dump | func Dump(w io.Writer) func(r *Rego) {
return func(r *Rego) {
r.dump = w
}
} | go | func Dump(w io.Writer) func(r *Rego) {
return func(r *Rego) {
r.dump = w
}
} | [
"func",
"Dump",
"(",
"w",
"io",
".",
"Writer",
")",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"return",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"r",
".",
"dump",
"=",
"w",
"\n",
"}",
"\n",
"}"
] | // Dump returns an argument that sets the writer to dump debugging information to. | [
"Dump",
"returns",
"an",
"argument",
"that",
"sets",
"the",
"writer",
"to",
"dump",
"debugging",
"information",
"to",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L377-L381 | train |
open-policy-agent/opa | rego/rego.go | Query | func Query(q string) func(r *Rego) {
return func(r *Rego) {
r.query = q
}
} | go | func Query(q string) func(r *Rego) {
return func(r *Rego) {
r.query = q
}
} | [
"func",
"Query",
"(",
"q",
"string",
")",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"return",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"r",
".",
"query",
"=",
"q",
"\n",
"}",
"\n",
"}"
] | // Query returns an argument that sets the Rego query. | [
"Query",
"returns",
"an",
"argument",
"that",
"sets",
"the",
"Rego",
"query",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L384-L388 | train |
open-policy-agent/opa | rego/rego.go | ParsedQuery | func ParsedQuery(q ast.Body) func(r *Rego) {
return func(r *Rego) {
r.parsedQuery = q
}
} | go | func ParsedQuery(q ast.Body) func(r *Rego) {
return func(r *Rego) {
r.parsedQuery = q
}
} | [
"func",
"ParsedQuery",
"(",
"q",
"ast",
".",
"Body",
")",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"return",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"r",
".",
"parsedQuery",
"=",
"q",
"\n",
"}",
"\n",
"}"
] | // ParsedQuery returns an argument that sets the Rego query. | [
"ParsedQuery",
"returns",
"an",
"argument",
"that",
"sets",
"the",
"Rego",
"query",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L391-L395 | train |
open-policy-agent/opa | rego/rego.go | Package | func Package(p string) func(r *Rego) {
return func(r *Rego) {
r.pkg = p
}
} | go | func Package(p string) func(r *Rego) {
return func(r *Rego) {
r.pkg = p
}
} | [
"func",
"Package",
"(",
"p",
"string",
")",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"return",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"r",
".",
"pkg",
"=",
"p",
"\n",
"}",
"\n",
"}"
] | // Package returns an argument that sets the Rego package on the query's
// context. | [
"Package",
"returns",
"an",
"argument",
"that",
"sets",
"the",
"Rego",
"package",
"on",
"the",
"query",
"s",
"context",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L399-L403 | train |
open-policy-agent/opa | rego/rego.go | ParsedPackage | func ParsedPackage(pkg *ast.Package) func(r *Rego) {
return func(r *Rego) {
r.parsedPackage = pkg
}
} | go | func ParsedPackage(pkg *ast.Package) func(r *Rego) {
return func(r *Rego) {
r.parsedPackage = pkg
}
} | [
"func",
"ParsedPackage",
"(",
"pkg",
"*",
"ast",
".",
"Package",
")",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"return",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"r",
".",
"parsedPackage",
"=",
"pkg",
"\n",
"}",
"\n",
"}"
] | // ParsedPackage returns an argument that sets the Rego package on the query's
// context. | [
"ParsedPackage",
"returns",
"an",
"argument",
"that",
"sets",
"the",
"Rego",
"package",
"on",
"the",
"query",
"s",
"context",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L407-L411 | train |
open-policy-agent/opa | rego/rego.go | Imports | func Imports(p []string) func(r *Rego) {
return func(r *Rego) {
r.imports = append(r.imports, p...)
}
} | go | func Imports(p []string) func(r *Rego) {
return func(r *Rego) {
r.imports = append(r.imports, p...)
}
} | [
"func",
"Imports",
"(",
"p",
"[",
"]",
"string",
")",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"return",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"r",
".",
"imports",
"=",
"append",
"(",
"r",
".",
"imports",
",",
"p",
"...",
")",
"\n",
"}",
"\n",
"}"
] | // Imports returns an argument that adds a Rego import to the query's context. | [
"Imports",
"returns",
"an",
"argument",
"that",
"adds",
"a",
"Rego",
"import",
"to",
"the",
"query",
"s",
"context",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L414-L418 | train |
open-policy-agent/opa | rego/rego.go | ParsedImports | func ParsedImports(imp []*ast.Import) func(r *Rego) {
return func(r *Rego) {
r.parsedImports = append(r.parsedImports, imp...)
}
} | go | func ParsedImports(imp []*ast.Import) func(r *Rego) {
return func(r *Rego) {
r.parsedImports = append(r.parsedImports, imp...)
}
} | [
"func",
"ParsedImports",
"(",
"imp",
"[",
"]",
"*",
"ast",
".",
"Import",
")",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"return",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"r",
".",
"parsedImports",
"=",
"append",
"(",
"r",
".",
"parsedImports",
",",
"imp",
"...",
")",
"\n",
"}",
"\n",
"}"
] | // ParsedImports returns an argument that adds Rego imports to the query's
// context. | [
"ParsedImports",
"returns",
"an",
"argument",
"that",
"adds",
"Rego",
"imports",
"to",
"the",
"query",
"s",
"context",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L422-L426 | train |
open-policy-agent/opa | rego/rego.go | ParsedInput | func ParsedInput(x ast.Value) func(r *Rego) {
return func(r *Rego) {
r.parsedInput = x
}
} | go | func ParsedInput(x ast.Value) func(r *Rego) {
return func(r *Rego) {
r.parsedInput = x
}
} | [
"func",
"ParsedInput",
"(",
"x",
"ast",
".",
"Value",
")",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"return",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"r",
".",
"parsedInput",
"=",
"x",
"\n",
"}",
"\n",
"}"
] | // ParsedInput returns an argument that sets the Rego input document. | [
"ParsedInput",
"returns",
"an",
"argument",
"that",
"sets",
"the",
"Rego",
"input",
"document",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/rego/rego.go#L437-L441 | train |
open-policy-agent/opa | rego/rego.go | Unknowns | func Unknowns(unknowns []string) func(r *Rego) {
return func(r *Rego) {
r.unknowns = unknowns
}
} | go | func Unknowns(unknowns []string) func(r *Rego) {
return func(r *Rego) {
r.unknowns = unknowns
}
} | [
"func",
"Unknowns",
"(",
"unknowns",
"[",
"]",
"string",
")",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"return",
"func",
"(",
"r",
"*",
"Rego",
")",
"{",
"r",
".",
"unknowns",
"=",
"unknowns",
"\n",
"}",
"\n",
"}"
] | // Unknowns returns an argument that sets the values to treat as unknown during
// partial evaluation. | [
"Unknowns",
"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#L445-L449 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.