Skip to content

Commit

Permalink
fix: Updated athena macro no_star (#939)
Browse files Browse the repository at this point in the history
Co-authored-by: k-rheinheimer <[email protected]>
  • Loading branch information
ronsh12 and k-rheinheimer authored Jul 3, 2024
1 parent 3c69f2a commit 539d378
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions transformations/aws/macros/iam/no_star.sql
Original file line number Diff line number Diff line change
Expand Up @@ -135,32 +135,31 @@ WITH pvs AS (
),
fix_resouce_action as (
SELECT
id,
statement_fixed,
CASE
WHEN json_array_length(json_extract(statement_fixed, '$.Resource')) IS NULL THEN
json_parse('[' || json_extract_scalar(statement_fixed, '$.Resource') || ']')
ELSE
json_extract(statement_fixed, '$.Resource')
END AS resource_fixed,
CASE
WHEN json_array_length(json_extract(statement_fixed, '$.Action')) IS NULL THEN
json_parse('[' || json_extract_scalar(statement_fixed, '$.Action') || ']')
ELSE
json_extract(statement_fixed, '$.Action')
END AS action_fixed
FROM pvs

id,
statement as statement_fixed,
CASE
WHEN json_array_length(json_extract(statement, '$.Resource')) IS NULL THEN
json_parse('["' || json_extract_scalar(statement, '$.Resource') || '"]')
ELSE
json_extract(statement, '$.Resource')
END AS resource_fixed,
CASE
WHEN json_array_length(json_extract(statement, '$.Action')) IS NULL THEN
json_parse('["' || json_extract_scalar(statement, '$.Action') || '"]')
ELSE
json_extract(statement, '$.Action')
END AS action_fixed
FROM pvs,
UNNEST(CAST(statement_fixed as array(json))) as t(statement)
),
violations as (
select
id,
COUNT(*) as violations
from fix_resouce_action,
UNNEST(CAST(statement_fixed as array(json))) as t(statement),
UNNEST(CAST(resource_fixed as array(varchar))) t(resource),
UNNEST(CAST(action_fixed as array(varchar))) t(action)
where JSON_EXTRACT_SCALAR(statement, '$.Effect') = 'Allow'
where JSON_EXTRACT_SCALAR(statement_fixed, '$.Effect') = 'Allow'
and resource = '*'
and ( action = '*' or action = '*:*' )
group by id
Expand Down

0 comments on commit 539d378

Please sign in to comment.