feat(identity): name, lifetime and last-used on personal API tokens
This commit is contained in:
23 files changed
+449
-99
No files matched your search
@@ -77,6 +77,37 @@ func (q *Queries) GetIdentity(ctx context.Context, id string) (Identity, error)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getIdentitySubjectUse = `-- name: GetIdentitySubjectUse :one
|
||||
SELECT subject, bound_at, name, expires_at, last_used_at FROM identity_subjects
|
||||
WHERE issuer = $1 AND subject = $2
|
||||
`
|
||||
|
||||
type GetIdentitySubjectUseParams struct {
|
||||
Issuer string
|
||||
Subject string
|
||||
}
|
||||
|
||||
type GetIdentitySubjectUseRow struct {
|
||||
Subject string
|
||||
BoundAt time.Time
|
||||
Name string
|
||||
ExpiresAt pgtype.Timestamptz
|
||||
LastUsedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
func (q *Queries) GetIdentitySubjectUse(ctx context.Context, arg GetIdentitySubjectUseParams) (GetIdentitySubjectUseRow, error) {
|
||||
row := q.db.QueryRow(ctx, getIdentitySubjectUse, arg.Issuer, arg.Subject)
|
||||
var i GetIdentitySubjectUseRow
|
||||
err := row.Scan(
|
||||
&i.Subject,
|
||||
&i.BoundAt,
|
||||
&i.Name,
|
||||
&i.ExpiresAt,
|
||||
&i.LastUsedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getVisibleIdentity = `-- name: GetVisibleIdentity :one
|
||||
SELECT id, kind, display_name, lifecycle, version, created_at, updated_at
|
||||
FROM identities WHERE id = $1 AND ($2::text IS NULL
|
||||
@@ -259,7 +290,7 @@ func (q *Queries) ListIdentities(ctx context.Context, scopeOrg pgtype.Text) ([]I
|
||||
}
|
||||
|
||||
const listIdentitySubjects = `-- name: ListIdentitySubjects :many
|
||||
SELECT subject, bound_at FROM identity_subjects
|
||||
SELECT subject, bound_at, name, expires_at, last_used_at FROM identity_subjects
|
||||
WHERE identity_id = $1 AND issuer = $2
|
||||
ORDER BY bound_at DESC
|
||||
`
|
||||
@@ -270,8 +301,11 @@ type ListIdentitySubjectsParams struct {
|
||||
}
|
||||
|
||||
type ListIdentitySubjectsRow struct {
|
||||
Subject string
|
||||
BoundAt time.Time
|
||||
Subject string
|
||||
BoundAt time.Time
|
||||
Name string
|
||||
ExpiresAt pgtype.Timestamptz
|
||||
LastUsedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
func (q *Queries) ListIdentitySubjects(ctx context.Context, arg ListIdentitySubjectsParams) ([]ListIdentitySubjectsRow, error) {
|
||||
@@ -283,7 +317,13 @@ func (q *Queries) ListIdentitySubjects(ctx context.Context, arg ListIdentitySubj
|
||||
var items []ListIdentitySubjectsRow
|
||||
for rows.Next() {
|
||||
var i ListIdentitySubjectsRow
|
||||
if err := rows.Scan(&i.Subject, &i.BoundAt); err != nil {
|
||||
if err := rows.Scan(
|
||||
&i.Subject,
|
||||
&i.BoundAt,
|
||||
&i.Name,
|
||||
&i.ExpiresAt,
|
||||
&i.LastUsedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
@@ -348,6 +388,21 @@ func (q *Queries) ResolveIdentitySubject(ctx context.Context, arg ResolveIdentit
|
||||
return i, err
|
||||
}
|
||||
|
||||
const touchIdentitySubject = `-- name: TouchIdentitySubject :exec
|
||||
UPDATE identity_subjects SET last_used_at = $3 WHERE issuer = $1 AND subject = $2
|
||||
`
|
||||
|
||||
type TouchIdentitySubjectParams struct {
|
||||
Issuer string
|
||||
Subject string
|
||||
LastUsedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
func (q *Queries) TouchIdentitySubject(ctx context.Context, arg TouchIdentitySubjectParams) error {
|
||||
_, err := q.db.Exec(ctx, touchIdentitySubject, arg.Issuer, arg.Subject, arg.LastUsedAt)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateIdentity = `-- name: UpdateIdentity :execrows
|
||||
UPDATE identities SET display_name = $2, lifecycle = $3, version = $4, updated_at = $5
|
||||
WHERE id = $1 AND version = $6
|
||||
@@ -392,9 +447,10 @@ func (q *Queries) UpdateTaskIdentity(ctx context.Context, arg UpdateTaskIdentity
|
||||
}
|
||||
|
||||
const upsertIdentitySubject = `-- name: UpsertIdentitySubject :exec
|
||||
INSERT INTO identity_subjects (issuer, subject, identity_id, bound_at)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
ON CONFLICT (issuer, subject) DO UPDATE SET identity_id = excluded.identity_id, bound_at = excluded.bound_at
|
||||
INSERT INTO identity_subjects (issuer, subject, identity_id, bound_at, name, expires_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
ON CONFLICT (issuer, subject) DO UPDATE SET identity_id = excluded.identity_id, bound_at = excluded.bound_at,
|
||||
name = excluded.name, expires_at = excluded.expires_at
|
||||
`
|
||||
|
||||
type UpsertIdentitySubjectParams struct {
|
||||
@@ -402,6 +458,8 @@ type UpsertIdentitySubjectParams struct {
|
||||
Subject string
|
||||
IdentityID string
|
||||
BoundAt time.Time
|
||||
Name string
|
||||
ExpiresAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertIdentitySubject(ctx context.Context, arg UpsertIdentitySubjectParams) error {
|
||||
@@ -410,6 +468,8 @@ func (q *Queries) UpsertIdentitySubject(ctx context.Context, arg UpsertIdentityS
|
||||
arg.Subject,
|
||||
arg.IdentityID,
|
||||
arg.BoundAt,
|
||||
arg.Name,
|
||||
arg.ExpiresAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
@@ -266,6 +266,9 @@ type IdentitySubject struct {
|
||||
Subject string
|
||||
IdentityID string
|
||||
BoundAt time.Time
|
||||
Name string
|
||||
ExpiresAt pgtype.Timestamptz
|
||||
LastUsedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type InstalledPackage struct {
|
||||
|
||||
Reference in new issue
Block a user