The previous sort would run the risk of missing items which collide on update or create times because of the compound comparison using strictly less than for both the timestamp and the public_id. Sorting both descending avoids thi issue.
183 lines
4.7 KiB
Go
183 lines
4.7 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package authtoken
|
|
|
|
const (
|
|
estimateCountAuthTokens = `
|
|
select reltuples::bigint as estimate from pg_class where oid in ('auth_token'::regclass)
|
|
`
|
|
listAuthTokensTemplate = `
|
|
with auth_tokens as (
|
|
select public_id,
|
|
auth_account_id,
|
|
create_time,
|
|
update_time,
|
|
approximate_last_access_time,
|
|
expiration_time,
|
|
status
|
|
from auth_token
|
|
order by create_time desc, public_id desc
|
|
limit %d
|
|
),
|
|
auth_accounts as (
|
|
select public_id,
|
|
auth_method_id,
|
|
scope_id,
|
|
iam_user_id,
|
|
iam_user_scope_id
|
|
from auth_account
|
|
where %s
|
|
and public_id in (select auth_account_id from auth_tokens)
|
|
),
|
|
final as (
|
|
select at.public_id,
|
|
at.auth_account_id,
|
|
aa.auth_method_id,
|
|
aa.scope_id,
|
|
aa.iam_user_id,
|
|
aa.iam_user_scope_id,
|
|
at.create_time,
|
|
at.update_time,
|
|
at.approximate_last_access_time,
|
|
at.expiration_time,
|
|
at.status
|
|
from auth_tokens at
|
|
join auth_accounts aa on aa.public_id = at.auth_account_id
|
|
)
|
|
select *
|
|
from final
|
|
order by create_time desc, public_id desc;
|
|
`
|
|
listAuthTokensPageTemplate = `
|
|
with auth_tokens as (
|
|
select public_id,
|
|
auth_account_id,
|
|
create_time,
|
|
update_time,
|
|
approximate_last_access_time,
|
|
expiration_time,
|
|
status
|
|
from auth_token
|
|
where (create_time, public_id) < (@last_item_create_time, @last_item_id)
|
|
order by create_time desc, public_id desc
|
|
limit %d
|
|
),
|
|
auth_accounts as (
|
|
select public_id,
|
|
auth_method_id,
|
|
scope_id,
|
|
iam_user_id,
|
|
iam_user_scope_id
|
|
from auth_account
|
|
where %s
|
|
and public_id in (select auth_account_id from auth_tokens)
|
|
),
|
|
final as (
|
|
select at.public_id,
|
|
at.auth_account_id,
|
|
aa.auth_method_id,
|
|
aa.scope_id,
|
|
aa.iam_user_id,
|
|
aa.iam_user_scope_id,
|
|
at.create_time,
|
|
at.update_time,
|
|
at.approximate_last_access_time,
|
|
at.expiration_time,
|
|
at.status
|
|
from auth_tokens at
|
|
join auth_accounts aa on aa.public_id = at.auth_account_id
|
|
)
|
|
select *
|
|
from final
|
|
order by create_time desc, public_id desc;
|
|
`
|
|
refreshAuthTokensTemplate = `
|
|
with auth_tokens as (
|
|
select public_id,
|
|
auth_account_id,
|
|
create_time,
|
|
update_time,
|
|
approximate_last_access_time,
|
|
expiration_time,
|
|
status
|
|
from auth_token
|
|
where update_time > @updated_after_time
|
|
order by update_time desc, public_id desc
|
|
limit %d
|
|
),
|
|
auth_accounts as (
|
|
select public_id,
|
|
auth_method_id,
|
|
scope_id,
|
|
iam_user_id,
|
|
iam_user_scope_id
|
|
from auth_account
|
|
where %s
|
|
and public_id in (select auth_account_id from auth_tokens)
|
|
),
|
|
final as (
|
|
select at.public_id,
|
|
at.auth_account_id,
|
|
aa.auth_method_id,
|
|
aa.scope_id,
|
|
aa.iam_user_id,
|
|
aa.iam_user_scope_id,
|
|
at.create_time,
|
|
at.update_time,
|
|
at.approximate_last_access_time,
|
|
at.expiration_time,
|
|
at.status
|
|
from auth_tokens at
|
|
join auth_accounts aa on aa.public_id = at.auth_account_id
|
|
)
|
|
select *
|
|
from final
|
|
order by update_time desc, public_id desc;
|
|
`
|
|
refreshAuthTokensPageTemplate = `
|
|
with auth_tokens as (
|
|
select public_id,
|
|
auth_account_id,
|
|
create_time,
|
|
update_time,
|
|
approximate_last_access_time,
|
|
expiration_time,
|
|
status
|
|
from auth_token
|
|
where update_time > @updated_after_time
|
|
and (update_time, public_id) < (@last_item_update_time, @last_item_id)
|
|
order by update_time desc, public_id desc
|
|
limit %d
|
|
),
|
|
auth_accounts as (
|
|
select public_id,
|
|
auth_method_id,
|
|
scope_id,
|
|
iam_user_id,
|
|
iam_user_scope_id
|
|
from auth_account
|
|
where %s
|
|
and public_id in (select auth_account_id from auth_tokens)
|
|
),
|
|
final as (
|
|
select at.public_id,
|
|
at.auth_account_id,
|
|
aa.auth_method_id,
|
|
aa.scope_id,
|
|
aa.iam_user_id,
|
|
aa.iam_user_scope_id,
|
|
at.create_time,
|
|
at.update_time,
|
|
at.approximate_last_access_time,
|
|
at.expiration_time,
|
|
at.status
|
|
from auth_tokens at
|
|
join auth_accounts aa on aa.public_id = at.auth_account_id
|
|
)
|
|
select *
|
|
from final
|
|
order by update_time desc, public_id desc;
|
|
`
|
|
)
|