MCPcopy
hub / github.com/dosco/graphjin / executeRoleQuery

Method executeRoleQuery

core/core.go:56–138  ·  view source on GitHub ↗
(c context.Context,
	conn *sql.Conn,
	vmap map[string]json.RawMessage,
	rc *RequestConfig,
)

Source from the content-addressed store, hash-verified

54}
55
56func (gj *graphjinEngine) executeRoleQuery(c context.Context,
57 conn *sql.Conn,
58 vmap map[string]json.RawMessage,
59 rc *RequestConfig,
60) (role string, err error) {
61 if c.Value(UserIDKey) == nil {
62 role = "anon"
63 return
64 }
65
66 pdb := gj.primaryDB()
67 if pdb == nil || pdb.db == nil || pdb.psqlCompiler == nil {
68 err = errors.New("roles_query: primary database not initialized")
69 return
70 }
71
72 needsConn := conn == nil && (rc == nil || rc.Tx == nil)
73 if needsConn {
74 c1, span := gj.spanStart(c, "Get Connection")
75 defer span.End()
76
77 err = retryOperation(c1, func() (err1 error) {
78 conn, err1 = pdb.db.Conn(c1)
79 return
80 })
81 if err != nil {
82 span.Error(err)
83 return
84 }
85 defer conn.Close() //nolint:errcheck
86 }
87 if conn == nil && (rc == nil || rc.Tx == nil) {
88 err = errors.New("roles_query: database connection not initialized")
89 return
90 }
91
92 c1, span := gj.spanStart(c, "Execute Role Query")
93 defer span.End()
94
95 if gj.roleQueryMode == roleQueryGraphQL {
96 role, err = gj.executeGraphQLRoleQuery(c1, conn, vmap, rc)
97 if err != nil {
98 span.Error(err)
99 return
100 }
101 span.SetAttributesString(StringAttr{"role", role})
102 return
103 }
104
105 ar, err := gj.argList(c,
106 gj.roleStatementMetadata,
107 vmap,
108 rc,
109 false,
110 pdb.psqlCompiler)
111 if err != nil {
112 span.Error(err)
113 return

Callers 1

subscribeMethod · 0.95

Calls 13

primaryDBMethod · 0.95
spanStartMethod · 0.95
argListMethod · 0.95
retryOperationFunction · 0.85
prepareQueryArgsForDBFunction · 0.85
retryOperationForDBFunction · 0.85
ValueMethod · 0.65
EndMethod · 0.65
ErrorMethod · 0.65
CloseMethod · 0.65
SetAttributesStringMethod · 0.65

Tested by

no test coverage detected