29 lines
996 B
Go
29 lines
996 B
Go
package postgres
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.cin.su/m/Assistant/contracts/identity"
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
type IdentityRepository struct{ pool *pgxpool.Pool }
|
|
|
|
func OpenIdentity(ctx context.Context, config ContinuityConfig) (*IdentityRepository, error) {
|
|
pool, err := openPool(ctx, config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &IdentityRepository{pool: pool}, nil
|
|
}
|
|
func (r *IdentityRepository) Close() { r.pool.Close() }
|
|
func (r *IdentityRepository) LoadBinding(ctx context.Context, actor identity.ActorID, principal identity.PrincipalID) (identity.PrincipalBinding, error) {
|
|
var binding identity.PrincipalBinding
|
|
err := r.pool.QueryRow(ctx, `SELECT actor_id, principal_id, active FROM identity.principal_bindings WHERE actor_id=$1 AND principal_id=$2`, actor, principal).Scan(&binding.ActorID, &binding.PrincipalID, &binding.Active)
|
|
if err != nil {
|
|
return identity.PrincipalBinding{}, fmt.Errorf("load identity binding: %w", err)
|
|
}
|
|
return binding, nil
|
|
}
|