MCPcopy
hub / github.com/autobrr/qui / GetByKeyHash

Method GetByKeyHash

internal/models/client_api_key.go:128–154  ·  view source on GitHub ↗
(ctx context.Context, keyHash string)

Source from the content-addressed store, hash-verified

126}
127
128func (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
156func (s *ClientAPIKeyStore) ValidateKey(ctx context.Context, rawKey string) (*ClientAPIKey, error) {
157 keyHash := HashAPIKey(rawKey)

Callers 1

ValidateKeyMethod · 0.95

Calls 3

ScanMethod · 0.80
QueryRowContextMethod · 0.65
IsMethod · 0.45

Tested by

no test coverage detected