Files
threshold/internal/target/query.go
T
Jeff Mitchell 4cf2a87e8d Update targets to new listing method (#2045)
This uses the prefetch method to fetch resource IDs and validate them
for authz by the user before then fetching the full list of targets.
2022-04-29 16:33:44 -04:00

54 lines
1.1 KiB
Go

package target
const (
setChangesQuery = `
with
set_libraries (library_id) as (
-- returns the SET list
select public_id
from credential_library
where public_id in (%s)
),
current_libraries (library_id) as (
-- returns the current list
select credential_library_id
from target_credential_library
where target_id = @target_id
and credential_purpose = @purpose
),
keep_libraries (library_id) as (
-- returns the KEEP list
select library_id
from current_libraries
where library_id in (select * from set_libraries)
),
delete_libraries (library_id) as (
-- returns the DELETE list
select library_id
from current_libraries
where library_id not in (select * from set_libraries)
),
insert_libraries (library_id) as (
-- returns the ADD list
select library_id
from set_libraries
where library_id not in (select * from keep_libraries)
),
final (action, library_id) as (
select 'delete', library_id
from delete_libraries
union
select 'add', library_id
from insert_libraries
)
select * from final
order by action, library_id;
`
targetPublicIdList = `
select public_id, scope_id from target
%s
;
`
)