-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for aws waf v2 #974
Open
robertdeheer
wants to merge
3
commits into
inspec:main
Choose a base branch
from
robertdeheer:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require "aws_backend" | ||
|
||
class AWSWAFV2ByteMatchSet < AwsResourceBase | ||
name "aws_wafv2_byte_match_set" | ||
desc "Describes one WAF byte set." | ||
|
||
example " | ||
describe aws_wafv2_byte_match_set(byte_match_set_id: 'BYTE_MATCH_SET_ID') do | ||
it { should exits } | ||
end | ||
" | ||
|
||
def initialize(opts = {}) | ||
opts = { byte_match_set_id: opts } if opts.is_a?(String) | ||
super(opts) | ||
validate_parameters(required: %i(byte_match_set_id)) | ||
raise ArgumentError, "#{@__resource_name__}: byte_match_set_id must be provided" unless opts[:byte_match_set_id] && !opts[:byte_match_set_id].empty? | ||
@display_name = opts[:byte_match_set_id] | ||
catch_aws_errors do | ||
resp = @aws.waf_client_v2.get_byte_match_set({ byte_match_set_id: opts[:byte_match_set_id] }) | ||
@resp = resp.byte_match_set.to_h | ||
create_resource_methods(@resp) | ||
end | ||
end | ||
|
||
def byte_match_set_id | ||
return nil unless exists? | ||
@resp[:byte_match_set_id] | ||
end | ||
|
||
def exists? | ||
[email protected]? && [email protected]? | ||
end | ||
|
||
def to_s | ||
"Byte Match Set ID: #{@display_name}" | ||
end | ||
|
||
def byte_match_tuples_field_to_matches | ||
byte_match_tuples.map(&:field_to_match) | ||
end | ||
|
||
def byte_match_tuples_field_to_match_types | ||
byte_match_tuples.map(&:field_to_match).map(&:type) | ||
end | ||
|
||
def byte_match_tuples_field_to_match_data | ||
byte_match_tuples.map(&:field_to_match).map(&:data) | ||
end | ||
|
||
def byte_match_tuples_target_strings | ||
byte_match_tuples.map(&:target_string) | ||
end | ||
|
||
def byte_match_tuples_text_transformations | ||
byte_match_tuples.map(&:text_transformation) | ||
end | ||
|
||
def byte_match_tuples_positional_constraints | ||
byte_match_tuples.map(&:positional_constraint) | ||
end | ||
|
||
def resource_id | ||
@display_name | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require "aws_backend" | ||
|
||
class AWSWAFV2ByteMatchSets < AwsResourceBase | ||
name "aws_wafv2_byte_match_sets" | ||
desc "Verifies settings for all the WAF rules." | ||
|
||
example " | ||
describe aws_wafv2_byte_match_sets do | ||
it { should exist } | ||
end | ||
" | ||
|
||
attr_reader :table | ||
|
||
def initialize(opts = {}) | ||
super(opts) | ||
validate_parameters | ||
@table = fetch_data | ||
end | ||
|
||
FilterTable.create | ||
.register_column(:byte_match_set_ids, field: :byte_match_set_id, style: :simple) | ||
.register_column(:names, field: :name, style: :simple) | ||
.install_filter_methods_on_resource(self, :table) | ||
|
||
def fetch_data | ||
catch_aws_errors do | ||
@resp = @aws.waf_client_v2.list_byte_match_sets.map do |table| | ||
table.map { |table_name| { | ||
byte_match_set_id: table_name.byte_match_sets.map(&:byte_match_set_id), | ||
name: table_name.byte_match_sets.map(&:name), | ||
} | ||
} | ||
end.flatten | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require "aws_backend" | ||
|
||
class AWSWAFV2IPSet < AwsResourceBase | ||
name "aws_wafv2_ip_set" | ||
desc "Describes one WAF IP set." | ||
|
||
example " | ||
describe aws_wafv2_ip_set(ip_set_id: 'IP_SET_ID') do | ||
it { should exits } | ||
end | ||
" | ||
|
||
def initialize(opts = {}) | ||
opts = { ip_set_id: opts } if opts.is_a?(String) | ||
super(opts) | ||
validate_parameters(required: %i(ip_set_id)) | ||
raise ArgumentError, "#{@__resource_name__}: ip_set_id must be provided" unless opts[:ip_set_id] && !opts[:ip_set_id].empty? | ||
@display_name = opts[:ip_set_id] | ||
catch_aws_errors do | ||
resp = @aws.waf_client_v2.get_ip_set({ ip_set_id: opts[:ip_set_id] }) | ||
@resp = resp.ip_set.to_h | ||
create_resource_methods(@resp) | ||
end | ||
end | ||
|
||
def ip_set_id | ||
return nil unless exists? | ||
@resp[:ip_set_id] | ||
end | ||
|
||
def exists? | ||
[email protected]? && [email protected]? | ||
end | ||
|
||
def to_s | ||
"IP Set ID: #{@display_name}" | ||
end | ||
|
||
def ip_set_descriptors_types | ||
ip_set_descriptors.map(&:type) | ||
end | ||
|
||
def ip_set_descriptors_values | ||
ip_set_descriptors.map(&:value) | ||
end | ||
|
||
def resource_id | ||
@display_name | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require "aws_backend" | ||
|
||
class AWSWAFV2IPSets < AwsResourceBase | ||
name "aws_wafv2_ip_sets" | ||
desc "Verifies settings for all the IP sets." | ||
|
||
example " | ||
describe aws_wafv2_ip_sets do | ||
it { should exist } | ||
end | ||
" | ||
|
||
attr_reader :table | ||
|
||
def initialize(opts = {}) | ||
super(opts) | ||
validate_parameters | ||
@table = fetch_data | ||
end | ||
|
||
FilterTable.create | ||
.register_column(:ip_set_ids, field: :ip_set_id, style: :simple) | ||
.register_column(:names, field: :name, style: :simple) | ||
.install_filter_methods_on_resource(self, :table) | ||
|
||
def fetch_data | ||
catch_aws_errors do | ||
@resp = @aws.waf_client_v2.list_ip_sets.map do |table| | ||
table.map { |table_name| { | ||
name: table_name.ip_sets.map(&:name), | ||
ip_set_id: table_name.ip_sets.map(&:ip_set_id), | ||
} | ||
} | ||
end.flatten | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require "aws_backend" | ||
|
||
class AWSWAFV2Rule < AwsResourceBase | ||
name "aws_wafv2_rule" | ||
desc "Describes one WAF rule." | ||
|
||
example " | ||
describe aws_wafv2_rule(rule_id: 'RULE_ID') do | ||
it { should exits } | ||
end | ||
" | ||
|
||
def initialize(opts = {}) | ||
opts = { rule_id: opts } if opts.is_a?(String) | ||
super(opts) | ||
validate_parameters(required: %i(rule_id)) | ||
raise ArgumentError, "#{@__resource_name__}: rule_id must be provided" unless opts[:rule_id] && !opts[:rule_id].empty? | ||
@display_name = opts[:rule_id] | ||
catch_aws_errors do | ||
resp = @aws.waf_client_v2.get_rule({ rule_id: opts[:rule_id] }) | ||
@resp = resp.rule.to_h | ||
create_resource_methods(@resp) | ||
end | ||
end | ||
|
||
def rule_id | ||
return nil unless exists? | ||
@resp[:rule_id] | ||
end | ||
|
||
def exists? | ||
[email protected]? && [email protected]? | ||
end | ||
|
||
def to_s | ||
"Rule ID: #{@display_name}" | ||
end | ||
|
||
def predicates_negated | ||
predicates.map(&:negated) | ||
end | ||
|
||
def predicates_type | ||
predicates.map(&:type) | ||
end | ||
|
||
def predicates_data_id | ||
predicates.map(&:data_id) | ||
end | ||
|
||
def resource_id | ||
@display_name | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require "aws_backend" | ||
|
||
class AWSWAFV2Rules < AwsResourceBase | ||
name "aws_wafv2_rules" | ||
desc "Verifies settings for all the WAF rules." | ||
|
||
example " | ||
describe aws_wafv2_rules do | ||
it { should exist } | ||
end | ||
" | ||
|
||
attr_reader :table | ||
|
||
def initialize(opts = {}) | ||
super(opts) | ||
validate_parameters | ||
@table = fetch_data | ||
end | ||
|
||
FilterTable.create | ||
.register_column(:rule_ids, field: :rule_id) | ||
.register_column(:names, field: :name) | ||
.install_filter_methods_on_resource(self, :table) | ||
|
||
def fetch_data | ||
catch_aws_errors do | ||
@resp = @aws.waf_client_v2.list_rules.map do |table| | ||
table.rules.map { |table_name| { | ||
rule_id: table_name[:rule_id], | ||
name: table_name[:name], | ||
} | ||
} | ||
end.flatten | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
require "aws_backend" | ||
|
||
class AWSWAFV2SizeConstraintSet < AwsResourceBase | ||
name "aws_wafv2_size_constraint_set" | ||
desc "Describes one WAF size constraint set." | ||
|
||
example " | ||
describe aws_wafv2_size_constraint_set(size_constraint_set_id: 'SIZE_CONSTRAINT_SET_ID') do | ||
it { should exits } | ||
end | ||
" | ||
|
||
def initialize(opts = {}) | ||
opts = { size_constraint_set_id: opts } if opts.is_a?(String) | ||
super(opts) | ||
validate_parameters(required: %i(size_constraint_set_id)) | ||
raise ArgumentError, "#{@__resource_name__}: size_constraint_set_id must be provided" unless opts[:size_constraint_set_id] && !opts[:size_constraint_set_id].empty? | ||
@display_name = opts[:size_constraint_set_id] | ||
catch_aws_errors do | ||
resp = @aws.waf_client_v2.get_size_constraint_set({ size_constraint_set_id: opts[:size_constraint_set_id] }) | ||
@resp = resp.size_constraint_set.to_h | ||
create_resource_methods(@resp) | ||
end | ||
end | ||
|
||
def size_constraint_set_id | ||
return nil unless exists? | ||
@resp[:size_constraint_set_id] | ||
end | ||
|
||
def exists? | ||
[email protected]? && [email protected]? | ||
end | ||
|
||
def to_s | ||
"Size Constraint Set ID: #{@display_name}" | ||
end | ||
|
||
def size_constraints_field_to_match_types | ||
size_constraints.map(&:field_to_match).map(&:type) | ||
end | ||
|
||
def size_constraints_field_to_match_data | ||
size_constraints.map(&:field_to_match).map(&:data) | ||
end | ||
|
||
def size_constraints_text_transformations | ||
size_constraints.map(&:text_transformation) | ||
end | ||
|
||
def size_constraints_comparison_operators | ||
size_constraints.map(&:comparison_operator) | ||
end | ||
|
||
def size_constraints_sizes | ||
size_constraints.map(&:size) | ||
end | ||
|
||
def resource_id | ||
@display_name | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there is an extra 'WAF' here -
Aws::WAFV2::Client
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/WAFV2/Client.html