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
ast/parser_ext.go
ParsePartialObjectDocRuleFromEqExpr
func ParsePartialObjectDocRuleFromEqExpr(module *Module, lhs, rhs *Term) (*Rule, error) { ref, ok := lhs.Value.(Ref) if !ok || len(ref) != 2 { return nil, fmt.Errorf("%v cannot be used for rule name", TypeName(lhs.Value)) } name := ref[0].Value.(Var) key := ref[1] rule := &Rule{ Location: rhs.Location, Head: &Head{ Location: rhs.Location, Name: name, Key: key, Value: rhs, }, Body: NewBody( NewExpr(BooleanTerm(true).SetLocation(rhs.Location)).SetLocation(rhs.Location), ), Module: module, } return rule, nil }
go
func ParsePartialObjectDocRuleFromEqExpr(module *Module, lhs, rhs *Term) (*Rule, error) { ref, ok := lhs.Value.(Ref) if !ok || len(ref) != 2 { return nil, fmt.Errorf("%v cannot be used for rule name", TypeName(lhs.Value)) } name := ref[0].Value.(Var) key := ref[1] rule := &Rule{ Location: rhs.Location, Head: &Head{ Location: rhs.Location, Name: name, Key: key, Value: rhs, }, Body: NewBody( NewExpr(BooleanTerm(true).SetLocation(rhs.Location)).SetLocation(rhs.Location), ), Module: module, } return rule, nil }
[ "func", "ParsePartialObjectDocRuleFromEqExpr", "(", "module", "*", "Module", ",", "lhs", ",", "rhs", "*", "Term", ")", "(", "*", "Rule", ",", "error", ")", "{", "ref", ",", "ok", ":=", "lhs", ".", "Value", ".", "(", "Ref", ")", "\n", "if", "!", "ok", "||", "len", "(", "ref", ")", "!=", "2", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "TypeName", "(", "lhs", ".", "Value", ")", ")", "\n", "}", "\n\n", "name", ":=", "ref", "[", "0", "]", ".", "Value", ".", "(", "Var", ")", "\n", "key", ":=", "ref", "[", "1", "]", "\n\n", "rule", ":=", "&", "Rule", "{", "Location", ":", "rhs", ".", "Location", ",", "Head", ":", "&", "Head", "{", "Location", ":", "rhs", ".", "Location", ",", "Name", ":", "name", ",", "Key", ":", "key", ",", "Value", ":", "rhs", ",", "}", ",", "Body", ":", "NewBody", "(", "NewExpr", "(", "BooleanTerm", "(", "true", ")", ".", "SetLocation", "(", "rhs", ".", "Location", ")", ")", ".", "SetLocation", "(", "rhs", ".", "Location", ")", ",", ")", ",", "Module", ":", "module", ",", "}", "\n\n", "return", "rule", ",", "nil", "\n", "}" ]
// ParsePartialObjectDocRuleFromEqExpr returns a rule if the expression can be // interpreted as a partial object document definition.
[ "ParsePartialObjectDocRuleFromEqExpr", "returns", "a", "rule", "if", "the", "expression", "can", "be", "interpreted", "as", "a", "partial", "object", "document", "definition", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L208-L233
train
open-policy-agent/opa
ast/parser_ext.go
ParsePartialSetDocRuleFromTerm
func ParsePartialSetDocRuleFromTerm(module *Module, term *Term) (*Rule, error) { ref, ok := term.Value.(Ref) if !ok { return nil, fmt.Errorf("%vs cannot be used for rule head", TypeName(term.Value)) } if len(ref) != 2 { return nil, fmt.Errorf("refs cannot be used for rule") } rule := &Rule{ Location: term.Location, Head: &Head{ Location: term.Location, Name: ref[0].Value.(Var), Key: ref[1], }, Body: NewBody( NewExpr(BooleanTerm(true).SetLocation(term.Location)).SetLocation(term.Location), ), Module: module, } return rule, nil }
go
func ParsePartialSetDocRuleFromTerm(module *Module, term *Term) (*Rule, error) { ref, ok := term.Value.(Ref) if !ok { return nil, fmt.Errorf("%vs cannot be used for rule head", TypeName(term.Value)) } if len(ref) != 2 { return nil, fmt.Errorf("refs cannot be used for rule") } rule := &Rule{ Location: term.Location, Head: &Head{ Location: term.Location, Name: ref[0].Value.(Var), Key: ref[1], }, Body: NewBody( NewExpr(BooleanTerm(true).SetLocation(term.Location)).SetLocation(term.Location), ), Module: module, } return rule, nil }
[ "func", "ParsePartialSetDocRuleFromTerm", "(", "module", "*", "Module", ",", "term", "*", "Term", ")", "(", "*", "Rule", ",", "error", ")", "{", "ref", ",", "ok", ":=", "term", ".", "Value", ".", "(", "Ref", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "TypeName", "(", "term", ".", "Value", ")", ")", "\n", "}", "\n\n", "if", "len", "(", "ref", ")", "!=", "2", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "rule", ":=", "&", "Rule", "{", "Location", ":", "term", ".", "Location", ",", "Head", ":", "&", "Head", "{", "Location", ":", "term", ".", "Location", ",", "Name", ":", "ref", "[", "0", "]", ".", "Value", ".", "(", "Var", ")", ",", "Key", ":", "ref", "[", "1", "]", ",", "}", ",", "Body", ":", "NewBody", "(", "NewExpr", "(", "BooleanTerm", "(", "true", ")", ".", "SetLocation", "(", "term", ".", "Location", ")", ")", ".", "SetLocation", "(", "term", ".", "Location", ")", ",", ")", ",", "Module", ":", "module", ",", "}", "\n\n", "return", "rule", ",", "nil", "\n", "}" ]
// ParsePartialSetDocRuleFromTerm returns a rule if the term can be interpreted // as a partial set document definition.
[ "ParsePartialSetDocRuleFromTerm", "returns", "a", "rule", "if", "the", "term", "can", "be", "interpreted", "as", "a", "partial", "set", "document", "definition", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L237-L262
train
open-policy-agent/opa
ast/parser_ext.go
ParseImports
func ParseImports(input string) ([]*Import, error) { stmts, _, err := ParseStatements("", input) if err != nil { return nil, err } result := []*Import{} for _, stmt := range stmts { if imp, ok := stmt.(*Import); ok { result = append(result, imp) } else { return nil, fmt.Errorf("expected import but got %T", stmt) } } return result, nil }
go
func ParseImports(input string) ([]*Import, error) { stmts, _, err := ParseStatements("", input) if err != nil { return nil, err } result := []*Import{} for _, stmt := range stmts { if imp, ok := stmt.(*Import); ok { result = append(result, imp) } else { return nil, fmt.Errorf("expected import but got %T", stmt) } } return result, nil }
[ "func", "ParseImports", "(", "input", "string", ")", "(", "[", "]", "*", "Import", ",", "error", ")", "{", "stmts", ",", "_", ",", "err", ":=", "ParseStatements", "(", "\"", "\"", ",", "input", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "result", ":=", "[", "]", "*", "Import", "{", "}", "\n", "for", "_", ",", "stmt", ":=", "range", "stmts", "{", "if", "imp", ",", "ok", ":=", "stmt", ".", "(", "*", "Import", ")", ";", "ok", "{", "result", "=", "append", "(", "result", ",", "imp", ")", "\n", "}", "else", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "stmt", ")", "\n", "}", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// ParseImports returns a slice of Import objects.
[ "ParseImports", "returns", "a", "slice", "of", "Import", "objects", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L315-L329
train
open-policy-agent/opa
ast/parser_ext.go
ParseModule
func ParseModule(filename, input string) (*Module, error) { stmts, comments, err := ParseStatements(filename, input) if err != nil { return nil, err } return parseModule(stmts, comments) }
go
func ParseModule(filename, input string) (*Module, error) { stmts, comments, err := ParseStatements(filename, input) if err != nil { return nil, err } return parseModule(stmts, comments) }
[ "func", "ParseModule", "(", "filename", ",", "input", "string", ")", "(", "*", "Module", ",", "error", ")", "{", "stmts", ",", "comments", ",", "err", ":=", "ParseStatements", "(", "filename", ",", "input", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "parseModule", "(", "stmts", ",", "comments", ")", "\n", "}" ]
// ParseModule returns a parsed Module object. // For details on Module objects and their fields, see policy.go. // Empty input will return nil, nil.
[ "ParseModule", "returns", "a", "parsed", "Module", "object", ".", "For", "details", "on", "Module", "objects", "and", "their", "fields", "see", "policy", ".", "go", ".", "Empty", "input", "will", "return", "nil", "nil", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L334-L340
train
open-policy-agent/opa
ast/parser_ext.go
ParseBody
func ParseBody(input string) (Body, error) { stmts, _, err := ParseStatements("", input) if err != nil { return nil, err } result := Body{} for _, stmt := range stmts { switch stmt := stmt.(type) { case Body: result = append(result, stmt...) case *Comment: // skip default: return nil, fmt.Errorf("expected body but got %T", stmt) } } setExprIndices(result) return result, nil }
go
func ParseBody(input string) (Body, error) { stmts, _, err := ParseStatements("", input) if err != nil { return nil, err } result := Body{} for _, stmt := range stmts { switch stmt := stmt.(type) { case Body: result = append(result, stmt...) case *Comment: // skip default: return nil, fmt.Errorf("expected body but got %T", stmt) } } setExprIndices(result) return result, nil }
[ "func", "ParseBody", "(", "input", "string", ")", "(", "Body", ",", "error", ")", "{", "stmts", ",", "_", ",", "err", ":=", "ParseStatements", "(", "\"", "\"", ",", "input", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "result", ":=", "Body", "{", "}", "\n\n", "for", "_", ",", "stmt", ":=", "range", "stmts", "{", "switch", "stmt", ":=", "stmt", ".", "(", "type", ")", "{", "case", "Body", ":", "result", "=", "append", "(", "result", ",", "stmt", "...", ")", "\n", "case", "*", "Comment", ":", "// skip", "default", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "stmt", ")", "\n", "}", "\n", "}", "\n\n", "setExprIndices", "(", "result", ")", "\n\n", "return", "result", ",", "nil", "\n", "}" ]
// ParseBody returns exactly one body. // If multiple bodies are parsed, an error is returned.
[ "ParseBody", "returns", "exactly", "one", "body", ".", "If", "multiple", "bodies", "are", "parsed", "an", "error", "is", "returned", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L344-L366
train
open-policy-agent/opa
ast/parser_ext.go
ParseExpr
func ParseExpr(input string) (*Expr, error) { body, err := ParseBody(input) if err != nil { return nil, errors.Wrap(err, "failed to parse expression") } if len(body) != 1 { return nil, fmt.Errorf("expected exactly one expression but got: %v", body) } return body[0], nil }
go
func ParseExpr(input string) (*Expr, error) { body, err := ParseBody(input) if err != nil { return nil, errors.Wrap(err, "failed to parse expression") } if len(body) != 1 { return nil, fmt.Errorf("expected exactly one expression but got: %v", body) } return body[0], nil }
[ "func", "ParseExpr", "(", "input", "string", ")", "(", "*", "Expr", ",", "error", ")", "{", "body", ",", "err", ":=", "ParseBody", "(", "input", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "body", ")", "!=", "1", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "body", ")", "\n", "}", "\n", "return", "body", "[", "0", "]", ",", "nil", "\n", "}" ]
// ParseExpr returns exactly one expression. // If multiple expressions are parsed, an error is returned.
[ "ParseExpr", "returns", "exactly", "one", "expression", ".", "If", "multiple", "expressions", "are", "parsed", "an", "error", "is", "returned", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L370-L379
train
open-policy-agent/opa
ast/parser_ext.go
ParsePackage
func ParsePackage(input string) (*Package, error) { stmt, err := ParseStatement(input) if err != nil { return nil, err } pkg, ok := stmt.(*Package) if !ok { return nil, fmt.Errorf("expected package but got %T", stmt) } return pkg, nil }
go
func ParsePackage(input string) (*Package, error) { stmt, err := ParseStatement(input) if err != nil { return nil, err } pkg, ok := stmt.(*Package) if !ok { return nil, fmt.Errorf("expected package but got %T", stmt) } return pkg, nil }
[ "func", "ParsePackage", "(", "input", "string", ")", "(", "*", "Package", ",", "error", ")", "{", "stmt", ",", "err", ":=", "ParseStatement", "(", "input", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "pkg", ",", "ok", ":=", "stmt", ".", "(", "*", "Package", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "stmt", ")", "\n", "}", "\n", "return", "pkg", ",", "nil", "\n", "}" ]
// ParsePackage returns exactly one Package. // If multiple statements are parsed, an error is returned.
[ "ParsePackage", "returns", "exactly", "one", "Package", ".", "If", "multiple", "statements", "are", "parsed", "an", "error", "is", "returned", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L383-L393
train
open-policy-agent/opa
ast/parser_ext.go
ParseTerm
func ParseTerm(input string) (*Term, error) { body, err := ParseBody(input) if err != nil { return nil, errors.Wrap(err, "failed to parse term") } if len(body) != 1 { return nil, fmt.Errorf("expected exactly one term but got: %v", body) } term, ok := body[0].Terms.(*Term) if !ok { return nil, fmt.Errorf("expected term but got %v", body[0].Terms) } return term, nil }
go
func ParseTerm(input string) (*Term, error) { body, err := ParseBody(input) if err != nil { return nil, errors.Wrap(err, "failed to parse term") } if len(body) != 1 { return nil, fmt.Errorf("expected exactly one term but got: %v", body) } term, ok := body[0].Terms.(*Term) if !ok { return nil, fmt.Errorf("expected term but got %v", body[0].Terms) } return term, nil }
[ "func", "ParseTerm", "(", "input", "string", ")", "(", "*", "Term", ",", "error", ")", "{", "body", ",", "err", ":=", "ParseBody", "(", "input", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "body", ")", "!=", "1", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "body", ")", "\n", "}", "\n", "term", ",", "ok", ":=", "body", "[", "0", "]", ".", "Terms", ".", "(", "*", "Term", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "body", "[", "0", "]", ".", "Terms", ")", "\n", "}", "\n", "return", "term", ",", "nil", "\n", "}" ]
// ParseTerm returns exactly one term. // If multiple terms are parsed, an error is returned.
[ "ParseTerm", "returns", "exactly", "one", "term", ".", "If", "multiple", "terms", "are", "parsed", "an", "error", "is", "returned", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L397-L410
train
open-policy-agent/opa
ast/parser_ext.go
ParseRef
func ParseRef(input string) (Ref, error) { term, err := ParseTerm(input) if err != nil { return nil, errors.Wrap(err, "failed to parse ref") } ref, ok := term.Value.(Ref) if !ok { return nil, fmt.Errorf("expected ref but got %v", term) } return ref, nil }
go
func ParseRef(input string) (Ref, error) { term, err := ParseTerm(input) if err != nil { return nil, errors.Wrap(err, "failed to parse ref") } ref, ok := term.Value.(Ref) if !ok { return nil, fmt.Errorf("expected ref but got %v", term) } return ref, nil }
[ "func", "ParseRef", "(", "input", "string", ")", "(", "Ref", ",", "error", ")", "{", "term", ",", "err", ":=", "ParseTerm", "(", "input", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "ref", ",", "ok", ":=", "term", ".", "Value", ".", "(", "Ref", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "term", ")", "\n", "}", "\n", "return", "ref", ",", "nil", "\n", "}" ]
// ParseRef returns exactly one reference.
[ "ParseRef", "returns", "exactly", "one", "reference", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L413-L423
train
open-policy-agent/opa
ast/parser_ext.go
ParseRule
func ParseRule(input string) (*Rule, error) { stmts, _, err := ParseStatements("", input) if err != nil { return nil, err } if len(stmts) != 1 { return nil, fmt.Errorf("expected exactly one statement (rule)") } rule, ok := stmts[0].(*Rule) if !ok { return nil, fmt.Errorf("expected rule but got %T", stmts[0]) } return rule, nil }
go
func ParseRule(input string) (*Rule, error) { stmts, _, err := ParseStatements("", input) if err != nil { return nil, err } if len(stmts) != 1 { return nil, fmt.Errorf("expected exactly one statement (rule)") } rule, ok := stmts[0].(*Rule) if !ok { return nil, fmt.Errorf("expected rule but got %T", stmts[0]) } return rule, nil }
[ "func", "ParseRule", "(", "input", "string", ")", "(", "*", "Rule", ",", "error", ")", "{", "stmts", ",", "_", ",", "err", ":=", "ParseStatements", "(", "\"", "\"", ",", "input", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "len", "(", "stmts", ")", "!=", "1", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "rule", ",", "ok", ":=", "stmts", "[", "0", "]", ".", "(", "*", "Rule", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "stmts", "[", "0", "]", ")", "\n", "}", "\n", "return", "rule", ",", "nil", "\n", "}" ]
// ParseRule returns exactly one rule. // If multiple rules are parsed, an error is returned.
[ "ParseRule", "returns", "exactly", "one", "rule", ".", "If", "multiple", "rules", "are", "parsed", "an", "error", "is", "returned", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L427-L440
train
open-policy-agent/opa
ast/parser_ext.go
ParseStatements
func ParseStatements(filename, input string) ([]Statement, []*Comment, error) { bs := []byte(input) parsed, err := Parse(filename, bs, GlobalStore(filenameKey, filename), CommentsOption()) if err != nil { return nil, nil, formatParserErrors(filename, bs, err) } var comments []*Comment var sl []interface{} if p, ok := parsed.(program); ok { sl = p.buf commentMap := p.comments.(map[commentKey]*Comment) commentKeys := []commentKey{} for k := range commentMap { commentKeys = append(commentKeys, k) } sort.Slice(commentKeys, func(i, j int) bool { return commentKeys[i].Compare(commentKeys[j]) < 0 }) for _, k := range commentKeys { comments = append(comments, commentMap[k]) } } else { sl = parsed.([]interface{}) } stmts := make([]Statement, 0, len(sl)) for _, x := range sl { if rules, ok := x.([]*Rule); ok { for _, rule := range rules { stmts = append(stmts, rule) } } else { // Unchecked cast should be safe. A panic indicates grammar is // out-of-sync. stmts = append(stmts, x.(Statement)) } } return stmts, comments, postProcess(filename, stmts) }
go
func ParseStatements(filename, input string) ([]Statement, []*Comment, error) { bs := []byte(input) parsed, err := Parse(filename, bs, GlobalStore(filenameKey, filename), CommentsOption()) if err != nil { return nil, nil, formatParserErrors(filename, bs, err) } var comments []*Comment var sl []interface{} if p, ok := parsed.(program); ok { sl = p.buf commentMap := p.comments.(map[commentKey]*Comment) commentKeys := []commentKey{} for k := range commentMap { commentKeys = append(commentKeys, k) } sort.Slice(commentKeys, func(i, j int) bool { return commentKeys[i].Compare(commentKeys[j]) < 0 }) for _, k := range commentKeys { comments = append(comments, commentMap[k]) } } else { sl = parsed.([]interface{}) } stmts := make([]Statement, 0, len(sl)) for _, x := range sl { if rules, ok := x.([]*Rule); ok { for _, rule := range rules { stmts = append(stmts, rule) } } else { // Unchecked cast should be safe. A panic indicates grammar is // out-of-sync. stmts = append(stmts, x.(Statement)) } } return stmts, comments, postProcess(filename, stmts) }
[ "func", "ParseStatements", "(", "filename", ",", "input", "string", ")", "(", "[", "]", "Statement", ",", "[", "]", "*", "Comment", ",", "error", ")", "{", "bs", ":=", "[", "]", "byte", "(", "input", ")", "\n\n", "parsed", ",", "err", ":=", "Parse", "(", "filename", ",", "bs", ",", "GlobalStore", "(", "filenameKey", ",", "filename", ")", ",", "CommentsOption", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "formatParserErrors", "(", "filename", ",", "bs", ",", "err", ")", "\n", "}", "\n\n", "var", "comments", "[", "]", "*", "Comment", "\n", "var", "sl", "[", "]", "interface", "{", "}", "\n", "if", "p", ",", "ok", ":=", "parsed", ".", "(", "program", ")", ";", "ok", "{", "sl", "=", "p", ".", "buf", "\n", "commentMap", ":=", "p", ".", "comments", ".", "(", "map", "[", "commentKey", "]", "*", "Comment", ")", "\n", "commentKeys", ":=", "[", "]", "commentKey", "{", "}", "\n", "for", "k", ":=", "range", "commentMap", "{", "commentKeys", "=", "append", "(", "commentKeys", ",", "k", ")", "\n", "}", "\n", "sort", ".", "Slice", "(", "commentKeys", ",", "func", "(", "i", ",", "j", "int", ")", "bool", "{", "return", "commentKeys", "[", "i", "]", ".", "Compare", "(", "commentKeys", "[", "j", "]", ")", "<", "0", "\n", "}", ")", "\n", "for", "_", ",", "k", ":=", "range", "commentKeys", "{", "comments", "=", "append", "(", "comments", ",", "commentMap", "[", "k", "]", ")", "\n", "}", "\n", "}", "else", "{", "sl", "=", "parsed", ".", "(", "[", "]", "interface", "{", "}", ")", "\n", "}", "\n", "stmts", ":=", "make", "(", "[", "]", "Statement", ",", "0", ",", "len", "(", "sl", ")", ")", "\n\n", "for", "_", ",", "x", ":=", "range", "sl", "{", "if", "rules", ",", "ok", ":=", "x", ".", "(", "[", "]", "*", "Rule", ")", ";", "ok", "{", "for", "_", ",", "rule", ":=", "range", "rules", "{", "stmts", "=", "append", "(", "stmts", ",", "rule", ")", "\n", "}", "\n", "}", "else", "{", "// Unchecked cast should be safe. A panic indicates grammar is", "// out-of-sync.", "stmts", "=", "append", "(", "stmts", ",", "x", ".", "(", "Statement", ")", ")", "\n", "}", "\n", "}", "\n\n", "return", "stmts", ",", "comments", ",", "postProcess", "(", "filename", ",", "stmts", ")", "\n", "}" ]
// ParseStatements returns a slice of parsed statements. // This is the default return value from the parser.
[ "ParseStatements", "returns", "a", "slice", "of", "parsed", "statements", ".", "This", "is", "the", "default", "return", "value", "from", "the", "parser", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L488-L530
train
open-policy-agent/opa
server/server.go
Init
func (s *Server) Init(ctx context.Context) (*Server, error) { s.initRouter() // Add authorization handler. This must come BEFORE authentication handler // so that the latter can run first. switch s.authorization { case AuthorizationBasic: s.Handler = authorizer.NewBasic( s.Handler, s.getCompiler, s.store, authorizer.Runtime(s.runtime), authorizer.Decision(s.manager.Config.DefaultAuthorizationDecisionRef)) } switch s.authentication { case AuthenticationToken: s.Handler = identifier.NewTokenBased(s.Handler) case AuthenticationTLS: s.Handler = identifier.NewTLSBased(s.Handler) } txn, err := s.store.NewTransaction(ctx, storage.WriteParams) if err != nil { return nil, err } // Register triggers so that if runtime reloads the policies, the // server sees the change. config := storage.TriggerConfig{ OnCommit: s.reload, } if _, err := s.store.Register(ctx, txn, config); err != nil { s.store.Abort(ctx, txn) return nil, err } s.manager.RegisterCompilerTrigger(s.migrateWatcher) s.watcher, err = watch.New(ctx, s.store, s.getCompiler(), txn) if err != nil { return nil, err } s.partials = map[string]rego.PartialResult{} bp := bundle.Lookup(s.manager) if bp != nil { s.bundleStatusMtx = new(sync.RWMutex) s.hasBundle = true bp.Register("REST API Server", func(status bundle.Status) { s.updateBundleStatus(status) }) } return s, s.store.Commit(ctx, txn) }
go
func (s *Server) Init(ctx context.Context) (*Server, error) { s.initRouter() // Add authorization handler. This must come BEFORE authentication handler // so that the latter can run first. switch s.authorization { case AuthorizationBasic: s.Handler = authorizer.NewBasic( s.Handler, s.getCompiler, s.store, authorizer.Runtime(s.runtime), authorizer.Decision(s.manager.Config.DefaultAuthorizationDecisionRef)) } switch s.authentication { case AuthenticationToken: s.Handler = identifier.NewTokenBased(s.Handler) case AuthenticationTLS: s.Handler = identifier.NewTLSBased(s.Handler) } txn, err := s.store.NewTransaction(ctx, storage.WriteParams) if err != nil { return nil, err } // Register triggers so that if runtime reloads the policies, the // server sees the change. config := storage.TriggerConfig{ OnCommit: s.reload, } if _, err := s.store.Register(ctx, txn, config); err != nil { s.store.Abort(ctx, txn) return nil, err } s.manager.RegisterCompilerTrigger(s.migrateWatcher) s.watcher, err = watch.New(ctx, s.store, s.getCompiler(), txn) if err != nil { return nil, err } s.partials = map[string]rego.PartialResult{} bp := bundle.Lookup(s.manager) if bp != nil { s.bundleStatusMtx = new(sync.RWMutex) s.hasBundle = true bp.Register("REST API Server", func(status bundle.Status) { s.updateBundleStatus(status) }) } return s, s.store.Commit(ctx, txn) }
[ "func", "(", "s", "*", "Server", ")", "Init", "(", "ctx", "context", ".", "Context", ")", "(", "*", "Server", ",", "error", ")", "{", "s", ".", "initRouter", "(", ")", "\n\n", "// Add authorization handler. This must come BEFORE authentication handler", "// so that the latter can run first.", "switch", "s", ".", "authorization", "{", "case", "AuthorizationBasic", ":", "s", ".", "Handler", "=", "authorizer", ".", "NewBasic", "(", "s", ".", "Handler", ",", "s", ".", "getCompiler", ",", "s", ".", "store", ",", "authorizer", ".", "Runtime", "(", "s", ".", "runtime", ")", ",", "authorizer", ".", "Decision", "(", "s", ".", "manager", ".", "Config", ".", "DefaultAuthorizationDecisionRef", ")", ")", "\n", "}", "\n\n", "switch", "s", ".", "authentication", "{", "case", "AuthenticationToken", ":", "s", ".", "Handler", "=", "identifier", ".", "NewTokenBased", "(", "s", ".", "Handler", ")", "\n", "case", "AuthenticationTLS", ":", "s", ".", "Handler", "=", "identifier", ".", "NewTLSBased", "(", "s", ".", "Handler", ")", "\n", "}", "\n\n", "txn", ",", "err", ":=", "s", ".", "store", ".", "NewTransaction", "(", "ctx", ",", "storage", ".", "WriteParams", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Register triggers so that if runtime reloads the policies, the", "// server sees the change.", "config", ":=", "storage", ".", "TriggerConfig", "{", "OnCommit", ":", "s", ".", "reload", ",", "}", "\n", "if", "_", ",", "err", ":=", "s", ".", "store", ".", "Register", "(", "ctx", ",", "txn", ",", "config", ")", ";", "err", "!=", "nil", "{", "s", ".", "store", ".", "Abort", "(", "ctx", ",", "txn", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "s", ".", "manager", ".", "RegisterCompilerTrigger", "(", "s", ".", "migrateWatcher", ")", "\n\n", "s", ".", "watcher", ",", "err", "=", "watch", ".", "New", "(", "ctx", ",", "s", ".", "store", ",", "s", ".", "getCompiler", "(", ")", ",", "txn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "s", ".", "partials", "=", "map", "[", "string", "]", "rego", ".", "PartialResult", "{", "}", "\n\n", "bp", ":=", "bundle", ".", "Lookup", "(", "s", ".", "manager", ")", "\n", "if", "bp", "!=", "nil", "{", "s", ".", "bundleStatusMtx", "=", "new", "(", "sync", ".", "RWMutex", ")", "\n", "s", ".", "hasBundle", "=", "true", "\n", "bp", ".", "Register", "(", "\"", "\"", ",", "func", "(", "status", "bundle", ".", "Status", ")", "{", "s", ".", "updateBundleStatus", "(", "status", ")", "\n", "}", ")", "\n", "}", "\n\n", "return", "s", ",", "s", ".", "store", ".", "Commit", "(", "ctx", ",", "txn", ")", "\n", "}" ]
// Init initializes the server. This function MUST be called before Loop.
[ "Init", "initializes", "the", "server", ".", "This", "function", "MUST", "be", "called", "before", "Loop", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/server.go#L124-L181
train
open-policy-agent/opa
server/server.go
Shutdown
func (s *Server) Shutdown(ctx context.Context) error { errChan := make(chan error) for _, srvr := range s.httpListeners { go func(s httpListener) { errChan <- s.Shutdown(ctx) }(srvr) } // wait until each server has finished shutting down var errorList []error for i := 0; i < len(s.httpListeners); i++ { err := <-errChan if err != nil { errorList = append(errorList, err) } } if len(errorList) > 0 { errMsg := "error while shutting down: " for i, err := range errorList { errMsg += fmt.Sprintf("(%d) %s. ", i, err.Error()) } return errors.New(errMsg) } return nil }
go
func (s *Server) Shutdown(ctx context.Context) error { errChan := make(chan error) for _, srvr := range s.httpListeners { go func(s httpListener) { errChan <- s.Shutdown(ctx) }(srvr) } // wait until each server has finished shutting down var errorList []error for i := 0; i < len(s.httpListeners); i++ { err := <-errChan if err != nil { errorList = append(errorList, err) } } if len(errorList) > 0 { errMsg := "error while shutting down: " for i, err := range errorList { errMsg += fmt.Sprintf("(%d) %s. ", i, err.Error()) } return errors.New(errMsg) } return nil }
[ "func", "(", "s", "*", "Server", ")", "Shutdown", "(", "ctx", "context", ".", "Context", ")", "error", "{", "errChan", ":=", "make", "(", "chan", "error", ")", "\n", "for", "_", ",", "srvr", ":=", "range", "s", ".", "httpListeners", "{", "go", "func", "(", "s", "httpListener", ")", "{", "errChan", "<-", "s", ".", "Shutdown", "(", "ctx", ")", "\n", "}", "(", "srvr", ")", "\n", "}", "\n", "// wait until each server has finished shutting down", "var", "errorList", "[", "]", "error", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "s", ".", "httpListeners", ")", ";", "i", "++", "{", "err", ":=", "<-", "errChan", "\n", "if", "err", "!=", "nil", "{", "errorList", "=", "append", "(", "errorList", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "if", "len", "(", "errorList", ")", ">", "0", "{", "errMsg", ":=", "\"", "\"", "\n", "for", "i", ",", "err", ":=", "range", "errorList", "{", "errMsg", "+=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "i", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "return", "errors", ".", "New", "(", "errMsg", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Shutdown will attempt to gracefully shutdown each of the http servers // currently in use by the OPA Server. If any exceed the deadline specified // by the context an error will be returned.
[ "Shutdown", "will", "attempt", "to", "gracefully", "shutdown", "each", "of", "the", "http", "servers", "currently", "in", "use", "by", "the", "OPA", "Server", ".", "If", "any", "exceed", "the", "deadline", "specified", "by", "the", "context", "an", "error", "will", "be", "returned", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/server.go#L186-L210
train
open-policy-agent/opa
server/server.go
WithAddresses
func (s *Server) WithAddresses(addrs []string) *Server { s.addrs = addrs return s }
go
func (s *Server) WithAddresses(addrs []string) *Server { s.addrs = addrs return s }
[ "func", "(", "s", "*", "Server", ")", "WithAddresses", "(", "addrs", "[", "]", "string", ")", "*", "Server", "{", "s", ".", "addrs", "=", "addrs", "\n", "return", "s", "\n", "}" ]
// WithAddresses sets the listening addresses that the server will bind to.
[ "WithAddresses", "sets", "the", "listening", "addresses", "that", "the", "server", "will", "bind", "to", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/server.go#L213-L216
train
open-policy-agent/opa
server/server.go
WithInsecureAddress
func (s *Server) WithInsecureAddress(addr string) *Server { s.insecureAddr = addr return s }
go
func (s *Server) WithInsecureAddress(addr string) *Server { s.insecureAddr = addr return s }
[ "func", "(", "s", "*", "Server", ")", "WithInsecureAddress", "(", "addr", "string", ")", "*", "Server", "{", "s", ".", "insecureAddr", "=", "addr", "\n", "return", "s", "\n", "}" ]
// WithInsecureAddress sets the listening address that the server will bind to.
[ "WithInsecureAddress", "sets", "the", "listening", "address", "that", "the", "server", "will", "bind", "to", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/server.go#L219-L222
train
open-policy-agent/opa
server/server.go
WithAuthentication
func (s *Server) WithAuthentication(scheme AuthenticationScheme) *Server { s.authentication = scheme return s }
go
func (s *Server) WithAuthentication(scheme AuthenticationScheme) *Server { s.authentication = scheme return s }
[ "func", "(", "s", "*", "Server", ")", "WithAuthentication", "(", "scheme", "AuthenticationScheme", ")", "*", "Server", "{", "s", ".", "authentication", "=", "scheme", "\n", "return", "s", "\n", "}" ]
// WithAuthentication sets authentication scheme to use on the server.
[ "WithAuthentication", "sets", "authentication", "scheme", "to", "use", "on", "the", "server", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/server.go#L225-L228
train
open-policy-agent/opa
server/server.go
WithAuthorization
func (s *Server) WithAuthorization(scheme AuthorizationScheme) *Server { s.authorization = scheme return s }
go
func (s *Server) WithAuthorization(scheme AuthorizationScheme) *Server { s.authorization = scheme return s }
[ "func", "(", "s", "*", "Server", ")", "WithAuthorization", "(", "scheme", "AuthorizationScheme", ")", "*", "Server", "{", "s", ".", "authorization", "=", "scheme", "\n", "return", "s", "\n", "}" ]
// WithAuthorization sets authorization scheme to use on the server.
[ "WithAuthorization", "sets", "authorization", "scheme", "to", "use", "on", "the", "server", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/server.go#L231-L234
train
open-policy-agent/opa
server/server.go
WithCertificate
func (s *Server) WithCertificate(cert *tls.Certificate) *Server { s.cert = cert return s }
go
func (s *Server) WithCertificate(cert *tls.Certificate) *Server { s.cert = cert return s }
[ "func", "(", "s", "*", "Server", ")", "WithCertificate", "(", "cert", "*", "tls", ".", "Certificate", ")", "*", "Server", "{", "s", ".", "cert", "=", "cert", "\n", "return", "s", "\n", "}" ]
// WithCertificate sets the server-side certificate that the server will use.
[ "WithCertificate", "sets", "the", "server", "-", "side", "certificate", "that", "the", "server", "will", "use", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/server.go#L237-L240
train
open-policy-agent/opa
server/server.go
WithCertPool
func (s *Server) WithCertPool(pool *x509.CertPool) *Server { s.certPool = pool return s }
go
func (s *Server) WithCertPool(pool *x509.CertPool) *Server { s.certPool = pool return s }
[ "func", "(", "s", "*", "Server", ")", "WithCertPool", "(", "pool", "*", "x509", ".", "CertPool", ")", "*", "Server", "{", "s", ".", "certPool", "=", "pool", "\n", "return", "s", "\n", "}" ]
// WithCertPool sets the server-side cert pool that the server will use.
[ "WithCertPool", "sets", "the", "server", "-", "side", "cert", "pool", "that", "the", "server", "will", "use", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/server.go#L243-L246
train
open-policy-agent/opa
server/server.go
WithStore
func (s *Server) WithStore(store storage.Store) *Server { s.store = store return s }
go
func (s *Server) WithStore(store storage.Store) *Server { s.store = store return s }
[ "func", "(", "s", "*", "Server", ")", "WithStore", "(", "store", "storage", ".", "Store", ")", "*", "Server", "{", "s", ".", "store", "=", "store", "\n", "return", "s", "\n", "}" ]
// WithStore sets the storage used by the server.
[ "WithStore", "sets", "the", "storage", "used", "by", "the", "server", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/server.go#L249-L252
train
open-policy-agent/opa
server/server.go
WithManager
func (s *Server) WithManager(manager *plugins.Manager) *Server { s.manager = manager return s }
go
func (s *Server) WithManager(manager *plugins.Manager) *Server { s.manager = manager return s }
[ "func", "(", "s", "*", "Server", ")", "WithManager", "(", "manager", "*", "plugins", ".", "Manager", ")", "*", "Server", "{", "s", ".", "manager", "=", "manager", "\n", "return", "s", "\n", "}" ]
// WithManager sets the plugins manager used by the server.
[ "WithManager", "sets", "the", "plugins", "manager", "used", "by", "the", "server", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/server.go#L255-L258
train
open-policy-agent/opa
server/server.go
WithCompilerErrorLimit
func (s *Server) WithCompilerErrorLimit(limit int) *Server { s.errLimit = limit return s }
go
func (s *Server) WithCompilerErrorLimit(limit int) *Server { s.errLimit = limit return s }
[ "func", "(", "s", "*", "Server", ")", "WithCompilerErrorLimit", "(", "limit", "int", ")", "*", "Server", "{", "s", ".", "errLimit", "=", "limit", "\n", "return", "s", "\n", "}" ]
// WithCompilerErrorLimit sets the limit on the number of compiler errors the server will // allow.
[ "WithCompilerErrorLimit", "sets", "the", "limit", "on", "the", "number", "of", "compiler", "errors", "the", "server", "will", "allow", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/server.go#L262-L265
train
open-policy-agent/opa
server/server.go
WithPprofEnabled
func (s *Server) WithPprofEnabled(pprofEnabled bool) *Server { s.pprofEnabled = pprofEnabled return s }
go
func (s *Server) WithPprofEnabled(pprofEnabled bool) *Server { s.pprofEnabled = pprofEnabled return s }
[ "func", "(", "s", "*", "Server", ")", "WithPprofEnabled", "(", "pprofEnabled", "bool", ")", "*", "Server", "{", "s", ".", "pprofEnabled", "=", "pprofEnabled", "\n", "return", "s", "\n", "}" ]
// WithPprofEnabled sets whether pprof endpoints are enabled
[ "WithPprofEnabled", "sets", "whether", "pprof", "endpoints", "are", "enabled" ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/server.go#L268-L271
train
open-policy-agent/opa
server/server.go
WithDiagnosticsBuffer
func (s *Server) WithDiagnosticsBuffer(buf Buffer) *Server { s.diagnostics = buf return s }
go
func (s *Server) WithDiagnosticsBuffer(buf Buffer) *Server { s.diagnostics = buf return s }
[ "func", "(", "s", "*", "Server", ")", "WithDiagnosticsBuffer", "(", "buf", "Buffer", ")", "*", "Server", "{", "s", ".", "diagnostics", "=", "buf", "\n", "return", "s", "\n", "}" ]
// WithDiagnosticsBuffer sets the diagnostics buffer used by the server. DEPRECATED.
[ "WithDiagnosticsBuffer", "sets", "the", "diagnostics", "buffer", "used", "by", "the", "server", ".", "DEPRECATED", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/server.go#L274-L277
train
open-policy-agent/opa
server/server.go
WithDecisionLogger
func (s *Server) WithDecisionLogger(logger func(context.Context, *Info)) *Server { s.logger = func(ctx context.Context, info *Info) error { logger(ctx, info) return nil } return s }
go
func (s *Server) WithDecisionLogger(logger func(context.Context, *Info)) *Server { s.logger = func(ctx context.Context, info *Info) error { logger(ctx, info) return nil } return s }
[ "func", "(", "s", "*", "Server", ")", "WithDecisionLogger", "(", "logger", "func", "(", "context", ".", "Context", ",", "*", "Info", ")", ")", "*", "Server", "{", "s", ".", "logger", "=", "func", "(", "ctx", "context", ".", "Context", ",", "info", "*", "Info", ")", "error", "{", "logger", "(", "ctx", ",", "info", ")", "\n", "return", "nil", "\n", "}", "\n", "return", "s", "\n", "}" ]
// WithDecisionLogger sets the decision logger used by the // server. DEPRECATED. Use WithDecisionLoggerWithErr instead.
[ "WithDecisionLogger", "sets", "the", "decision", "logger", "used", "by", "the", "server", ".", "DEPRECATED", ".", "Use", "WithDecisionLoggerWithErr", "instead", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/server.go#L281-L287
train
open-policy-agent/opa
server/server.go
WithDecisionLoggerWithErr
func (s *Server) WithDecisionLoggerWithErr(logger func(context.Context, *Info) error) *Server { s.logger = logger return s }
go
func (s *Server) WithDecisionLoggerWithErr(logger func(context.Context, *Info) error) *Server { s.logger = logger return s }
[ "func", "(", "s", "*", "Server", ")", "WithDecisionLoggerWithErr", "(", "logger", "func", "(", "context", ".", "Context", ",", "*", "Info", ")", "error", ")", "*", "Server", "{", "s", ".", "logger", "=", "logger", "\n", "return", "s", "\n", "}" ]
// WithDecisionLoggerWithErr sets the decision logger used by the server.
[ "WithDecisionLoggerWithErr", "sets", "the", "decision", "logger", "used", "by", "the", "server", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/server.go#L290-L293
train
open-policy-agent/opa
server/server.go
WithDecisionIDFactory
func (s *Server) WithDecisionIDFactory(f func() string) *Server { s.decisionIDFactory = f return s }
go
func (s *Server) WithDecisionIDFactory(f func() string) *Server { s.decisionIDFactory = f return s }
[ "func", "(", "s", "*", "Server", ")", "WithDecisionIDFactory", "(", "f", "func", "(", ")", "string", ")", "*", "Server", "{", "s", ".", "decisionIDFactory", "=", "f", "\n", "return", "s", "\n", "}" ]
// WithDecisionIDFactory sets a function on the server to generate decision IDs.
[ "WithDecisionIDFactory", "sets", "a", "function", "on", "the", "server", "to", "generate", "decision", "IDs", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/server.go#L296-L299
train
open-policy-agent/opa
server/server.go
WithRouter
func (s *Server) WithRouter(router *mux.Router) *Server { s.router = router return s }
go
func (s *Server) WithRouter(router *mux.Router) *Server { s.router = router return s }
[ "func", "(", "s", "*", "Server", ")", "WithRouter", "(", "router", "*", "mux", ".", "Router", ")", "*", "Server", "{", "s", ".", "router", "=", "router", "\n", "return", "s", "\n", "}" ]
// WithRouter sets the mux.Router to attach OPA's HTTP API routes onto. If a // router is not supplied, the server will create it's own.
[ "WithRouter", "sets", "the", "mux", ".", "Router", "to", "attach", "OPA", "s", "HTTP", "API", "routes", "onto", ".", "If", "a", "router", "is", "not", "supplied", "the", "server", "will", "create", "it", "s", "own", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/server.go#L309-L312
train
open-policy-agent/opa
server/server.go
Listeners
func (s *Server) Listeners() ([]Loop, error) { loops := []Loop{} for _, addr := range s.addrs { parsedURL, err := parseURL(addr, s.cert != nil) if err != nil { return nil, err } var loop Loop var listener httpListener switch parsedURL.Scheme { case "unix": loop, listener, err = s.getListenerForUNIXSocket(parsedURL) case "http": loop, listener, err = s.getListenerForHTTPServer(parsedURL) case "https": loop, listener, err = s.getListenerForHTTPSServer(parsedURL) default: err = fmt.Errorf("invalid url scheme %q", parsedURL.Scheme) } if err != nil { return nil, err } s.httpListeners = append(s.httpListeners, listener) loops = append(loops, loop) } if s.insecureAddr != "" { parsedURL, err := parseURL(s.insecureAddr, false) if err != nil { return nil, err } loop, httpListener, err := s.getListenerForHTTPServer(parsedURL) if err != nil { return nil, err } s.httpListeners = append(s.httpListeners, httpListener) loops = append(loops, loop) } return loops, nil }
go
func (s *Server) Listeners() ([]Loop, error) { loops := []Loop{} for _, addr := range s.addrs { parsedURL, err := parseURL(addr, s.cert != nil) if err != nil { return nil, err } var loop Loop var listener httpListener switch parsedURL.Scheme { case "unix": loop, listener, err = s.getListenerForUNIXSocket(parsedURL) case "http": loop, listener, err = s.getListenerForHTTPServer(parsedURL) case "https": loop, listener, err = s.getListenerForHTTPSServer(parsedURL) default: err = fmt.Errorf("invalid url scheme %q", parsedURL.Scheme) } if err != nil { return nil, err } s.httpListeners = append(s.httpListeners, listener) loops = append(loops, loop) } if s.insecureAddr != "" { parsedURL, err := parseURL(s.insecureAddr, false) if err != nil { return nil, err } loop, httpListener, err := s.getListenerForHTTPServer(parsedURL) if err != nil { return nil, err } s.httpListeners = append(s.httpListeners, httpListener) loops = append(loops, loop) } return loops, nil }
[ "func", "(", "s", "*", "Server", ")", "Listeners", "(", ")", "(", "[", "]", "Loop", ",", "error", ")", "{", "loops", ":=", "[", "]", "Loop", "{", "}", "\n", "for", "_", ",", "addr", ":=", "range", "s", ".", "addrs", "{", "parsedURL", ",", "err", ":=", "parseURL", "(", "addr", ",", "s", ".", "cert", "!=", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "loop", "Loop", "\n", "var", "listener", "httpListener", "\n", "switch", "parsedURL", ".", "Scheme", "{", "case", "\"", "\"", ":", "loop", ",", "listener", ",", "err", "=", "s", ".", "getListenerForUNIXSocket", "(", "parsedURL", ")", "\n", "case", "\"", "\"", ":", "loop", ",", "listener", ",", "err", "=", "s", ".", "getListenerForHTTPServer", "(", "parsedURL", ")", "\n", "case", "\"", "\"", ":", "loop", ",", "listener", ",", "err", "=", "s", ".", "getListenerForHTTPSServer", "(", "parsedURL", ")", "\n", "default", ":", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "parsedURL", ".", "Scheme", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "s", ".", "httpListeners", "=", "append", "(", "s", ".", "httpListeners", ",", "listener", ")", "\n", "loops", "=", "append", "(", "loops", ",", "loop", ")", "\n", "}", "\n\n", "if", "s", ".", "insecureAddr", "!=", "\"", "\"", "{", "parsedURL", ",", "err", ":=", "parseURL", "(", "s", ".", "insecureAddr", ",", "false", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "loop", ",", "httpListener", ",", "err", ":=", "s", ".", "getListenerForHTTPServer", "(", "parsedURL", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "s", ".", "httpListeners", "=", "append", "(", "s", ".", "httpListeners", ",", "httpListener", ")", "\n", "loops", "=", "append", "(", "loops", ",", "loop", ")", "\n", "}", "\n\n", "return", "loops", ",", "nil", "\n", "}" ]
// Listeners returns functions that listen and serve connections.
[ "Listeners", "returns", "functions", "that", "listen", "and", "serve", "connections", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/server.go#L315-L355
train
open-policy-agent/opa
cover/cover.go
Report
func (c *Cover) Report(modules map[string]*ast.Module) (report Report) { report.Files = map[string]*FileReport{} for file, hits := range c.hits { covered := make(PositionSlice, 0, len(hits)) for pos := range hits { covered = append(covered, pos) } covered.Sort() fr, ok := report.Files[file] if !ok { fr = &FileReport{} report.Files[file] = fr } fr.Covered = sortedPositionSliceToRangeSlice(covered) } for file, module := range modules { notCovered := PositionSlice{} ast.WalkRules(module, func(x *ast.Rule) bool { if hasFileLocation(x.Head.Location) { if !report.IsCovered(x.Location.File, x.Location.Row) { notCovered = append(notCovered, Position{x.Head.Location.Row}) } } return false }) ast.WalkExprs(module, func(x *ast.Expr) bool { if hasFileLocation(x.Location) { if !report.IsCovered(x.Location.File, x.Location.Row) { notCovered = append(notCovered, Position{x.Location.Row}) } } return false }) notCovered.Sort() fr, ok := report.Files[file] if !ok { fr = &FileReport{} report.Files[file] = fr } fr.NotCovered = sortedPositionSliceToRangeSlice(notCovered) } var coveredLoc, notCoveredLoc int var overallCoverage float64 for _, fr := range report.Files { fr.Coverage = fr.computeCoveragePercentage() coveredLoc += fr.locCovered() notCoveredLoc += fr.locNotCovered() } totalLoc := coveredLoc + notCoveredLoc if totalLoc != 0 { overallCoverage = 100.0 * float64(coveredLoc) / float64(totalLoc) } report.Coverage = round(overallCoverage, 2) return }
go
func (c *Cover) Report(modules map[string]*ast.Module) (report Report) { report.Files = map[string]*FileReport{} for file, hits := range c.hits { covered := make(PositionSlice, 0, len(hits)) for pos := range hits { covered = append(covered, pos) } covered.Sort() fr, ok := report.Files[file] if !ok { fr = &FileReport{} report.Files[file] = fr } fr.Covered = sortedPositionSliceToRangeSlice(covered) } for file, module := range modules { notCovered := PositionSlice{} ast.WalkRules(module, func(x *ast.Rule) bool { if hasFileLocation(x.Head.Location) { if !report.IsCovered(x.Location.File, x.Location.Row) { notCovered = append(notCovered, Position{x.Head.Location.Row}) } } return false }) ast.WalkExprs(module, func(x *ast.Expr) bool { if hasFileLocation(x.Location) { if !report.IsCovered(x.Location.File, x.Location.Row) { notCovered = append(notCovered, Position{x.Location.Row}) } } return false }) notCovered.Sort() fr, ok := report.Files[file] if !ok { fr = &FileReport{} report.Files[file] = fr } fr.NotCovered = sortedPositionSliceToRangeSlice(notCovered) } var coveredLoc, notCoveredLoc int var overallCoverage float64 for _, fr := range report.Files { fr.Coverage = fr.computeCoveragePercentage() coveredLoc += fr.locCovered() notCoveredLoc += fr.locNotCovered() } totalLoc := coveredLoc + notCoveredLoc if totalLoc != 0 { overallCoverage = 100.0 * float64(coveredLoc) / float64(totalLoc) } report.Coverage = round(overallCoverage, 2) return }
[ "func", "(", "c", "*", "Cover", ")", "Report", "(", "modules", "map", "[", "string", "]", "*", "ast", ".", "Module", ")", "(", "report", "Report", ")", "{", "report", ".", "Files", "=", "map", "[", "string", "]", "*", "FileReport", "{", "}", "\n", "for", "file", ",", "hits", ":=", "range", "c", ".", "hits", "{", "covered", ":=", "make", "(", "PositionSlice", ",", "0", ",", "len", "(", "hits", ")", ")", "\n", "for", "pos", ":=", "range", "hits", "{", "covered", "=", "append", "(", "covered", ",", "pos", ")", "\n", "}", "\n", "covered", ".", "Sort", "(", ")", "\n", "fr", ",", "ok", ":=", "report", ".", "Files", "[", "file", "]", "\n", "if", "!", "ok", "{", "fr", "=", "&", "FileReport", "{", "}", "\n", "report", ".", "Files", "[", "file", "]", "=", "fr", "\n", "}", "\n", "fr", ".", "Covered", "=", "sortedPositionSliceToRangeSlice", "(", "covered", ")", "\n", "}", "\n", "for", "file", ",", "module", ":=", "range", "modules", "{", "notCovered", ":=", "PositionSlice", "{", "}", "\n", "ast", ".", "WalkRules", "(", "module", ",", "func", "(", "x", "*", "ast", ".", "Rule", ")", "bool", "{", "if", "hasFileLocation", "(", "x", ".", "Head", ".", "Location", ")", "{", "if", "!", "report", ".", "IsCovered", "(", "x", ".", "Location", ".", "File", ",", "x", ".", "Location", ".", "Row", ")", "{", "notCovered", "=", "append", "(", "notCovered", ",", "Position", "{", "x", ".", "Head", ".", "Location", ".", "Row", "}", ")", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}", ")", "\n", "ast", ".", "WalkExprs", "(", "module", ",", "func", "(", "x", "*", "ast", ".", "Expr", ")", "bool", "{", "if", "hasFileLocation", "(", "x", ".", "Location", ")", "{", "if", "!", "report", ".", "IsCovered", "(", "x", ".", "Location", ".", "File", ",", "x", ".", "Location", ".", "Row", ")", "{", "notCovered", "=", "append", "(", "notCovered", ",", "Position", "{", "x", ".", "Location", ".", "Row", "}", ")", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}", ")", "\n", "notCovered", ".", "Sort", "(", ")", "\n", "fr", ",", "ok", ":=", "report", ".", "Files", "[", "file", "]", "\n", "if", "!", "ok", "{", "fr", "=", "&", "FileReport", "{", "}", "\n", "report", ".", "Files", "[", "file", "]", "=", "fr", "\n", "}", "\n", "fr", ".", "NotCovered", "=", "sortedPositionSliceToRangeSlice", "(", "notCovered", ")", "\n", "}", "\n\n", "var", "coveredLoc", ",", "notCoveredLoc", "int", "\n", "var", "overallCoverage", "float64", "\n\n", "for", "_", ",", "fr", ":=", "range", "report", ".", "Files", "{", "fr", ".", "Coverage", "=", "fr", ".", "computeCoveragePercentage", "(", ")", "\n", "coveredLoc", "+=", "fr", ".", "locCovered", "(", ")", "\n", "notCoveredLoc", "+=", "fr", ".", "locNotCovered", "(", ")", "\n", "}", "\n", "totalLoc", ":=", "coveredLoc", "+", "notCoveredLoc", "\n\n", "if", "totalLoc", "!=", "0", "{", "overallCoverage", "=", "100.0", "*", "float64", "(", "coveredLoc", ")", "/", "float64", "(", "totalLoc", ")", "\n", "}", "\n", "report", ".", "Coverage", "=", "round", "(", "overallCoverage", ",", "2", ")", "\n\n", "return", "\n", "}" ]
// Report returns a coverage Report for the given modules.
[ "Report", "returns", "a", "coverage", "Report", "for", "the", "given", "modules", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/cover/cover.go#L35-L93
train
open-policy-agent/opa
cover/cover.go
Trace
func (c *Cover) Trace(event *topdown.Event) { switch event.Op { case topdown.ExitOp: if rule, ok := event.Node.(*ast.Rule); ok { c.setHit(rule.Head.Location) } case topdown.EvalOp: if expr := event.Node.(*ast.Expr); expr != nil { c.setHit(expr.Location) } } }
go
func (c *Cover) Trace(event *topdown.Event) { switch event.Op { case topdown.ExitOp: if rule, ok := event.Node.(*ast.Rule); ok { c.setHit(rule.Head.Location) } case topdown.EvalOp: if expr := event.Node.(*ast.Expr); expr != nil { c.setHit(expr.Location) } } }
[ "func", "(", "c", "*", "Cover", ")", "Trace", "(", "event", "*", "topdown", ".", "Event", ")", "{", "switch", "event", ".", "Op", "{", "case", "topdown", ".", "ExitOp", ":", "if", "rule", ",", "ok", ":=", "event", ".", "Node", ".", "(", "*", "ast", ".", "Rule", ")", ";", "ok", "{", "c", ".", "setHit", "(", "rule", ".", "Head", ".", "Location", ")", "\n", "}", "\n", "case", "topdown", ".", "EvalOp", ":", "if", "expr", ":=", "event", ".", "Node", ".", "(", "*", "ast", ".", "Expr", ")", ";", "expr", "!=", "nil", "{", "c", ".", "setHit", "(", "expr", ".", "Location", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Trace updates the coverage state.
[ "Trace", "updates", "the", "coverage", "state", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/cover/cover.go#L96-L107
train
open-policy-agent/opa
cover/cover.go
Sort
func (sl PositionSlice) Sort() { sort.Slice(sl, func(i, j int) bool { return sl[i].Row < sl[j].Row }) }
go
func (sl PositionSlice) Sort() { sort.Slice(sl, func(i, j int) bool { return sl[i].Row < sl[j].Row }) }
[ "func", "(", "sl", "PositionSlice", ")", "Sort", "(", ")", "{", "sort", ".", "Slice", "(", "sl", ",", "func", "(", "i", ",", "j", "int", ")", "bool", "{", "return", "sl", "[", "i", "]", ".", "Row", "<", "sl", "[", "j", "]", ".", "Row", "\n", "}", ")", "\n", "}" ]
// Sort sorts the slice by line number.
[ "Sort", "sorts", "the", "slice", "by", "line", "number", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/cover/cover.go#L129-L133
train
open-policy-agent/opa
cover/cover.go
In
func (r Range) In(row int) bool { return row >= r.Start.Row && row <= r.End.Row }
go
func (r Range) In(row int) bool { return row >= r.Start.Row && row <= r.End.Row }
[ "func", "(", "r", "Range", ")", "In", "(", "row", "int", ")", "bool", "{", "return", "row", ">=", "r", ".", "Start", ".", "Row", "&&", "row", "<=", "r", ".", "End", ".", "Row", "\n", "}" ]
// In returns true if the row is inside the range.
[ "In", "returns", "true", "if", "the", "row", "is", "inside", "the", "range", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/cover/cover.go#L142-L144
train
open-policy-agent/opa
cover/cover.go
IsCovered
func (fr *FileReport) IsCovered(row int) bool { if fr == nil { return false } for _, r := range fr.Covered { if r.In(row) { return true } } return false }
go
func (fr *FileReport) IsCovered(row int) bool { if fr == nil { return false } for _, r := range fr.Covered { if r.In(row) { return true } } return false }
[ "func", "(", "fr", "*", "FileReport", ")", "IsCovered", "(", "row", "int", ")", "bool", "{", "if", "fr", "==", "nil", "{", "return", "false", "\n", "}", "\n", "for", "_", ",", "r", ":=", "range", "fr", ".", "Covered", "{", "if", "r", ".", "In", "(", "row", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// IsCovered returns true if the row is marked as covered in the report.
[ "IsCovered", "returns", "true", "if", "the", "row", "is", "marked", "as", "covered", "in", "the", "report", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/cover/cover.go#L154-L164
train
open-policy-agent/opa
cover/cover.go
IsNotCovered
func (fr *FileReport) IsNotCovered(row int) bool { if fr == nil { return false } for _, r := range fr.NotCovered { if r.In(row) { return true } } return false }
go
func (fr *FileReport) IsNotCovered(row int) bool { if fr == nil { return false } for _, r := range fr.NotCovered { if r.In(row) { return true } } return false }
[ "func", "(", "fr", "*", "FileReport", ")", "IsNotCovered", "(", "row", "int", ")", "bool", "{", "if", "fr", "==", "nil", "{", "return", "false", "\n", "}", "\n", "for", "_", ",", "r", ":=", "range", "fr", ".", "NotCovered", "{", "if", "r", ".", "In", "(", "row", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// IsNotCovered returns true if the row is marked as NOT covered in the report. // This is not the same as simply not being reported. For example, certain // statements like imports are not included in the report.
[ "IsNotCovered", "returns", "true", "if", "the", "row", "is", "marked", "as", "NOT", "covered", "in", "the", "report", ".", "This", "is", "not", "the", "same", "as", "simply", "not", "being", "reported", ".", "For", "example", "certain", "statements", "like", "imports", "are", "not", "included", "in", "the", "report", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/cover/cover.go#L169-L179
train
open-policy-agent/opa
cover/cover.go
locCovered
func (fr *FileReport) locCovered() (loc int) { for _, r := range fr.Covered { loc += r.End.Row - r.Start.Row + 1 } return }
go
func (fr *FileReport) locCovered() (loc int) { for _, r := range fr.Covered { loc += r.End.Row - r.Start.Row + 1 } return }
[ "func", "(", "fr", "*", "FileReport", ")", "locCovered", "(", ")", "(", "loc", "int", ")", "{", "for", "_", ",", "r", ":=", "range", "fr", ".", "Covered", "{", "loc", "+=", "r", ".", "End", ".", "Row", "-", "r", ".", "Start", ".", "Row", "+", "1", "\n", "}", "\n", "return", "\n", "}" ]
// locCovered returns the number of lines of code covered by tests
[ "locCovered", "returns", "the", "number", "of", "lines", "of", "code", "covered", "by", "tests" ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/cover/cover.go#L182-L187
train
open-policy-agent/opa
cover/cover.go
locNotCovered
func (fr *FileReport) locNotCovered() (loc int) { for _, r := range fr.NotCovered { loc += r.End.Row - r.Start.Row + 1 } return }
go
func (fr *FileReport) locNotCovered() (loc int) { for _, r := range fr.NotCovered { loc += r.End.Row - r.Start.Row + 1 } return }
[ "func", "(", "fr", "*", "FileReport", ")", "locNotCovered", "(", ")", "(", "loc", "int", ")", "{", "for", "_", ",", "r", ":=", "range", "fr", ".", "NotCovered", "{", "loc", "+=", "r", ".", "End", ".", "Row", "-", "r", ".", "Start", ".", "Row", "+", "1", "\n", "}", "\n", "return", "\n", "}" ]
// locNotCovered returns the number of lines of code not covered by tests
[ "locNotCovered", "returns", "the", "number", "of", "lines", "of", "code", "not", "covered", "by", "tests" ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/cover/cover.go#L190-L195
train
open-policy-agent/opa
cover/cover.go
computeCoveragePercentage
func (fr *FileReport) computeCoveragePercentage() float64 { coveredLoc := fr.locCovered() notCoveredLoc := fr.locNotCovered() totalLoc := coveredLoc + notCoveredLoc if totalLoc == 0 { return 0.0 } return round(100.0*float64(coveredLoc)/float64(totalLoc), 2) }
go
func (fr *FileReport) computeCoveragePercentage() float64 { coveredLoc := fr.locCovered() notCoveredLoc := fr.locNotCovered() totalLoc := coveredLoc + notCoveredLoc if totalLoc == 0 { return 0.0 } return round(100.0*float64(coveredLoc)/float64(totalLoc), 2) }
[ "func", "(", "fr", "*", "FileReport", ")", "computeCoveragePercentage", "(", ")", "float64", "{", "coveredLoc", ":=", "fr", ".", "locCovered", "(", ")", "\n", "notCoveredLoc", ":=", "fr", ".", "locNotCovered", "(", ")", "\n", "totalLoc", ":=", "coveredLoc", "+", "notCoveredLoc", "\n\n", "if", "totalLoc", "==", "0", "{", "return", "0.0", "\n", "}", "\n\n", "return", "round", "(", "100.0", "*", "float64", "(", "coveredLoc", ")", "/", "float64", "(", "totalLoc", ")", ",", "2", ")", "\n", "}" ]
// computeCoveragePercentage returns the code coverage percentage of the file
[ "computeCoveragePercentage", "returns", "the", "code", "coverage", "percentage", "of", "the", "file" ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/cover/cover.go#L198-L208
train
open-policy-agent/opa
cover/cover.go
IsCovered
func (r Report) IsCovered(file string, row int) bool { return r.Files[file].IsCovered(row) }
go
func (r Report) IsCovered(file string, row int) bool { return r.Files[file].IsCovered(row) }
[ "func", "(", "r", "Report", ")", "IsCovered", "(", "file", "string", ",", "row", "int", ")", "bool", "{", "return", "r", ".", "Files", "[", "file", "]", ".", "IsCovered", "(", "row", ")", "\n", "}" ]
// IsCovered returns true if the row in the given file is covered.
[ "IsCovered", "returns", "true", "if", "the", "row", "in", "the", "given", "file", "is", "covered", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/cover/cover.go#L217-L219
train
open-policy-agent/opa
cover/cover.go
round
func round(number float64, precision int) float64 { return math.Round(number*10*float64(precision)) / (10.0 * float64(precision)) }
go
func round(number float64, precision int) float64 { return math.Round(number*10*float64(precision)) / (10.0 * float64(precision)) }
[ "func", "round", "(", "number", "float64", ",", "precision", "int", ")", "float64", "{", "return", "math", ".", "Round", "(", "number", "*", "10", "*", "float64", "(", "precision", ")", ")", "/", "(", "10.0", "*", "float64", "(", "precision", ")", ")", "\n", "}" ]
// round returns the number with the specified precision.
[ "round", "returns", "the", "number", "with", "the", "specified", "precision", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/cover/cover.go#L258-L260
train
open-policy-agent/opa
internal/planner/planner.go
New
func New() *Planner { return &Planner{ lcurr: ir.Input + 1, vars: map[ast.Var]ir.Local{ ast.InputRootDocument.Value.(ast.Var): ir.Input, }, } }
go
func New() *Planner { return &Planner{ lcurr: ir.Input + 1, vars: map[ast.Var]ir.Local{ ast.InputRootDocument.Value.(ast.Var): ir.Input, }, } }
[ "func", "New", "(", ")", "*", "Planner", "{", "return", "&", "Planner", "{", "lcurr", ":", "ir", ".", "Input", "+", "1", ",", "vars", ":", "map", "[", "ast", ".", "Var", "]", "ir", ".", "Local", "{", "ast", ".", "InputRootDocument", ".", "Value", ".", "(", "ast", ".", "Var", ")", ":", "ir", ".", "Input", ",", "}", ",", "}", "\n", "}" ]
// New returns a new Planner object.
[ "New", "returns", "a", "new", "Planner", "object", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/planner/planner.go#L30-L37
train
open-policy-agent/opa
internal/planner/planner.go
WithQueries
func (p *Planner) WithQueries(queries []ast.Body) *Planner { p.queries = queries return p }
go
func (p *Planner) WithQueries(queries []ast.Body) *Planner { p.queries = queries return p }
[ "func", "(", "p", "*", "Planner", ")", "WithQueries", "(", "queries", "[", "]", "ast", ".", "Body", ")", "*", "Planner", "{", "p", ".", "queries", "=", "queries", "\n", "return", "p", "\n", "}" ]
// WithQueries sets the query set to generate a plan for.
[ "WithQueries", "sets", "the", "query", "set", "to", "generate", "a", "plan", "for", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/planner/planner.go#L40-L43
train
open-policy-agent/opa
internal/planner/planner.go
Plan
func (p *Planner) Plan() (*ir.Policy, error) { for _, q := range p.queries { p.curr = &ir.Block{} defined := false if err := p.planQuery(q, 0, func() error { p.appendStmt(ir.ReturnStmt{ Code: ir.Defined, }) defined = true return nil }); err != nil { return nil, err } if defined { p.blocks = append(p.blocks, *p.curr) } } p.blocks = append(p.blocks, ir.Block{ Stmts: []ir.Stmt{ ir.ReturnStmt{ Code: ir.Undefined, }, }, }) policy := ir.Policy{ Static: ir.Static{ Strings: p.strings, }, Plan: ir.Plan{ Blocks: p.blocks, }, } return &policy, nil }
go
func (p *Planner) Plan() (*ir.Policy, error) { for _, q := range p.queries { p.curr = &ir.Block{} defined := false if err := p.planQuery(q, 0, func() error { p.appendStmt(ir.ReturnStmt{ Code: ir.Defined, }) defined = true return nil }); err != nil { return nil, err } if defined { p.blocks = append(p.blocks, *p.curr) } } p.blocks = append(p.blocks, ir.Block{ Stmts: []ir.Stmt{ ir.ReturnStmt{ Code: ir.Undefined, }, }, }) policy := ir.Policy{ Static: ir.Static{ Strings: p.strings, }, Plan: ir.Plan{ Blocks: p.blocks, }, } return &policy, nil }
[ "func", "(", "p", "*", "Planner", ")", "Plan", "(", ")", "(", "*", "ir", ".", "Policy", ",", "error", ")", "{", "for", "_", ",", "q", ":=", "range", "p", ".", "queries", "{", "p", ".", "curr", "=", "&", "ir", ".", "Block", "{", "}", "\n", "defined", ":=", "false", "\n\n", "if", "err", ":=", "p", ".", "planQuery", "(", "q", ",", "0", ",", "func", "(", ")", "error", "{", "p", ".", "appendStmt", "(", "ir", ".", "ReturnStmt", "{", "Code", ":", "ir", ".", "Defined", ",", "}", ")", "\n", "defined", "=", "true", "\n", "return", "nil", "\n", "}", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "defined", "{", "p", ".", "blocks", "=", "append", "(", "p", ".", "blocks", ",", "*", "p", ".", "curr", ")", "\n", "}", "\n", "}", "\n\n", "p", ".", "blocks", "=", "append", "(", "p", ".", "blocks", ",", "ir", ".", "Block", "{", "Stmts", ":", "[", "]", "ir", ".", "Stmt", "{", "ir", ".", "ReturnStmt", "{", "Code", ":", "ir", ".", "Undefined", ",", "}", ",", "}", ",", "}", ")", "\n\n", "policy", ":=", "ir", ".", "Policy", "{", "Static", ":", "ir", ".", "Static", "{", "Strings", ":", "p", ".", "strings", ",", "}", ",", "Plan", ":", "ir", ".", "Plan", "{", "Blocks", ":", "p", ".", "blocks", ",", "}", ",", "}", "\n\n", "return", "&", "policy", ",", "nil", "\n", "}" ]
// Plan returns a IR plan for the policy query.
[ "Plan", "returns", "a", "IR", "plan", "for", "the", "policy", "query", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/planner/planner.go#L46-L85
train
open-policy-agent/opa
loader/loader.go
ParsedModules
func (l *Result) ParsedModules() map[string]*ast.Module { modules := make(map[string]*ast.Module) for _, module := range l.Modules { modules[module.Name] = module.Parsed } return modules }
go
func (l *Result) ParsedModules() map[string]*ast.Module { modules := make(map[string]*ast.Module) for _, module := range l.Modules { modules[module.Name] = module.Parsed } return modules }
[ "func", "(", "l", "*", "Result", ")", "ParsedModules", "(", ")", "map", "[", "string", "]", "*", "ast", ".", "Module", "{", "modules", ":=", "make", "(", "map", "[", "string", "]", "*", "ast", ".", "Module", ")", "\n", "for", "_", ",", "module", ":=", "range", "l", ".", "Modules", "{", "modules", "[", "module", ".", "Name", "]", "=", "module", ".", "Parsed", "\n", "}", "\n", "return", "modules", "\n", "}" ]
// ParsedModules returns the parsed modules stored on the result.
[ "ParsedModules", "returns", "the", "parsed", "modules", "stored", "on", "the", "result", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/loader/loader.go#L33-L39
train
open-policy-agent/opa
loader/loader.go
Compiler
func (l *Result) Compiler() (*ast.Compiler, error) { compiler := ast.NewCompiler() compiler.Compile(l.ParsedModules()) if compiler.Failed() { return nil, compiler.Errors } return compiler, nil }
go
func (l *Result) Compiler() (*ast.Compiler, error) { compiler := ast.NewCompiler() compiler.Compile(l.ParsedModules()) if compiler.Failed() { return nil, compiler.Errors } return compiler, nil }
[ "func", "(", "l", "*", "Result", ")", "Compiler", "(", ")", "(", "*", "ast", ".", "Compiler", ",", "error", ")", "{", "compiler", ":=", "ast", ".", "NewCompiler", "(", ")", "\n", "compiler", ".", "Compile", "(", "l", ".", "ParsedModules", "(", ")", ")", "\n", "if", "compiler", ".", "Failed", "(", ")", "{", "return", "nil", ",", "compiler", ".", "Errors", "\n", "}", "\n", "return", "compiler", ",", "nil", "\n", "}" ]
// Compiler returns a Compiler object with the compiled modules from this loader // result.
[ "Compiler", "returns", "a", "Compiler", "object", "with", "the", "compiled", "modules", "from", "this", "loader", "result", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/loader/loader.go#L43-L50
train
open-policy-agent/opa
loader/loader.go
Store
func (l *Result) Store() (storage.Store, error) { return inmem.NewFromObject(l.Documents), nil }
go
func (l *Result) Store() (storage.Store, error) { return inmem.NewFromObject(l.Documents), nil }
[ "func", "(", "l", "*", "Result", ")", "Store", "(", ")", "(", "storage", ".", "Store", ",", "error", ")", "{", "return", "inmem", ".", "NewFromObject", "(", "l", ".", "Documents", ")", ",", "nil", "\n", "}" ]
// Store returns a Store object with the documents from this loader result.
[ "Store", "returns", "a", "Store", "object", "with", "the", "documents", "from", "this", "loader", "result", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/loader/loader.go#L53-L55
train
open-policy-agent/opa
loader/loader.go
GlobExcludeName
func GlobExcludeName(pattern string, minDepth int) Filter { return func(abspath string, info os.FileInfo, depth int) bool { match, _ := filepath.Match(pattern, info.Name()) return match && depth >= minDepth } }
go
func GlobExcludeName(pattern string, minDepth int) Filter { return func(abspath string, info os.FileInfo, depth int) bool { match, _ := filepath.Match(pattern, info.Name()) return match && depth >= minDepth } }
[ "func", "GlobExcludeName", "(", "pattern", "string", ",", "minDepth", "int", ")", "Filter", "{", "return", "func", "(", "abspath", "string", ",", "info", "os", ".", "FileInfo", ",", "depth", "int", ")", "bool", "{", "match", ",", "_", ":=", "filepath", ".", "Match", "(", "pattern", ",", "info", ".", "Name", "(", ")", ")", "\n", "return", "match", "&&", "depth", ">=", "minDepth", "\n", "}", "\n", "}" ]
// GlobExcludeName excludes files and directories whose names do not match the // shell style pattern at minDepth or greater.
[ "GlobExcludeName", "excludes", "files", "and", "directories", "whose", "names", "do", "not", "match", "the", "shell", "style", "pattern", "at", "minDepth", "or", "greater", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/loader/loader.go#L70-L75
train
open-policy-agent/opa
loader/loader.go
Rego
func Rego(path string) (*RegoFile, error) { bs, err := ioutil.ReadFile(path) if err != nil { return nil, err } return loadRego(path, bs) }
go
func Rego(path string) (*RegoFile, error) { bs, err := ioutil.ReadFile(path) if err != nil { return nil, err } return loadRego(path, bs) }
[ "func", "Rego", "(", "path", "string", ")", "(", "*", "RegoFile", ",", "error", ")", "{", "bs", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "loadRego", "(", "path", ",", "bs", ")", "\n", "}" ]
// Rego returns a RegoFile object loaded from the given path.
[ "Rego", "returns", "a", "RegoFile", "object", "loaded", "from", "the", "given", "path", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/loader/loader.go#L120-L126
train
open-policy-agent/opa
loader/loader.go
Paths
func Paths(path string, recurse bool) (paths []string, err error) { err = filepath.Walk(path, func(f string, info os.FileInfo, err error) error { if !recurse { if path != f && path != filepath.Dir(f) { return filepath.SkipDir } } paths = append(paths, f) return nil }) return paths, err }
go
func Paths(path string, recurse bool) (paths []string, err error) { err = filepath.Walk(path, func(f string, info os.FileInfo, err error) error { if !recurse { if path != f && path != filepath.Dir(f) { return filepath.SkipDir } } paths = append(paths, f) return nil }) return paths, err }
[ "func", "Paths", "(", "path", "string", ",", "recurse", "bool", ")", "(", "paths", "[", "]", "string", ",", "err", "error", ")", "{", "err", "=", "filepath", ".", "Walk", "(", "path", ",", "func", "(", "f", "string", ",", "info", "os", ".", "FileInfo", ",", "err", "error", ")", "error", "{", "if", "!", "recurse", "{", "if", "path", "!=", "f", "&&", "path", "!=", "filepath", ".", "Dir", "(", "f", ")", "{", "return", "filepath", ".", "SkipDir", "\n", "}", "\n", "}", "\n", "paths", "=", "append", "(", "paths", ",", "f", ")", "\n", "return", "nil", "\n", "}", ")", "\n", "return", "paths", ",", "err", "\n", "}" ]
// Paths returns a sorted list of files contained at path. If recurse is true // and path is a directory, then Paths will walk the directory structure // recursively and list files at each level.
[ "Paths", "returns", "a", "sorted", "list", "of", "files", "contained", "at", "path", ".", "If", "recurse", "is", "true", "and", "path", "is", "a", "directory", "then", "Paths", "will", "walk", "the", "directory", "structure", "recursively", "and", "list", "files", "at", "each", "level", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/loader/loader.go#L136-L147
train
open-policy-agent/opa
loader/loader.go
SplitPrefix
func SplitPrefix(path string) ([]string, string) { parts := strings.SplitN(path, ":", 2) if len(parts) == 2 && len(parts[0]) > 0 { return strings.Split(parts[0], "."), parts[1] } return nil, path }
go
func SplitPrefix(path string) ([]string, string) { parts := strings.SplitN(path, ":", 2) if len(parts) == 2 && len(parts[0]) > 0 { return strings.Split(parts[0], "."), parts[1] } return nil, path }
[ "func", "SplitPrefix", "(", "path", "string", ")", "(", "[", "]", "string", ",", "string", ")", "{", "parts", ":=", "strings", ".", "SplitN", "(", "path", ",", "\"", "\"", ",", "2", ")", "\n", "if", "len", "(", "parts", ")", "==", "2", "&&", "len", "(", "parts", "[", "0", "]", ")", ">", "0", "{", "return", "strings", ".", "Split", "(", "parts", "[", "0", "]", ",", "\"", "\"", ")", ",", "parts", "[", "1", "]", "\n", "}", "\n", "return", "nil", ",", "path", "\n", "}" ]
// SplitPrefix returns a tuple specifying the document prefix and the file // path.
[ "SplitPrefix", "returns", "a", "tuple", "specifying", "the", "document", "prefix", "and", "the", "file", "path", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/loader/loader.go#L151-L157
train
open-policy-agent/opa
internal/wasm/encoding/reader.go
ReadModule
func ReadModule(r io.Reader) (*module.Module, error) { wr := &reader{r: r, n: 0} module, err := readModule(wr) if err != nil { return nil, errors.Wrapf(err, "offset 0x%x", wr.n) } return module, nil }
go
func ReadModule(r io.Reader) (*module.Module, error) { wr := &reader{r: r, n: 0} module, err := readModule(wr) if err != nil { return nil, errors.Wrapf(err, "offset 0x%x", wr.n) } return module, nil }
[ "func", "ReadModule", "(", "r", "io", ".", "Reader", ")", "(", "*", "module", ".", "Module", ",", "error", ")", "{", "wr", ":=", "&", "reader", "{", "r", ":", "r", ",", "n", ":", "0", "}", "\n", "module", ",", "err", ":=", "readModule", "(", "wr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "wr", ".", "n", ")", "\n", "}", "\n\n", "return", "module", ",", "nil", "\n", "}" ]
// ReadModule reads a binary-encoded WASM module from r.
[ "ReadModule", "reads", "a", "binary", "-", "encoded", "WASM", "module", "from", "r", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/wasm/encoding/reader.go#L23-L32
train
open-policy-agent/opa
internal/wasm/encoding/reader.go
ReadCodeEntry
func ReadCodeEntry(r io.Reader) (*module.CodeEntry, error) { wr := &reader{r: r, n: 0} entry, err := readCodeEntry(wr) if err != nil { return nil, errors.Wrapf(err, "offset 0x%x", wr.n) } return entry, nil }
go
func ReadCodeEntry(r io.Reader) (*module.CodeEntry, error) { wr := &reader{r: r, n: 0} entry, err := readCodeEntry(wr) if err != nil { return nil, errors.Wrapf(err, "offset 0x%x", wr.n) } return entry, nil }
[ "func", "ReadCodeEntry", "(", "r", "io", ".", "Reader", ")", "(", "*", "module", ".", "CodeEntry", ",", "error", ")", "{", "wr", ":=", "&", "reader", "{", "r", ":", "r", ",", "n", ":", "0", "}", "\n", "entry", ",", "err", ":=", "readCodeEntry", "(", "wr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "wr", ".", "n", ")", "\n", "}", "\n\n", "return", "entry", ",", "nil", "\n", "}" ]
// ReadCodeEntry reads a binary-encoded WASM code entry from r.
[ "ReadCodeEntry", "reads", "a", "binary", "-", "encoded", "WASM", "code", "entry", "from", "r", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/wasm/encoding/reader.go#L35-L44
train
open-policy-agent/opa
internal/wasm/encoding/reader.go
CodeEntries
func CodeEntries(m *module.Module) ([]*module.CodeEntry, error) { entries := make([]*module.CodeEntry, len(m.Code.Segments)) for i, s := range m.Code.Segments { buf := bytes.NewBuffer(s.Code) entry, err := ReadCodeEntry(buf) if err != nil { return nil, err } entries[i] = entry } return entries, nil }
go
func CodeEntries(m *module.Module) ([]*module.CodeEntry, error) { entries := make([]*module.CodeEntry, len(m.Code.Segments)) for i, s := range m.Code.Segments { buf := bytes.NewBuffer(s.Code) entry, err := ReadCodeEntry(buf) if err != nil { return nil, err } entries[i] = entry } return entries, nil }
[ "func", "CodeEntries", "(", "m", "*", "module", ".", "Module", ")", "(", "[", "]", "*", "module", ".", "CodeEntry", ",", "error", ")", "{", "entries", ":=", "make", "(", "[", "]", "*", "module", ".", "CodeEntry", ",", "len", "(", "m", ".", "Code", ".", "Segments", ")", ")", "\n\n", "for", "i", ",", "s", ":=", "range", "m", ".", "Code", ".", "Segments", "{", "buf", ":=", "bytes", ".", "NewBuffer", "(", "s", ".", "Code", ")", "\n", "entry", ",", "err", ":=", "ReadCodeEntry", "(", "buf", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "entries", "[", "i", "]", "=", "entry", "\n", "}", "\n\n", "return", "entries", ",", "nil", "\n", "}" ]
// CodeEntries returns the WASM code entries contained in r.
[ "CodeEntries", "returns", "the", "WASM", "code", "entries", "contained", "in", "r", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/wasm/encoding/reader.go#L47-L61
train
open-policy-agent/opa
plugins/bundle/status.go
SetActivateSuccess
func (s *Status) SetActivateSuccess(revision string) { s.LastSuccessfulActivation = time.Now().UTC() s.ActiveRevision = revision }
go
func (s *Status) SetActivateSuccess(revision string) { s.LastSuccessfulActivation = time.Now().UTC() s.ActiveRevision = revision }
[ "func", "(", "s", "*", "Status", ")", "SetActivateSuccess", "(", "revision", "string", ")", "{", "s", ".", "LastSuccessfulActivation", "=", "time", ".", "Now", "(", ")", ".", "UTC", "(", ")", "\n", "s", ".", "ActiveRevision", "=", "revision", "\n", "}" ]
// SetActivateSuccess updates the status object to reflect a successful // activation.
[ "SetActivateSuccess", "updates", "the", "status", "object", "to", "reflect", "a", "successful", "activation", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/plugins/bundle/status.go#L32-L35
train
open-policy-agent/opa
plugins/bundle/status.go
SetError
func (s *Status) SetError(err error) { if err == nil { s.Code = "" s.Message = "" s.Errors = nil return } cause := errors.Cause(err) if astErr, ok := cause.(ast.Errors); ok { s.Code = errCode s.Message = types.MsgCompileModuleError s.Errors = make([]error, len(astErr)) for i := range astErr { s.Errors[i] = astErr[i] } } else { s.Code = errCode s.Message = err.Error() s.Errors = nil } }
go
func (s *Status) SetError(err error) { if err == nil { s.Code = "" s.Message = "" s.Errors = nil return } cause := errors.Cause(err) if astErr, ok := cause.(ast.Errors); ok { s.Code = errCode s.Message = types.MsgCompileModuleError s.Errors = make([]error, len(astErr)) for i := range astErr { s.Errors[i] = astErr[i] } } else { s.Code = errCode s.Message = err.Error() s.Errors = nil } }
[ "func", "(", "s", "*", "Status", ")", "SetError", "(", "err", "error", ")", "{", "if", "err", "==", "nil", "{", "s", ".", "Code", "=", "\"", "\"", "\n", "s", ".", "Message", "=", "\"", "\"", "\n", "s", ".", "Errors", "=", "nil", "\n", "return", "\n", "}", "\n\n", "cause", ":=", "errors", ".", "Cause", "(", "err", ")", "\n\n", "if", "astErr", ",", "ok", ":=", "cause", ".", "(", "ast", ".", "Errors", ")", ";", "ok", "{", "s", ".", "Code", "=", "errCode", "\n", "s", ".", "Message", "=", "types", ".", "MsgCompileModuleError", "\n", "s", ".", "Errors", "=", "make", "(", "[", "]", "error", ",", "len", "(", "astErr", ")", ")", "\n", "for", "i", ":=", "range", "astErr", "{", "s", ".", "Errors", "[", "i", "]", "=", "astErr", "[", "i", "]", "\n", "}", "\n", "}", "else", "{", "s", ".", "Code", "=", "errCode", "\n", "s", ".", "Message", "=", "err", ".", "Error", "(", ")", "\n", "s", ".", "Errors", "=", "nil", "\n", "}", "\n", "}" ]
// SetError updates the status object to reflect a failure to download or // activate. If err is nil, the error status is cleared.
[ "SetError", "updates", "the", "status", "object", "to", "reflect", "a", "failure", "to", "download", "or", "activate", ".", "If", "err", "is", "nil", "the", "error", "status", "is", "cleared", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/plugins/bundle/status.go#L45-L68
train
open-policy-agent/opa
ast/index.go
NewIndexResult
func NewIndexResult(kind DocKind) *IndexResult { return &IndexResult{ Kind: kind, Else: map[*Rule][]*Rule{}, } }
go
func NewIndexResult(kind DocKind) *IndexResult { return &IndexResult{ Kind: kind, Else: map[*Rule][]*Rule{}, } }
[ "func", "NewIndexResult", "(", "kind", "DocKind", ")", "*", "IndexResult", "{", "return", "&", "IndexResult", "{", "Kind", ":", "kind", ",", "Else", ":", "map", "[", "*", "Rule", "]", "[", "]", "*", "Rule", "{", "}", ",", "}", "\n", "}" ]
// NewIndexResult returns a new IndexResult object.
[ "NewIndexResult", "returns", "a", "new", "IndexResult", "object", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/index.go#L37-L42
train
open-policy-agent/opa
ast/index.go
Empty
func (ir *IndexResult) Empty() bool { return len(ir.Rules) == 0 && ir.Default == nil }
go
func (ir *IndexResult) Empty() bool { return len(ir.Rules) == 0 && ir.Default == nil }
[ "func", "(", "ir", "*", "IndexResult", ")", "Empty", "(", ")", "bool", "{", "return", "len", "(", "ir", ".", "Rules", ")", "==", "0", "&&", "ir", ".", "Default", "==", "nil", "\n", "}" ]
// Empty returns true if there are no rules to evaluate.
[ "Empty", "returns", "true", "if", "there", "are", "no", "rules", "to", "evaluate", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/index.go#L45-L47
train
open-policy-agent/opa
internal/ir/pretty.go
Pretty
func Pretty(w io.Writer, x interface{}) { pp := &prettyPrinter{ depth: -1, w: w, } Walk(pp, x) }
go
func Pretty(w io.Writer, x interface{}) { pp := &prettyPrinter{ depth: -1, w: w, } Walk(pp, x) }
[ "func", "Pretty", "(", "w", "io", ".", "Writer", ",", "x", "interface", "{", "}", ")", "{", "pp", ":=", "&", "prettyPrinter", "{", "depth", ":", "-", "1", ",", "w", ":", "w", ",", "}", "\n", "Walk", "(", "pp", ",", "x", ")", "\n", "}" ]
// Pretty writes a human-readable representation of an IR object to w.
[ "Pretty", "writes", "a", "human", "-", "readable", "representation", "of", "an", "IR", "object", "to", "w", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/ir/pretty.go#L14-L21
train
open-policy-agent/opa
server/writer/writer.go
ErrorAuto
func ErrorAuto(w http.ResponseWriter, err error) { if types.IsBadRequest(err) { ErrorString(w, http.StatusBadRequest, types.CodeInvalidParameter, err) return } if storage.IsWriteConflictError(err) { ErrorString(w, http.StatusNotFound, types.CodeResourceConflict, err) return } if topdown.IsError(err) { Error(w, http.StatusInternalServerError, types.NewErrorV1(types.CodeInternal, types.MsgEvaluationError).WithError(err)) return } if storage.IsInvalidPatch(err) { ErrorString(w, http.StatusBadRequest, types.CodeInvalidParameter, err) return } if storage.IsNotFound(err) { ErrorString(w, http.StatusNotFound, types.CodeResourceNotFound, err) return } ErrorString(w, http.StatusInternalServerError, types.CodeInternal, err) }
go
func ErrorAuto(w http.ResponseWriter, err error) { if types.IsBadRequest(err) { ErrorString(w, http.StatusBadRequest, types.CodeInvalidParameter, err) return } if storage.IsWriteConflictError(err) { ErrorString(w, http.StatusNotFound, types.CodeResourceConflict, err) return } if topdown.IsError(err) { Error(w, http.StatusInternalServerError, types.NewErrorV1(types.CodeInternal, types.MsgEvaluationError).WithError(err)) return } if storage.IsInvalidPatch(err) { ErrorString(w, http.StatusBadRequest, types.CodeInvalidParameter, err) return } if storage.IsNotFound(err) { ErrorString(w, http.StatusNotFound, types.CodeResourceNotFound, err) return } ErrorString(w, http.StatusInternalServerError, types.CodeInternal, err) }
[ "func", "ErrorAuto", "(", "w", "http", ".", "ResponseWriter", ",", "err", "error", ")", "{", "if", "types", ".", "IsBadRequest", "(", "err", ")", "{", "ErrorString", "(", "w", ",", "http", ".", "StatusBadRequest", ",", "types", ".", "CodeInvalidParameter", ",", "err", ")", "\n", "return", "\n", "}", "\n\n", "if", "storage", ".", "IsWriteConflictError", "(", "err", ")", "{", "ErrorString", "(", "w", ",", "http", ".", "StatusNotFound", ",", "types", ".", "CodeResourceConflict", ",", "err", ")", "\n", "return", "\n", "}", "\n\n", "if", "topdown", ".", "IsError", "(", "err", ")", "{", "Error", "(", "w", ",", "http", ".", "StatusInternalServerError", ",", "types", ".", "NewErrorV1", "(", "types", ".", "CodeInternal", ",", "types", ".", "MsgEvaluationError", ")", ".", "WithError", "(", "err", ")", ")", "\n", "return", "\n", "}", "\n\n", "if", "storage", ".", "IsInvalidPatch", "(", "err", ")", "{", "ErrorString", "(", "w", ",", "http", ".", "StatusBadRequest", ",", "types", ".", "CodeInvalidParameter", ",", "err", ")", "\n", "return", "\n", "}", "\n\n", "if", "storage", ".", "IsNotFound", "(", "err", ")", "{", "ErrorString", "(", "w", ",", "http", ".", "StatusNotFound", ",", "types", ".", "CodeResourceNotFound", ",", "err", ")", "\n", "return", "\n", "}", "\n\n", "ErrorString", "(", "w", ",", "http", ".", "StatusInternalServerError", ",", "types", ".", "CodeInternal", ",", "err", ")", "\n", "}" ]
// ErrorAuto writes a response with status and code set automatically based on // the type of err.
[ "ErrorAuto", "writes", "a", "response", "with", "status", "and", "code", "set", "automatically", "based", "on", "the", "type", "of", "err", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/writer/writer.go#L27-L54
train
open-policy-agent/opa
server/writer/writer.go
ErrorString
func ErrorString(w http.ResponseWriter, status int, code string, err error) { Error(w, status, types.NewErrorV1(code, err.Error())) }
go
func ErrorString(w http.ResponseWriter, status int, code string, err error) { Error(w, status, types.NewErrorV1(code, err.Error())) }
[ "func", "ErrorString", "(", "w", "http", ".", "ResponseWriter", ",", "status", "int", ",", "code", "string", ",", "err", "error", ")", "{", "Error", "(", "w", ",", "status", ",", "types", ".", "NewErrorV1", "(", "code", ",", "err", ".", "Error", "(", ")", ")", ")", "\n", "}" ]
// ErrorString writes a response with specified status, code, and message set to // the the err's string representation.
[ "ErrorString", "writes", "a", "response", "with", "specified", "status", "code", "and", "message", "set", "to", "the", "the", "err", "s", "string", "representation", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/writer/writer.go#L58-L60
train
open-policy-agent/opa
server/writer/writer.go
Error
func Error(w http.ResponseWriter, status int, err *types.ErrorV1) { headers := w.Header() headers.Add("Content-Type", "application/json") Bytes(w, status, err.Bytes()) w.Write([]byte("\n")) }
go
func Error(w http.ResponseWriter, status int, err *types.ErrorV1) { headers := w.Header() headers.Add("Content-Type", "application/json") Bytes(w, status, err.Bytes()) w.Write([]byte("\n")) }
[ "func", "Error", "(", "w", "http", ".", "ResponseWriter", ",", "status", "int", ",", "err", "*", "types", ".", "ErrorV1", ")", "{", "headers", ":=", "w", ".", "Header", "(", ")", "\n", "headers", ".", "Add", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "Bytes", "(", "w", ",", "status", ",", "err", ".", "Bytes", "(", ")", ")", "\n", "w", ".", "Write", "(", "[", "]", "byte", "(", "\"", "\\n", "\"", ")", ")", "\n", "}" ]
// Error writes a response with specified status and error response.
[ "Error", "writes", "a", "response", "with", "specified", "status", "and", "error", "response", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/writer/writer.go#L63-L68
train
open-policy-agent/opa
server/writer/writer.go
JSON
func JSON(w http.ResponseWriter, code int, v interface{}, pretty bool) { var bs []byte var err error if pretty { bs, err = json.MarshalIndent(v, "", " ") } else { bs, err = json.Marshal(v) } if err != nil { ErrorAuto(w, err) return } headers := w.Header() headers.Add("Content-Type", "application/json") Bytes(w, code, bs) if pretty { w.Write([]byte("\n")) } }
go
func JSON(w http.ResponseWriter, code int, v interface{}, pretty bool) { var bs []byte var err error if pretty { bs, err = json.MarshalIndent(v, "", " ") } else { bs, err = json.Marshal(v) } if err != nil { ErrorAuto(w, err) return } headers := w.Header() headers.Add("Content-Type", "application/json") Bytes(w, code, bs) if pretty { w.Write([]byte("\n")) } }
[ "func", "JSON", "(", "w", "http", ".", "ResponseWriter", ",", "code", "int", ",", "v", "interface", "{", "}", ",", "pretty", "bool", ")", "{", "var", "bs", "[", "]", "byte", "\n", "var", "err", "error", "\n\n", "if", "pretty", "{", "bs", ",", "err", "=", "json", ".", "MarshalIndent", "(", "v", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "}", "else", "{", "bs", ",", "err", "=", "json", ".", "Marshal", "(", "v", ")", "\n", "}", "\n\n", "if", "err", "!=", "nil", "{", "ErrorAuto", "(", "w", ",", "err", ")", "\n", "return", "\n", "}", "\n", "headers", ":=", "w", ".", "Header", "(", ")", "\n", "headers", ".", "Add", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "Bytes", "(", "w", ",", "code", ",", "bs", ")", "\n\n", "if", "pretty", "{", "w", ".", "Write", "(", "[", "]", "byte", "(", "\"", "\\n", "\"", ")", ")", "\n", "}", "\n", "}" ]
// JSON writes a response with the specified status code and object. The object // will be JSON serialized.
[ "JSON", "writes", "a", "response", "with", "the", "specified", "status", "code", "and", "object", ".", "The", "object", "will", "be", "JSON", "serialized", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/writer/writer.go#L72-L94
train
open-policy-agent/opa
server/writer/writer.go
Bytes
func Bytes(w http.ResponseWriter, code int, bs []byte) { w.WriteHeader(code) if code == 204 { return } w.Write(bs) }
go
func Bytes(w http.ResponseWriter, code int, bs []byte) { w.WriteHeader(code) if code == 204 { return } w.Write(bs) }
[ "func", "Bytes", "(", "w", "http", ".", "ResponseWriter", ",", "code", "int", ",", "bs", "[", "]", "byte", ")", "{", "w", ".", "WriteHeader", "(", "code", ")", "\n", "if", "code", "==", "204", "{", "return", "\n", "}", "\n", "w", ".", "Write", "(", "bs", ")", "\n", "}" ]
// Bytes writes a response with the specified status code and bytes.
[ "Bytes", "writes", "a", "response", "with", "the", "specified", "status", "code", "and", "bytes", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/writer/writer.go#L97-L103
train
open-policy-agent/opa
ast/conflicts.go
CheckPathConflicts
func CheckPathConflicts(c *Compiler, exists func([]string) (bool, error)) Errors { var errs Errors root := c.RuleTree.Child(DefaultRootDocument.Value) if root == nil { return nil } for _, node := range root.Children { errs = append(errs, checkDocumentConflicts(node, exists, nil)...) } return errs }
go
func CheckPathConflicts(c *Compiler, exists func([]string) (bool, error)) Errors { var errs Errors root := c.RuleTree.Child(DefaultRootDocument.Value) if root == nil { return nil } for _, node := range root.Children { errs = append(errs, checkDocumentConflicts(node, exists, nil)...) } return errs }
[ "func", "CheckPathConflicts", "(", "c", "*", "Compiler", ",", "exists", "func", "(", "[", "]", "string", ")", "(", "bool", ",", "error", ")", ")", "Errors", "{", "var", "errs", "Errors", "\n\n", "root", ":=", "c", ".", "RuleTree", ".", "Child", "(", "DefaultRootDocument", ".", "Value", ")", "\n", "if", "root", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "for", "_", ",", "node", ":=", "range", "root", ".", "Children", "{", "errs", "=", "append", "(", "errs", ",", "checkDocumentConflicts", "(", "node", ",", "exists", ",", "nil", ")", "...", ")", "\n", "}", "\n\n", "return", "errs", "\n", "}" ]
// CheckPathConflicts returns a set of errors indicating paths that // are in conflict with the result of the provided callable.
[ "CheckPathConflicts", "returns", "a", "set", "of", "errors", "indicating", "paths", "that", "are", "in", "conflict", "with", "the", "result", "of", "the", "provided", "callable", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/conflicts.go#L13-L26
train
open-policy-agent/opa
internal/version/version.go
Write
func Write(ctx context.Context, store storage.Store, txn storage.Transaction) error { if err := storage.MakeDir(ctx, store, txn, versionPath); err != nil { return err } if err := store.Write(ctx, txn, storage.AddOp, versionPath, map[string]interface{}{ "version": version.Version, "build_commit": version.Vcs, "build_timestamp": version.Timestamp, "build_hostname": version.Hostname, }); err != nil { return err } return nil }
go
func Write(ctx context.Context, store storage.Store, txn storage.Transaction) error { if err := storage.MakeDir(ctx, store, txn, versionPath); err != nil { return err } if err := store.Write(ctx, txn, storage.AddOp, versionPath, map[string]interface{}{ "version": version.Version, "build_commit": version.Vcs, "build_timestamp": version.Timestamp, "build_hostname": version.Hostname, }); err != nil { return err } return nil }
[ "func", "Write", "(", "ctx", "context", ".", "Context", ",", "store", "storage", ".", "Store", ",", "txn", "storage", ".", "Transaction", ")", "error", "{", "if", "err", ":=", "storage", ".", "MakeDir", "(", "ctx", ",", "store", ",", "txn", ",", "versionPath", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "store", ".", "Write", "(", "ctx", ",", "txn", ",", "storage", ".", "AddOp", ",", "versionPath", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "version", ".", "Version", ",", "\"", "\"", ":", "version", ".", "Vcs", ",", "\"", "\"", ":", "version", ".", "Timestamp", ",", "\"", "\"", ":", "version", ".", "Hostname", ",", "}", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Write the build version information into storage. This makes the // version information available to the REPL and the HTTP server.
[ "Write", "the", "build", "version", "information", "into", "storage", ".", "This", "makes", "the", "version", "information", "available", "to", "the", "REPL", "and", "the", "HTTP", "server", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/version/version.go#L19-L35
train
open-policy-agent/opa
topdown/builtins.go
RegisterFunctionalBuiltin1
func RegisterFunctionalBuiltin1(name string, fun FunctionalBuiltin1) { builtinFunctions[name] = functionalWrapper1(name, fun) }
go
func RegisterFunctionalBuiltin1(name string, fun FunctionalBuiltin1) { builtinFunctions[name] = functionalWrapper1(name, fun) }
[ "func", "RegisterFunctionalBuiltin1", "(", "name", "string", ",", "fun", "FunctionalBuiltin1", ")", "{", "builtinFunctions", "[", "name", "]", "=", "functionalWrapper1", "(", "name", ",", "fun", ")", "\n", "}" ]
// RegisterFunctionalBuiltin1 adds a new built-in function to the evaluation // engine.
[ "RegisterFunctionalBuiltin1", "adds", "a", "new", "built", "-", "in", "function", "to", "the", "evaluation", "engine", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/builtins.go#L81-L83
train
open-policy-agent/opa
topdown/builtins.go
RegisterFunctionalBuiltin2
func RegisterFunctionalBuiltin2(name string, fun FunctionalBuiltin2) { builtinFunctions[name] = functionalWrapper2(name, fun) }
go
func RegisterFunctionalBuiltin2(name string, fun FunctionalBuiltin2) { builtinFunctions[name] = functionalWrapper2(name, fun) }
[ "func", "RegisterFunctionalBuiltin2", "(", "name", "string", ",", "fun", "FunctionalBuiltin2", ")", "{", "builtinFunctions", "[", "name", "]", "=", "functionalWrapper2", "(", "name", ",", "fun", ")", "\n", "}" ]
// RegisterFunctionalBuiltin2 adds a new built-in function to the evaluation // engine.
[ "RegisterFunctionalBuiltin2", "adds", "a", "new", "built", "-", "in", "function", "to", "the", "evaluation", "engine", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/builtins.go#L87-L89
train
open-policy-agent/opa
topdown/builtins.go
RegisterFunctionalBuiltin3
func RegisterFunctionalBuiltin3(name string, fun FunctionalBuiltin3) { builtinFunctions[name] = functionalWrapper3(name, fun) }
go
func RegisterFunctionalBuiltin3(name string, fun FunctionalBuiltin3) { builtinFunctions[name] = functionalWrapper3(name, fun) }
[ "func", "RegisterFunctionalBuiltin3", "(", "name", "string", ",", "fun", "FunctionalBuiltin3", ")", "{", "builtinFunctions", "[", "name", "]", "=", "functionalWrapper3", "(", "name", ",", "fun", ")", "\n", "}" ]
// RegisterFunctionalBuiltin3 adds a new built-in function to the evaluation // engine.
[ "RegisterFunctionalBuiltin3", "adds", "a", "new", "built", "-", "in", "function", "to", "the", "evaluation", "engine", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/builtins.go#L93-L95
train
open-policy-agent/opa
topdown/builtins.go
RegisterFunctionalBuiltin4
func RegisterFunctionalBuiltin4(name string, fun FunctionalBuiltin4) { builtinFunctions[name] = functionalWrapper4(name, fun) }
go
func RegisterFunctionalBuiltin4(name string, fun FunctionalBuiltin4) { builtinFunctions[name] = functionalWrapper4(name, fun) }
[ "func", "RegisterFunctionalBuiltin4", "(", "name", "string", ",", "fun", "FunctionalBuiltin4", ")", "{", "builtinFunctions", "[", "name", "]", "=", "functionalWrapper4", "(", "name", ",", "fun", ")", "\n", "}" ]
// RegisterFunctionalBuiltin4 adds a new built-in function to the evaluation // engine.
[ "RegisterFunctionalBuiltin4", "adds", "a", "new", "built", "-", "in", "function", "to", "the", "evaluation", "engine", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/builtins.go#L99-L101
train
open-policy-agent/opa
topdown/sets.go
builtinSetIntersection
func builtinSetIntersection(a ast.Value) (ast.Value, error) { inputSet, err := builtins.SetOperand(a, 1) if err != nil { return nil, err } // empty input set if inputSet.Len() == 0 { return ast.NewSet(), nil } var result ast.Set err = inputSet.Iter(func(x *ast.Term) error { n, err := builtins.SetOperand(x.Value, 1) if err != nil { return err } if result == nil { result = n } else { result = result.Intersect(n) } return nil }) return result, err }
go
func builtinSetIntersection(a ast.Value) (ast.Value, error) { inputSet, err := builtins.SetOperand(a, 1) if err != nil { return nil, err } // empty input set if inputSet.Len() == 0 { return ast.NewSet(), nil } var result ast.Set err = inputSet.Iter(func(x *ast.Term) error { n, err := builtins.SetOperand(x.Value, 1) if err != nil { return err } if result == nil { result = n } else { result = result.Intersect(n) } return nil }) return result, err }
[ "func", "builtinSetIntersection", "(", "a", "ast", ".", "Value", ")", "(", "ast", ".", "Value", ",", "error", ")", "{", "inputSet", ",", "err", ":=", "builtins", ".", "SetOperand", "(", "a", ",", "1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// empty input set", "if", "inputSet", ".", "Len", "(", ")", "==", "0", "{", "return", "ast", ".", "NewSet", "(", ")", ",", "nil", "\n", "}", "\n\n", "var", "result", "ast", ".", "Set", "\n\n", "err", "=", "inputSet", ".", "Iter", "(", "func", "(", "x", "*", "ast", ".", "Term", ")", "error", "{", "n", ",", "err", ":=", "builtins", ".", "SetOperand", "(", "x", ".", "Value", ",", "1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "result", "==", "nil", "{", "result", "=", "n", "\n", "}", "else", "{", "result", "=", "result", ".", "Intersect", "(", "n", ")", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "return", "result", ",", "err", "\n", "}" ]
// builtinSetIntersection returns the intersection of the given input sets
[ "builtinSetIntersection", "returns", "the", "intersection", "of", "the", "given", "input", "sets" ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/sets.go#L29-L57
train
open-policy-agent/opa
topdown/sets.go
builtinSetUnion
func builtinSetUnion(a ast.Value) (ast.Value, error) { inputSet, err := builtins.SetOperand(a, 1) if err != nil { return nil, err } result := ast.NewSet() err = inputSet.Iter(func(x *ast.Term) error { n, err := builtins.SetOperand(x.Value, 1) if err != nil { return err } result = result.Union(n) return nil }) return result, err }
go
func builtinSetUnion(a ast.Value) (ast.Value, error) { inputSet, err := builtins.SetOperand(a, 1) if err != nil { return nil, err } result := ast.NewSet() err = inputSet.Iter(func(x *ast.Term) error { n, err := builtins.SetOperand(x.Value, 1) if err != nil { return err } result = result.Union(n) return nil }) return result, err }
[ "func", "builtinSetUnion", "(", "a", "ast", ".", "Value", ")", "(", "ast", ".", "Value", ",", "error", ")", "{", "inputSet", ",", "err", ":=", "builtins", ".", "SetOperand", "(", "a", ",", "1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "result", ":=", "ast", ".", "NewSet", "(", ")", "\n\n", "err", "=", "inputSet", ".", "Iter", "(", "func", "(", "x", "*", "ast", ".", "Term", ")", "error", "{", "n", ",", "err", ":=", "builtins", ".", "SetOperand", "(", "x", ".", "Value", ",", "1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "result", "=", "result", ".", "Union", "(", "n", ")", "\n", "return", "nil", "\n", "}", ")", "\n", "return", "result", ",", "err", "\n", "}" ]
// builtinSetUnion returns the union of the given input sets
[ "builtinSetUnion", "returns", "the", "union", "of", "the", "given", "input", "sets" ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/sets.go#L60-L78
train
open-policy-agent/opa
internal/wasm/module/pretty.go
Pretty
func Pretty(w io.Writer, m *Module, opts ...PrettyOption) { fmt.Fprintln(w, "version:", m.Version) fmt.Fprintln(w, "types:") for _, fn := range m.Type.Functions { fmt.Fprintln(w, " -", fn) } fmt.Fprintln(w, "imports:") for i, imp := range m.Import.Imports { if imp.Descriptor.Kind() == FunctionImportType { fmt.Printf(" - [%d] %v\n", i, imp) } else { fmt.Fprintln(w, " -", imp) } } fmt.Fprintln(w, "functions:") for _, fn := range m.Function.TypeIndices { if fn >= uint32(len(m.Type.Functions)) { fmt.Fprintln(w, " -", "???") } else { fmt.Fprintln(w, " -", m.Type.Functions[fn]) } } fmt.Fprintln(w, "exports:") for _, exp := range m.Export.Exports { fmt.Fprintln(w, " -", exp) } fmt.Fprintln(w, "code:") for _, seg := range m.Code.Segments { fmt.Fprintln(w, " -", seg) } fmt.Fprintln(w, "data:") for _, seg := range m.Data.Segments { fmt.Fprintln(w, " -", seg) } if len(opts) == 0 { return } fmt.Fprintln(w) for _, opt := range opts { if opt.Contents { newline := false if len(m.Data.Segments) > 0 { fmt.Fprintln(w, "data section:") for _, seg := range m.Data.Segments { if newline { fmt.Fprintln(w) } fmt.Fprintln(w, hex.Dump(seg.Init)) newline = true } newline = false } if len(m.Code.Segments) > 0 { fmt.Fprintln(w, "code section:") for _, seg := range m.Code.Segments { if newline { fmt.Fprintln(w) } fmt.Fprintln(w, hex.Dump(seg.Code)) newline = true } newline = false } } } }
go
func Pretty(w io.Writer, m *Module, opts ...PrettyOption) { fmt.Fprintln(w, "version:", m.Version) fmt.Fprintln(w, "types:") for _, fn := range m.Type.Functions { fmt.Fprintln(w, " -", fn) } fmt.Fprintln(w, "imports:") for i, imp := range m.Import.Imports { if imp.Descriptor.Kind() == FunctionImportType { fmt.Printf(" - [%d] %v\n", i, imp) } else { fmt.Fprintln(w, " -", imp) } } fmt.Fprintln(w, "functions:") for _, fn := range m.Function.TypeIndices { if fn >= uint32(len(m.Type.Functions)) { fmt.Fprintln(w, " -", "???") } else { fmt.Fprintln(w, " -", m.Type.Functions[fn]) } } fmt.Fprintln(w, "exports:") for _, exp := range m.Export.Exports { fmt.Fprintln(w, " -", exp) } fmt.Fprintln(w, "code:") for _, seg := range m.Code.Segments { fmt.Fprintln(w, " -", seg) } fmt.Fprintln(w, "data:") for _, seg := range m.Data.Segments { fmt.Fprintln(w, " -", seg) } if len(opts) == 0 { return } fmt.Fprintln(w) for _, opt := range opts { if opt.Contents { newline := false if len(m.Data.Segments) > 0 { fmt.Fprintln(w, "data section:") for _, seg := range m.Data.Segments { if newline { fmt.Fprintln(w) } fmt.Fprintln(w, hex.Dump(seg.Init)) newline = true } newline = false } if len(m.Code.Segments) > 0 { fmt.Fprintln(w, "code section:") for _, seg := range m.Code.Segments { if newline { fmt.Fprintln(w) } fmt.Fprintln(w, hex.Dump(seg.Code)) newline = true } newline = false } } } }
[ "func", "Pretty", "(", "w", "io", ".", "Writer", ",", "m", "*", "Module", ",", "opts", "...", "PrettyOption", ")", "{", "fmt", ".", "Fprintln", "(", "w", ",", "\"", "\"", ",", "m", ".", "Version", ")", "\n", "fmt", ".", "Fprintln", "(", "w", ",", "\"", "\"", ")", "\n", "for", "_", ",", "fn", ":=", "range", "m", ".", "Type", ".", "Functions", "{", "fmt", ".", "Fprintln", "(", "w", ",", "\"", "\"", ",", "fn", ")", "\n", "}", "\n", "fmt", ".", "Fprintln", "(", "w", ",", "\"", "\"", ")", "\n", "for", "i", ",", "imp", ":=", "range", "m", ".", "Import", ".", "Imports", "{", "if", "imp", ".", "Descriptor", ".", "Kind", "(", ")", "==", "FunctionImportType", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "i", ",", "imp", ")", "\n", "}", "else", "{", "fmt", ".", "Fprintln", "(", "w", ",", "\"", "\"", ",", "imp", ")", "\n", "}", "\n", "}", "\n", "fmt", ".", "Fprintln", "(", "w", ",", "\"", "\"", ")", "\n", "for", "_", ",", "fn", ":=", "range", "m", ".", "Function", ".", "TypeIndices", "{", "if", "fn", ">=", "uint32", "(", "len", "(", "m", ".", "Type", ".", "Functions", ")", ")", "{", "fmt", ".", "Fprintln", "(", "w", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "}", "else", "{", "fmt", ".", "Fprintln", "(", "w", ",", "\"", "\"", ",", "m", ".", "Type", ".", "Functions", "[", "fn", "]", ")", "\n", "}", "\n", "}", "\n", "fmt", ".", "Fprintln", "(", "w", ",", "\"", "\"", ")", "\n", "for", "_", ",", "exp", ":=", "range", "m", ".", "Export", ".", "Exports", "{", "fmt", ".", "Fprintln", "(", "w", ",", "\"", "\"", ",", "exp", ")", "\n", "}", "\n", "fmt", ".", "Fprintln", "(", "w", ",", "\"", "\"", ")", "\n", "for", "_", ",", "seg", ":=", "range", "m", ".", "Code", ".", "Segments", "{", "fmt", ".", "Fprintln", "(", "w", ",", "\"", "\"", ",", "seg", ")", "\n", "}", "\n", "fmt", ".", "Fprintln", "(", "w", ",", "\"", "\"", ")", "\n", "for", "_", ",", "seg", ":=", "range", "m", ".", "Data", ".", "Segments", "{", "fmt", ".", "Fprintln", "(", "w", ",", "\"", "\"", ",", "seg", ")", "\n", "}", "\n", "if", "len", "(", "opts", ")", "==", "0", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprintln", "(", "w", ")", "\n", "for", "_", ",", "opt", ":=", "range", "opts", "{", "if", "opt", ".", "Contents", "{", "newline", ":=", "false", "\n", "if", "len", "(", "m", ".", "Data", ".", "Segments", ")", ">", "0", "{", "fmt", ".", "Fprintln", "(", "w", ",", "\"", "\"", ")", "\n", "for", "_", ",", "seg", ":=", "range", "m", ".", "Data", ".", "Segments", "{", "if", "newline", "{", "fmt", ".", "Fprintln", "(", "w", ")", "\n", "}", "\n", "fmt", ".", "Fprintln", "(", "w", ",", "hex", ".", "Dump", "(", "seg", ".", "Init", ")", ")", "\n", "newline", "=", "true", "\n", "}", "\n", "newline", "=", "false", "\n", "}", "\n", "if", "len", "(", "m", ".", "Code", ".", "Segments", ")", ">", "0", "{", "fmt", ".", "Fprintln", "(", "w", ",", "\"", "\"", ")", "\n", "for", "_", ",", "seg", ":=", "range", "m", ".", "Code", ".", "Segments", "{", "if", "newline", "{", "fmt", ".", "Fprintln", "(", "w", ")", "\n", "}", "\n", "fmt", ".", "Fprintln", "(", "w", ",", "hex", ".", "Dump", "(", "seg", ".", "Code", ")", ")", "\n", "newline", "=", "true", "\n", "}", "\n", "newline", "=", "false", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// Pretty writes a human-readable representation of m to w.
[ "Pretty", "writes", "a", "human", "-", "readable", "representation", "of", "m", "to", "w", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/wasm/module/pretty.go#L19-L84
train
open-policy-agent/opa
topdown/crypto.go
createRootCAs
func createRootCAs(tlsCACertFile string, tlsCACertEnvVar []byte, tlsUseSystemCerts bool) (*x509.CertPool, error) { var newRootCAs *x509.CertPool if tlsUseSystemCerts { systemCertPool, err := x509.SystemCertPool() if err != nil { return nil, err } newRootCAs = systemCertPool } else { newRootCAs = x509.NewCertPool() } if len(tlsCACertFile) > 0 { // Append our cert to the system pool caCert, err := readCertFromFile(tlsCACertFile) if err != nil { return nil, err } if ok := newRootCAs.AppendCertsFromPEM(caCert); !ok { return nil, fmt.Errorf("could not append CA cert from %q", tlsCACertFile) } } if len(tlsCACertEnvVar) > 0 { // Append our cert to the system pool if ok := newRootCAs.AppendCertsFromPEM(tlsCACertEnvVar); !ok { return nil, fmt.Errorf("error appending cert from env var %q into system certs", tlsCACertEnvVar) } } return newRootCAs, nil }
go
func createRootCAs(tlsCACertFile string, tlsCACertEnvVar []byte, tlsUseSystemCerts bool) (*x509.CertPool, error) { var newRootCAs *x509.CertPool if tlsUseSystemCerts { systemCertPool, err := x509.SystemCertPool() if err != nil { return nil, err } newRootCAs = systemCertPool } else { newRootCAs = x509.NewCertPool() } if len(tlsCACertFile) > 0 { // Append our cert to the system pool caCert, err := readCertFromFile(tlsCACertFile) if err != nil { return nil, err } if ok := newRootCAs.AppendCertsFromPEM(caCert); !ok { return nil, fmt.Errorf("could not append CA cert from %q", tlsCACertFile) } } if len(tlsCACertEnvVar) > 0 { // Append our cert to the system pool if ok := newRootCAs.AppendCertsFromPEM(tlsCACertEnvVar); !ok { return nil, fmt.Errorf("error appending cert from env var %q into system certs", tlsCACertEnvVar) } } return newRootCAs, nil }
[ "func", "createRootCAs", "(", "tlsCACertFile", "string", ",", "tlsCACertEnvVar", "[", "]", "byte", ",", "tlsUseSystemCerts", "bool", ")", "(", "*", "x509", ".", "CertPool", ",", "error", ")", "{", "var", "newRootCAs", "*", "x509", ".", "CertPool", "\n\n", "if", "tlsUseSystemCerts", "{", "systemCertPool", ",", "err", ":=", "x509", ".", "SystemCertPool", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "newRootCAs", "=", "systemCertPool", "\n", "}", "else", "{", "newRootCAs", "=", "x509", ".", "NewCertPool", "(", ")", "\n", "}", "\n\n", "if", "len", "(", "tlsCACertFile", ")", ">", "0", "{", "// Append our cert to the system pool", "caCert", ",", "err", ":=", "readCertFromFile", "(", "tlsCACertFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "ok", ":=", "newRootCAs", ".", "AppendCertsFromPEM", "(", "caCert", ")", ";", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "tlsCACertFile", ")", "\n", "}", "\n", "}", "\n\n", "if", "len", "(", "tlsCACertEnvVar", ")", ">", "0", "{", "// Append our cert to the system pool", "if", "ok", ":=", "newRootCAs", ".", "AppendCertsFromPEM", "(", "tlsCACertEnvVar", ")", ";", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "tlsCACertEnvVar", ")", "\n", "}", "\n", "}", "\n\n", "return", "newRootCAs", ",", "nil", "\n", "}" ]
// createRootCAs creates a new Cert Pool from scratch or adds to a copy of System Certs
[ "createRootCAs", "creates", "a", "new", "Cert", "Pool", "from", "scratch", "or", "adds", "to", "a", "copy", "of", "System", "Certs" ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/crypto.go#L48-L81
train
open-policy-agent/opa
topdown/crypto.go
readCertFromFile
func readCertFromFile(localCertFile string) ([]byte, error) { // Read in the cert file certPEM, err := ioutil.ReadFile(localCertFile) if err != nil { return nil, err } return certPEM, nil }
go
func readCertFromFile(localCertFile string) ([]byte, error) { // Read in the cert file certPEM, err := ioutil.ReadFile(localCertFile) if err != nil { return nil, err } return certPEM, nil }
[ "func", "readCertFromFile", "(", "localCertFile", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// Read in the cert file", "certPEM", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "localCertFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "certPEM", ",", "nil", "\n", "}" ]
// ReadCertFromFile reads a cert from file
[ "ReadCertFromFile", "reads", "a", "cert", "from", "file" ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/crypto.go#L84-L91
train
open-policy-agent/opa
topdown/crypto.go
readKeyFromFile
func readKeyFromFile(localKeyFile string) ([]byte, error) { // Read in the cert file key, err := ioutil.ReadFile(localKeyFile) if err != nil { return nil, err } return key, nil }
go
func readKeyFromFile(localKeyFile string) ([]byte, error) { // Read in the cert file key, err := ioutil.ReadFile(localKeyFile) if err != nil { return nil, err } return key, nil }
[ "func", "readKeyFromFile", "(", "localKeyFile", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// Read in the cert file", "key", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "localKeyFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "key", ",", "nil", "\n", "}" ]
// ReadKeyFromFile reads a key from file
[ "ReadKeyFromFile", "reads", "a", "key", "from", "file" ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/crypto.go#L94-L101
train
open-policy-agent/opa
download/download.go
New
func New(config Config, client rest.Client, path string) *Downloader { return &Downloader{ config: config, client: client, path: path, stop: make(chan chan struct{}), } }
go
func New(config Config, client rest.Client, path string) *Downloader { return &Downloader{ config: config, client: client, path: path, stop: make(chan chan struct{}), } }
[ "func", "New", "(", "config", "Config", ",", "client", "rest", ".", "Client", ",", "path", "string", ")", "*", "Downloader", "{", "return", "&", "Downloader", "{", "config", ":", "config", ",", "client", ":", "client", ",", "path", ":", "path", ",", "stop", ":", "make", "(", "chan", "chan", "struct", "{", "}", ")", ",", "}", "\n", "}" ]
// New returns a new Downloader that can be started.
[ "New", "returns", "a", "new", "Downloader", "that", "can", "be", "started", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/download/download.go#L50-L57
train
open-policy-agent/opa
download/download.go
WithCallback
func (d *Downloader) WithCallback(f func(context.Context, Update)) *Downloader { d.f = f return d }
go
func (d *Downloader) WithCallback(f func(context.Context, Update)) *Downloader { d.f = f return d }
[ "func", "(", "d", "*", "Downloader", ")", "WithCallback", "(", "f", "func", "(", "context", ".", "Context", ",", "Update", ")", ")", "*", "Downloader", "{", "d", ".", "f", "=", "f", "\n", "return", "d", "\n", "}" ]
// WithCallback registers a function f to be called when download updates occur.
[ "WithCallback", "registers", "a", "function", "f", "to", "be", "called", "when", "download", "updates", "occur", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/download/download.go#L60-L63
train
open-policy-agent/opa
download/download.go
Stop
func (d *Downloader) Stop(ctx context.Context) { done := make(chan struct{}) d.stop <- done _ = <-done }
go
func (d *Downloader) Stop(ctx context.Context) { done := make(chan struct{}) d.stop <- done _ = <-done }
[ "func", "(", "d", "*", "Downloader", ")", "Stop", "(", "ctx", "context", ".", "Context", ")", "{", "done", ":=", "make", "(", "chan", "struct", "{", "}", ")", "\n", "d", ".", "stop", "<-", "done", "\n", "_", "=", "<-", "done", "\n", "}" ]
// Stop tells the Downloader to stop begin downloading bundles.
[ "Stop", "tells", "the", "Downloader", "to", "stop", "begin", "downloading", "bundles", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/download/download.go#L78-L82
train
open-policy-agent/opa
storage/inmem/inmem.go
New
func New() storage.Store { return &store{ data: map[string]interface{}{}, triggers: map[*handle]storage.TriggerConfig{}, policies: map[string][]byte{}, indices: newIndices(), } }
go
func New() storage.Store { return &store{ data: map[string]interface{}{}, triggers: map[*handle]storage.TriggerConfig{}, policies: map[string][]byte{}, indices: newIndices(), } }
[ "func", "New", "(", ")", "storage", ".", "Store", "{", "return", "&", "store", "{", "data", ":", "map", "[", "string", "]", "interface", "{", "}", "{", "}", ",", "triggers", ":", "map", "[", "*", "handle", "]", "storage", ".", "TriggerConfig", "{", "}", ",", "policies", ":", "map", "[", "string", "]", "[", "]", "byte", "{", "}", ",", "indices", ":", "newIndices", "(", ")", ",", "}", "\n", "}" ]
// New returns an empty in-memory store.
[ "New", "returns", "an", "empty", "in", "-", "memory", "store", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/inmem/inmem.go#L31-L38
train
open-policy-agent/opa
storage/inmem/inmem.go
NewFromObject
func NewFromObject(data map[string]interface{}) storage.Store { db := New() ctx := context.Background() txn, err := db.NewTransaction(ctx, storage.WriteParams) if err != nil { panic(err) } if err := db.Write(ctx, txn, storage.AddOp, storage.Path{}, data); err != nil { panic(err) } if err := db.Commit(ctx, txn); err != nil { panic(err) } return db }
go
func NewFromObject(data map[string]interface{}) storage.Store { db := New() ctx := context.Background() txn, err := db.NewTransaction(ctx, storage.WriteParams) if err != nil { panic(err) } if err := db.Write(ctx, txn, storage.AddOp, storage.Path{}, data); err != nil { panic(err) } if err := db.Commit(ctx, txn); err != nil { panic(err) } return db }
[ "func", "NewFromObject", "(", "data", "map", "[", "string", "]", "interface", "{", "}", ")", "storage", ".", "Store", "{", "db", ":=", "New", "(", ")", "\n", "ctx", ":=", "context", ".", "Background", "(", ")", "\n", "txn", ",", "err", ":=", "db", ".", "NewTransaction", "(", "ctx", ",", "storage", ".", "WriteParams", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "db", ".", "Write", "(", "ctx", ",", "txn", ",", "storage", ".", "AddOp", ",", "storage", ".", "Path", "{", "}", ",", "data", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "db", ".", "Commit", "(", "ctx", ",", "txn", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "db", "\n", "}" ]
// NewFromObject returns a new in-memory store from the supplied data object.
[ "NewFromObject", "returns", "a", "new", "in", "-", "memory", "store", "from", "the", "supplied", "data", "object", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/inmem/inmem.go#L41-L55
train
open-policy-agent/opa
storage/inmem/inmem.go
NewFromReader
func NewFromReader(r io.Reader) storage.Store { d := util.NewJSONDecoder(r) var data map[string]interface{} if err := d.Decode(&data); err != nil { panic(err) } return NewFromObject(data) }
go
func NewFromReader(r io.Reader) storage.Store { d := util.NewJSONDecoder(r) var data map[string]interface{} if err := d.Decode(&data); err != nil { panic(err) } return NewFromObject(data) }
[ "func", "NewFromReader", "(", "r", "io", ".", "Reader", ")", "storage", ".", "Store", "{", "d", ":=", "util", ".", "NewJSONDecoder", "(", "r", ")", "\n", "var", "data", "map", "[", "string", "]", "interface", "{", "}", "\n", "if", "err", ":=", "d", ".", "Decode", "(", "&", "data", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "NewFromObject", "(", "data", ")", "\n", "}" ]
// NewFromReader returns a new in-memory store from a reader that produces a // JSON serialized object. This function is for test purposes.
[ "NewFromReader", "returns", "a", "new", "in", "-", "memory", "store", "from", "a", "reader", "that", "produces", "a", "JSON", "serialized", "object", ".", "This", "function", "is", "for", "test", "purposes", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/inmem/inmem.go#L59-L66
train
open-policy-agent/opa
ast/varset.go
NewVarSet
func NewVarSet(vs ...Var) VarSet { s := VarSet{} for _, v := range vs { s.Add(v) } return s }
go
func NewVarSet(vs ...Var) VarSet { s := VarSet{} for _, v := range vs { s.Add(v) } return s }
[ "func", "NewVarSet", "(", "vs", "...", "Var", ")", "VarSet", "{", "s", ":=", "VarSet", "{", "}", "\n", "for", "_", ",", "v", ":=", "range", "vs", "{", "s", ".", "Add", "(", "v", ")", "\n", "}", "\n", "return", "s", "\n", "}" ]
// NewVarSet returns a new VarSet containing the specified variables.
[ "NewVarSet", "returns", "a", "new", "VarSet", "containing", "the", "specified", "variables", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/varset.go#L16-L22
train
open-policy-agent/opa
ast/varset.go
Contains
func (s VarSet) Contains(v Var) bool { _, ok := s[v] return ok }
go
func (s VarSet) Contains(v Var) bool { _, ok := s[v] return ok }
[ "func", "(", "s", "VarSet", ")", "Contains", "(", "v", "Var", ")", "bool", "{", "_", ",", "ok", ":=", "s", "[", "v", "]", "\n", "return", "ok", "\n", "}" ]
// Contains returns true if the set contains the variable "v".
[ "Contains", "returns", "true", "if", "the", "set", "contains", "the", "variable", "v", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/varset.go#L30-L33
train
open-policy-agent/opa
ast/varset.go
Copy
func (s VarSet) Copy() VarSet { cpy := VarSet{} for v := range s { cpy.Add(v) } return cpy }
go
func (s VarSet) Copy() VarSet { cpy := VarSet{} for v := range s { cpy.Add(v) } return cpy }
[ "func", "(", "s", "VarSet", ")", "Copy", "(", ")", "VarSet", "{", "cpy", ":=", "VarSet", "{", "}", "\n", "for", "v", ":=", "range", "s", "{", "cpy", ".", "Add", "(", "v", ")", "\n", "}", "\n", "return", "cpy", "\n", "}" ]
// Copy returns a shallow copy of the VarSet.
[ "Copy", "returns", "a", "shallow", "copy", "of", "the", "VarSet", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/varset.go#L36-L42
train
open-policy-agent/opa
ast/varset.go
Diff
func (s VarSet) Diff(vs VarSet) VarSet { r := VarSet{} for v := range s { if !vs.Contains(v) { r.Add(v) } } return r }
go
func (s VarSet) Diff(vs VarSet) VarSet { r := VarSet{} for v := range s { if !vs.Contains(v) { r.Add(v) } } return r }
[ "func", "(", "s", "VarSet", ")", "Diff", "(", "vs", "VarSet", ")", "VarSet", "{", "r", ":=", "VarSet", "{", "}", "\n", "for", "v", ":=", "range", "s", "{", "if", "!", "vs", ".", "Contains", "(", "v", ")", "{", "r", ".", "Add", "(", "v", ")", "\n", "}", "\n", "}", "\n", "return", "r", "\n", "}" ]
// Diff returns a VarSet containing variables in s that are not in vs.
[ "Diff", "returns", "a", "VarSet", "containing", "variables", "in", "s", "that", "are", "not", "in", "vs", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/varset.go#L45-L53
train
open-policy-agent/opa
ast/varset.go
Equal
func (s VarSet) Equal(vs VarSet) bool { if len(s.Diff(vs)) > 0 { return false } return len(vs.Diff(s)) == 0 }
go
func (s VarSet) Equal(vs VarSet) bool { if len(s.Diff(vs)) > 0 { return false } return len(vs.Diff(s)) == 0 }
[ "func", "(", "s", "VarSet", ")", "Equal", "(", "vs", "VarSet", ")", "bool", "{", "if", "len", "(", "s", ".", "Diff", "(", "vs", ")", ")", ">", "0", "{", "return", "false", "\n", "}", "\n", "return", "len", "(", "vs", ".", "Diff", "(", "s", ")", ")", "==", "0", "\n", "}" ]
// Equal returns true if s contains exactly the same elements as vs.
[ "Equal", "returns", "true", "if", "s", "contains", "exactly", "the", "same", "elements", "as", "vs", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/varset.go#L56-L61
train
open-policy-agent/opa
ast/varset.go
Intersect
func (s VarSet) Intersect(vs VarSet) VarSet { r := VarSet{} for v := range s { if vs.Contains(v) { r.Add(v) } } return r }
go
func (s VarSet) Intersect(vs VarSet) VarSet { r := VarSet{} for v := range s { if vs.Contains(v) { r.Add(v) } } return r }
[ "func", "(", "s", "VarSet", ")", "Intersect", "(", "vs", "VarSet", ")", "VarSet", "{", "r", ":=", "VarSet", "{", "}", "\n", "for", "v", ":=", "range", "s", "{", "if", "vs", ".", "Contains", "(", "v", ")", "{", "r", ".", "Add", "(", "v", ")", "\n", "}", "\n", "}", "\n", "return", "r", "\n", "}" ]
// Intersect returns a VarSet containing variables in s that are in vs.
[ "Intersect", "returns", "a", "VarSet", "containing", "variables", "in", "s", "that", "are", "in", "vs", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/varset.go#L64-L72
train
open-policy-agent/opa
ast/varset.go
Update
func (s VarSet) Update(vs VarSet) { for v := range vs { s.Add(v) } }
go
func (s VarSet) Update(vs VarSet) { for v := range vs { s.Add(v) } }
[ "func", "(", "s", "VarSet", ")", "Update", "(", "vs", "VarSet", ")", "{", "for", "v", ":=", "range", "vs", "{", "s", ".", "Add", "(", "v", ")", "\n", "}", "\n", "}" ]
// Update merges the other VarSet into this VarSet.
[ "Update", "merges", "the", "other", "VarSet", "into", "this", "VarSet", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/varset.go#L75-L79
train
open-policy-agent/opa
ast/builtins.go
RegisterBuiltin
func RegisterBuiltin(b *Builtin) { Builtins = append(Builtins, b) BuiltinMap[b.Name] = b if len(b.Infix) > 0 { BuiltinMap[b.Infix] = b } }
go
func RegisterBuiltin(b *Builtin) { Builtins = append(Builtins, b) BuiltinMap[b.Name] = b if len(b.Infix) > 0 { BuiltinMap[b.Infix] = b } }
[ "func", "RegisterBuiltin", "(", "b", "*", "Builtin", ")", "{", "Builtins", "=", "append", "(", "Builtins", ",", "b", ")", "\n", "BuiltinMap", "[", "b", ".", "Name", "]", "=", "b", "\n", "if", "len", "(", "b", ".", "Infix", ")", ">", "0", "{", "BuiltinMap", "[", "b", ".", "Infix", "]", "=", "b", "\n", "}", "\n", "}" ]
// RegisterBuiltin adds a new built-in function to the registry.
[ "RegisterBuiltin", "adds", "a", "new", "built", "-", "in", "function", "to", "the", "registry", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/builtins.go#L18-L24
train
open-policy-agent/opa
ast/builtins.go
Expr
func (b *Builtin) Expr(operands ...*Term) *Expr { ts := make([]*Term, len(operands)+1) ts[0] = NewTerm(b.Ref()) for i := range operands { ts[i+1] = operands[i] } return &Expr{ Terms: ts, } }
go
func (b *Builtin) Expr(operands ...*Term) *Expr { ts := make([]*Term, len(operands)+1) ts[0] = NewTerm(b.Ref()) for i := range operands { ts[i+1] = operands[i] } return &Expr{ Terms: ts, } }
[ "func", "(", "b", "*", "Builtin", ")", "Expr", "(", "operands", "...", "*", "Term", ")", "*", "Expr", "{", "ts", ":=", "make", "(", "[", "]", "*", "Term", ",", "len", "(", "operands", ")", "+", "1", ")", "\n", "ts", "[", "0", "]", "=", "NewTerm", "(", "b", ".", "Ref", "(", ")", ")", "\n", "for", "i", ":=", "range", "operands", "{", "ts", "[", "i", "+", "1", "]", "=", "operands", "[", "i", "]", "\n", "}", "\n", "return", "&", "Expr", "{", "Terms", ":", "ts", ",", "}", "\n", "}" ]
// Expr creates a new expression for the built-in with the given operands.
[ "Expr", "creates", "a", "new", "expression", "for", "the", "built", "-", "in", "with", "the", "given", "operands", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/builtins.go#L1437-L1446
train
open-policy-agent/opa
ast/builtins.go
Call
func (b *Builtin) Call(operands ...*Term) *Term { call := make(Call, len(operands)+1) call[0] = NewTerm(b.Ref()) for i := range operands { call[i+1] = operands[i] } return NewTerm(call) }
go
func (b *Builtin) Call(operands ...*Term) *Term { call := make(Call, len(operands)+1) call[0] = NewTerm(b.Ref()) for i := range operands { call[i+1] = operands[i] } return NewTerm(call) }
[ "func", "(", "b", "*", "Builtin", ")", "Call", "(", "operands", "...", "*", "Term", ")", "*", "Term", "{", "call", ":=", "make", "(", "Call", ",", "len", "(", "operands", ")", "+", "1", ")", "\n", "call", "[", "0", "]", "=", "NewTerm", "(", "b", ".", "Ref", "(", ")", ")", "\n", "for", "i", ":=", "range", "operands", "{", "call", "[", "i", "+", "1", "]", "=", "operands", "[", "i", "]", "\n", "}", "\n", "return", "NewTerm", "(", "call", ")", "\n", "}" ]
// Call creates a new term for the built-in with the given operands.
[ "Call", "creates", "a", "new", "term", "for", "the", "built", "-", "in", "with", "the", "given", "operands", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/builtins.go#L1449-L1456
train
open-policy-agent/opa
ast/builtins.go
Ref
func (b *Builtin) Ref() Ref { parts := strings.Split(b.Name, ".") ref := make(Ref, len(parts)) ref[0] = VarTerm(parts[0]) for i := 1; i < len(parts); i++ { ref[i] = StringTerm(parts[i]) } return ref }
go
func (b *Builtin) Ref() Ref { parts := strings.Split(b.Name, ".") ref := make(Ref, len(parts)) ref[0] = VarTerm(parts[0]) for i := 1; i < len(parts); i++ { ref[i] = StringTerm(parts[i]) } return ref }
[ "func", "(", "b", "*", "Builtin", ")", "Ref", "(", ")", "Ref", "{", "parts", ":=", "strings", ".", "Split", "(", "b", ".", "Name", ",", "\"", "\"", ")", "\n", "ref", ":=", "make", "(", "Ref", ",", "len", "(", "parts", ")", ")", "\n", "ref", "[", "0", "]", "=", "VarTerm", "(", "parts", "[", "0", "]", ")", "\n", "for", "i", ":=", "1", ";", "i", "<", "len", "(", "parts", ")", ";", "i", "++", "{", "ref", "[", "i", "]", "=", "StringTerm", "(", "parts", "[", "i", "]", ")", "\n", "}", "\n", "return", "ref", "\n", "}" ]
// Ref returns a Ref that refers to the built-in function.
[ "Ref", "returns", "a", "Ref", "that", "refers", "to", "the", "built", "-", "in", "function", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/builtins.go#L1459-L1467
train
open-policy-agent/opa
ast/builtins.go
IsTargetPos
func (b *Builtin) IsTargetPos(i int) bool { return len(b.Decl.Args()) == i }
go
func (b *Builtin) IsTargetPos(i int) bool { return len(b.Decl.Args()) == i }
[ "func", "(", "b", "*", "Builtin", ")", "IsTargetPos", "(", "i", "int", ")", "bool", "{", "return", "len", "(", "b", ".", "Decl", ".", "Args", "(", ")", ")", "==", "i", "\n", "}" ]
// IsTargetPos returns true if a variable in the i-th position will be bound by // evaluating the call expression.
[ "IsTargetPos", "returns", "true", "if", "a", "variable", "in", "the", "i", "-", "th", "position", "will", "be", "bound", "by", "evaluating", "the", "call", "expression", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/builtins.go#L1471-L1473
train
open-policy-agent/opa
ast/env.go
selectConstant
func selectConstant(tpe types.Type, term *Term) types.Type { x, err := JSON(term.Value) if err == nil { return types.Select(tpe, x) } return nil }
go
func selectConstant(tpe types.Type, term *Term) types.Type { x, err := JSON(term.Value) if err == nil { return types.Select(tpe, x) } return nil }
[ "func", "selectConstant", "(", "tpe", "types", ".", "Type", ",", "term", "*", "Term", ")", "types", ".", "Type", "{", "x", ",", "err", ":=", "JSON", "(", "term", ".", "Value", ")", "\n", "if", "err", "==", "nil", "{", "return", "types", ".", "Select", "(", "tpe", ",", "x", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// selectConstant returns the attribute of the type referred to by the term. If // the attribute type cannot be determined, nil is returned.
[ "selectConstant", "returns", "the", "attribute", "of", "the", "type", "referred", "to", "by", "the", "term", ".", "If", "the", "attribute", "type", "cannot", "be", "determined", "nil", "is", "returned", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/env.go#L297-L303
train
open-policy-agent/opa
ast/env.go
selectRef
func selectRef(tpe types.Type, ref Ref) types.Type { if tpe == nil || len(ref) == 0 { return tpe } head, tail := ref[0], ref[1:] switch head.Value.(type) { case Var, Ref, Array, Object, Set: return selectRef(types.Values(tpe), tail) default: return selectRef(selectConstant(tpe, head), tail) } }
go
func selectRef(tpe types.Type, ref Ref) types.Type { if tpe == nil || len(ref) == 0 { return tpe } head, tail := ref[0], ref[1:] switch head.Value.(type) { case Var, Ref, Array, Object, Set: return selectRef(types.Values(tpe), tail) default: return selectRef(selectConstant(tpe, head), tail) } }
[ "func", "selectRef", "(", "tpe", "types", ".", "Type", ",", "ref", "Ref", ")", "types", ".", "Type", "{", "if", "tpe", "==", "nil", "||", "len", "(", "ref", ")", "==", "0", "{", "return", "tpe", "\n", "}", "\n\n", "head", ",", "tail", ":=", "ref", "[", "0", "]", ",", "ref", "[", "1", ":", "]", "\n\n", "switch", "head", ".", "Value", ".", "(", "type", ")", "{", "case", "Var", ",", "Ref", ",", "Array", ",", "Object", ",", "Set", ":", "return", "selectRef", "(", "types", ".", "Values", "(", "tpe", ")", ",", "tail", ")", "\n", "default", ":", "return", "selectRef", "(", "selectConstant", "(", "tpe", ",", "head", ")", ",", "tail", ")", "\n", "}", "\n", "}" ]
// selectRef returns the type of the nested attribute referred to by ref. If // the attribute type cannot be determined, nil is returned. If the ref // contains vars or refs, then the returned type will be a union of the // possible types.
[ "selectRef", "returns", "the", "type", "of", "the", "nested", "attribute", "referred", "to", "by", "ref", ".", "If", "the", "attribute", "type", "cannot", "be", "determined", "nil", "is", "returned", ".", "If", "the", "ref", "contains", "vars", "or", "refs", "then", "the", "returned", "type", "will", "be", "a", "union", "of", "the", "possible", "types", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/env.go#L309-L323
train
open-policy-agent/opa
internal/compiler/wasm/opa/opa.go
Bytes
func Bytes() ([]byte, error) { gr, err := gzip.NewReader(bytes.NewBuffer(gzipped)) if err != nil { return nil, err } return ioutil.ReadAll(gr) }
go
func Bytes() ([]byte, error) { gr, err := gzip.NewReader(bytes.NewBuffer(gzipped)) if err != nil { return nil, err } return ioutil.ReadAll(gr) }
[ "func", "Bytes", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "gr", ",", "err", ":=", "gzip", ".", "NewReader", "(", "bytes", ".", "NewBuffer", "(", "gzipped", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "ioutil", ".", "ReadAll", "(", "gr", ")", "\n", "}" ]
// Bytes returns the OPA-WASM bytecode.
[ "Bytes", "returns", "the", "OPA", "-", "WASM", "bytecode", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/compiler/wasm/opa/opa.go#L17-L23
train
open-policy-agent/opa
util/graph.go
DFS
func DFS(t Traversal, f Iter, u T) bool { lifo := NewLIFO(u) for lifo.Size() > 0 { next, _ := lifo.Pop() if t.Visited(next) { continue } if f(next) { return true } for _, v := range t.Edges(next) { lifo.Push(v) } } return false }
go
func DFS(t Traversal, f Iter, u T) bool { lifo := NewLIFO(u) for lifo.Size() > 0 { next, _ := lifo.Pop() if t.Visited(next) { continue } if f(next) { return true } for _, v := range t.Edges(next) { lifo.Push(v) } } return false }
[ "func", "DFS", "(", "t", "Traversal", ",", "f", "Iter", ",", "u", "T", ")", "bool", "{", "lifo", ":=", "NewLIFO", "(", "u", ")", "\n", "for", "lifo", ".", "Size", "(", ")", ">", "0", "{", "next", ",", "_", ":=", "lifo", ".", "Pop", "(", ")", "\n", "if", "t", ".", "Visited", "(", "next", ")", "{", "continue", "\n", "}", "\n", "if", "f", "(", "next", ")", "{", "return", "true", "\n", "}", "\n", "for", "_", ",", "v", ":=", "range", "t", ".", "Edges", "(", "next", ")", "{", "lifo", ".", "Push", "(", "v", ")", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// DFS performs a depth first traversal calling f for each node starting from u. // If f returns true, traversal stops and DFS returns true.
[ "DFS", "performs", "a", "depth", "first", "traversal", "calling", "f", "for", "each", "node", "starting", "from", "u", ".", "If", "f", "returns", "true", "traversal", "stops", "and", "DFS", "returns", "true", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/graph.go#L27-L42
train
open-policy-agent/opa
util/graph.go
BFS
func BFS(t Traversal, f Iter, u T) bool { fifo := NewFIFO(u) for fifo.Size() > 0 { next, _ := fifo.Pop() if t.Visited(next) { continue } if f(next) { return true } for _, v := range t.Edges(next) { fifo.Push(v) } } return false }
go
func BFS(t Traversal, f Iter, u T) bool { fifo := NewFIFO(u) for fifo.Size() > 0 { next, _ := fifo.Pop() if t.Visited(next) { continue } if f(next) { return true } for _, v := range t.Edges(next) { fifo.Push(v) } } return false }
[ "func", "BFS", "(", "t", "Traversal", ",", "f", "Iter", ",", "u", "T", ")", "bool", "{", "fifo", ":=", "NewFIFO", "(", "u", ")", "\n", "for", "fifo", ".", "Size", "(", ")", ">", "0", "{", "next", ",", "_", ":=", "fifo", ".", "Pop", "(", ")", "\n", "if", "t", ".", "Visited", "(", "next", ")", "{", "continue", "\n", "}", "\n", "if", "f", "(", "next", ")", "{", "return", "true", "\n", "}", "\n", "for", "_", ",", "v", ":=", "range", "t", ".", "Edges", "(", "next", ")", "{", "fifo", ".", "Push", "(", "v", ")", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// BFS performs a breadth first traversal calling f for each node starting from // u. If f returns true, traversal stops and BFS returns true.
[ "BFS", "performs", "a", "breadth", "first", "traversal", "calling", "f", "for", "each", "node", "starting", "from", "u", ".", "If", "f", "returns", "true", "traversal", "stops", "and", "BFS", "returns", "true", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/graph.go#L46-L61
train
open-policy-agent/opa
util/graph.go
DFSPath
func DFSPath(t Traversal, eq Equals, a, z T) []T { p := dfsRecursive(t, eq, a, z, []T{}) for i := len(p)/2 - 1; i >= 0; i-- { o := len(p) - i - 1 p[i], p[o] = p[o], p[i] } return p }
go
func DFSPath(t Traversal, eq Equals, a, z T) []T { p := dfsRecursive(t, eq, a, z, []T{}) for i := len(p)/2 - 1; i >= 0; i-- { o := len(p) - i - 1 p[i], p[o] = p[o], p[i] } return p }
[ "func", "DFSPath", "(", "t", "Traversal", ",", "eq", "Equals", ",", "a", ",", "z", "T", ")", "[", "]", "T", "{", "p", ":=", "dfsRecursive", "(", "t", ",", "eq", ",", "a", ",", "z", ",", "[", "]", "T", "{", "}", ")", "\n", "for", "i", ":=", "len", "(", "p", ")", "/", "2", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "o", ":=", "len", "(", "p", ")", "-", "i", "-", "1", "\n", "p", "[", "i", "]", ",", "p", "[", "o", "]", "=", "p", "[", "o", "]", ",", "p", "[", "i", "]", "\n", "}", "\n", "return", "p", "\n", "}" ]
// DFSPath returns a path from node a to node z found by performing // a depth first traversal. If no path is found, an empty slice is returned.
[ "DFSPath", "returns", "a", "path", "from", "node", "a", "to", "node", "z", "found", "by", "performing", "a", "depth", "first", "traversal", ".", "If", "no", "path", "is", "found", "an", "empty", "slice", "is", "returned", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/graph.go#L65-L72
train
open-policy-agent/opa
topdown/trace.go
HasRule
func (evt *Event) HasRule() bool { _, ok := evt.Node.(*ast.Rule) return ok }
go
func (evt *Event) HasRule() bool { _, ok := evt.Node.(*ast.Rule) return ok }
[ "func", "(", "evt", "*", "Event", ")", "HasRule", "(", ")", "bool", "{", "_", ",", "ok", ":=", "evt", ".", "Node", ".", "(", "*", "ast", ".", "Rule", ")", "\n", "return", "ok", "\n", "}" ]
// HasRule returns true if the Event contains an ast.Rule.
[ "HasRule", "returns", "true", "if", "the", "Event", "contains", "an", "ast", ".", "Rule", "." ]
589105aff580587c1b27b87df7123105af3e212a
https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/topdown/trace.go#L58-L61
train