939 lines
21 KiB
Go
939 lines
21 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: query.sql
|
|
|
|
package database
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const createAccount = `-- name: CreateAccount :one
|
|
|
|
INSERT INTO account (
|
|
principal_id,
|
|
password_hash,
|
|
password_changed_at,
|
|
must_change_password,
|
|
state,
|
|
failed_attempts,
|
|
locked_until,
|
|
last_login_at,
|
|
created_at
|
|
) VALUES (
|
|
?1,
|
|
?2,
|
|
?3,
|
|
?4,
|
|
?5,
|
|
?6,
|
|
?7,
|
|
?8,
|
|
?9
|
|
)
|
|
RETURNING principal_id, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
|
`
|
|
|
|
type CreateAccountParams struct {
|
|
PrincipalID string
|
|
PasswordHash sql.NullString
|
|
PasswordChangedAt sql.NullInt64
|
|
MustChangePassword int64
|
|
State string
|
|
FailedAttempts int64
|
|
LockedUntil sql.NullInt64
|
|
LastLoginAt sql.NullInt64
|
|
CreatedAt int64
|
|
}
|
|
|
|
// ============================================================================
|
|
// account
|
|
// ============================================================================
|
|
func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (Account, error) {
|
|
row := q.db.QueryRowContext(ctx, createAccount,
|
|
arg.PrincipalID,
|
|
arg.PasswordHash,
|
|
arg.PasswordChangedAt,
|
|
arg.MustChangePassword,
|
|
arg.State,
|
|
arg.FailedAttempts,
|
|
arg.LockedUntil,
|
|
arg.LastLoginAt,
|
|
arg.CreatedAt,
|
|
)
|
|
var i Account
|
|
err := row.Scan(
|
|
&i.PrincipalID,
|
|
&i.PasswordHash,
|
|
&i.PasswordChangedAt,
|
|
&i.MustChangePassword,
|
|
&i.State,
|
|
&i.FailedAttempts,
|
|
&i.LockedUntil,
|
|
&i.LastLoginAt,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const createMembership = `-- name: CreateMembership :one
|
|
|
|
INSERT INTO membership (
|
|
group_id,
|
|
member_id,
|
|
role,
|
|
created_at,
|
|
disabled_at
|
|
) VALUES (
|
|
?1,
|
|
?2,
|
|
?3,
|
|
?4,
|
|
?5
|
|
)
|
|
RETURNING group_id, member_id, role, created_at, disabled_at
|
|
`
|
|
|
|
type CreateMembershipParams struct {
|
|
GroupID string
|
|
MemberID string
|
|
Role string
|
|
CreatedAt int64
|
|
DisabledAt sql.NullInt64
|
|
}
|
|
|
|
// ============================================================================
|
|
// membership
|
|
// ============================================================================
|
|
func (q *Queries) CreateMembership(ctx context.Context, arg CreateMembershipParams) (Membership, error) {
|
|
row := q.db.QueryRowContext(ctx, createMembership,
|
|
arg.GroupID,
|
|
arg.MemberID,
|
|
arg.Role,
|
|
arg.CreatedAt,
|
|
arg.DisabledAt,
|
|
)
|
|
var i Membership
|
|
err := row.Scan(
|
|
&i.GroupID,
|
|
&i.MemberID,
|
|
&i.Role,
|
|
&i.CreatedAt,
|
|
&i.DisabledAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const createPrincipal = `-- name: CreatePrincipal :one
|
|
|
|
INSERT INTO principal (
|
|
id,
|
|
kind,
|
|
name,
|
|
public_key,
|
|
status,
|
|
created_at,
|
|
disabled_at
|
|
) VALUES (
|
|
?1,
|
|
?2,
|
|
?3,
|
|
?4,
|
|
?5,
|
|
?6,
|
|
?7
|
|
)
|
|
RETURNING id, kind, name, public_key, status, created_at, disabled_at
|
|
`
|
|
|
|
type CreatePrincipalParams struct {
|
|
ID string
|
|
Kind string
|
|
Name string
|
|
PublicKey []byte
|
|
Status string
|
|
CreatedAt int64
|
|
DisabledAt sql.NullInt64
|
|
}
|
|
|
|
// ============================================================================
|
|
// principal
|
|
// ============================================================================
|
|
func (q *Queries) CreatePrincipal(ctx context.Context, arg CreatePrincipalParams) (Principal, error) {
|
|
row := q.db.QueryRowContext(ctx, createPrincipal,
|
|
arg.ID,
|
|
arg.Kind,
|
|
arg.Name,
|
|
arg.PublicKey,
|
|
arg.Status,
|
|
arg.CreatedAt,
|
|
arg.DisabledAt,
|
|
)
|
|
var i Principal
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Kind,
|
|
&i.Name,
|
|
&i.PublicKey,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.DisabledAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteAccount = `-- name: DeleteAccount :exec
|
|
DELETE FROM account
|
|
WHERE principal_id = ?1
|
|
`
|
|
|
|
func (q *Queries) DeleteAccount(ctx context.Context, principalID string) error {
|
|
_, err := q.db.ExecContext(ctx, deleteAccount, principalID)
|
|
return err
|
|
}
|
|
|
|
const deleteMembership = `-- name: DeleteMembership :exec
|
|
DELETE FROM membership
|
|
WHERE group_id = ?1
|
|
AND member_id = ?2
|
|
`
|
|
|
|
type DeleteMembershipParams struct {
|
|
GroupID string
|
|
MemberID string
|
|
}
|
|
|
|
func (q *Queries) DeleteMembership(ctx context.Context, arg DeleteMembershipParams) error {
|
|
_, err := q.db.ExecContext(ctx, deleteMembership, arg.GroupID, arg.MemberID)
|
|
return err
|
|
}
|
|
|
|
const deletePrincipal = `-- name: DeletePrincipal :exec
|
|
DELETE FROM principal
|
|
WHERE id = ?1
|
|
`
|
|
|
|
func (q *Queries) DeletePrincipal(ctx context.Context, id string) error {
|
|
_, err := q.db.ExecContext(ctx, deletePrincipal, id)
|
|
return err
|
|
}
|
|
|
|
const disableMembership = `-- name: DisableMembership :one
|
|
UPDATE membership
|
|
SET disabled_at = ?1
|
|
WHERE group_id = ?2
|
|
AND member_id = ?3
|
|
RETURNING group_id, member_id, role, created_at, disabled_at
|
|
`
|
|
|
|
type DisableMembershipParams struct {
|
|
DisabledAt sql.NullInt64
|
|
GroupID string
|
|
MemberID string
|
|
}
|
|
|
|
func (q *Queries) DisableMembership(ctx context.Context, arg DisableMembershipParams) (Membership, error) {
|
|
row := q.db.QueryRowContext(ctx, disableMembership, arg.DisabledAt, arg.GroupID, arg.MemberID)
|
|
var i Membership
|
|
err := row.Scan(
|
|
&i.GroupID,
|
|
&i.MemberID,
|
|
&i.Role,
|
|
&i.CreatedAt,
|
|
&i.DisabledAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const enableMembership = `-- name: EnableMembership :one
|
|
UPDATE membership
|
|
SET disabled_at = NULL
|
|
WHERE group_id = ?1
|
|
AND member_id = ?2
|
|
RETURNING group_id, member_id, role, created_at, disabled_at
|
|
`
|
|
|
|
type EnableMembershipParams struct {
|
|
GroupID string
|
|
MemberID string
|
|
}
|
|
|
|
func (q *Queries) EnableMembership(ctx context.Context, arg EnableMembershipParams) (Membership, error) {
|
|
row := q.db.QueryRowContext(ctx, enableMembership, arg.GroupID, arg.MemberID)
|
|
var i Membership
|
|
err := row.Scan(
|
|
&i.GroupID,
|
|
&i.MemberID,
|
|
&i.Role,
|
|
&i.CreatedAt,
|
|
&i.DisabledAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getAccount = `-- name: GetAccount :one
|
|
SELECT principal_id, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
|
FROM account
|
|
WHERE principal_id = ?1
|
|
`
|
|
|
|
func (q *Queries) GetAccount(ctx context.Context, principalID string) (Account, error) {
|
|
row := q.db.QueryRowContext(ctx, getAccount, principalID)
|
|
var i Account
|
|
err := row.Scan(
|
|
&i.PrincipalID,
|
|
&i.PasswordHash,
|
|
&i.PasswordChangedAt,
|
|
&i.MustChangePassword,
|
|
&i.State,
|
|
&i.FailedAttempts,
|
|
&i.LockedUntil,
|
|
&i.LastLoginAt,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getMembership = `-- name: GetMembership :one
|
|
SELECT group_id, member_id, role, created_at, disabled_at
|
|
FROM membership
|
|
WHERE group_id = ?1
|
|
AND member_id = ?2
|
|
`
|
|
|
|
type GetMembershipParams struct {
|
|
GroupID string
|
|
MemberID string
|
|
}
|
|
|
|
func (q *Queries) GetMembership(ctx context.Context, arg GetMembershipParams) (Membership, error) {
|
|
row := q.db.QueryRowContext(ctx, getMembership, arg.GroupID, arg.MemberID)
|
|
var i Membership
|
|
err := row.Scan(
|
|
&i.GroupID,
|
|
&i.MemberID,
|
|
&i.Role,
|
|
&i.CreatedAt,
|
|
&i.DisabledAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getPrincipal = `-- name: GetPrincipal :one
|
|
SELECT id, kind, name, public_key, status, created_at, disabled_at
|
|
FROM principal
|
|
WHERE id = ?1
|
|
`
|
|
|
|
func (q *Queries) GetPrincipal(ctx context.Context, id string) (Principal, error) {
|
|
row := q.db.QueryRowContext(ctx, getPrincipal, id)
|
|
var i Principal
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Kind,
|
|
&i.Name,
|
|
&i.PublicKey,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.DisabledAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getPrincipalByName = `-- name: GetPrincipalByName :one
|
|
SELECT id, kind, name, public_key, status, created_at, disabled_at
|
|
FROM principal
|
|
WHERE name = ?1
|
|
`
|
|
|
|
func (q *Queries) GetPrincipalByName(ctx context.Context, name string) (Principal, error) {
|
|
row := q.db.QueryRowContext(ctx, getPrincipalByName, name)
|
|
var i Principal
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Kind,
|
|
&i.Name,
|
|
&i.PublicKey,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.DisabledAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const incrementFailedAttempts = `-- name: IncrementFailedAttempts :one
|
|
UPDATE account
|
|
SET failed_attempts = failed_attempts + 1
|
|
WHERE principal_id = ?1
|
|
RETURNING principal_id, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
|
`
|
|
|
|
func (q *Queries) IncrementFailedAttempts(ctx context.Context, principalID string) (Account, error) {
|
|
row := q.db.QueryRowContext(ctx, incrementFailedAttempts, principalID)
|
|
var i Account
|
|
err := row.Scan(
|
|
&i.PrincipalID,
|
|
&i.PasswordHash,
|
|
&i.PasswordChangedAt,
|
|
&i.MustChangePassword,
|
|
&i.State,
|
|
&i.FailedAttempts,
|
|
&i.LockedUntil,
|
|
&i.LastLoginAt,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listActivePrincipals = `-- name: ListActivePrincipals :many
|
|
SELECT id, kind, name, public_key, status, created_at, disabled_at
|
|
FROM principal
|
|
WHERE status = 'active'
|
|
ORDER BY name
|
|
`
|
|
|
|
func (q *Queries) ListActivePrincipals(ctx context.Context) ([]Principal, error) {
|
|
rows, err := q.db.QueryContext(ctx, listActivePrincipals)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Principal
|
|
for rows.Next() {
|
|
var i Principal
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Kind,
|
|
&i.Name,
|
|
&i.PublicKey,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.DisabledAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listGroupMembers = `-- name: ListGroupMembers :many
|
|
SELECT p.id, p.kind, p.name, p.public_key, p.status, p.created_at, p.disabled_at
|
|
FROM membership m
|
|
JOIN principal p ON p.id = m.member_id
|
|
WHERE m.group_id = ?1
|
|
AND m.disabled_at IS NULL
|
|
ORDER BY p.name
|
|
`
|
|
|
|
func (q *Queries) ListGroupMembers(ctx context.Context, groupID string) ([]Principal, error) {
|
|
rows, err := q.db.QueryContext(ctx, listGroupMembers, groupID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Principal
|
|
for rows.Next() {
|
|
var i Principal
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Kind,
|
|
&i.Name,
|
|
&i.PublicKey,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.DisabledAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listMemberGroups = `-- name: ListMemberGroups :many
|
|
SELECT p.id, p.kind, p.name, p.public_key, p.status, p.created_at, p.disabled_at
|
|
FROM membership m
|
|
JOIN principal p ON p.id = m.group_id
|
|
WHERE m.member_id = ?1
|
|
AND m.disabled_at IS NULL
|
|
ORDER BY p.name
|
|
`
|
|
|
|
func (q *Queries) ListMemberGroups(ctx context.Context, memberID string) ([]Principal, error) {
|
|
rows, err := q.db.QueryContext(ctx, listMemberGroups, memberID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Principal
|
|
for rows.Next() {
|
|
var i Principal
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Kind,
|
|
&i.Name,
|
|
&i.PublicKey,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.DisabledAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listMembershipsByGroup = `-- name: ListMembershipsByGroup :many
|
|
SELECT group_id, member_id, role, created_at, disabled_at
|
|
FROM membership
|
|
WHERE group_id = ?1
|
|
ORDER BY created_at
|
|
`
|
|
|
|
func (q *Queries) ListMembershipsByGroup(ctx context.Context, groupID string) ([]Membership, error) {
|
|
rows, err := q.db.QueryContext(ctx, listMembershipsByGroup, groupID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Membership
|
|
for rows.Next() {
|
|
var i Membership
|
|
if err := rows.Scan(
|
|
&i.GroupID,
|
|
&i.MemberID,
|
|
&i.Role,
|
|
&i.CreatedAt,
|
|
&i.DisabledAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listMembershipsByMember = `-- name: ListMembershipsByMember :many
|
|
SELECT group_id, member_id, role, created_at, disabled_at
|
|
FROM membership
|
|
WHERE member_id = ?1
|
|
ORDER BY created_at
|
|
`
|
|
|
|
func (q *Queries) ListMembershipsByMember(ctx context.Context, memberID string) ([]Membership, error) {
|
|
rows, err := q.db.QueryContext(ctx, listMembershipsByMember, memberID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Membership
|
|
for rows.Next() {
|
|
var i Membership
|
|
if err := rows.Scan(
|
|
&i.GroupID,
|
|
&i.MemberID,
|
|
&i.Role,
|
|
&i.CreatedAt,
|
|
&i.DisabledAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listPrincipals = `-- name: ListPrincipals :many
|
|
SELECT id, kind, name, public_key, status, created_at, disabled_at
|
|
FROM principal
|
|
ORDER BY name
|
|
`
|
|
|
|
func (q *Queries) ListPrincipals(ctx context.Context) ([]Principal, error) {
|
|
rows, err := q.db.QueryContext(ctx, listPrincipals)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Principal
|
|
for rows.Next() {
|
|
var i Principal
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Kind,
|
|
&i.Name,
|
|
&i.PublicKey,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.DisabledAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listPrincipalsByKind = `-- name: ListPrincipalsByKind :many
|
|
SELECT id, kind, name, public_key, status, created_at, disabled_at
|
|
FROM principal
|
|
WHERE kind = ?1
|
|
ORDER BY name
|
|
`
|
|
|
|
func (q *Queries) ListPrincipalsByKind(ctx context.Context, kind string) ([]Principal, error) {
|
|
rows, err := q.db.QueryContext(ctx, listPrincipalsByKind, kind)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Principal
|
|
for rows.Next() {
|
|
var i Principal
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Kind,
|
|
&i.Name,
|
|
&i.PublicKey,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.DisabledAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const lockAccount = `-- name: LockAccount :one
|
|
UPDATE account
|
|
SET state = 'locked',
|
|
locked_until = ?1
|
|
WHERE principal_id = ?2
|
|
RETURNING principal_id, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
|
`
|
|
|
|
type LockAccountParams struct {
|
|
LockedUntil sql.NullInt64
|
|
PrincipalID string
|
|
}
|
|
|
|
func (q *Queries) LockAccount(ctx context.Context, arg LockAccountParams) (Account, error) {
|
|
row := q.db.QueryRowContext(ctx, lockAccount, arg.LockedUntil, arg.PrincipalID)
|
|
var i Account
|
|
err := row.Scan(
|
|
&i.PrincipalID,
|
|
&i.PasswordHash,
|
|
&i.PasswordChangedAt,
|
|
&i.MustChangePassword,
|
|
&i.State,
|
|
&i.FailedAttempts,
|
|
&i.LockedUntil,
|
|
&i.LastLoginAt,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const recordLogin = `-- name: RecordLogin :one
|
|
UPDATE account
|
|
SET last_login_at = ?1,
|
|
failed_attempts = 0,
|
|
locked_until = NULL
|
|
WHERE principal_id = ?2
|
|
RETURNING principal_id, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
|
`
|
|
|
|
type RecordLoginParams struct {
|
|
LastLoginAt sql.NullInt64
|
|
PrincipalID string
|
|
}
|
|
|
|
func (q *Queries) RecordLogin(ctx context.Context, arg RecordLoginParams) (Account, error) {
|
|
row := q.db.QueryRowContext(ctx, recordLogin, arg.LastLoginAt, arg.PrincipalID)
|
|
var i Account
|
|
err := row.Scan(
|
|
&i.PrincipalID,
|
|
&i.PasswordHash,
|
|
&i.PasswordChangedAt,
|
|
&i.MustChangePassword,
|
|
&i.State,
|
|
&i.FailedAttempts,
|
|
&i.LockedUntil,
|
|
&i.LastLoginAt,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const resetFailedAttempts = `-- name: ResetFailedAttempts :one
|
|
UPDATE account
|
|
SET failed_attempts = 0,
|
|
locked_until = NULL
|
|
WHERE principal_id = ?1
|
|
RETURNING principal_id, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
|
`
|
|
|
|
func (q *Queries) ResetFailedAttempts(ctx context.Context, principalID string) (Account, error) {
|
|
row := q.db.QueryRowContext(ctx, resetFailedAttempts, principalID)
|
|
var i Account
|
|
err := row.Scan(
|
|
&i.PrincipalID,
|
|
&i.PasswordHash,
|
|
&i.PasswordChangedAt,
|
|
&i.MustChangePassword,
|
|
&i.State,
|
|
&i.FailedAttempts,
|
|
&i.LockedUntil,
|
|
&i.LastLoginAt,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const unlockAccount = `-- name: UnlockAccount :one
|
|
UPDATE account
|
|
SET state = 'active',
|
|
failed_attempts = 0,
|
|
locked_until = NULL
|
|
WHERE principal_id = ?1
|
|
RETURNING principal_id, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
|
`
|
|
|
|
func (q *Queries) UnlockAccount(ctx context.Context, principalID string) (Account, error) {
|
|
row := q.db.QueryRowContext(ctx, unlockAccount, principalID)
|
|
var i Account
|
|
err := row.Scan(
|
|
&i.PrincipalID,
|
|
&i.PasswordHash,
|
|
&i.PasswordChangedAt,
|
|
&i.MustChangePassword,
|
|
&i.State,
|
|
&i.FailedAttempts,
|
|
&i.LockedUntil,
|
|
&i.LastLoginAt,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateAccountState = `-- name: UpdateAccountState :one
|
|
UPDATE account
|
|
SET state = ?1
|
|
WHERE principal_id = ?2
|
|
RETURNING principal_id, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
|
`
|
|
|
|
type UpdateAccountStateParams struct {
|
|
State string
|
|
PrincipalID string
|
|
}
|
|
|
|
func (q *Queries) UpdateAccountState(ctx context.Context, arg UpdateAccountStateParams) (Account, error) {
|
|
row := q.db.QueryRowContext(ctx, updateAccountState, arg.State, arg.PrincipalID)
|
|
var i Account
|
|
err := row.Scan(
|
|
&i.PrincipalID,
|
|
&i.PasswordHash,
|
|
&i.PasswordChangedAt,
|
|
&i.MustChangePassword,
|
|
&i.State,
|
|
&i.FailedAttempts,
|
|
&i.LockedUntil,
|
|
&i.LastLoginAt,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateMembershipRole = `-- name: UpdateMembershipRole :one
|
|
UPDATE membership
|
|
SET role = ?1
|
|
WHERE group_id = ?2
|
|
AND member_id = ?3
|
|
RETURNING group_id, member_id, role, created_at, disabled_at
|
|
`
|
|
|
|
type UpdateMembershipRoleParams struct {
|
|
Role string
|
|
GroupID string
|
|
MemberID string
|
|
}
|
|
|
|
func (q *Queries) UpdateMembershipRole(ctx context.Context, arg UpdateMembershipRoleParams) (Membership, error) {
|
|
row := q.db.QueryRowContext(ctx, updateMembershipRole, arg.Role, arg.GroupID, arg.MemberID)
|
|
var i Membership
|
|
err := row.Scan(
|
|
&i.GroupID,
|
|
&i.MemberID,
|
|
&i.Role,
|
|
&i.CreatedAt,
|
|
&i.DisabledAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updatePassword = `-- name: UpdatePassword :one
|
|
UPDATE account
|
|
SET password_hash = ?1,
|
|
password_changed_at = ?2,
|
|
must_change_password = 0,
|
|
failed_attempts = 0,
|
|
locked_until = NULL
|
|
WHERE principal_id = ?3
|
|
RETURNING principal_id, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
|
`
|
|
|
|
type UpdatePasswordParams struct {
|
|
PasswordHash sql.NullString
|
|
PasswordChangedAt sql.NullInt64
|
|
PrincipalID string
|
|
}
|
|
|
|
func (q *Queries) UpdatePassword(ctx context.Context, arg UpdatePasswordParams) (Account, error) {
|
|
row := q.db.QueryRowContext(ctx, updatePassword, arg.PasswordHash, arg.PasswordChangedAt, arg.PrincipalID)
|
|
var i Account
|
|
err := row.Scan(
|
|
&i.PrincipalID,
|
|
&i.PasswordHash,
|
|
&i.PasswordChangedAt,
|
|
&i.MustChangePassword,
|
|
&i.State,
|
|
&i.FailedAttempts,
|
|
&i.LockedUntil,
|
|
&i.LastLoginAt,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updatePrincipalName = `-- name: UpdatePrincipalName :one
|
|
UPDATE principal
|
|
SET name = ?1
|
|
WHERE id = ?2
|
|
RETURNING id, kind, name, public_key, status, created_at, disabled_at
|
|
`
|
|
|
|
type UpdatePrincipalNameParams struct {
|
|
Name string
|
|
ID string
|
|
}
|
|
|
|
func (q *Queries) UpdatePrincipalName(ctx context.Context, arg UpdatePrincipalNameParams) (Principal, error) {
|
|
row := q.db.QueryRowContext(ctx, updatePrincipalName, arg.Name, arg.ID)
|
|
var i Principal
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Kind,
|
|
&i.Name,
|
|
&i.PublicKey,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.DisabledAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updatePrincipalPublicKey = `-- name: UpdatePrincipalPublicKey :one
|
|
UPDATE principal
|
|
SET public_key = ?1
|
|
WHERE id = ?2
|
|
RETURNING id, kind, name, public_key, status, created_at, disabled_at
|
|
`
|
|
|
|
type UpdatePrincipalPublicKeyParams struct {
|
|
PublicKey []byte
|
|
ID string
|
|
}
|
|
|
|
func (q *Queries) UpdatePrincipalPublicKey(ctx context.Context, arg UpdatePrincipalPublicKeyParams) (Principal, error) {
|
|
row := q.db.QueryRowContext(ctx, updatePrincipalPublicKey, arg.PublicKey, arg.ID)
|
|
var i Principal
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Kind,
|
|
&i.Name,
|
|
&i.PublicKey,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.DisabledAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updatePrincipalStatus = `-- name: UpdatePrincipalStatus :one
|
|
UPDATE principal
|
|
SET status = ?1,
|
|
disabled_at = ?2
|
|
WHERE id = ?3
|
|
RETURNING id, kind, name, public_key, status, created_at, disabled_at
|
|
`
|
|
|
|
type UpdatePrincipalStatusParams struct {
|
|
Status string
|
|
DisabledAt sql.NullInt64
|
|
ID string
|
|
}
|
|
|
|
func (q *Queries) UpdatePrincipalStatus(ctx context.Context, arg UpdatePrincipalStatusParams) (Principal, error) {
|
|
row := q.db.QueryRowContext(ctx, updatePrincipalStatus, arg.Status, arg.DisabledAt, arg.ID)
|
|
var i Principal
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Kind,
|
|
&i.Name,
|
|
&i.PublicKey,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.DisabledAt,
|
|
)
|
|
return i, err
|
|
}
|