|
| 1 | +import cuid from 'cuid' |
| 2 | +import { |
| 3 | + formatFieldToMatch, |
| 4 | + formatRuleLabels, |
| 5 | + formatRuleStatement, |
| 6 | + formatRuleAction, |
| 7 | + formatRuleOverrideAction, |
| 8 | + formatDefaultAction, |
| 9 | + formatFirewallManagerRuleGroups, |
| 10 | + formatVisibilityConfig |
| 11 | +} from './utils' |
| 12 | +import { AwsWafV2WebAcl } from '../../types/generated' |
| 13 | +import { RawAwsWafV2WebAcl } from './data' |
| 14 | + |
| 15 | +/** |
| 16 | + * WafV2WebAcl |
| 17 | + */ |
| 18 | + |
| 19 | +export default ({ |
| 20 | + account, |
| 21 | + service: rawData, |
| 22 | + region, |
| 23 | +}: { |
| 24 | + account: string |
| 25 | + service: RawAwsWafV2WebAcl |
| 26 | + region: string |
| 27 | +}): AwsWafV2WebAcl => { |
| 28 | + const { |
| 29 | + Id: id, |
| 30 | + ARN: arn, |
| 31 | + Name: name, |
| 32 | + Description: description, |
| 33 | + Rules, |
| 34 | + DefaultAction, |
| 35 | + Capacity: capacity, |
| 36 | + VisibilityConfig, |
| 37 | + PreProcessFirewallManagerRuleGroups, |
| 38 | + PostProcessFirewallManagerRuleGroups, |
| 39 | + ManagedByFirewallManager, |
| 40 | + LabelNamespace: labelNamespace, |
| 41 | + CustomResponseBodies, |
| 42 | + loggingConfiguration, |
| 43 | + } = rawData |
| 44 | + |
| 45 | + const mappedRules = Rules?.map(rule => ({ |
| 46 | + id: cuid(), |
| 47 | + name: rule.Name, |
| 48 | + priority: rule.Priority, |
| 49 | + statement: formatRuleStatement(rule.Statement), |
| 50 | + action: formatRuleAction(rule.Action), |
| 51 | + overrideAction: formatRuleOverrideAction(rule.OverrideAction), |
| 52 | + ruleLabels: formatRuleLabels(rule.RuleLabels), |
| 53 | + visibilityConfig: formatVisibilityConfig(rule.VisibilityConfig), |
| 54 | + })) |
| 55 | + |
| 56 | + const mappedCustomResponseBodies = Object.keys( |
| 57 | + CustomResponseBodies ?? {} |
| 58 | + ).map(key => ({ |
| 59 | + id: cuid(), |
| 60 | + key, |
| 61 | + contentType: CustomResponseBodies[key]?.ContentType, |
| 62 | + content: CustomResponseBodies[key]?.Content, |
| 63 | + })) |
| 64 | + |
| 65 | + const formattedLoggingConfig = { |
| 66 | + resourceArn: loggingConfiguration?.ResourceArn, |
| 67 | + logDestinationConfigs: loggingConfiguration?.LogDestinationConfigs, |
| 68 | + redactedFields: loggingConfiguration?.RedactedFields?.map(formatFieldToMatch), |
| 69 | + managedByFirewallManager: loggingConfiguration?.ManagedByFirewallManager, |
| 70 | + loggingFilter: { |
| 71 | + filters: loggingConfiguration?.LoggingFilter?.Filters?.map(filter => ({ |
| 72 | + id: cuid(), |
| 73 | + behavior: filter.Behavior, |
| 74 | + requirement: filter.Requirement, |
| 75 | + conditions: filter.Conditions?.map(condition => ({ |
| 76 | + id: cuid(), |
| 77 | + actionCondtion: { |
| 78 | + action: condition?.ActionCondition?.Action, |
| 79 | + }, |
| 80 | + labelNameCondition: { |
| 81 | + labelName: condition?.LabelNameCondition?.LabelName, |
| 82 | + }, |
| 83 | + })), |
| 84 | + })), |
| 85 | + defaultBehavior: loggingConfiguration?.LoggingFilter?.DefaultBehavior |
| 86 | + }, |
| 87 | + } |
| 88 | + |
| 89 | + return { |
| 90 | + id, |
| 91 | + region, |
| 92 | + accountId: account, |
| 93 | + arn, |
| 94 | + name, |
| 95 | + description, |
| 96 | + ManagedByFirewallManager, |
| 97 | + capacity, |
| 98 | + labelNamespace, |
| 99 | + rules: mappedRules, |
| 100 | + defaultAction: formatDefaultAction(DefaultAction), |
| 101 | + visibilityConfig: formatVisibilityConfig(VisibilityConfig), |
| 102 | + preProcessFirewallManagerRuleGroups: formatFirewallManagerRuleGroups( |
| 103 | + PreProcessFirewallManagerRuleGroups |
| 104 | + ), |
| 105 | + postProcessFirewallManagerRuleGroups: formatFirewallManagerRuleGroups( |
| 106 | + PostProcessFirewallManagerRuleGroups |
| 107 | + ), |
| 108 | + customResponseBodies: mappedCustomResponseBodies, |
| 109 | + loggingConfiguration: formattedLoggingConfig, |
| 110 | + } |
| 111 | +} |
0 commit comments