MCPcopy Index your code
hub / github.com/coder/coder / ConvertVariable

Method ConvertVariable

coderd/rbac/regosql/acl_mapping_var.go:64–110  ·  view source on GitHub ↗
(rego ast.Ref)

Source from the content-addressed store, hash-verified

62func (ACLMappingVar) UseAs() sqltypes.Node { return ACLMappingVar{} }
63
64func (g ACLMappingVar) ConvertVariable(rego ast.Ref) (sqltypes.Node, bool) {
65 // left is the rego variable that maps the actor's id to the actions they
66 // are allowed to take.
67 // {
68 // "<actor_id>": ["<action>", "<action>"]
69 // }
70 left, err := sqltypes.RegoVarPath(g.StructPath, rego)
71 if err != nil {
72 return nil, false
73 }
74
75 aclGrp := ACLMappingVar{
76 SelectSQL: g.SelectSQL,
77 IndexMatcher: g.IndexMatcher,
78 Subfield: g.Subfield,
79
80 StructPath: g.StructPath,
81
82 Source: sqltypes.RegoSource(rego.String()),
83 }
84
85 // We expect 1 more term. Either a ref or a string.
86 if len(left) != 1 {
87 return nil, false
88 }
89
90 // If the remaining is a variable, then we need to convert it.
91 // Assuming we support variable fields.
92 ref, ok := left[0].Value.(ast.Ref)
93 if ok && g.IndexMatcher != nil {
94 groupNode, ok := g.IndexMatcher.ConvertVariable(ref)
95 if ok {
96 aclGrp.GroupNode = groupNode
97 return aclGrp, true
98 }
99 }
100
101 // If it is a string, we assume it is a literal
102 groupName, ok := left[0].Value.(ast.String)
103 if ok {
104 aclGrp.GroupNode = sqltypes.String(string(groupName))
105 return aclGrp, true
106 }
107
108 // If we have not matched it yet, then it is something we do not recognize.
109 return nil, false
110}
111
112func (g ACLMappingVar) SQLString(cfg *sqltypes.SQLGenerator) string {
113 if g.Subfield != "" {

Callers

nothing calls this directly

Calls 5

RegoVarPathFunction · 0.92
RegoSourceTypeAlias · 0.92
StringFunction · 0.92
ConvertVariableMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected