mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-14 09:37:50 +02:00
databroker: add list types method (#3937)
* databroker: add list types method * fix test * Update pkg/storage/redis/redis.go Co-authored-by: Denis Mishin <dmishin@pomerium.com> --------- Co-authored-by: Denis Mishin <dmishin@pomerium.com>
This commit is contained in:
parent
424b743b11
commit
7895bf431f
13 changed files with 495 additions and 232 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -284,6 +285,36 @@ func listServices(ctx context.Context, q querier) ([]*registry.Service, error) {
|
|||
return services, nil
|
||||
}
|
||||
|
||||
func listTypes(ctx context.Context, q querier) ([]string, error) {
|
||||
query := `
|
||||
SELECT DISTINCT type
|
||||
FROM ` + schemaName + `.` + recordsTableName + `
|
||||
`
|
||||
rows, err := q.Query(ctx, query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("postgres: failed to execute query: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var types []string
|
||||
for rows.Next() {
|
||||
var recordType string
|
||||
err = rows.Scan(&recordType)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("postgres: failed to scan row: %w", err)
|
||||
}
|
||||
|
||||
types = append(types, recordType)
|
||||
}
|
||||
err = rows.Err()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("postgres: error iterating over rows: %w", err)
|
||||
}
|
||||
|
||||
sort.Strings(types)
|
||||
return types, nil
|
||||
}
|
||||
|
||||
func maybeAcquireLease(ctx context.Context, q querier, leaseName, leaseID string, ttl time.Duration) (leaseHolderID string, err error) {
|
||||
tbl := schemaName + "." + leasesTableName
|
||||
expiresAt := timestamptzFromTimestamppb(timestamppb.New(time.Now().Add(ttl)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue