GetOAuth2Client looks up a client by client_id (the table's primary key). Workspace is no longer a lookup key — clients are workspace-agnostic since DCR runs unauthenticated.
(ctx context.Context, clientID string)
| 56 | // Workspace is no longer a lookup key — clients are workspace-agnostic since |
| 57 | // DCR runs unauthenticated. |
| 58 | func (s *Store) GetOAuth2Client(ctx context.Context, clientID string) (*OAuth2ClientMessage, error) { |
| 59 | q := qb.Q().Space(` |
| 60 | SELECT client_id, workspace, client_secret_hash, config, last_active_at |
| 61 | FROM oauth2_client |
| 62 | WHERE client_id = ? |
| 63 | `, clientID) |
| 64 | |
| 65 | query, args, err := q.ToSQL() |
| 66 | if err != nil { |
| 67 | return nil, err |
| 68 | } |
| 69 | |
| 70 | client := &OAuth2ClientMessage{} |
| 71 | var workspace sql.NullString |
| 72 | var configBytes []byte |
| 73 | if err := s.GetDB().QueryRowContext(ctx, query, args...).Scan( // NOSONAR: query is parameterized via qb.Query |
| 74 | &client.ClientID, &workspace, &client.ClientSecretHash, &configBytes, &client.LastActiveAt, |
| 75 | ); err != nil { |
| 76 | if errors.Is(err, sql.ErrNoRows) { |
| 77 | return nil, nil |
| 78 | } |
| 79 | return nil, errors.Wrap(err, "failed to query OAuth2 client") |
| 80 | } |
| 81 | client.Workspace = workspace.String |
| 82 | client.Config = &storepb.OAuth2ClientConfig{} |
| 83 | if err := common.ProtojsonUnmarshaler.Unmarshal(configBytes, client.Config); err != nil { |
| 84 | return nil, errors.Wrap(err, "failed to unmarshal config") |
| 85 | } |
| 86 | return client, nil |
| 87 | } |
| 88 | |
| 89 | func (s *Store) UpdateOAuth2ClientLastActiveAt(ctx context.Context, clientID string) error { |
| 90 | q := qb.Q().Space(` |
no test coverage detected