(c context.Context, conn *sql.Conn, vmap map[string]json.RawMessage, rc *RequestConfig, )
| 54 | } |
| 55 | |
| 56 | func (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 |
no test coverage detected