(ctx context.Context, keyHash string)
| 126 | } |
| 127 | |
| 128 | func (s *ClientAPIKeyStore) GetByKeyHash(ctx context.Context, keyHash string) (*ClientAPIKey, error) { |
| 129 | query := ` |
| 130 | SELECT id, key_hash, client_name, instance_id, created_at, last_used_at |
| 131 | FROM client_api_keys_view |
| 132 | WHERE key_hash = ? |
| 133 | ` |
| 134 | |
| 135 | key := &ClientAPIKey{} |
| 136 | err := s.db.QueryRowContext(ctx, query, keyHash).Scan( |
| 137 | &key.ID, |
| 138 | &key.KeyHash, |
| 139 | &key.ClientName, |
| 140 | &key.InstanceID, |
| 141 | &key.CreatedAt, |
| 142 | &key.LastUsedAt, |
| 143 | ) |
| 144 | |
| 145 | if errors.Is(err, sql.ErrNoRows) { |
| 146 | return nil, ErrClientAPIKeyNotFound |
| 147 | } |
| 148 | |
| 149 | if err != nil { |
| 150 | return nil, err |
| 151 | } |
| 152 | |
| 153 | return key, nil |
| 154 | } |
| 155 | |
| 156 | func (s *ClientAPIKeyStore) ValidateKey(ctx context.Context, rawKey string) (*ClientAPIKey, error) { |
| 157 | keyHash := HashAPIKey(rawKey) |
no test coverage detected