diff --git a/Gemfile b/Gemfile index fee6f685c..4ce46d1ff 100644 --- a/Gemfile +++ b/Gemfile @@ -10,6 +10,9 @@ gem 'bundle' # Note if the gem required is commented out, please raise a PR against the train-aws repo first # In the mean time the gem can be added here for local development +# TODO: remove when https://github.com/inspec/train-aws/pull/457 is merged +gem 'aws-sdk-account', '~> 1.14' + # Use Latest Inspec gem 'inspec-bin' diff --git a/docs/resources/aws_cloudfront_distribution.md b/docs/resources/aws_cloudfront_distribution.md new file mode 100644 index 000000000..59cd8688c --- /dev/null +++ b/docs/resources/aws_cloudfront_distribution.md @@ -0,0 +1,108 @@ +--- +title: About the aws_cloudfront_distribution Resource +platform: aws +--- + +# aws\_cloudfront\_distribution + +Use the `aws_cloudfront_distribution` InSpec audit resource to test properties of a single AWS CloudFront distribution. + +## Syntax + +Ensure that an `aws_cloudfront_distribution` exists: + + describe aws_cloudfront_distribution('DISTRIBUTION') do + it { should exist } + end + + describe aws_cloudfront_distribution(distribution_id: 'DISTRIBUTION') do + it { should exist } + end + +#### Parameters + +##### distribution\_id _(required)_ + +The ID of the CloudFront distribution. This can be passed either as a string or as a `name: 'value'` key-value entry in a hash. + +##### disallowed\_ssl\_protocols _(optional)_ + +If provided, this parameter is expected to be an array of strings identifying SSL/TLS protocols that you wish not to allow. + +Included in the array should be the union of disallowed identifiers for: +- custom origin SSL/TLS protocols (currently SSLv3 | TLSv1 | TLSv1.1 | TLSv1.2) +- identifiers for the minimum SSL/TLS protocol in the Viewer Certificate that CloudFront can use to communicate with viewers (currently SSLv3 | TLSv1 | TLSv1_1026 | TLSv1.1_2016 | TLSv1.2_2018 | TLSv1.2_2019 | TLSv1.2_2021). + +Newer protocol identification strings (when available) may be provided in the set, as validity is not checked. The default value for disallowed_ssl_protocols is `%w{SSLv3 TLSv1 TLSv1_2016}`. + +For additional information, see the [AWS API reference for CloudFront distributions](https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_distribution.html) documentation. For available SSL/TLS version identifiers, see [OriginSslProtocols](https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_OriginSslProtocols.html) and [AWS::CloudFront::distribution ViewerCertificate](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-distribution-viewercertificate.html) documentation. + +## Properties + +|Property | Description| +| --- | --- | +|distribution\_id | The identifier for the CloudFront distribution. | +|viewer\_protocol\_policies | An array of viewer protocol policies for all caches in this distribution; valid policy names are `allow-all` (which allows HTTP and HTTPS), `https-only` or `redirect-to-https`. | +|custom\_origin\_ssl\_protocols | An array containing SSL/TLS protocols allowed by custom origins in this distribution. Empty if there are no custom origins (one or more standard S3 bucket origins). Current valid values: `SSLv3`, `TLSv1`, `TLSv1.1`, `TLSv1.2`. | +|viewer\_certificate\_minimum\_ssl\_protocol | The minimum SSL/TLS protocol version in the Viewer Certificate. Current valid values: `SSLv3`, `TLSv1`, `TLSv1_2016`, `TLSv1.1_2016`, `TLSv1.2_2018`, `TLSv1.2_2019`, `TLSv1.2_2021`. | +|s3\_origin\_config | True if there are any S3 origin configs in the distribution (i.e. standard S3 bucket origins), else false. | + +## Examples + +### Test that a CloudFront distribution has secure protocols configured + + describe aws_cloudfront_distribution('DISTRIBUTION_ID') do + its('viewer_certificate_minimum_ssl_protocol') { should_not match /SSLv3|TLSv1$|TLSv1_2016/ } + its('viewer_protocol_policies') { should_not include 'allow-all' } + {SSLv3 TLSv1}.each do |protocol| + its('custom_origin_ssl_protocols') { should_not include protocol } + end + end + +## Matchers + +This InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/). + +### have_viewer_protocol_policies_allowing_http + +The `have_viewer_protocol_policies_allowing_http` matcher tests if any of the caches for origins, including the default cache, has its viewer_protocol_policy set to 'allow-all'. + + it { should_not have_viewer_protocol_policies_allowing_http } + +### have\_disallowed\_custom\_origin\_ssl\_protocols + +The `have_disallowed_custom_origin_ssl_protocols` matcher tests whether any of the the SSL/TLS protocols defined in the ssl_protocols for all custom origins in the distribution are present in the `disallowed_ssl_protocols` parameter (if provided), or in the default disallowed SSL/TLS protocol list (if not). + + it { should_not have_disallowed_custom_origin_ssl_protocols } + +### have\_disallowed\_viewer\_certificate\_minimum\_ssl\_protocol + +The `have_disallowed_viewer_minimum_ssl_protocol` matcher tests whether the minimum SSL/TLS protocol for the distribution's Viewer Certificate is in the `disallowed_ssl_protocols` parameter (if provided), or in the default disallowed SSL/TLS protocol list (if not). + + it { should_not have_disallowed_viewer_certificate_minimum_ssl_protocol } + +### have\_s3\_origin\_configs + +The `have_s3_origin_configs` matcher tests whether the distribution has a non-nil s3_origin_configs setting in any of its origins. + + it { should_not have_s3_origin_configs } + +### exist + +The control will pass if the describe returns at least one result. + + describe aws_cloudfront_distribution('EXISTING_DISTRIBUTION_ID') do + it { should exist } + end + +Use `should_not` to test the entity should not exist. + + describe cloudfront_distribution('NONEXISTING_DISTRIBUTION_ID') do + it { should_not exist } + end + +## AWS Permissions + +Your [Principal](https://docs.aws.amazon.com/IAM/latest/UserGuide/intro-structure.html#intro-structure-principal) will need the `cloudfront:GetDistribution` action set to Allow. + +You can find detailed documentation at [Identity and Access Management (IAM) in CloudFront](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/auth-and-access-control.html). diff --git a/docs/resources/aws_cloudfront_distributions.md b/docs/resources/aws_cloudfront_distributions.md new file mode 100644 index 000000000..2d67776b2 --- /dev/null +++ b/docs/resources/aws_cloudfront_distributions.md @@ -0,0 +1,72 @@ +--- +title: About the aws_cloudfront_distributions Resource +platform: aws +--- + +# aws\_cloudfront\_distributions + +Use the `aws_cloudfront_distributions` InSpec audit resource to test properties of a collection of AWS CloudFront distributions. + +## Syntax + +Ensure that a particular CloudFront distribution exists in `aws_cloudfront_distributions`: + + describe aws_cloudfront_distributions do + its('distribution_ids') { should include 'DISTRIBUTION_ID' } + end + +## Parameters + +This resource does not expect any parameters. + +See also the [AWS API reference for CloudFront distributions](https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_distribution.html). + +## Properties + +|Property | Description| +| --- | --- | +|distribution_ids | The names of the CloudFront distributions. | +|distribution_arns | The Amazon Resource Name (ARN) of the CloudFront distributions. | +|statuses | The statuses of the CloudFront distributions (`InProgress` or `Deployed`). | +|domain_names | The domain names for the CloudFront distributions. | +|origin_domains_names | The domain names for the CloudFront distributions' origins (an array for each distribution). | +|default_cache_viewer_protocol_policies | The viewer protocol policy for the default cache for each of the CloudFront distributions. Values: `http-only`, `redirect-to-https` or `allow-all`. | +|cache_viewer_protocol_policies | The viewer protocol policy for all non-default caches for each of the CloudFront distributions (an array for each distribution). Values: `http-only`, `redirect-to-https` or `allow-all`. There may be an empty array for a distribution if no non-default caches are present.| +|custom_origin_ssl_protocols | An array for each CloudFront distribution containing SSL/TLS protocols allowed by all of the custom origins in that distribution, empty where no custom origins exist for a distribution. Current SSL/TLS protocol identifiers: `SSLv3`, `TLSv1`, `TLSv1_1026`, `TLSv1.1_2016`, `TLSv1.2_2018`, `TLSv1.2_2019` and `TLSv1.2_2021`. | +|s3_origin_config | Booleans indicating whether there are any S3 origin configs in a particular distribution (non-custom S3 bucket origins). | +|price_classes | The price classes for distributions, which corresponds with the maximum price that you want to pay for CloudFront service. Valid Values: `PriceClass_100`, `PriceClass_200`, `PriceClass_All`. | +|enabled | Booleans indicating whether the distributions are enabled. | +|viewer_certificate_ssl_support_methods | The SSL support methods for Viewer Certificates for the distributions, only set for distributions with aliases. Valid values: `sni-only`, `vip` or `static-ip`. | +|viewer_certificate_minimum_ssl_protocols | The minimum SSL/TLS protocol allowed by the Viewer Certificate in each distribution. Current valid values: `SSLv3`, `TLSv1`, `TLSv1_2016`, `TLSv1.1_2016`, `TLSv1.2_2018`, `TLSv1.2_2019`, `TLSv1.2_2021`. | +|http_versions | The maximum HTTP versions that viewers may to use to communicate with CloudFront distributions. Valid values: `http1.1` or `http2`. | +|ipv6_enabled | Booleans indicating whether IPv6 is enabled for CloudFront distributions. | + +## Examples + +### Test that a particular CloudFront distribution exists, and that no cache viewer protocol policies allow HTTP + + describe aws_cloudfront_distributions do + its('distribution_ids') { should include 'DISTRIBUTION_ID' } + its('default_cache_viewer_protocol_policies') { should_not include 'allow-all' } + its('cache_viewer_protocol_policies') { should_not include 'allow-all' } + end + +## Matchers + +This InSpec audit resource has no special matchers. For a full list of available matchers, please visit our [Universal Matchers page](https://www.inspec.io/docs/reference/matchers/). + +### exist + +The control will pass if the describe returns at least one result. + +Use `should_not` to test the entity should not exist. + + describe aws_cloudfront_distributions do + it { should exist } + end + +## AWS Permissions + +Your [Principal](https://docs.aws.amazon.com/IAM/latest/UserGuide/intro-structure.html#intro-structure-principal) will need the `cloudfront:Listdistributions` action set to Allow. + +You can find detailed documentation at [Identity and Access Management (IAM) in CloudFront](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/auth-and-access-control.html). diff --git a/libraries/aws_account.rb b/libraries/aws_account.rb new file mode 100644 index 000000000..e0491072f --- /dev/null +++ b/libraries/aws_account.rb @@ -0,0 +1,249 @@ +require "aws_backend" +require "pry" + +class AwsPrimaryAccount < AwsResourceBase + name "aws_primary_contact" + desc "Verifies the primary contact information for an AWS Account." + example <<~EXAMPLE + describe aws_primary_account do + it { should be_configured } + its('full_name') { should cmp 'John Smith' } + its('address_line_1') { should cmp '42 Wallaby Way' } + end + EXAMPLE + + attr_reader :table, :raw_data + + FilterTable.create + .register_column(:address_line_1, field: :address_line_1, style: :simple) + .register_column(:adress_line_2, field: :adress_line_2, style: :simple) + .register_column(:address_line_3, field: :address_line_3, style: :simple) + .register_column(:city, field: :city, style: :simple) + .register_column(:company_name, field: :company_name, style: :simple) + .register_column(:country_code, field: :country_code, style: :simple) + .register_column(:district_or_county, field: :district_or_county, style: :simple) + .register_column(:full_name, field: :full_name, style: :simple) + .register_column(:phone_number, field: :phone_number, style: :simple) + .register_column(:postal_code, field: :postal_code, style: :simple) + .register_column(:state_or_region, field: :state_or_region, style: :simple) + .register_column(:website_url, field: :website_url, style: :simple) + .register_custom_matcher(:configured?) { |x| x.entries.any? } + .install_filter_methods_on_resource(self, :table) + + def initialize(opts = {}) + super(opts) + validate_parameters + # binding.pry + @table = fetch_data + end + + def resource_id + "AWS Account for #{@table[0][:full_name]}" || "AWS Account Contact Information" + end + + def to_s + "AWS Account Primary Contact" + end + + def fetch_data + @raw_data = [] + loop do + catch_aws_errors do + @api_response = @aws.account_client.get_contact_information.contact_information + end + return [] if !@api_response || @api_response.empty? + + @raw_data << { + address_line_1: @api_response.address_line_1, + address_line_2: @api_response.address_line_2, + address_line_3: @api_response.address_line_3, + city: @api_response.city, + company_name: @api_response.company_name, + country_code: @api_response.country_code, + district_or_county: @api_response.district_or_county, + full_name: @api_response.full_name, + phone_number: @api_response.phone_number, + postal_code: @api_response.postal_code, + state_or_region: @api_response.state_or_region, + website_url: @api_response.website_url, + } + break + end + @raw_data + end + + # @aws.account_client.get_alternate_contact({alternate_contact_type: "BILLING"}).alternate_contact.to_h.transform_keys(&:to_s) + # resp.alternate_contact.alternate_contact_type #=> String, one of "BILLING", "OPERATIONS", "SECURITY" + # resp.alternate_contact.email_address #=> String + # resp.alternate_contact.name #=> String + # resp.alternate_contact.phone_number #=> String + # resp.alternate_contact.title #=> String + + class AwsBillingAccount < AwsResourceBase + name "aws_billing_contact" + desc "Verifies the billing contact information for an AWS Account." + example <<~EXAMPLE + describe aws_billing_account do + it { should be_configured } + its('name') { should cmp 'John Smith' } + its('email_address') { should cmp 'jsmith@acme.com' } + end + EXAMPLE + + attr_reader :table, :raw_data + + FilterTable.create + .register_column(:email_address, field: :email_address, style: :simple) + .register_column(:name, field: :name, style: :simple) + .register_column(:phone_number, field: :phone_number, style: :simple) + .register_column(:title, field: :title, style: :simple) + .register_custom_matcher(:configured?) { |x| x.entries.any? } + .install_filter_methods_on_resource(self, :table) + + def initialize(opts = {}) + super(opts) + validate_parameters + @table = fetch_data + end + + def resource_id + "AWS Billing for #{@table[0][:name]}" || "AWS Account Billing Information" + end + + def to_s + "AWS Account Billing Contact" + end + + def fetch_data + @raw_data = [] + loop do + catch_aws_errors do + @api_response = @aws.account_client.get_alternate_contact({ alternate_contact_type: "BILLING" }).alternate_contact + end + return [] if !@api_response || @api_response.empty? + + @raw_data << { + email_address: @api_response.email_address, + name: @api_response.name, + phone_number: @api_response.phone_number, + title: @api_response.title, + } + break + end + @raw_data + end + end + + # @aws.account_client.get_alternate_contact({alternate_contact_type: "OPERATIONS"}).alternate_contact.to_h.transform_keys(&:to_s) + + class AwsAccountOperationsContact < AwsResourceBase + name "aws_operations_contact" + desc "Verifies the operations contact information for an AWS Account." + example <<~EXAMPLE + describe aws_operations_account do + it { should be_configured } + its('name') { should cmp 'John Smith' } + its('email_address') { should cmp 'jsmith@acme.com' } + end + EXAMPLE + + attr_reader :table, :raw_data + + FilterTable.create + .register_column(:email_address, field: :email_address, style: :simple) + .register_column(:name, field: :name, style: :simple) + .register_column(:phone_number, field: :phone_number, style: :simple) + .register_column(:title, field: :title, style: :simple) + .register_custom_matcher(:configured?) { |x| x.entries.any? } + .install_filter_methods_on_resource(self, :table) + + def initialize(opts = {}) + super(opts) + validate_parameters + @table = fetch_data + end + + def resource_id + "AWS Operations Contact for #{@table[0][:name]}" || "AWS Account Operations Contact Information" + end + + def to_s + "AWS Account Operations Contact Information" + end + + def fetch_data + @raw_data = [] + loop do + catch_aws_errors do + @api_response = @aws.account_client.get_alternate_contact({ alternate_contact_type: "OPERATIONS" }).alternate_contact + end + return [] if !@api_response || @api_response.empty? + + @raw_data << { + email_address: @api_response.email_address, + name: @api_response.name, + phone_number: @api_response.phone_number, + title: @api_response.title, + } + break + end + @raw_data + end + end + + # @aws.account_client.get_alternate_contact({alternate_contact_type: "SECURITY"}).alternate_contact.to_h.transform_keys(&:to_s) + class AwsAccountSecurityContact < AwsResourceBase + name "aws_security_contact" + desc "Verifies the security contact information for an AWS Account." + example <<~EXAMPLE + describe aws_security_account do + it { should be_configured } + its('name') { should cmp 'John Smith' } + its('email_address') { should cmp 'jsmith@acme.com' } + end + EXAMPLE + + attr_reader :table, :raw_data + + FilterTable.create + .register_column(:email_address, field: :email_address, style: :simple) + .register_column(:name, field: :name, style: :simple) + .register_column(:phone_number, field: :phone_number, style: :simple) + .register_column(:title, field: :title, style: :simple) + .register_custom_matcher(:configured?) { |x| x.entries.any? } + .install_filter_methods_on_resource(self, :table) + + def initialize(opts = {}) + super(opts) + validate_parameters + @table = fetch_data + end + + def resource_id + "AWS Security Contact for #{@table[0][:name]}" || "AWS Account Security Contact Information" + end + + def to_s + "AWS Account Security Contact" + end + + def fetch_data + @raw_data = [] + loop do + catch_aws_errors do + @api_response = @aws.account_client.get_alternate_contact({ alternate_contact_type: "SECURITY" }).alternate_contact + end + return [] if !@api_response || @api_response.empty? + + @raw_data << { + email_address: @api_response.email_address, + name: @api_response.name, + phone_number: @api_response.phone_number, + title: @api_response.title, + } + break + end + @raw_data + end + end +end diff --git a/libraries/aws_amplify_app.rb b/libraries/aws_amplify_app.rb index 93afac3fd..103446e77 100644 --- a/libraries/aws_amplify_app.rb +++ b/libraries/aws_amplify_app.rb @@ -14,7 +14,9 @@ def initialize(opts = {}) super(opts) validate_parameters(required: [:app_id]) - raise ArgumentError, "#{@__resource_name__}: app_id must be provided" unless opts[:app_id] && !opts[:app_id].empty? + unless opts[:app_id] && !opts[:app_id].empty? + raise ArgumentError, "#{@__resource_name__}: app_id must be provided" + end @display_name = opts[:app_id] resp = @aws.amplify_client.get_app({ app_id: opts[:app_id] }) @apps = resp.app.to_h @@ -27,7 +29,7 @@ def app_id end def resource_id - @apps? @apps[:app_id] : @display_name + @apps ? @apps[:app_id] : @display_name end def exists? diff --git a/libraries/aws_amplify_branch.rb b/libraries/aws_amplify_branch.rb index a7a5dab5c..dbb565517 100644 --- a/libraries/aws_amplify_branch.rb +++ b/libraries/aws_amplify_branch.rb @@ -13,10 +13,17 @@ def initialize(opts = {}) opts = { app_id: opts } if opts.is_a?(String) opts = { branch_name: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(app_id branch_name)) - raise ArgumentError, "#{@__resource_name__}: app_id and branch_name must be provided" unless opts[:app_id] && !opts[:app_id].empty? && opts[:branch_name] && !opts[:branch_name].empty? + validate_parameters(required: %i[app_id branch_name]) + unless opts[:app_id] && !opts[:app_id].empty? && opts[:branch_name] && + !opts[:branch_name].empty? + raise ArgumentError, + "#{@__resource_name__}: app_id and branch_name must be provided" + end @display_name = opts[:branch_name] - resp = @aws.amplify_client.get_branch({ app_id: opts[:app_id], branch_name: opts[:branch_name] }) + resp = + @aws.amplify_client.get_branch( + { app_id: opts[:app_id], branch_name: opts[:branch_name] } + ) @apps = resp.branch.to_h create_resource_methods(@apps) end diff --git a/libraries/aws_api_gateway_deployment.rb b/libraries/aws_api_gateway_deployment.rb index fffda4a8e..f7e1d645d 100644 --- a/libraries/aws_api_gateway_deployment.rb +++ b/libraries/aws_api_gateway_deployment.rb @@ -11,12 +11,23 @@ class AWSApiGatewayDeployment < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(rest_api_id deployment_id)) - raise ArgumentError, "#{@__resource_name__}: rest_api_id must be provided" unless opts[:rest_api_id] && !opts[:rest_api_id].empty? - raise ArgumentError, "#{@__resource_name__}: deployment_id must be provided" unless opts[:deployment_id] && !opts[:deployment_id].empty? + validate_parameters(required: %i[rest_api_id deployment_id]) + unless opts[:rest_api_id] && !opts[:rest_api_id].empty? + raise ArgumentError, "#{@__resource_name__}: rest_api_id must be provided" + end + unless opts[:deployment_id] && !opts[:deployment_id].empty? + raise ArgumentError, + "#{@__resource_name__}: deployment_id must be provided" + end @display_name = opts[:rest_api_id] catch_aws_errors do - resp = @aws.apigateway_client.get_deployment({ rest_api_id: opts[:rest_api_id], deployment_id: opts[:deployment_id] }) + resp = + @aws.apigateway_client.get_deployment( + { + rest_api_id: opts[:rest_api_id], + deployment_id: opts[:deployment_id] + } + ) @res = resp.to_h create_resource_methods(@res) end diff --git a/libraries/aws_api_gateway_documentation_part.rb b/libraries/aws_api_gateway_documentation_part.rb index a09dc248c..8825f9bb6 100644 --- a/libraries/aws_api_gateway_documentation_part.rb +++ b/libraries/aws_api_gateway_documentation_part.rb @@ -11,12 +11,23 @@ class AWSApiGatewayDocumentationPart < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(rest_api_id documentation_part_id)) - raise ArgumentError, "#{@__resource_name__}: rest_api_id must be provided" unless opts[:rest_api_id] && !opts[:rest_api_id].empty? - raise ArgumentError, "#{@__resource_name__}: documentation_part_id must be provided" unless opts[:documentation_part_id] && !opts[:documentation_part_id].empty? + validate_parameters(required: %i[rest_api_id documentation_part_id]) + unless opts[:rest_api_id] && !opts[:rest_api_id].empty? + raise ArgumentError, "#{@__resource_name__}: rest_api_id must be provided" + end + unless opts[:documentation_part_id] && !opts[:documentation_part_id].empty? + raise ArgumentError, + "#{@__resource_name__}: documentation_part_id must be provided" + end @display_name = opts[:documentation_part_id] catch_aws_errors do - resp = @aws.apigateway_client.get_documentation_part({ rest_api_id: opts[:rest_api_id], documentation_part_id: opts[:documentation_part_id] }) + resp = + @aws.apigateway_client.get_documentation_part( + { + rest_api_id: opts[:rest_api_id], + documentation_part_id: opts[:documentation_part_id] + } + ) @res = resp.to_h create_resource_methods(@res) end diff --git a/libraries/aws_api_gateway_documentation_version.rb b/libraries/aws_api_gateway_documentation_version.rb index 31dbc0ef0..c2485be20 100644 --- a/libraries/aws_api_gateway_documentation_version.rb +++ b/libraries/aws_api_gateway_documentation_version.rb @@ -11,12 +11,23 @@ class AWSApiGatewayDocumentationVersion < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(rest_api_id documentation_version)) - raise ArgumentError, "#{@__resource_name__}: rest_api_id must be provided" unless opts[:rest_api_id] && !opts[:rest_api_id].empty? - raise ArgumentError, "#{@__resource_name__}: documentation_version must be provided" unless opts[:documentation_version] && !opts[:documentation_version].empty? + validate_parameters(required: %i[rest_api_id documentation_version]) + unless opts[:rest_api_id] && !opts[:rest_api_id].empty? + raise ArgumentError, "#{@__resource_name__}: rest_api_id must be provided" + end + unless opts[:documentation_version] && !opts[:documentation_version].empty? + raise ArgumentError, + "#{@__resource_name__}: documentation_version must be provided" + end @display_name = opts[:documentation_version] catch_aws_errors do - resp = @aws.apigateway_client.get_documentation_version({ rest_api_id: opts[:rest_api_id], documentation_version: opts[:documentation_version] }) + resp = + @aws.apigateway_client.get_documentation_version( + { + rest_api_id: opts[:rest_api_id], + documentation_version: opts[:documentation_version] + } + ) @res = resp.to_h create_resource_methods(@res) end diff --git a/libraries/aws_api_gateway_domain_name.rb b/libraries/aws_api_gateway_domain_name.rb index 0aaf0c980..bba526ce6 100644 --- a/libraries/aws_api_gateway_domain_name.rb +++ b/libraries/aws_api_gateway_domain_name.rb @@ -12,18 +12,24 @@ class AWSApiGatewayDomainName < AwsResourceBase def initialize(opts = {}) opts = { domain_name: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(domain_name)) - raise ArgumentError, "#{@__resource_name__}: domain_name must be provided!" if opts[:domain_name].blank? + validate_parameters(required: %i[domain_name]) + if opts[:domain_name].blank? + raise ArgumentError, + "#{@__resource_name__}: domain_name must be provided!" + end @display_name = opts[:domain_name] catch_aws_errors do - resp = @aws.apigateway_client.get_domain_name({ domain_name: opts[:domain_name] }) + resp = + @aws.apigateway_client.get_domain_name( + { domain_name: opts[:domain_name] } + ) @res = resp.to_h create_resource_methods(@res) end end def resource_id - @res? "#{@res[:domain_name]}_#{@res[:certificate_arn]}" : "" + @res ? "#{@res[:domain_name]}_#{@res[:certificate_arn]}" : "" end def exists? diff --git a/libraries/aws_api_gateway_method.rb b/libraries/aws_api_gateway_method.rb index 47f6a2436..997a639ca 100644 --- a/libraries/aws_api_gateway_method.rb +++ b/libraries/aws_api_gateway_method.rb @@ -10,15 +10,32 @@ class AWSApiGatewayMethod < AwsResourceBase EXAMPLE def initialize(opts = {}) - opts = { rest_api_id: opts, resource_id: opts, http_method: opts } if opts.is_a?(String) + opts = { + rest_api_id: opts, + resource_id: opts, + http_method: opts + } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(rest_api_id resource_id http_method)) - raise ArgumentError, "#{@__resource_name__}: rest_api_id must be provided" unless opts[:rest_api_id] && !opts[:rest_api_id].empty? - raise ArgumentError, "#{@__resource_name__}: resource_id must be provided" unless opts[:resource_id] && !opts[:resource_id].empty? - raise ArgumentError, "#{@__resource_name__}: http_method must be provided" unless opts[:http_method] && !opts[:http_method].empty? + validate_parameters(required: %i[rest_api_id resource_id http_method]) + unless opts[:rest_api_id] && !opts[:rest_api_id].empty? + raise ArgumentError, "#{@__resource_name__}: rest_api_id must be provided" + end + unless opts[:resource_id] && !opts[:resource_id].empty? + raise ArgumentError, "#{@__resource_name__}: resource_id must be provided" + end + unless opts[:http_method] && !opts[:http_method].empty? + raise ArgumentError, "#{@__resource_name__}: http_method must be provided" + end @rest_api_id = opts[:rest_api_id] catch_aws_errors do - resp = @aws.apigateway_client.get_method({ rest_api_id: opts[:rest_api_id], resource_id: opts[:resource_id], http_method: opts[:http_method] }) + resp = + @aws.apigateway_client.get_method( + { + rest_api_id: opts[:rest_api_id], + resource_id: opts[:resource_id], + http_method: opts[:http_method] + } + ) @res = resp.to_h create_resource_methods(@res) end diff --git a/libraries/aws_api_gateway_model.rb b/libraries/aws_api_gateway_model.rb index f3ad3b6ba..10747b15c 100644 --- a/libraries/aws_api_gateway_model.rb +++ b/libraries/aws_api_gateway_model.rb @@ -11,12 +11,19 @@ class AWSApiGatewayModel < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(rest_api_id model_name)) - raise ArgumentError, "#{@__resource_name__}: rest_api_id must be provided" unless opts[:rest_api_id] && !opts[:rest_api_id].empty? - raise ArgumentError, "#{@__resource_name__}: model_name must be provided" unless opts[:model_name] && !opts[:model_name].empty? + validate_parameters(required: %i[rest_api_id model_name]) + unless opts[:rest_api_id] && !opts[:rest_api_id].empty? + raise ArgumentError, "#{@__resource_name__}: rest_api_id must be provided" + end + unless opts[:model_name] && !opts[:model_name].empty? + raise ArgumentError, "#{@__resource_name__}: model_name must be provided" + end @display_name = opts[:model_name] catch_aws_errors do - resp = @aws.apigateway_client.get_model({ rest_api_id: opts[:rest_api_id], model_name: opts[:model_name] }) + resp = + @aws.apigateway_client.get_model( + { rest_api_id: opts[:rest_api_id], model_name: opts[:model_name] } + ) @res = resp.to_h create_resource_methods(@res) end @@ -32,7 +39,7 @@ def model_name end def resource_id - @res? @res[:id] : @display_name + @res ? @res[:id] : @display_name end def to_s diff --git a/libraries/aws_api_gateway_response.rb b/libraries/aws_api_gateway_response.rb index d5acc093a..70e838559 100644 --- a/libraries/aws_api_gateway_response.rb +++ b/libraries/aws_api_gateway_response.rb @@ -11,12 +11,23 @@ class AWSApiGatewayResponse < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(rest_api_id response_type)) - raise ArgumentError, "#{@__resource_name__}: rest_api_id must be provided" unless opts[:rest_api_id] && !opts[:rest_api_id].empty? - raise ArgumentError, "#{@__resource_name__}: response_type must be provided" unless opts[:response_type] && !opts[:response_type].empty? + validate_parameters(required: %i[rest_api_id response_type]) + unless opts[:rest_api_id] && !opts[:rest_api_id].empty? + raise ArgumentError, "#{@__resource_name__}: rest_api_id must be provided" + end + unless opts[:response_type] && !opts[:response_type].empty? + raise ArgumentError, + "#{@__resource_name__}: response_type must be provided" + end @display_name = opts[:response_type] catch_aws_errors do - resp = @aws.apigateway_client.get_gateway_response({ rest_api_id: opts[:rest_api_id], response_type: opts[:response_type] }) + resp = + @aws.apigateway_client.get_gateway_response( + { + rest_api_id: opts[:rest_api_id], + response_type: opts[:response_type] + } + ) @res = resp.to_h create_resource_methods(@res) end diff --git a/libraries/aws_api_gateway_restapi.rb b/libraries/aws_api_gateway_restapi.rb index abf13d6b8..43a0509bf 100644 --- a/libraries/aws_api_gateway_restapi.rb +++ b/libraries/aws_api_gateway_restapi.rb @@ -12,11 +12,14 @@ class AWSApiGatewayRestApi < AwsResourceBase def initialize(opts = {}) opts = { rest_api_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(rest_api_id)) - raise ArgumentError, "#{@__resource_name__}: rest_api_id must be provided" unless opts[:rest_api_id] && !opts[:rest_api_id].empty? + validate_parameters(required: %i[rest_api_id]) + unless opts[:rest_api_id] && !opts[:rest_api_id].empty? + raise ArgumentError, "#{@__resource_name__}: rest_api_id must be provided" + end @display_name = opts[:rest_api_id] catch_aws_errors do - resp = @aws.apigateway_client.get_rest_api({ rest_api_id: opts[:rest_api_id] }) + resp = + @aws.apigateway_client.get_rest_api({ rest_api_id: opts[:rest_api_id] }) @res = resp.to_h create_resource_methods(@res) end @@ -28,7 +31,7 @@ def rest_api_id end def resource_id - @res? @res[:id]:@display_name + @res ? @res[:id] : @display_name end def exists? diff --git a/libraries/aws_api_gateway_stage.rb b/libraries/aws_api_gateway_stage.rb index 916c768f7..87b99fe5f 100644 --- a/libraries/aws_api_gateway_stage.rb +++ b/libraries/aws_api_gateway_stage.rb @@ -11,12 +11,19 @@ class AWSApiGatewayStage < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(rest_api_id stage_name)) - raise ArgumentError, "#{@__resource_name__}: rest_api_id must be provided" unless opts[:rest_api_id] && !opts[:rest_api_id].empty? - raise ArgumentError, "#{@__resource_name__}: stage_name must be provided" unless opts[:stage_name] && !opts[:stage_name].empty? + validate_parameters(required: %i[rest_api_id stage_name]) + unless opts[:rest_api_id] && !opts[:rest_api_id].empty? + raise ArgumentError, "#{@__resource_name__}: rest_api_id must be provided" + end + unless opts[:stage_name] && !opts[:stage_name].empty? + raise ArgumentError, "#{@__resource_name__}: stage_name must be provided" + end @display_name = opts[:stage_name] catch_aws_errors do - resp = @aws.apigateway_client.get_stage({ rest_api_id: opts[:rest_api_id], stage_name: opts[:stage_name] }) + resp = + @aws.apigateway_client.get_stage( + { rest_api_id: opts[:rest_api_id], stage_name: opts[:stage_name] } + ) @res = resp.to_h create_resource_methods(@res) end @@ -28,7 +35,7 @@ def stage_name end def resource_id - @res? @res[:stage_name] : @display_name + @res ? @res[:stage_name] : @display_name end def exists? diff --git a/libraries/aws_api_gateway_usage_plan.rb b/libraries/aws_api_gateway_usage_plan.rb index b1b887c15..c5eb11ede 100644 --- a/libraries/aws_api_gateway_usage_plan.rb +++ b/libraries/aws_api_gateway_usage_plan.rb @@ -11,11 +11,17 @@ class AWSApiGatewayUsagePlan < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(usage_plan_id)) - raise ArgumentError, "#{@__resource_name__}: usage_plan_id must be provided" if opts[:usage_plan_id].blank? + validate_parameters(required: %i[usage_plan_id]) + if opts[:usage_plan_id].blank? + raise ArgumentError, + "#{@__resource_name__}: usage_plan_id must be provided" + end @display_name = opts[:usage_plan_id] catch_aws_errors do - resp = @aws.apigateway_client.get_usage_plan({ usage_plan_id: opts[:usage_plan_id] }) + resp = + @aws.apigateway_client.get_usage_plan( + { usage_plan_id: opts[:usage_plan_id] } + ) @res = resp.to_h @usage_plan_id = @res[:id] create_resource_methods(@res) @@ -23,7 +29,7 @@ def initialize(opts = {}) end def resource_id - @res? @usage_plan_id: @display_name + @res ? @usage_plan_id : @display_name end def exists? diff --git a/libraries/aws_api_gateway_usage_plan_key.rb b/libraries/aws_api_gateway_usage_plan_key.rb index 6d5ec413f..fad6f228a 100644 --- a/libraries/aws_api_gateway_usage_plan_key.rb +++ b/libraries/aws_api_gateway_usage_plan_key.rb @@ -12,13 +12,21 @@ class AWSApiGatewayUsagePlanKey < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(usage_plan_id key_id)) - raise ArgumentError, "#{@__resource_name__}: usage_plan_id must be provided" if opts[:usage_plan_id].blank? - raise ArgumentError, "#{@__resource_name__}: key_id must be provided" if opts[:key_id].blank? + validate_parameters(required: %i[usage_plan_id key_id]) + if opts[:usage_plan_id].blank? + raise ArgumentError, + "#{@__resource_name__}: usage_plan_id must be provided" + end + if opts[:key_id].blank? + raise ArgumentError, "#{@__resource_name__}: key_id must be provided" + end @display_name = opts[:key_id] @usage_plan_id = opts[:usage_plan_id] catch_aws_errors do - resp = @aws.apigateway_client.get_usage_plan_key({ usage_plan_id: opts[:usage_plan_id], key_id: opts[:key_id] }) + resp = + @aws.apigateway_client.get_usage_plan_key( + { usage_plan_id: opts[:usage_plan_id], key_id: opts[:key_id] } + ) @res = resp.to_h @usage_plan_key_id = @res[:id] @usage_plan_key_name = @res[:name] @@ -27,7 +35,7 @@ def initialize(opts = {}) end def resource_id - "#{@res? @usage_plan_key_id: @display_name}_#{@res? @usage_plan_key_name: ""}" + "#{@res ? @usage_plan_key_id : @display_name}_#{@res ? @usage_plan_key_name : ""}" end def exists? diff --git a/libraries/aws_api_gateway_v2_api.rb b/libraries/aws_api_gateway_v2_api.rb index d734fcedc..34d4248be 100644 --- a/libraries/aws_api_gateway_v2_api.rb +++ b/libraries/aws_api_gateway_v2_api.rb @@ -12,8 +12,10 @@ class AwsApiGatewayV2Api < AwsResourceBase def initialize(opts = {}) opts = { api_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(api_id)) - raise ArgumentError, "#{@__resource_name__}: api_id must be provided!" if opts[:api_id].blank? + validate_parameters(required: %i[api_id]) + if opts[:api_id].blank? + raise ArgumentError, "#{@__resource_name__}: api_id must be provided!" + end @display_name = opts[:api_id] catch_aws_errors do resp = @aws.apigatewayv2_client.get_api({ api_id: opts[:api_id] }) @@ -32,7 +34,7 @@ def exists? end def resource_id - @res? @res[:api_endpoint] : @display_name + @res ? @res[:api_endpoint] : @display_name end def to_s diff --git a/libraries/aws_api_gateway_v2_api_mapping.rb b/libraries/aws_api_gateway_v2_api_mapping.rb index 82ee3dfcb..d875d4897 100644 --- a/libraries/aws_api_gateway_v2_api_mapping.rb +++ b/libraries/aws_api_gateway_v2_api_mapping.rb @@ -12,12 +12,24 @@ class AwsApiGatewayV2ApiMapping < AwsResourceBase def initialize(opts = {}) opts = { api_mapping_id: opts, domain_name: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(api_mapping_id domain_name)) - raise ArgumentError, "#{@__resource_name__}: api_mapping_id must be provided!" if opts[:api_mapping_id].blank? - raise ArgumentError, "#{@__resource_name__}: domain_name must be provided!" if opts[:domain_name].blank? + validate_parameters(required: %i[api_mapping_id domain_name]) + if opts[:api_mapping_id].blank? + raise ArgumentError, + "#{@__resource_name__}: api_mapping_id must be provided!" + end + if opts[:domain_name].blank? + raise ArgumentError, + "#{@__resource_name__}: domain_name must be provided!" + end @display_name = opts[:api_mapping_id] catch_aws_errors do - resp = @aws.apigatewayv2_client.get_api_mapping({ api_mapping_id: opts[:api_mapping_id], domain_name: opts[:domain_name] }) + resp = + @aws.apigatewayv2_client.get_api_mapping( + { + api_mapping_id: opts[:api_mapping_id], + domain_name: opts[:domain_name] + } + ) @res = resp.to_h create_resource_methods(@res) end @@ -33,7 +45,7 @@ def exists? end def resource_id - @res? @res[:api_mapping_id]: @display_name + @res ? @res[:api_mapping_id] : @display_name end def to_s diff --git a/libraries/aws_api_gateway_v2_authorizer.rb b/libraries/aws_api_gateway_v2_authorizer.rb index 1e733825a..597741551 100644 --- a/libraries/aws_api_gateway_v2_authorizer.rb +++ b/libraries/aws_api_gateway_v2_authorizer.rb @@ -14,12 +14,20 @@ class AwsApiGatewayV2Authorizer < AwsResourceBase def initialize(opts = {}) opts = { api_id: opts, authorizer_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(api_id authorizer_id)) - raise ArgumentError, "#{@__resource_name__}: api_id must be provided!" if opts[:api_id].blank? - raise ArgumentError, "#{@__resource_name__}: authorizer_id must be provided!" if opts[:authorizer_id].blank? + validate_parameters(required: %i[api_id authorizer_id]) + if opts[:api_id].blank? + raise ArgumentError, "#{@__resource_name__}: api_id must be provided!" + end + if opts[:authorizer_id].blank? + raise ArgumentError, + "#{@__resource_name__}: authorizer_id must be provided!" + end @display_name = opts[:authorizer_id] catch_aws_errors do - resp = @aws.apigatewayv2_client.get_authorizer({ api_id: opts[:api_id], authorizer_id: opts[:authorizer_id] }) + resp = + @aws.apigatewayv2_client.get_authorizer( + { api_id: opts[:api_id], authorizer_id: opts[:authorizer_id] } + ) @res = resp.to_h create_resource_methods(@res) end @@ -35,7 +43,7 @@ def exists? end def resource_id - @res? @res[:authorizer_id] : @display_name + @res ? @res[:authorizer_id] : @display_name end def to_s diff --git a/libraries/aws_api_gateway_v2_deployment.rb b/libraries/aws_api_gateway_v2_deployment.rb index 9084d6480..408a8b6db 100644 --- a/libraries/aws_api_gateway_v2_deployment.rb +++ b/libraries/aws_api_gateway_v2_deployment.rb @@ -15,12 +15,20 @@ class AwsApiGatewayV2Deployment < AwsResourceBase def initialize(opts = {}) opts = { api_id: opts, deployment_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(api_id deployment_id)) - raise ArgumentError, "#{@__resource_name__}: api_id must be provided!" if opts[:api_id].blank? - raise ArgumentError, "#{@__resource_name__}: deployment_id must be provided!" if opts[:deployment_id].blank? + validate_parameters(required: %i[api_id deployment_id]) + if opts[:api_id].blank? + raise ArgumentError, "#{@__resource_name__}: api_id must be provided!" + end + if opts[:deployment_id].blank? + raise ArgumentError, + "#{@__resource_name__}: deployment_id must be provided!" + end @display_name = opts[:deployment_id] catch_aws_errors do - resp = @aws.apigatewayv2_client.get_deployment({ api_id: opts[:api_id], deployment_id: opts[:deployment_id] }) + resp = + @aws.apigatewayv2_client.get_deployment( + { api_id: opts[:api_id], deployment_id: opts[:deployment_id] } + ) @res = resp.to_h create_resource_methods(@res) end @@ -36,7 +44,7 @@ def exists? end def resource_id - @res? @res[:deployment_id]: @display_name + @res ? @res[:deployment_id] : @display_name end def to_s diff --git a/libraries/aws_api_gateway_v2_domain_name.rb b/libraries/aws_api_gateway_v2_domain_name.rb index ea08faef5..6a96fba70 100644 --- a/libraries/aws_api_gateway_v2_domain_name.rb +++ b/libraries/aws_api_gateway_v2_domain_name.rb @@ -12,11 +12,17 @@ class AwsApiGatewayV2DomainName < AwsResourceBase def initialize(opts = {}) opts = { domain_name: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(domain_name)) - raise ArgumentError, "#{@__resource_name__}: domain_name must be provided!" if opts[:domain_name].blank? + validate_parameters(required: %i[domain_name]) + if opts[:domain_name].blank? + raise ArgumentError, + "#{@__resource_name__}: domain_name must be provided!" + end @display_name = opts[:domain_name] catch_aws_errors do - resp = @aws.apigatewayv2_client.get_domain_name({ domain_name: opts[:domain_name] }) + resp = + @aws.apigatewayv2_client.get_domain_name( + { domain_name: opts[:domain_name] } + ) @res = resp.to_h create_resource_methods(@res) end @@ -32,7 +38,7 @@ def exists? end def resource_id - @res? @res[:domain_name]: @display_name + @res ? @res[:domain_name] : @display_name end def to_s diff --git a/libraries/aws_api_gateway_v2_integration.rb b/libraries/aws_api_gateway_v2_integration.rb index 792581681..550cb86bc 100644 --- a/libraries/aws_api_gateway_v2_integration.rb +++ b/libraries/aws_api_gateway_v2_integration.rb @@ -15,12 +15,20 @@ class AwsApiGatewayV2Integration < AwsResourceBase def initialize(opts = {}) opts = { api_id: opts, integration_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(api_id integration_id)) - raise ArgumentError, "#{@__resource_name__}: api_id must be provided!" if opts[:api_id].blank? - raise ArgumentError, "#{@__resource_name__}: integration_id must be provided!" if opts[:integration_id].blank? + validate_parameters(required: %i[api_id integration_id]) + if opts[:api_id].blank? + raise ArgumentError, "#{@__resource_name__}: api_id must be provided!" + end + if opts[:integration_id].blank? + raise ArgumentError, + "#{@__resource_name__}: integration_id must be provided!" + end @display_name = opts[:integration_id] catch_aws_errors do - resp = @aws.apigatewayv2_client.get_integration({ api_id: opts[:api_id], integration_id: opts[:integration_id] }) + resp = + @aws.apigatewayv2_client.get_integration( + { api_id: opts[:api_id], integration_id: opts[:integration_id] } + ) @res = resp.to_h create_resource_methods(@res) end @@ -36,7 +44,7 @@ def exists? end def resource_id - @res? @res[:integration_id]: @display_name + @res ? @res[:integration_id] : @display_name end def to_s diff --git a/libraries/aws_api_gateway_v2_integration_response.rb b/libraries/aws_api_gateway_v2_integration_response.rb index a88d58ba1..a45442f4b 100644 --- a/libraries/aws_api_gateway_v2_integration_response.rb +++ b/libraries/aws_api_gateway_v2_integration_response.rb @@ -10,15 +10,36 @@ class AwsApiGatewayV2IntegrationResponse < AwsResourceBase EXAMPLE def initialize(opts = {}) - opts = { api_id: opts, integration_id: opts, integration_response_id: opts } if opts.is_a?(String) + opts = { + api_id: opts, + integration_id: opts, + integration_response_id: opts + } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(api_id integration_id integration_response_id)) - raise ArgumentError, "#{@__resource_name__}: api_id must be provided!" if opts[:api_id].blank? - raise ArgumentError, "#{@__resource_name__}: integration_id must be provided!" if opts[:integration_id].blank? - raise ArgumentError, "#{@__resource_name__}: integration_response_id must be provided!" if opts[:integration_response_id].blank? + validate_parameters( + required: %i[api_id integration_id integration_response_id] + ) + if opts[:api_id].blank? + raise ArgumentError, "#{@__resource_name__}: api_id must be provided!" + end + if opts[:integration_id].blank? + raise ArgumentError, + "#{@__resource_name__}: integration_id must be provided!" + end + if opts[:integration_response_id].blank? + raise ArgumentError, + "#{@__resource_name__}: integration_response_id must be provided!" + end @display_name = opts[:integration_response_id] catch_aws_errors do - resp = @aws.apigatewayv2_client.get_integration_response({ api_id: opts[:api_id], integration_id: opts[:integration_id], integration_response_id: opts[:integration_response_id] }) + resp = + @aws.apigatewayv2_client.get_integration_response( + { + api_id: opts[:api_id], + integration_id: opts[:integration_id], + integration_response_id: opts[:integration_response_id] + } + ) @res = resp.to_h create_resource_methods(@res) end @@ -34,7 +55,7 @@ def exists? end def resource_id - @res? @res[:integration_response_id]: @display_name + @res ? @res[:integration_response_id] : @display_name end def to_s diff --git a/libraries/aws_api_gateway_v2_model.rb b/libraries/aws_api_gateway_v2_model.rb index 9abd7d964..5ad645f5e 100644 --- a/libraries/aws_api_gateway_v2_model.rb +++ b/libraries/aws_api_gateway_v2_model.rb @@ -14,12 +14,19 @@ class AwsApiGatewayV2Model < AwsResourceBase def initialize(opts = {}) opts = { api_id: opts, model_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(api_id model_id)) - raise ArgumentError, "#{@__resource_name__}: api_id must be provided!" if opts[:api_id].blank? - raise ArgumentError, "#{@__resource_name__}: model_id must be provided!" if opts[:model_id].blank? + validate_parameters(required: %i[api_id model_id]) + if opts[:api_id].blank? + raise ArgumentError, "#{@__resource_name__}: api_id must be provided!" + end + if opts[:model_id].blank? + raise ArgumentError, "#{@__resource_name__}: model_id must be provided!" + end @display_name = opts[:model_id] catch_aws_errors do - resp = @aws.apigatewayv2_client.get_model({ api_id: opts[:api_id], model_id: opts[:model_id] }) + resp = + @aws.apigatewayv2_client.get_model( + { api_id: opts[:api_id], model_id: opts[:model_id] } + ) @res = resp.to_h create_resource_methods(@res) end @@ -35,7 +42,7 @@ def exists? end def resource_id - @res? @res[:model_id]: @display_name + @res ? @res[:model_id] : @display_name end def to_s diff --git a/libraries/aws_api_gateway_v2_route.rb b/libraries/aws_api_gateway_v2_route.rb index 0557b0cb2..c9bccbfa2 100644 --- a/libraries/aws_api_gateway_v2_route.rb +++ b/libraries/aws_api_gateway_v2_route.rb @@ -12,12 +12,19 @@ class AwsApiGatewayV2Route < AwsResourceBase def initialize(opts = {}) opts = { api_id: opts, route_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(api_id route_id)) - raise ArgumentError, "#{@__resource_name__}: api_id must be provided!" if opts[:api_id].blank? - raise ArgumentError, "#{@__resource_name__}: route_id must be provided!" if opts[:route_id].blank? + validate_parameters(required: %i[api_id route_id]) + if opts[:api_id].blank? + raise ArgumentError, "#{@__resource_name__}: api_id must be provided!" + end + if opts[:route_id].blank? + raise ArgumentError, "#{@__resource_name__}: route_id must be provided!" + end @display_name = opts[:route_id] catch_aws_errors do - resp = @aws.apigatewayv2_client.get_route({ api_id: opts[:api_id], route_id: opts[:route_id] }) + resp = + @aws.apigatewayv2_client.get_route( + { api_id: opts[:api_id], route_id: opts[:route_id] } + ) @res = resp.to_h create_resource_methods(@res) end @@ -33,7 +40,7 @@ def exists? end def resource_id - @res? @res[:route_id]: @display_name + @res ? @res[:route_id] : @display_name end def to_s diff --git a/libraries/aws_api_gateway_vpc_link.rb b/libraries/aws_api_gateway_vpc_link.rb index 18d06982e..2c7c1496a 100644 --- a/libraries/aws_api_gateway_vpc_link.rb +++ b/libraries/aws_api_gateway_vpc_link.rb @@ -12,18 +12,21 @@ class AWSApiGatewayVPCLink < AwsResourceBase def initialize(opts = {}) opts = { vpc_link_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(vpc_link_id)) - raise ArgumentError, "#{@__resource_name__}: vpc_link_id must be provided" if opts[:vpc_link_id].blank? + validate_parameters(required: %i[vpc_link_id]) + if opts[:vpc_link_id].blank? + raise ArgumentError, "#{@__resource_name__}: vpc_link_id must be provided" + end @display_name = opts[:vpc_link_id] catch_aws_errors do - resp = @aws.apigateway_client.get_vpc_link({ vpc_link_id: opts[:vpc_link_id] }) + resp = + @aws.apigateway_client.get_vpc_link({ vpc_link_id: opts[:vpc_link_id] }) @res = resp.to_h create_resource_methods(@res) end end def resource_id - @res? "#{@res[:id]}_#{@res[:name]}" : @display_name + @res ? "#{@res[:id]}_#{@res[:name]}" : @display_name end def exists? diff --git a/libraries/aws_apigateway_api_key.rb b/libraries/aws_apigateway_api_key.rb index f6157f96e..133340918 100644 --- a/libraries/aws_apigateway_api_key.rb +++ b/libraries/aws_apigateway_api_key.rb @@ -12,8 +12,10 @@ class AWSApiGatewayAPIKey < AwsResourceBase def initialize(opts = {}) opts = { api_key: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(api_key)) - raise ArgumentError, "#{@__resource_name__}: api_key must be provided" unless opts[:api_key] && !opts[:api_key].empty? + validate_parameters(required: %i[api_key]) + unless opts[:api_key] && !opts[:api_key].empty? + raise ArgumentError, "#{@__resource_name__}: api_key must be provided" + end @display_name = opts[:api_key] catch_aws_errors do resp = @aws.apigateway_client.get_api_key({ api_key: opts[:api_key] }) @@ -32,7 +34,7 @@ def exists? end def resource_id - @res? @res[:id] : @display_name + @res ? @res[:id] : @display_name end def to_s diff --git a/libraries/aws_apigateway_authorizer.rb b/libraries/aws_apigateway_authorizer.rb index c1b510420..d9f7c1078 100644 --- a/libraries/aws_apigateway_authorizer.rb +++ b/libraries/aws_apigateway_authorizer.rb @@ -13,12 +13,23 @@ def initialize(opts = {}) opts = { api_id: opts } if opts.is_a?(String) opts = { authorizer_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(rest_api_id authorizer_id)) - raise ArgumentError, "#{@__resource_name__}: rest_api_id must be provided" unless opts[:rest_api_id] && !opts[:rest_api_id].empty? - raise ArgumentError, "#{@__resource_name__}: authorizer_id must be provided" unless opts[:authorizer_id] && !opts[:authorizer_id].empty? + validate_parameters(required: %i[rest_api_id authorizer_id]) + unless opts[:rest_api_id] && !opts[:rest_api_id].empty? + raise ArgumentError, "#{@__resource_name__}: rest_api_id must be provided" + end + unless opts[:authorizer_id] && !opts[:authorizer_id].empty? + raise ArgumentError, + "#{@__resource_name__}: authorizer_id must be provided" + end @display_name = opts[:authorizer_id] catch_aws_errors do - resp = @aws.apigateway_client.get_authorizer({ rest_api_id: opts[:rest_api_id], authorizer_id: opts[:authorizer_id] }) + resp = + @aws.apigateway_client.get_authorizer( + { + rest_api_id: opts[:rest_api_id], + authorizer_id: opts[:authorizer_id] + } + ) @res = resp.to_h create_resource_methods(@res) end @@ -30,7 +41,7 @@ def authorizer_id end def resource_id - @res? @res[:id] : @display_name + @res ? @res[:id] : @display_name end def exists? diff --git a/libraries/aws_apigateway_base_path_mapping.rb b/libraries/aws_apigateway_base_path_mapping.rb index 237e71d2e..5ff535067 100644 --- a/libraries/aws_apigateway_base_path_mapping.rb +++ b/libraries/aws_apigateway_base_path_mapping.rb @@ -13,12 +13,19 @@ def initialize(opts = {}) opts = { domain_name: opts } if opts.is_a?(String) opts = { base_path: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(domain_name base_path)) - raise ArgumentError, "#{@__resource_name__}: domain_name must be provided" unless opts[:domain_name] && !opts[:domain_name].empty? - raise ArgumentError, "#{@__resource_name__}: base_path must be provided" unless opts[:base_path] && !opts[:base_path].empty? + validate_parameters(required: %i[domain_name base_path]) + unless opts[:domain_name] && !opts[:domain_name].empty? + raise ArgumentError, "#{@__resource_name__}: domain_name must be provided" + end + unless opts[:base_path] && !opts[:base_path].empty? + raise ArgumentError, "#{@__resource_name__}: base_path must be provided" + end @display_name = opts[:base_path] catch_aws_errors do - resp = @aws.apigateway_client.get_base_path_mapping({ domain_name: opts[:domain_name], base_path: opts[:base_path] }) + resp = + @aws.apigateway_client.get_base_path_mapping( + { domain_name: opts[:domain_name], base_path: opts[:base_path] } + ) @res = resp.to_h create_resource_methods(@res) end diff --git a/libraries/aws_apigateway_client_certificate.rb b/libraries/aws_apigateway_client_certificate.rb index ebf695ef8..686886148 100644 --- a/libraries/aws_apigateway_client_certificate.rb +++ b/libraries/aws_apigateway_client_certificate.rb @@ -12,23 +12,29 @@ class AWSApiGatewayClientCertificate < AwsResourceBase def initialize(opts = {}) opts = { client_certificate_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(client_certificate_id)) - raise ArgumentError, "#{@__resource_name__}: client_certificate_id must be provided" unless opts[:client_certificate_id] && !opts[:client_certificate_id].empty? + validate_parameters(required: %i[client_certificate_id]) + unless opts[:client_certificate_id] && !opts[:client_certificate_id].empty? + raise ArgumentError, + "#{@__resource_name__}: client_certificate_id must be provided" + end @display_name = opts[:client_certificate_id] catch_aws_errors do - resp = @aws.apigateway_client.get_client_certificate({ client_certificate_id: opts[:client_certificate_id] }) + resp = + @aws.apigateway_client.get_client_certificate( + { client_certificate_id: opts[:client_certificate_id] } + ) @res = resp.to_h create_resource_methods(@res) end end def client_certificate_id - return nil unless exists? + return unless exists? @res[:client_certificate_id] end def resource_id - @res? @res[:client_certificate_id] : @display_name + @res ? @res[:client_certificate_id] : @display_name end def exists? diff --git a/libraries/aws_application_autoscaling_scalable_target.rb b/libraries/aws_application_autoscaling_scalable_target.rb index 971dad38a..f0755d1d8 100644 --- a/libraries/aws_application_autoscaling_scalable_target.rb +++ b/libraries/aws_application_autoscaling_scalable_target.rb @@ -13,10 +13,16 @@ def initialize(opts = {}) opts = { service_namespace: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:service_namespace]) - raise ArgumentError, "#{@__resource_name__}: service_namespace must be provided" unless opts[:service_namespace] && !opts[:service_namespace].empty? + unless opts[:service_namespace] && !opts[:service_namespace].empty? + raise ArgumentError, + "#{@__resource_name__}: service_namespace must be provided" + end @display_name = opts[:service_namespace] catch_aws_errors do - resp = @aws.applicationautoscaling_client.describe_scalable_targets({ service_namespace: opts[:service_namespace] }) + resp = + @aws.applicationautoscaling_client.describe_scalable_targets( + { service_namespace: opts[:service_namespace] } + ) @scalable_targets = resp.scalable_targets[0].to_h create_resource_methods(@scalable_targets) end @@ -28,7 +34,7 @@ def service_namespace end def resource_id - @scalable_targets? @scalable_targets[:resource_id]: "" + @scalable_targets ? @scalable_targets[:resource_id] : "" end def exists? diff --git a/libraries/aws_application_autoscaling_scaling_policy.rb b/libraries/aws_application_autoscaling_scaling_policy.rb index 7f07583b5..c194e5094 100644 --- a/libraries/aws_application_autoscaling_scaling_policy.rb +++ b/libraries/aws_application_autoscaling_scaling_policy.rb @@ -14,10 +14,16 @@ def initialize(opts = {}) super(opts) validate_parameters(required: [:service_namespace]) - raise ArgumentError, "#{@__resource_name__}: service_namespace must be provided" unless opts[:service_namespace] && !opts[:service_namespace].empty? + unless opts[:service_namespace] && !opts[:service_namespace].empty? + raise ArgumentError, + "#{@__resource_name__}: service_namespace must be provided" + end @display_name = opts[:service_namespace] catch_aws_errors do - resp = @aws.applicationautoscaling_client.describe_scaling_policies({ service_namespace: opts[:service_namespace] }) + resp = + @aws.applicationautoscaling_client.describe_scaling_policies( + { service_namespace: opts[:service_namespace] } + ) @scaling_policies = resp.scaling_policies[0].to_h create_resource_methods(@scaling_policies) end @@ -29,7 +35,7 @@ def service_namespace end def resource_id - @scaling_policies ? @scaling_policies[:resource_id]: "" + @scaling_policies ? @scaling_policies[:resource_id] : "" end def exists? diff --git a/libraries/aws_athena_work_group.rb b/libraries/aws_athena_work_group.rb index a92f95613..3e3ba96bd 100644 --- a/libraries/aws_athena_work_group.rb +++ b/libraries/aws_athena_work_group.rb @@ -14,10 +14,13 @@ def initialize(opts = {}) super(opts) validate_parameters(required: [:work_group]) - raise ArgumentError, "#{@__resource_name__}: work_group must be provided" unless opts[:work_group] && !opts[:work_group].empty? + unless opts[:work_group] && !opts[:work_group].empty? + raise ArgumentError, "#{@__resource_name__}: work_group must be provided" + end @display_name = opts[:work_group] catch_aws_errors do - resp = @aws.athena_client.get_work_group({ work_group: opts[:work_group] }) + resp = + @aws.athena_client.get_work_group({ work_group: opts[:work_group] }) @work_group = resp.work_group.to_h create_resource_methods(@work_group) end diff --git a/libraries/aws_auto_scaling_group.rb b/libraries/aws_auto_scaling_group.rb index 3450bb79c..d81b187c2 100644 --- a/libraries/aws_auto_scaling_group.rb +++ b/libraries/aws_auto_scaling_group.rb @@ -19,7 +19,7 @@ def initialize(opts = {}) catch_aws_errors do resp = @aws.service_client.describe_auto_scaling_groups(auto_scaling_group_names: [opts[:auto_scaling_group_name]]) - return nil if resp.auto_scaling_groups.nil? || resp.auto_scaling_groups.empty? + return if resp.auto_scaling_groups.nil? || resp.auto_scaling_groups.empty? auto_scaling_group = resp.auto_scaling_groups[0] @name = auto_scaling_group[:auto_scaling_group_name] @min_size = auto_scaling_group[:min_size].to_i diff --git a/libraries/aws_autoscaling_scaling_policy.rb b/libraries/aws_autoscaling_scaling_policy.rb index 80e63fbcc..b2142e14e 100644 --- a/libraries/aws_autoscaling_scaling_policy.rb +++ b/libraries/aws_autoscaling_scaling_policy.rb @@ -15,10 +15,17 @@ def initialize(opts = {}) super(opts) validate_parameters(required: [:auto_scaling_group_name]) - raise ArgumentError, "#{@__resource_name__}: auto_scaling_group_name must be provided" unless opts[:auto_scaling_group_name] && !opts[:auto_scaling_group_name].empty? + unless opts[:auto_scaling_group_name] && + !opts[:auto_scaling_group_name].empty? + raise ArgumentError, + "#{@__resource_name__}: auto_scaling_group_name must be provided" + end @display_name = opts[:auto_scaling_group_name] catch_aws_errors do - resp = @aws.autoscaling_client.describe_policies({ auto_scaling_group_name: opts[:auto_scaling_group_name] }) + resp = + @aws.autoscaling_client.describe_policies( + { auto_scaling_group_name: opts[:auto_scaling_group_name] } + ) @scaling_policies = resp.scaling_policies[0].to_h create_resource_methods(@scaling_policies) end diff --git a/libraries/aws_backend.rb b/libraries/aws_backend.rb index 217ba5a83..b4471656d 100644 --- a/libraries/aws_backend.rb +++ b/libraries/aws_backend.rb @@ -62,6 +62,7 @@ require "aws-sdk-waf" require "aws-sdk-synthetics" require "aws-sdk-apigatewayv2" +require "aws-sdk-account" # AWS Inspec Backend Classes # @@ -338,6 +339,10 @@ def synthetics_client def apigatewayv2_client aws_client(Aws::ApiGatewayV2::Client) end + + def account_client + aws_client(Aws::Account::Client) + end end # Base class for AWS resources @@ -364,7 +369,6 @@ def initialize(opts) client_args[:client_args][:retry_backoff] = "lambda { |c| sleep(#{opts[:aws_retry_backoff]}) }" if opts[:aws_retry_backoff] # this catches the stub_data true option for unit testing - and others that could be useful for consumers client_args[:client_args].update(opts[:client_args]) if opts[:client_args] - @resource_data = opts[:resource_data].presence&.to_h end @aws = AwsConnection.new(client_args) @@ -436,6 +440,10 @@ def catch_aws_errors Inspec::Log.error "It appears that you have not set your AWS credentials. See https://www.inspec.io/docs/reference/platforms for details." fail_resource("No AWS credentials available") nil + rescue Aws::Account::Errors::ResourceNotFoundException => e + Inspec::Log.warn "#{e.message}" + fail_resource("#{e.message}") + nil rescue Aws::Errors::NoSuchEndpointError Inspec::Log.error "The endpoint that is trying to be accessed does not exist." fail_resource("Invalid Endpoint error") diff --git a/libraries/aws_batch_compute_environment.rb b/libraries/aws_batch_compute_environment.rb index 951dea9d4..d85f787c1 100644 --- a/libraries/aws_batch_compute_environment.rb +++ b/libraries/aws_batch_compute_environment.rb @@ -14,10 +14,17 @@ def initialize(opts = {}) super(opts) validate_parameters(required: [:compute_environment_name]) - raise ArgumentError, "#{@__resource_name__}: compute_environment_name must be provided" unless opts[:compute_environment_name] && !opts[:compute_environment_name].empty? + unless opts[:compute_environment_name] && + !opts[:compute_environment_name].empty? + raise ArgumentError, + "#{@__resource_name__}: compute_environment_name must be provided" + end @display_name = opts[:compute_environment_name] catch_aws_errors do - resp = @aws.batch_client.describe_compute_environments({ compute_environments: [opts[:compute_environment_name]] }) + resp = + @aws.batch_client.describe_compute_environments( + { compute_environments: [opts[:compute_environment_name]] } + ) @compute_environments = resp.compute_environments[0].to_h create_resource_methods(@compute_environments) end diff --git a/libraries/aws_batch_job_definition.rb b/libraries/aws_batch_job_definition.rb index ff1b2f750..b250851cc 100644 --- a/libraries/aws_batch_job_definition.rb +++ b/libraries/aws_batch_job_definition.rb @@ -14,15 +14,21 @@ def initialize(opts = {}) super(opts) validate_parameters(required: [:job_definition_name]) - raise ArgumentError, "#{@__resource_name__}: job_definition_name must be provided" unless opts[:job_definition_name] && !opts[:job_definition_name].empty? + unless opts[:job_definition_name] && !opts[:job_definition_name].empty? + raise ArgumentError, + "#{@__resource_name__}: job_definition_name must be provided" + end @display_name = opts[:job_definition_name] - resp = @aws.batch_client.describe_job_definitions({ job_definition_name: opts[:job_definition_name] }) + resp = + @aws.batch_client.describe_job_definitions( + { job_definition_name: opts[:job_definition_name] } + ) @job_definitions = resp.job_definitions[0].to_h create_resource_methods(@job_definitions) end def job_definition_name - return nil unless exists? + return unless exists? @job_definitions[:job_definition_name] end diff --git a/libraries/aws_batch_job_queue.rb b/libraries/aws_batch_job_queue.rb index 1519fd72a..23dddc07e 100644 --- a/libraries/aws_batch_job_queue.rb +++ b/libraries/aws_batch_job_queue.rb @@ -14,10 +14,16 @@ def initialize(opts = {}) super(opts) validate_parameters(required: [:job_queue_name]) - raise ArgumentError, "#{@__resource_name__}: job_queue_name must be provided" unless opts[:job_queue_name] && !opts[:job_queue_name].empty? + unless opts[:job_queue_name] && !opts[:job_queue_name].empty? + raise ArgumentError, + "#{@__resource_name__}: job_queue_name must be provided" + end @display_name = opts[:job_queue_name] catch_aws_errors do - resp = @aws.batch_client.describe_job_queues({ job_queues: [opts[:job_queue_name]] }) + resp = + @aws.batch_client.describe_job_queues( + { job_queues: [opts[:job_queue_name]] } + ) @job_queues = resp.job_queues[0].to_h create_resource_methods(@job_queues) end diff --git a/libraries/aws_cloud_formation_stack_set.rb b/libraries/aws_cloud_formation_stack_set.rb index e3e8bb8c2..f9469c00b 100644 --- a/libraries/aws_cloud_formation_stack_set.rb +++ b/libraries/aws_cloud_formation_stack_set.rb @@ -13,9 +13,15 @@ def initialize(opts = {}) opts = { stack_set_name: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:stack_set_name]) - raise ArgumentError, "#{@__resource_name__}: stack_set_name must be provided" unless opts[:stack_set_name] && !opts[:stack_set_name].empty? + unless opts[:stack_set_name] && !opts[:stack_set_name].empty? + raise ArgumentError, + "#{@__resource_name__}: stack_set_name must be provided" + end @display_name = opts[:stack_set_name] - resp = @aws.cloudformation_client.describe_stack_set({ stack_set_name: opts[:stack_set_name] }) + resp = + @aws.cloudformation_client.describe_stack_set( + { stack_set_name: opts[:stack_set_name] } + ) @resp = resp.stack_set.to_h @stack_set_id = @resp[:stack_set_id] create_resource_methods(@resp) diff --git a/libraries/aws_cloudformation_stack.rb b/libraries/aws_cloudformation_stack.rb index 13f158492..0c3970c38 100644 --- a/libraries/aws_cloudformation_stack.rb +++ b/libraries/aws_cloudformation_stack.rb @@ -21,7 +21,7 @@ def initialize(opts = {}) catch_aws_errors do name = { stack_name: opts[:stack_name] } resp = @aws.cloudformation_client.describe_stacks(name) - return nil if resp.stacks.nil? || resp.stacks.empty? + return if resp.stacks.nil? || resp.stacks.empty? stack = resp.stacks.first @stack_id = stack.stack_id @stack_name = stack.stack_name diff --git a/libraries/aws_cloudformation_template.rb b/libraries/aws_cloudformation_template.rb index 85c4c9af9..522cc8c4f 100644 --- a/libraries/aws_cloudformation_template.rb +++ b/libraries/aws_cloudformation_template.rb @@ -23,10 +23,13 @@ class AWSCloudFormationTemplate < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(require_any_of: %i(stack_name stack_set_name template_url template_body)) + validate_parameters( + require_any_of: %i[stack_name stack_set_name template_url template_body] + ) @stack_name = opts[:stack_name] @template_url = opts[:template_url] - @query_params = opts.slice(:stack_name, :stack_set_name, :template_url, :template_body) + @query_params = + opts.slice(:stack_name, :stack_set_name, :template_url, :template_body) @query_stack_name = opts.slice(:stack_name) catch_aws_errors do resp = @aws.cloudformation_client.get_template_summary(@query_params) @@ -42,7 +45,8 @@ def resource_id def template_body return nil unless exists? catch_aws_errors do - @template_body ||= @aws.cloudformation_client.get_template(@query_stack_name) + @template_body ||= + @aws.cloudformation_client.get_template(@query_stack_name) end end diff --git a/libraries/aws_cloudfront_cache_policy.rb b/libraries/aws_cloudfront_cache_policy.rb index 5c2baa70a..6251e7d18 100644 --- a/libraries/aws_cloudfront_cache_policy.rb +++ b/libraries/aws_cloudfront_cache_policy.rb @@ -12,8 +12,10 @@ class AWSCloudFrontCachePolicy < AwsResourceBase def initialize(opts = {}) opts = { id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(id)) - raise ArgumentError, "#{@__resource_name__}: id must be provided" unless opts[:id] && !opts[:id].empty? + validate_parameters(required: %i[id]) + unless opts[:id] && !opts[:id].empty? + raise ArgumentError, "#{@__resource_name__}: id must be provided" + end @display_name = opts[:id] catch_aws_errors do resp = @aws.cloudfront_client.get_cache_policy({ id: opts[:id] }) @@ -23,7 +25,7 @@ def initialize(opts = {}) end def resource_id - @res? @res[:id]: @display_name + @res ? @res[:id] : @display_name end def id diff --git a/libraries/aws_cloudfront_key_group.rb b/libraries/aws_cloudfront_key_group.rb index 743386290..7d471b9ab 100644 --- a/libraries/aws_cloudfront_key_group.rb +++ b/libraries/aws_cloudfront_key_group.rb @@ -13,7 +13,9 @@ def initialize(opts = {}) opts = { id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:id]) - raise ArgumentError, "#{@__resource_name__}: id must be provided" unless opts[:id] && !opts[:id].empty? + unless opts[:id] && !opts[:id].empty? + raise ArgumentError, "#{@__resource_name__}: id must be provided" + end @display_name = opts[:id] catch_aws_errors do resp = @aws.cloudfront_client.get_key_group({ id: opts[:id] }) @@ -23,11 +25,11 @@ def initialize(opts = {}) end def resource_id - @resp? @resp[:id]: @display_name + @resp ? @resp[:id] : @display_name end def id - return nil unless exists? + return unless exists? @resp[:id] end diff --git a/libraries/aws_cloudfront_origin_access_identity.rb b/libraries/aws_cloudfront_origin_access_identity.rb index e9e8e478c..c61ff1235 100644 --- a/libraries/aws_cloudfront_origin_access_identity.rb +++ b/libraries/aws_cloudfront_origin_access_identity.rb @@ -12,22 +12,27 @@ class AWSCloudFrontOriginAccessIdentity < AwsResourceBase def initialize(opts = {}) opts = { id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(id)) - raise ArgumentError, "#{@__resource_name__}: id must be provided" unless opts[:id] && !opts[:id].empty? + validate_parameters(required: %i[id]) + unless opts[:id] && !opts[:id].empty? + raise ArgumentError, "#{@__resource_name__}: id must be provided" + end @display_name = opts[:id] catch_aws_errors do - resp = @aws.cloudfront_client.get_cloud_front_origin_access_identity({ id: opts[:id] }) + resp = + @aws.cloudfront_client.get_cloud_front_origin_access_identity( + { id: opts[:id] } + ) @res = resp.cloud_front_origin_access_identity.to_h create_resource_methods(@res) end end def resource_id - @res? @res[:id]: @display_name + @res ? @res[:id] : @display_name end def id - return nil unless exists? + return unless exists? @res[:id] end diff --git a/libraries/aws_cloudfront_origin_request_policy.rb b/libraries/aws_cloudfront_origin_request_policy.rb index ed536cd43..3c4644f6a 100644 --- a/libraries/aws_cloudfront_origin_request_policy.rb +++ b/libraries/aws_cloudfront_origin_request_policy.rb @@ -13,7 +13,9 @@ def initialize(opts = {}) opts = { id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:id]) - raise ArgumentError, "#{@__resource_name__}: id must be provided" unless opts[:id] && !opts[:id].empty? + unless opts[:id] && !opts[:id].empty? + raise ArgumentError, "#{@__resource_name__}: id must be provided" + end @display_name = opts[:id] resp = @aws.cloudfront_client.get_origin_request_policy({ id: opts[:id] }) @origin_request_policy = resp.origin_request_policy.to_h diff --git a/libraries/aws_cloudfront_public_key.rb b/libraries/aws_cloudfront_public_key.rb index b5681f003..50ab40bd6 100644 --- a/libraries/aws_cloudfront_public_key.rb +++ b/libraries/aws_cloudfront_public_key.rb @@ -12,8 +12,10 @@ class AWSCloudFrontPublicKey < AwsResourceBase def initialize(opts = {}) opts = { id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(id)) - raise ArgumentError, "#{@__resource_name__}: id must be provided" unless opts[:id] && !opts[:id].empty? + validate_parameters(required: %i[id]) + unless opts[:id] && !opts[:id].empty? + raise ArgumentError, "#{@__resource_name__}: id must be provided" + end @display_name = opts[:id] catch_aws_errors do resp = @aws.cloudfront_client.get_public_key({ id: opts[:id] }) @@ -23,7 +25,7 @@ def initialize(opts = {}) end def resource_id - @res? @res[:id]: @display_name + @res ? @res[:id] : @display_name end def id diff --git a/libraries/aws_cloudfront_realtime_log_config.rb b/libraries/aws_cloudfront_realtime_log_config.rb index 4646ce511..b43c61a8f 100644 --- a/libraries/aws_cloudfront_realtime_log_config.rb +++ b/libraries/aws_cloudfront_realtime_log_config.rb @@ -12,11 +12,14 @@ class AwsCloudFrontRealtimeLogConfig < AwsResourceBase def initialize(opts = {}) opts = { name: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(name)) - raise ArgumentError, "#{@__resource_name__}: name must be provided" unless opts[:name] && !opts[:name].empty? + validate_parameters(required: %i[name]) + unless opts[:name] && !opts[:name].empty? + raise ArgumentError, "#{@__resource_name__}: name must be provided" + end @display_name = opts[:name] catch_aws_errors do - resp = @aws.cloudfront_client.get_realtime_log_config({ name: opts[:name] }) + resp = + @aws.cloudfront_client.get_realtime_log_config({ name: opts[:name] }) @res = resp.realtime_log_config.to_h @arn = @res[:arn] create_resource_methods(@res) diff --git a/libraries/aws_cloudfront_streaming_distribution.rb b/libraries/aws_cloudfront_streaming_distribution.rb index 74ab8186c..a83c29ffe 100644 --- a/libraries/aws_cloudfront_streaming_distribution.rb +++ b/libraries/aws_cloudfront_streaming_distribution.rb @@ -12,11 +12,14 @@ class AWSCloudFrontStreamingDistribution < AwsResourceBase def initialize(opts = {}) opts = { id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(id)) - raise ArgumentError, "#{@__resource_name__}: id must be provided" unless opts[:id] && !opts[:id].empty? + validate_parameters(required: %i[id]) + unless opts[:id] && !opts[:id].empty? + raise ArgumentError, "#{@__resource_name__}: id must be provided" + end @display_name = opts[:id] catch_aws_errors do - resp = @aws.cloudfront_client.get_streaming_distribution({ id: opts[:id] }) + resp = + @aws.cloudfront_client.get_streaming_distribution({ id: opts[:id] }) @res = resp.streaming_distribution.to_h @arn = @res[:arn] create_resource_methods(@res) diff --git a/libraries/aws_cloudtrail_trail.rb b/libraries/aws_cloudtrail_trail.rb index bb55764c8..e387eca13 100644 --- a/libraries/aws_cloudtrail_trail.rb +++ b/libraries/aws_cloudtrail_trail.rb @@ -9,9 +9,17 @@ class AwsCloudTrailTrail < AwsResourceBase end EXAMPLE - attr_reader :cloud_watch_logs_log_group_arn, :cloud_watch_logs_role_arn, :home_region, :trail_name, - :kms_key_id, :s3_bucket_name, :s3_key_prefix, :trail_arn, :is_multi_region_trail, - :log_file_validation_enabled, :is_organization_trail + attr_reader :cloud_watch_logs_log_group_arn, + :cloud_watch_logs_role_arn, + :home_region, + :trail_name, + :kms_key_id, + :s3_bucket_name, + :s3_key_prefix, + :trail_arn, + :is_multi_region_trail, + :log_file_validation_enabled, + :is_organization_trail alias multi_region_trail? is_multi_region_trail alias log_file_validation_enabled? log_file_validation_enabled @@ -25,7 +33,10 @@ def initialize(opts = {}) @trail_name = opts[:trail_name] catch_aws_errors do - resp = @aws.cloudtrail_client.describe_trails({ trail_name_list: [@trail_name] }) + resp = + @aws.cloudtrail_client.describe_trails( + { trail_name_list: [@trail_name] } + ) @trail = resp.trail_list[0].to_h @trail_arn = @trail[:trail_arn] @kms_key_id = @trail[:kms_key_id] @@ -45,11 +56,17 @@ def resource_id end def delivered_logs_days_ago - return nil unless exists? + return unless exists? catch_aws_errors do begin - trail_status = @aws.cloudtrail_client.get_trail_status({ name: @trail_name }).to_h - ((Time.now - trail_status[:latest_cloud_watch_logs_delivery_time]) / (24 * 60 * 60)).to_i unless trail_status[:latest_cloud_watch_logs_delivery_time].nil? + trail_status = + @aws.cloudtrail_client.get_trail_status({ name: @trail_name }).to_h + unless trail_status[:latest_cloud_watch_logs_delivery_time].nil? + ( + (Time.now - trail_status[:latest_cloud_watch_logs_delivery_time]) / + (24 * 60 * 60) + ).to_i + end rescue Aws::CloudTrail::Errors::TrailNotFoundException nil end @@ -59,7 +76,9 @@ def delivered_logs_days_ago def logging? catch_aws_errors do begin - @aws.cloudtrail_client.get_trail_status({ name: @trail_name }).to_h[:is_logging] + @aws.cloudtrail_client.get_trail_status({ name: @trail_name }).to_h[ + :is_logging + ] rescue Aws::CloudTrail::Errors::TrailNotFoundException nil end @@ -71,19 +90,23 @@ def encrypted? end def get_log_group_for_multi_region_active_mgmt_rw_all - return nil unless exists? - return nil unless @cloud_watch_logs_log_group_arn - return nil if @cloud_watch_logs_log_group_arn.split(":").count < 6 - return @cloud_watch_logs_log_group_arn.split(":")[6] if has_event_selector_mgmt_events_rw_type_all? && logging? + return unless exists? + return unless @cloud_watch_logs_log_group_arn + return if @cloud_watch_logs_log_group_arn.split(":").count < 6 + if has_event_selector_mgmt_events_rw_type_all? && logging? + return @cloud_watch_logs_log_group_arn.split(":")[6] + end end def has_event_selector_mgmt_events_rw_type_all? - return nil unless exists? + return unless exists? event_selector_found = false begin - event_selectors = @aws.cloudtrail_client.get_event_selectors(trail_name: @trail_name) + event_selectors = + @aws.cloudtrail_client.get_event_selectors(trail_name: @trail_name) event_selectors.event_selectors.each do |es| - event_selector_found = true if es.read_write_type == "All" && es.include_management_events == true + event_selector_found = true if es.read_write_type == "All" && + es.include_management_events == true end rescue Aws::CloudTrail::Errors::TrailNotFoundException event_selector_found diff --git a/libraries/aws_cloudwatch_anomaly_detector.rb b/libraries/aws_cloudwatch_anomaly_detector.rb index 2b5e26db5..4a2e3f3fd 100644 --- a/libraries/aws_cloudwatch_anomaly_detector.rb +++ b/libraries/aws_cloudwatch_anomaly_detector.rb @@ -12,18 +12,23 @@ class AwsCloudwatchAnomalyDetector < AwsResourceBase def initialize(opts = {}) opts = { metric_name: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(metric_name)) - raise ArgumentError, "#{@__resource_name__}: metric_name must be provided" unless opts[:metric_name] && !opts[:metric_name].empty? + validate_parameters(required: %i[metric_name]) + unless opts[:metric_name] && !opts[:metric_name].empty? + raise ArgumentError, "#{@__resource_name__}: metric_name must be provided" + end @display_name = opts[:metric_name] catch_aws_errors do - resp = @aws.cloudwatch_client.describe_anomaly_detectors({ metric_name: opts[:metric_name] }) + resp = + @aws.cloudwatch_client.describe_anomaly_detectors( + { metric_name: opts[:metric_name] } + ) @res = resp.anomaly_detectors[0].to_h create_resource_methods(@res) end end def resource_id - "#{@res? @res[:metric_name]: ""}_#{@res? @res[:namespace]: ""}" + "#{@res ? @res[:metric_name] : ""}_#{@res ? @res[:namespace] : ""}" end def metric_name diff --git a/libraries/aws_cloudwatch_composite_alarm.rb b/libraries/aws_cloudwatch_composite_alarm.rb index b59638e18..44459feb0 100644 --- a/libraries/aws_cloudwatch_composite_alarm.rb +++ b/libraries/aws_cloudwatch_composite_alarm.rb @@ -12,11 +12,16 @@ class AwsCloudwatchCompositeAlarm < AwsResourceBase def initialize(opts = {}) opts = { alarm_name: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(alarm_name)) - raise ArgumentError, "#{@__resource_name__}: alarm_name must be provided" unless opts[:alarm_name] && !opts[:alarm_name].empty? + validate_parameters(required: %i[alarm_name]) + unless opts[:alarm_name] && !opts[:alarm_name].empty? + raise ArgumentError, "#{@__resource_name__}: alarm_name must be provided" + end @display_name = opts[:alarm_name] catch_aws_errors do - resp = @aws.cloudwatch_client.describe_alarms({ alarm_names: [opts[:alarm_name]], alarm_types: ["CompositeAlarm"] }) + resp = + @aws.cloudwatch_client.describe_alarms( + { alarm_names: [opts[:alarm_name]], alarm_types: ["CompositeAlarm"] } + ) @res = resp.composite_alarms[0].to_h @alarm_arn = @res[:alarm_arn] create_resource_methods(@res) diff --git a/libraries/aws_cloudwatch_dashboard.rb b/libraries/aws_cloudwatch_dashboard.rb index b3ca0f962..a184d8634 100644 --- a/libraries/aws_cloudwatch_dashboard.rb +++ b/libraries/aws_cloudwatch_dashboard.rb @@ -13,10 +13,16 @@ def initialize(opts = {}) opts = { dashboard_name: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:dashboard_name]) - raise ArgumentError, "#{@__resource_name__}: dashboard_name must be provided" unless opts[:dashboard_name] && !opts[:dashboard_name].empty? + unless opts[:dashboard_name] && !opts[:dashboard_name].empty? + raise ArgumentError, + "#{@__resource_name__}: dashboard_name must be provided" + end @display_name = opts[:dashboard_name] catch_aws_errors do - resp = @aws.cloudwatch_client.get_dashboard({ dashboard_name: opts[:dashboard_name] }) + resp = + @aws.cloudwatch_client.get_dashboard( + { dashboard_name: opts[:dashboard_name] } + ) @dashboard = resp.to_h @dashboard_arn = @dashboard[:dashboard_arn] create_resource_methods(@dashboard) diff --git a/libraries/aws_cloudwatch_metric_stream.rb b/libraries/aws_cloudwatch_metric_stream.rb index 80e07b0a7..ec18ef3ff 100644 --- a/libraries/aws_cloudwatch_metric_stream.rb +++ b/libraries/aws_cloudwatch_metric_stream.rb @@ -13,10 +13,16 @@ def initialize(opts = {}) opts = { metric_stream_name: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:metric_stream_name]) - raise ArgumentError, "#{@__resource_name__}: metric_stream_name must be provided" unless opts[:metric_stream_name] && !opts[:metric_stream_name].empty? + unless opts[:metric_stream_name] && !opts[:metric_stream_name].empty? + raise ArgumentError, + "#{@__resource_name__}: metric_stream_name must be provided" + end @display_name = opts[:metric_stream_name] catch_aws_errors do - resp = @aws.cloudwatch_client.get_metric_stream({ name: opts[:metric_stream_name] }) + resp = + @aws.cloudwatch_client.get_metric_stream( + { name: opts[:metric_stream_name] } + ) @stream = resp.to_h @stream_name = @stream[:name] @stream_arn = @stream[:arn] diff --git a/libraries/aws_cloudwatchlogs_destinantion.rb b/libraries/aws_cloudwatchlogs_destinantion.rb index 25a4182d0..5e1583e8e 100644 --- a/libraries/aws_cloudwatchlogs_destinantion.rb +++ b/libraries/aws_cloudwatchlogs_destinantion.rb @@ -13,10 +13,17 @@ def initialize(opts = {}) opts = { destination_name_prefix: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:destination_name_prefix]) - raise ArgumentError, "#{@__resource_name__}: destination_name_prefix must be provided" unless opts[:destination_name_prefix] && !opts[:destination_name_prefix].empty? + unless opts[:destination_name_prefix] && + !opts[:destination_name_prefix].empty? + raise ArgumentError, + "#{@__resource_name__}: destination_name_prefix must be provided" + end @display_name = opts[:destination_name_prefix] catch_aws_errors do - resp = @aws.cloudwatchlogs_client.describe_destinations({ destination_name_prefix: opts[:destination_name_prefix] }) + resp = + @aws.cloudwatchlogs_client.describe_destinations( + { destination_name_prefix: opts[:destination_name_prefix] } + ) @destinations = resp.destinations[0].to_h @destination_name = @destinations[:destination_name] @destination_arn = @destinations[:arn] @@ -29,7 +36,7 @@ def resource_id end def destination_name_prefix - return nil unless exists? + return unless exists? @destinations[:destination_name_prefix] end diff --git a/libraries/aws_cloudwatchlogs_log_stream.rb b/libraries/aws_cloudwatchlogs_log_stream.rb index 6aa2cdc1b..6b53b8938 100644 --- a/libraries/aws_cloudwatchlogs_log_stream.rb +++ b/libraries/aws_cloudwatchlogs_log_stream.rb @@ -12,12 +12,25 @@ class AWSCloudWatchLogsLogStream < AwsResourceBase def initialize(opts = {}) opts = { log_stream_name_prefix: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(log_stream_name_prefix log_group_name)) - raise ArgumentError, "#{@__resource_name__}: log_stream_name_prefix must be provided." unless opts[:log_stream_name_prefix] && !opts[:log_stream_name_prefix].empty? - raise ArgumentError, "#{@__resource_name__}: log_group_name must be provided." unless opts[:log_group_name] && !opts[:log_group_name].empty? + validate_parameters(required: %i[log_stream_name_prefix log_group_name]) + unless opts[:log_stream_name_prefix] && + !opts[:log_stream_name_prefix].empty? + raise ArgumentError, + "#{@__resource_name__}: log_stream_name_prefix must be provided." + end + unless opts[:log_group_name] && !opts[:log_group_name].empty? + raise ArgumentError, + "#{@__resource_name__}: log_group_name must be provided." + end @display_name = opts[:log_stream_name_prefix] catch_aws_errors do - resp = @aws.cloudwatchlogs_client.describe_log_streams({ log_stream_name_prefix: opts[:log_stream_name_prefix], log_group_name: opts[:log_group_name] }) + resp = + @aws.cloudwatchlogs_client.describe_log_streams( + { + log_stream_name_prefix: opts[:log_stream_name_prefix], + log_group_name: opts[:log_group_name] + } + ) @log_streams = resp.log_streams[0].to_h @log_stream_name = @log_streams[:log_stream_name] @log_stream_arn = @log_streams[:arn] diff --git a/libraries/aws_cloudwatchlogs_subscription_filter.rb b/libraries/aws_cloudwatchlogs_subscription_filter.rb index 809ac2564..4ff7e4041 100644 --- a/libraries/aws_cloudwatchlogs_subscription_filter.rb +++ b/libraries/aws_cloudwatchlogs_subscription_filter.rb @@ -12,12 +12,24 @@ class AWSCloudWatchLogsSubscriptionFilter < AwsResourceBase def initialize(opts = {}) opts = { filter_name_prefix: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(log_group_name filter_name_prefix)) - raise ArgumentError, "#{@__resource_name__}: log_group_name must be provided" unless opts[:log_group_name] && !opts[:log_group_name].empty? - raise ArgumentError, "#{@__resource_name__}: filter_name_prefix must be provided" unless opts[:filter_name_prefix] && !opts[:filter_name_prefix].empty? + validate_parameters(required: %i[log_group_name filter_name_prefix]) + unless opts[:log_group_name] && !opts[:log_group_name].empty? + raise ArgumentError, + "#{@__resource_name__}: log_group_name must be provided" + end + unless opts[:filter_name_prefix] && !opts[:filter_name_prefix].empty? + raise ArgumentError, + "#{@__resource_name__}: filter_name_prefix must be provided" + end @display_name = opts[:filter_name_prefix] catch_aws_errors do - resp = @aws.cloudwatchlogs_client.describe_subscription_filters({ log_group_name: opts[:log_group_name], filter_name_prefix: opts[:filter_name_prefix] }) + resp = + @aws.cloudwatchlogs_client.describe_subscription_filters( + { + log_group_name: opts[:log_group_name], + filter_name_prefix: opts[:filter_name_prefix] + } + ) @filter = resp.subscription_filters[0].to_h @filter_name = @filter[:filter_name] @filter_log_group_name = @filter[:log_group_name] diff --git a/libraries/aws_cognito_identity_pool.rb b/libraries/aws_cognito_identity_pool.rb index ff05ce71d..3a1498af4 100644 --- a/libraries/aws_cognito_identity_pool.rb +++ b/libraries/aws_cognito_identity_pool.rb @@ -13,10 +13,16 @@ def initialize(opts = {}) opts = { identity_pool_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:identity_pool_id]) - raise ArgumentError, "#{@__resource_name__}: identity_pool_id must be provided" unless opts[:identity_pool_id] && !opts[:identity_pool_id].empty? + unless opts[:identity_pool_id] && !opts[:identity_pool_id].empty? + raise ArgumentError, + "#{@__resource_name__}: identity_pool_id must be provided" + end @display_name = opts[:identity_pool_id] catch_aws_errors do - resp = @aws.cognitoidentity_client.describe_identity_pool({ identity_pool_id: opts[:identity_pool_id] }) + resp = + @aws.cognitoidentity_client.describe_identity_pool( + { identity_pool_id: opts[:identity_pool_id] } + ) @res = resp.to_h create_resource_methods(@res) end diff --git a/libraries/aws_cognito_userpool.rb b/libraries/aws_cognito_userpool.rb index fb4ad0141..523272b58 100644 --- a/libraries/aws_cognito_userpool.rb +++ b/libraries/aws_cognito_userpool.rb @@ -14,10 +14,16 @@ def initialize(opts = {}) super(opts) validate_parameters(required: [:user_pool_id]) - raise ArgumentError, "#{@__resource_name__}: user_pool_id must be provided" unless opts[:user_pool_id] && !opts[:user_pool_id].empty? + unless opts[:user_pool_id] && !opts[:user_pool_id].empty? + raise ArgumentError, + "#{@__resource_name__}: user_pool_id must be provided" + end @display_name = opts[:user_pool_id] catch_aws_errors do - resp = @aws.cognitoidentityprovider_client.describe_user_pool({ user_pool_id: opts[:user_pool_id] }) + resp = + @aws.cognitoidentityprovider_client.describe_user_pool( + { user_pool_id: opts[:user_pool_id] } + ) @user_pool = resp.user_pool.to_h create_resource_methods(@user_pool) end diff --git a/libraries/aws_cognito_userpool_client.rb b/libraries/aws_cognito_userpool_client.rb index 477a57463..9e089469d 100644 --- a/libraries/aws_cognito_userpool_client.rb +++ b/libraries/aws_cognito_userpool_client.rb @@ -12,9 +12,12 @@ class AWSCognitoUserPoolClient < AwsResourceBase def initialize(opts = {}) opts = { user_pool_id: opts, client_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(user_pool_id client_id)) + validate_parameters(required: %i[user_pool_id client_id]) catch_aws_errors do - resp = @aws.cognitoidentityprovider_client.describe_user_pool_client({ user_pool_id: opts[:user_pool_id], client_id: opts[:client_id] }) + resp = + @aws.cognitoidentityprovider_client.describe_user_pool_client( + { user_pool_id: opts[:user_pool_id], client_id: opts[:client_id] } + ) @user_pool_client = resp.user_pool_client.to_h create_resource_methods(@user_pool_client) end diff --git a/libraries/aws_dms_endpoint.rb b/libraries/aws_dms_endpoint.rb index d355de63c..ddfc6f58d 100644 --- a/libraries/aws_dms_endpoint.rb +++ b/libraries/aws_dms_endpoint.rb @@ -15,11 +15,17 @@ def initialize(opts = {}) super(opts) validate_parameters(required: [:endpoint_arn]) - raise ArgumentError, "#{@__resource_name__}: endpoint_arn must be provided" unless opts[:endpoint_arn] && !opts[:endpoint_arn].empty? + unless opts[:endpoint_arn] && !opts[:endpoint_arn].empty? + raise ArgumentError, + "#{@__resource_name__}: endpoint_arn must be provided" + end @display_name = opts[:endpoint_arn] filter = { name: "endpoint-arn", values: [opts[:endpoint_arn]] } catch_aws_errors do - resp = @aws.dmsmigrationservice_client.describe_endpoints({ filters: [filter] }) + resp = + @aws.dmsmigrationservice_client.describe_endpoints( + { filters: [filter] } + ) @endpoints = resp.endpoints[0].to_h create_resource_methods(@endpoints) end diff --git a/libraries/aws_dms_replication_instance.rb b/libraries/aws_dms_replication_instance.rb index bd8b7a45c..2be424ba3 100644 --- a/libraries/aws_dms_replication_instance.rb +++ b/libraries/aws_dms_replication_instance.rb @@ -13,14 +13,16 @@ def initialize(opts = {}) super(opts) validate_parameters catch_aws_errors do - resp = @aws.dmsmigrationservice_client.describe_orderable_replication_instances - @orderable_replication_instances = resp.orderable_replication_instances[0].to_h + resp = + @aws.dmsmigrationservice_client.describe_orderable_replication_instances + @orderable_replication_instances = + resp.orderable_replication_instances[0].to_h create_resource_methods(@orderable_replication_instances) end end def resource_id - "#{@orderable_replication_instances? @orderable_replication_instances[:replication_instance_class]: ""}_#{@orderable_replication_instances? @orderable_replication_instances[:engine_version]: ""}" + "#{@orderable_replication_instances ? @orderable_replication_instances[:replication_instance_class] : ""}_#{@orderable_replication_instances ? @orderable_replication_instances[:engine_version] : ""}" end def replication_instance_class @@ -29,6 +31,7 @@ def replication_instance_class end def exists? - !@orderable_replication_instances.nil? && !@orderable_replication_instances.empty? + !@orderable_replication_instances.nil? && + !@orderable_replication_instances.empty? end end diff --git a/libraries/aws_dms_replication_subnet_group.rb b/libraries/aws_dms_replication_subnet_group.rb index 137c8e785..77a596ec2 100644 --- a/libraries/aws_dms_replication_subnet_group.rb +++ b/libraries/aws_dms_replication_subnet_group.rb @@ -13,19 +13,24 @@ def initialize(opts = {}) opts = { replication_subnet_group_identifier: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:replication_subnet_group_identifier]) - raise ArgumentError, "#{@__resource_name__}: replication_subnet_group_identifier must be provided" unless opts[:replication_subnet_group_identifier] && !opts[:replication_subnet_group_identifier].empty? + unless opts[:replication_subnet_group_identifier] && + !opts[:replication_subnet_group_identifier].empty? + raise ArgumentError, + "#{@__resource_name__}: replication_subnet_group_identifier must be provided" + end @display_name = opts[:replication_subnet_group_identifier] catch_aws_errors do - resp = @aws.dmsmigrationservice_client.describe_replication_subnet_groups( - { - filters: [ - { - name: "replication-subnet-group-id", - values: [opts[:replication_subnet_group_identifier]], - }, - ], - }, - ) + resp = + @aws.dmsmigrationservice_client.describe_replication_subnet_groups( + { + filters: [ + { + name: "replication-subnet-group-id", + values: [opts[:replication_subnet_group_identifier]] + } + ] + } + ) @replication_subnet_groups = resp.replication_subnet_groups[0].to_h create_resource_methods(@replication_subnet_groups) end diff --git a/libraries/aws_dynamodb_table.rb b/libraries/aws_dynamodb_table.rb index 328f9baf9..f4c1abab8 100644 --- a/libraries/aws_dynamodb_table.rb +++ b/libraries/aws_dynamodb_table.rb @@ -21,7 +21,7 @@ def initialize(opts = {}) catch_aws_errors do begin resp = @aws.dynamodb_client.describe_table(table_name: opts[:table_name]) - return nil if resp[0].nil? || resp[0].empty? + return if resp[0].nil? || resp[0].empty? rescue Aws::DynamoDB::Errors::ResourceNotFoundException return end diff --git a/libraries/aws_ebs_volume.rb b/libraries/aws_ebs_volume.rb index 5a1de8730..87741258a 100644 --- a/libraries/aws_ebs_volume.rb +++ b/libraries/aws_ebs_volume.rb @@ -18,10 +18,13 @@ class AwsEbsVolume < AwsResourceBase def initialize(opts = {}) opts = { volume_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(require_any_of: %i(volume_id name)) + validate_parameters(require_any_of: %i[volume_id name]) if opts[:volume_id] && !opts[:volume_id].empty? - raise ArgumentError, "#{@__resource_name__}: must be in the format 'vol- followed by 8 or 17 hexadecimal characters." if opts[:volume_id] !~ /^vol\-([0-9a-f]{8})|(^vol\-[0-9a-f]{17})$/ + if opts[:volume_id] !~ /^vol\-([0-9a-f]{8})|(^vol\-[0-9a-f]{17})$/ + raise ArgumentError, + "#{@__resource_name__}: must be in the format 'vol- followed by 8 or 17 hexadecimal characters." + end @display_name = opts[:volume_id] volume_arguments = { volume_ids: [opts[:volume_id]] } elsif opts[:name] && !opts[:name].empty? @@ -29,7 +32,8 @@ def initialize(opts = {}) filter = { name: "tag:Name", values: [opts[:name]] } volume_arguments = { filters: [filter] } else - raise ArgumentError, "#{@__resource_name__}: `volume_id` or `name` must be provided" + raise ArgumentError, + "#{@__resource_name__}: `volume_id` or `name` must be provided" end catch_aws_errors do diff --git a/libraries/aws_ec2_capacity_reservation.rb b/libraries/aws_ec2_capacity_reservation.rb index 1fbfc6d21..d8b43d9d6 100644 --- a/libraries/aws_ec2_capacity_reservation.rb +++ b/libraries/aws_ec2_capacity_reservation.rb @@ -13,12 +13,20 @@ def initialize(opts = {}) opts = { capacity_reservation_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:capacity_reservation_id]) - raise ArgumentError, "#{@__resource_name__}: capacity_reservation_id must be provided" unless opts[:capacity_reservation_id] && !opts[:capacity_reservation_id].empty? + unless opts[:capacity_reservation_id] && + !opts[:capacity_reservation_id].empty? + raise ArgumentError, + "#{@__resource_name__}: capacity_reservation_id must be provided" + end @display_name = opts[:capacity_reservation_id] catch_aws_errors do - resp = @aws.compute_client.describe_capacity_reservations({ capacity_reservation_ids: [opts[:capacity_reservation_id]] }) + resp = + @aws.compute_client.describe_capacity_reservations( + { capacity_reservation_ids: [opts[:capacity_reservation_id]] } + ) @resp = resp.capacity_reservations[0].to_h - @capacity_reservation_id = resp.capacity_reservations[0].capacity_reservation_id + @capacity_reservation_id = + resp.capacity_reservations[0].capacity_reservation_id create_resource_methods(@resp) end end diff --git a/libraries/aws_ec2_carrier_gateway.rb b/libraries/aws_ec2_carrier_gateway.rb index 5a51a1ca1..88c973f5b 100644 --- a/libraries/aws_ec2_carrier_gateway.rb +++ b/libraries/aws_ec2_carrier_gateway.rb @@ -13,10 +13,16 @@ def initialize(opts = {}) opts = { carrier_gateway_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:carrier_gateway_id]) - raise ArgumentError, "#{@__resource_name__}: carrier_gateway_id must be provided" unless opts[:carrier_gateway_id] && !opts[:carrier_gateway_id].empty? + unless opts[:carrier_gateway_id] && !opts[:carrier_gateway_id].empty? + raise ArgumentError, + "#{@__resource_name__}: carrier_gateway_id must be provided" + end @display_name = opts[:carrier_gateway_id] catch_aws_errors do - resp = @aws.compute_client.describe_carrier_gateways({ carrier_gateway_ids: [opts[:carrier_gateway_id]] }) + resp = + @aws.compute_client.describe_carrier_gateways( + { carrier_gateway_ids: [opts[:carrier_gateway_id]] } + ) @resp = resp.carrier_gateways[0].to_h @carrier_gateway_id = resp.carrier_gateways[0].carrier_gateway_id create_resource_methods(@resp) diff --git a/libraries/aws_ec2_client_vpn_authorization_rule.rb b/libraries/aws_ec2_client_vpn_authorization_rule.rb index 61314127a..c3999fc39 100644 --- a/libraries/aws_ec2_client_vpn_authorization_rule.rb +++ b/libraries/aws_ec2_client_vpn_authorization_rule.rb @@ -12,14 +12,25 @@ class AWSEC2ClientVPNAuthorizationRule < AwsResourceBase def initialize(opts = {}) opts = { client_vpn_endpoint_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(client_vpn_endpoint_id group_id)) - raise ArgumentError, "#{@__resource_name__}: client_vpn_endpoint_id must be provided" unless opts[:client_vpn_endpoint_id] && !opts[:client_vpn_endpoint_id].empty? - raise ArgumentError, "#{@__resource_name__}: group_id must be provided" unless opts[:group_id] && !opts[:group_id].empty? + validate_parameters(required: %i[client_vpn_endpoint_id group_id]) + unless opts[:client_vpn_endpoint_id] && + !opts[:client_vpn_endpoint_id].empty? + raise ArgumentError, + "#{@__resource_name__}: client_vpn_endpoint_id must be provided" + end + unless opts[:group_id] && !opts[:group_id].empty? + raise ArgumentError, "#{@__resource_name__}: group_id must be provided" + end @display_name = opts[:client_vpn_endpoint_id] - filter = [{ name: "group-id", - values: [opts[:group_id]] }] + filter = [{ name: "group-id", values: [opts[:group_id]] }] catch_aws_errors do - resp = @aws.compute_client.describe_client_vpn_authorization_rules({ client_vpn_endpoint_id: opts[:client_vpn_endpoint_id], filters: filter }) + resp = + @aws.compute_client.describe_client_vpn_authorization_rules( + { + client_vpn_endpoint_id: opts[:client_vpn_endpoint_id], + filters: filter + } + ) @res = resp.authorization_rules[0].to_h create_resource_methods(@res) end diff --git a/libraries/aws_ec2_client_vpn_endpoint.rb b/libraries/aws_ec2_client_vpn_endpoint.rb index 7b7de6224..feb45492f 100644 --- a/libraries/aws_ec2_client_vpn_endpoint.rb +++ b/libraries/aws_ec2_client_vpn_endpoint.rb @@ -13,10 +13,17 @@ def initialize(opts = {}) opts = { client_vpn_endpoint_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:client_vpn_endpoint_id]) - raise ArgumentError, "#{@__resource_name__}: client_vpn_endpoint_id must be provided" unless opts[:client_vpn_endpoint_id] && !opts[:client_vpn_endpoint_id].empty? + unless opts[:client_vpn_endpoint_id] && + !opts[:client_vpn_endpoint_id].empty? + raise ArgumentError, + "#{@__resource_name__}: client_vpn_endpoint_id must be provided" + end @display_name = opts[:client_vpn_endpoint_id] catch_aws_errors do - resp = @aws.compute_client.describe_client_vpn_endpoints({ client_vpn_endpoint_ids: [opts[:client_vpn_endpoint_id]] }) + resp = + @aws.compute_client.describe_client_vpn_endpoints( + { client_vpn_endpoint_ids: [opts[:client_vpn_endpoint_id]] } + ) @res = resp.client_vpn_endpoints[0].to_h create_resource_methods(@res) end diff --git a/libraries/aws_ec2_client_vpn_route.rb b/libraries/aws_ec2_client_vpn_route.rb index d42872cb6..09cb0d958 100644 --- a/libraries/aws_ec2_client_vpn_route.rb +++ b/libraries/aws_ec2_client_vpn_route.rb @@ -12,14 +12,26 @@ class AWSEC2ClientVPNRoute < AwsResourceBase def initialize(opts = {}) opts = { client_vpn_endpoint_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(client_vpn_endpoint_id target_subnet)) - raise ArgumentError, "#{@__resource_name__}: client_vpn_endpoint_id must be provided" unless opts[:client_vpn_endpoint_id] && !opts[:client_vpn_endpoint_id].empty? - raise ArgumentError, "#{@__resource_name__}: target_subnet must be provided" unless opts[:target_subnet] && !opts[:target_subnet].empty? + validate_parameters(required: %i[client_vpn_endpoint_id target_subnet]) + unless opts[:client_vpn_endpoint_id] && + !opts[:client_vpn_endpoint_id].empty? + raise ArgumentError, + "#{@__resource_name__}: client_vpn_endpoint_id must be provided" + end + unless opts[:target_subnet] && !opts[:target_subnet].empty? + raise ArgumentError, + "#{@__resource_name__}: target_subnet must be provided" + end @display_name = opts[:client_vpn_endpoint_id] - filter = [{ name: "target-subnet", - values: [opts[:target_subnet]] }] + filter = [{ name: "target-subnet", values: [opts[:target_subnet]] }] catch_aws_errors do - resp = @aws.compute_client.describe_client_vpn_routes({ client_vpn_endpoint_id: opts[:client_vpn_endpoint_id], filters: filter }) + resp = + @aws.compute_client.describe_client_vpn_routes( + { + client_vpn_endpoint_id: opts[:client_vpn_endpoint_id], + filters: filter + } + ) @res = resp.routes[0].to_h create_resource_methods(@res) end diff --git a/libraries/aws_ec2_client_vpn_target_network_association.rb b/libraries/aws_ec2_client_vpn_target_network_association.rb index a9e854e66..c5c53fe2a 100644 --- a/libraries/aws_ec2_client_vpn_target_network_association.rb +++ b/libraries/aws_ec2_client_vpn_target_network_association.rb @@ -12,18 +12,26 @@ class AWSEC2ClientVPNTargetNetworkAssociation < AwsResourceBase def initialize(opts = {}) opts = { client_vpn_endpoint_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(client_vpn_endpoint_id association_id)) - raise ArgumentError, "#{@__resource_name__}: client_vpn_endpoint_id must be provided" unless opts[:client_vpn_endpoint_id] && !opts[:client_vpn_endpoint_id].empty? - raise ArgumentError, "#{@__resource_name__}: association_id must be provided" unless opts[:association_id] && !opts[:association_id].empty? + validate_parameters(required: %i[client_vpn_endpoint_id association_id]) + unless opts[:client_vpn_endpoint_id] && + !opts[:client_vpn_endpoint_id].empty? + raise ArgumentError, + "#{@__resource_name__}: client_vpn_endpoint_id must be provided" + end + unless opts[:association_id] && !opts[:association_id].empty? + raise ArgumentError, + "#{@__resource_name__}: association_id must be provided" + end @display_name = opts[:client_vpn_endpoint_id] - filter = [ - { - name: "association-id", - values: [opts[:association_id]], - }, - ] + filter = [{ name: "association-id", values: [opts[:association_id]] }] catch_aws_errors do - resp = @aws.compute_client.describe_client_vpn_target_networks({ client_vpn_endpoint_id: opts[:client_vpn_endpoint_id], filters: filter }) + resp = + @aws.compute_client.describe_client_vpn_target_networks( + { + client_vpn_endpoint_id: opts[:client_vpn_endpoint_id], + filters: filter + } + ) @res = resp.client_vpn_target_networks[0].to_h create_resource_methods(@res) end diff --git a/libraries/aws_ec2_customer_gateway.rb b/libraries/aws_ec2_customer_gateway.rb index f94a4931d..1ae8b33cf 100644 --- a/libraries/aws_ec2_customer_gateway.rb +++ b/libraries/aws_ec2_customer_gateway.rb @@ -13,10 +13,16 @@ def initialize(opts = {}) opts = { customer_gateway_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:customer_gateway_id]) - raise ArgumentError, "#{@__resource_name__}: customer_gateway_id must be provided" unless opts[:customer_gateway_id] && !opts[:customer_gateway_id].empty? + unless opts[:customer_gateway_id] && !opts[:customer_gateway_id].empty? + raise ArgumentError, + "#{@__resource_name__}: customer_gateway_id must be provided" + end @display_name = opts[:customer_gateway_id] catch_aws_errors do - resp = @aws.compute_client.describe_customer_gateways({ customer_gateway_ids: [opts[:customer_gateway_id]] }) + resp = + @aws.compute_client.describe_customer_gateways( + { customer_gateway_ids: [opts[:customer_gateway_id]] } + ) @resp = resp.customer_gateways[0].to_h create_resource_methods(@resp) end diff --git a/libraries/aws_ec2_egress_only_internet_gateway.rb b/libraries/aws_ec2_egress_only_internet_gateway.rb index 0f973a24a..cec32fe0f 100644 --- a/libraries/aws_ec2_egress_only_internet_gateway.rb +++ b/libraries/aws_ec2_egress_only_internet_gateway.rb @@ -14,10 +14,21 @@ def initialize(opts = {}) opts = { egress_only_internet_gateway_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:egress_only_internet_gateway_id]) - raise ArgumentError, "#{@__resource_name__}: egress_only_internet_gateway_id must be provided" unless opts[:egress_only_internet_gateway_id] && !opts[:egress_only_internet_gateway_id].empty? + unless opts[:egress_only_internet_gateway_id] && + !opts[:egress_only_internet_gateway_id].empty? + raise ArgumentError, + "#{@__resource_name__}: egress_only_internet_gateway_id must be provided" + end @display_name = opts[:egress_only_internet_gateway_id] catch_aws_errors do - resp = @aws.compute_client.describe_egress_only_internet_gateways({ egress_only_internet_gateway_ids: [opts[:egress_only_internet_gateway_id]] }) + resp = + @aws.compute_client.describe_egress_only_internet_gateways( + { + egress_only_internet_gateway_ids: [ + opts[:egress_only_internet_gateway_id] + ] + } + ) @resp = resp.egress_only_internet_gateways[0].to_h create_resource_methods(@resp) end diff --git a/libraries/aws_ec2_eip.rb b/libraries/aws_ec2_eip.rb index c2bbcb5a3..b1d422d06 100644 --- a/libraries/aws_ec2_eip.rb +++ b/libraries/aws_ec2_eip.rb @@ -19,10 +19,15 @@ def initialize(opts = {}) super(opts) validate_parameters(required: [:public_ip]) - raise ArgumentError, "#{@__resource_name__}: public_ip must be provided" unless opts[:public_ip] && !opts[:public_ip].empty? + unless opts[:public_ip] && !opts[:public_ip].empty? + raise ArgumentError, "#{@__resource_name__}: public_ip must be provided" + end @display_name = opts[:public_ip] catch_aws_errors do - resp = @aws.compute_client.describe_addresses({ public_ips: [opts[:public_ip]] }) + resp = + @aws.compute_client.describe_addresses( + { public_ips: [opts[:public_ip]] } + ) @addresses = resp.addresses[0].to_h create_resource_methods(@addresses) end diff --git a/libraries/aws_ec2_eip_association.rb b/libraries/aws_ec2_eip_association.rb index 4257898ce..e966fc38b 100644 --- a/libraries/aws_ec2_eip_association.rb +++ b/libraries/aws_ec2_eip_association.rb @@ -13,14 +13,12 @@ class AWSEC2EIPAssociation < AwsResourceBase def initialize(opts = {}) opts = { association_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(association_id)) - raise ArgumentError, "#{@__resource_name__}: association_id must be provided" unless opts[:association_id] && !opts[:association_id].empty? - filter = [ - { - name: "association-id", - values: [opts[:association_id]], - }, - ] + validate_parameters(required: %i[association_id]) + unless opts[:association_id] && !opts[:association_id].empty? + raise ArgumentError, + "#{@__resource_name__}: association_id must be provided" + end + filter = [{ name: "association-id", values: [opts[:association_id]] }] @display_name = opts[:association_id] catch_aws_errors do resp = @aws.compute_client.describe_addresses({ filters: filter }) diff --git a/libraries/aws_ec2_fleet.rb b/libraries/aws_ec2_fleet.rb index fbc5b82be..a75455e53 100644 --- a/libraries/aws_ec2_fleet.rb +++ b/libraries/aws_ec2_fleet.rb @@ -14,10 +14,13 @@ def initialize(opts = {}) opts = { fleet_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:fleet_id]) - raise ArgumentError, "#{@__resource_name__}: fleet_id must be provided" unless opts[:fleet_id] && !opts[:fleet_id].empty? + unless opts[:fleet_id] && !opts[:fleet_id].empty? + raise ArgumentError, "#{@__resource_name__}: fleet_id must be provided" + end @display_name = opts[:fleet_id] catch_aws_errors do - resp = @aws.compute_client.describe_fleets({ fleet_ids: [opts[:fleet_id]] }) + resp = + @aws.compute_client.describe_fleets({ fleet_ids: [opts[:fleet_id]] }) @resp = resp.fleets[0].to_h create_resource_methods(@resp) end diff --git a/libraries/aws_ec2_host.rb b/libraries/aws_ec2_host.rb index 24d6d732e..834ab39da 100644 --- a/libraries/aws_ec2_host.rb +++ b/libraries/aws_ec2_host.rb @@ -14,7 +14,9 @@ def initialize(opts = {}) opts = { host_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:host_id]) - raise ArgumentError, "#{@__resource_name__}: host_id must be provided" unless opts[:host_id] && !opts[:host_id].empty? + unless opts[:host_id] && !opts[:host_id].empty? + raise ArgumentError, "#{@__resource_name__}: host_id must be provided" + end @display_name = opts[:host_id] catch_aws_errors do resp = @aws.compute_client.describe_hosts({ host_ids: [opts[:host_id]] }) @@ -24,7 +26,7 @@ def initialize(opts = {}) end def host_id - return nil unless exists? + return unless exists? @resp[:host_id] end diff --git a/libraries/aws_ec2_instance.rb b/libraries/aws_ec2_instance.rb index 4a511ed4b..afa038dd5 100644 --- a/libraries/aws_ec2_instance.rb +++ b/libraries/aws_ec2_instance.rb @@ -19,28 +19,35 @@ class AwsEc2Instance < AwsResourceBase def initialize(opts = {}) opts = { instance_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(require_any_of: %i(instance_id name)) + validate_parameters(require_any_of: %i[instance_id name]) if opts[:instance_id] && !opts[:instance_id].empty? # Use instance_id, if provided - if !opts[:instance_id].is_a?(String) || opts[:instance_id] !~ /(^i-[0-9a-f]{8})|(^i-[0-9a-f]{17})$/ - raise ArgumentError, "#{@__resource_name__}: `instance_id` must be a string in the format of 'i-' followed by 8 or 17 hexadecimal characters." + if !opts[:instance_id].is_a?(String) || + opts[:instance_id] !~ /(^i-[0-9a-f]{8})|(^i-[0-9a-f]{17})$/ + raise ArgumentError, + "#{@__resource_name__}: `instance_id` must be a string in the format of 'i-' followed by 8 or 17 hexadecimal characters." end @display_name = opts[:instance_id] instance_arguments = { instance_ids: [opts[:instance_id]] } elsif opts[:name] && !opts[:name].empty? # Otherwise use name, if provided @display_name = opts[:name] - instance_arguments = { filters: [{ name: "tag:Name", values: [opts[:name]] }] } + instance_arguments = { + filters: [{ name: "tag:Name", values: [opts[:name]] }] + } else - raise ArgumentError, "#{@__resource_name__}: either instance_id or name must be provided." + raise ArgumentError, + "#{@__resource_name__}: either instance_id or name must be provided." end catch_aws_errors do resp = @aws.compute_client.describe_instances(instance_arguments) - if resp.reservations.first.nil? || resp.reservations.first.instances.first.nil? + if resp.reservations.first.nil? || + resp.reservations.first.instances.first.nil? empty_response_warn return end - if resp.reservations.count > 1 || resp.reservations.first.instances.count > 1 + if resp.reservations.count > 1 || + resp.reservations.first.instances.count > 1 resource_fail return else @@ -52,12 +59,14 @@ def initialize(opts = {}) # Methods required to ensure backwards compatibility class << self def state - return nil unless @instance[:state] + return unless @instance[:state] @instance[:state][:name] end def security_groups - @instance[:security_groups].map { |sg| { id: sg[:group_id], name: sg[:group_name] } } + @instance[:security_groups].map do |sg| + { id: sg[:group_id], name: sg[:group_name] } + end end def tags @@ -73,35 +82,43 @@ def exists? end def security_group_ids - return nil unless @instance[:security_groups] + return unless @instance[:security_groups] @instance[:security_groups].map { |sg| sg[:group_id] } end def availability_zone - return nil unless @instance[:placement] - return nil unless @instance[:placement].include?(:availability_zone) + return unless @instance[:placement] + return unless @instance[:placement].include?(:availability_zone) @instance[:placement][:availability_zone] end def ebs_volumes - return nil unless @instance[:block_device_mappings] - return nil if @instance[:block_device_mappings].count == 0 - @instance[:block_device_mappings].map { |vol| { id: vol[:ebs][:volume_id], name: vol[:device_name] } } + return unless @instance[:block_device_mappings] + return if @instance[:block_device_mappings].count == 0 + @instance[:block_device_mappings].map do |vol| + { id: vol[:ebs][:volume_id], name: vol[:device_name] } + end end def network_interface_ids - return nil unless @instance[:network_interfaces] - return nil if @instance[:network_interfaces].count == 0 + return unless @instance[:network_interfaces] + return if @instance[:network_interfaces].count == 0 @instance[:network_interfaces].map { |nic| nic[:network_interface_id] } end def has_roles? - return false unless @instance[:iam_instance_profile] && @instance[:iam_instance_profile][:arn] + unless @instance[:iam_instance_profile] && + @instance[:iam_instance_profile][:arn] + return false + end instance_profile = @instance[:iam_instance_profile][:arn].split("/").last @returned_roles = nil # Check if there is a role created at the attached profile catch_aws_errors do - resp = @aws.iam_client.get_instance_profile({ instance_profile_name: instance_profile }) + resp = + @aws.iam_client.get_instance_profile( + { instance_profile_name: instance_profile } + ) @returned_roles = resp.instance_profile.roles end @returned_roles && !@returned_roles.empty? @@ -117,7 +134,15 @@ def role end # Generate a matcher for each state - %w{pending running shutting-down terminated stopping stopped unknown}.each do |state_name| + %w[ + pending + running + shutting-down + terminated + stopping + stopped + unknown + ].each do |state_name| define_method "#{state_name.tr("-", "_")}?" do state == state_name end @@ -132,7 +157,7 @@ def to_s end def tags_hash - return unless exists? + return nil unless exists? map_tags(tags) end end diff --git a/libraries/aws_ec2_internet_gateway.rb b/libraries/aws_ec2_internet_gateway.rb index c20dd048a..876b6b544 100644 --- a/libraries/aws_ec2_internet_gateway.rb +++ b/libraries/aws_ec2_internet_gateway.rb @@ -14,10 +14,16 @@ def initialize(opts = {}) opts = { internet_gateway_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:internet_gateway_id]) - raise ArgumentError, "#{@__resource_name__}: internet_gateway_id must be provided" unless opts[:internet_gateway_id] && !opts[:internet_gateway_id].empty? + unless opts[:internet_gateway_id] && !opts[:internet_gateway_id].empty? + raise ArgumentError, + "#{@__resource_name__}: internet_gateway_id must be provided" + end @display_name = opts[:internet_gateway_id] catch_aws_errors do - resp = @aws.compute_client.describe_internet_gateways({ internet_gateway_ids: [opts[:internet_gateway_id]] }) + resp = + @aws.compute_client.describe_internet_gateways( + { internet_gateway_ids: [opts[:internet_gateway_id]] } + ) @res = resp.internet_gateways[0].to_h create_resource_methods(@res) end diff --git a/libraries/aws_ec2_network_insights_analysis.rb b/libraries/aws_ec2_network_insights_analysis.rb index b4a7e10f5..071b9f49f 100644 --- a/libraries/aws_ec2_network_insights_analysis.rb +++ b/libraries/aws_ec2_network_insights_analysis.rb @@ -14,10 +14,19 @@ def initialize(opts = {}) opts = { network_insights_analysis_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:network_insights_analysis_id]) - raise ArgumentError, "#{@__resource_name__}: network_insights_analysis_id must be provided" unless opts[:network_insights_analysis_id] && !opts[:network_insights_analysis_id].empty? + unless opts[:network_insights_analysis_id] && + !opts[:network_insights_analysis_id].empty? + raise ArgumentError, + "#{@__resource_name__}: network_insights_analysis_id must be provided" + end @display_name = opts[:network_insights_analysis_id] catch_aws_errors do - resp = @aws.compute_client.describe_network_insights_analyses({ network_insights_analysis_ids: [opts[:network_insights_analysis_id]] }) + resp = + @aws.compute_client.describe_network_insights_analyses( + { + network_insights_analysis_ids: [opts[:network_insights_analysis_id]] + } + ) @res = resp.network_insights_analyses[0].to_h create_resource_methods(@res) end diff --git a/libraries/aws_ec2_network_insights_path.rb b/libraries/aws_ec2_network_insights_path.rb index 031489070..e55bd9567 100644 --- a/libraries/aws_ec2_network_insights_path.rb +++ b/libraries/aws_ec2_network_insights_path.rb @@ -14,10 +14,17 @@ def initialize(opts = {}) opts = { network_insights_path_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:network_insights_path_id]) - raise ArgumentError, "#{@__resource_name__}: network_insights_path_id must be provided" unless opts[:network_insights_path_id] && !opts[:network_insights_path_id].empty? + unless opts[:network_insights_path_id] && + !opts[:network_insights_path_id].empty? + raise ArgumentError, + "#{@__resource_name__}: network_insights_path_id must be provided" + end @display_name = opts[:network_insights_path_id] catch_aws_errors do - resp = @aws.compute_client.describe_network_insights_paths({ network_insights_path_ids: [opts[:network_insights_path_id]] }) + resp = + @aws.compute_client.describe_network_insights_paths( + { network_insights_path_ids: [opts[:network_insights_path_id]] } + ) @res = resp.network_insights_paths[0].to_h create_resource_methods(@res) end diff --git a/libraries/aws_ec2_network_interface.rb b/libraries/aws_ec2_network_interface.rb index 569cc151e..77bba95ab 100644 --- a/libraries/aws_ec2_network_interface.rb +++ b/libraries/aws_ec2_network_interface.rb @@ -14,10 +14,16 @@ def initialize(opts = {}) opts = { network_interface_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:network_interface_id]) - raise ArgumentError, "#{@__resource_name__}: network_interface_id must be provided" unless opts[:network_interface_id] && !opts[:network_interface_id].empty? + unless opts[:network_interface_id] && !opts[:network_interface_id].empty? + raise ArgumentError, + "#{@__resource_name__}: network_interface_id must be provided" + end @display_name = opts[:network_interface_id] catch_aws_errors do - resp = @aws.compute_client.describe_network_interfaces({ network_interface_ids: [opts[:network_interface_id]] }) + resp = + @aws.compute_client.describe_network_interfaces( + { network_interface_ids: [opts[:network_interface_id]] } + ) @res = resp.network_interfaces[0].to_h create_resource_methods(@res) end diff --git a/libraries/aws_ec2_placement_group.rb b/libraries/aws_ec2_placement_group.rb index 1666450de..e65ab17f4 100644 --- a/libraries/aws_ec2_placement_group.rb +++ b/libraries/aws_ec2_placement_group.rb @@ -14,10 +14,16 @@ def initialize(opts = {}) opts = { placement_group_name: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:placement_group_name]) - raise ArgumentError, "#{@__resource_name__}: placement_group_name must be provided" unless opts[:placement_group_name] && !opts[:placement_group_name].empty? + unless opts[:placement_group_name] && !opts[:placement_group_name].empty? + raise ArgumentError, + "#{@__resource_name__}: placement_group_name must be provided" + end @display_name = opts[:placement_group_name] catch_aws_errors do - resp = @aws.compute_client.describe_placement_groups({ group_names: [opts[:placement_group_name]] }) + resp = + @aws.compute_client.describe_placement_groups( + { group_names: [opts[:placement_group_name]] } + ) @resp = resp.placement_groups[0].to_h @placement_group_name = resp.placement_groups[0].group_name create_resource_methods(@resp) diff --git a/libraries/aws_ec2_prefix_list.rb b/libraries/aws_ec2_prefix_list.rb index 4bc024a5c..095d77b37 100644 --- a/libraries/aws_ec2_prefix_list.rb +++ b/libraries/aws_ec2_prefix_list.rb @@ -14,10 +14,16 @@ def initialize(opts = {}) opts = { prefix_list_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:prefix_list_id]) - raise ArgumentError, "#{@__resource_name__}: prefix_list_id must be provided" unless opts[:prefix_list_id] && !opts[:prefix_list_id].empty? + unless opts[:prefix_list_id] && !opts[:prefix_list_id].empty? + raise ArgumentError, + "#{@__resource_name__}: prefix_list_id must be provided" + end @display_name = opts[:prefix_list_id] catch_aws_errors do - resp = @aws.compute_client.describe_managed_prefix_lists({ prefix_list_ids: [opts[:prefix_list_id]] }) + resp = + @aws.compute_client.describe_managed_prefix_lists( + { prefix_list_ids: [opts[:prefix_list_id]] } + ) @res = resp.prefix_lists[0].to_h create_resource_methods(@res) end diff --git a/libraries/aws_ec2_spot_fleet.rb b/libraries/aws_ec2_spot_fleet.rb index 7e38880b4..97ab3ff0c 100644 --- a/libraries/aws_ec2_spot_fleet.rb +++ b/libraries/aws_ec2_spot_fleet.rb @@ -14,10 +14,16 @@ def initialize(opts = {}) opts = { spot_fleet_request_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:spot_fleet_request_id]) - raise ArgumentError, "#{@__resource_name__}: spot_fleet_request_id must be provided" unless opts[:spot_fleet_request_id] && !opts[:spot_fleet_request_id].empty? + unless opts[:spot_fleet_request_id] && !opts[:spot_fleet_request_id].empty? + raise ArgumentError, + "#{@__resource_name__}: spot_fleet_request_id must be provided" + end @display_name = opts[:spot_fleet_request_id] catch_aws_errors do - resp = @aws.compute_client.describe_spot_fleet_requests({ spot_fleet_request_ids: [opts[:spot_fleet_request_id]] }) + resp = + @aws.compute_client.describe_spot_fleet_requests( + { spot_fleet_request_ids: [opts[:spot_fleet_request_id]] } + ) @res = resp.spot_fleet_request_configs[0].to_h create_resource_methods(@res) end diff --git a/libraries/aws_ec2_traffic_mirror_filter.rb b/libraries/aws_ec2_traffic_mirror_filter.rb index d7dcce763..75006f62c 100644 --- a/libraries/aws_ec2_traffic_mirror_filter.rb +++ b/libraries/aws_ec2_traffic_mirror_filter.rb @@ -13,16 +13,25 @@ class AWSEc2TrafficMirrorFilter < AwsResourceBase def initialize(opts = {}) opts = { traffic_mirror_filter_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(traffic_mirror_filter_id)) - if opts[:traffic_mirror_filter_id] && !opts[:traffic_mirror_filter_id].empty? # Use instance_id, if provided - if !opts[:traffic_mirror_filter_id].is_a?(String) || opts[:traffic_mirror_filter_id] !~ /(^tmf-[0-9a-f]{8})|(^tmf-[0-9a-f]{17})$/ - raise ArgumentError, "#{@__resource_name__}: `traffic_mirror_filter_id` must be a string in the format of 'tfm-' followed by 8 or 17 hexadecimal characters." + validate_parameters(required: %i[traffic_mirror_filter_id]) + if opts[:traffic_mirror_filter_id] && + !opts[:traffic_mirror_filter_id].empty? # Use instance_id, if provided + if !opts[:traffic_mirror_filter_id].is_a?(String) || + opts[:traffic_mirror_filter_id] !~ + /(^tmf-[0-9a-f]{8})|(^tmf-[0-9a-f]{17})$/ + raise ArgumentError, + "#{@__resource_name__}: `traffic_mirror_filter_id` must be a string in the format of 'tfm-' followed by 8 or 17 hexadecimal characters." end @display_name = opts[:traffic_mirror_filter_id] - traffic_mirror_filters_arguments = { traffic_mirror_filter_ids: [opts[:traffic_mirror_filter_id]] } + traffic_mirror_filters_arguments = { + traffic_mirror_filter_ids: [opts[:traffic_mirror_filter_id]] + } end catch_aws_errors do - resp = @aws.compute_client.describe_traffic_mirror_filters(traffic_mirror_filters_arguments) + resp = + @aws.compute_client.describe_traffic_mirror_filters( + traffic_mirror_filters_arguments + ) @traffic_mirror_filters = resp.traffic_mirror_filters[0].to_h create_resource_methods(@traffic_mirror_filters) end @@ -38,7 +47,11 @@ def exists? end def resource_id - @traffic_mirror_filters ? @traffic_mirror_filters[:traffic_mirror_filter_id] : @display_name + if @traffic_mirror_filters + @traffic_mirror_filters[:traffic_mirror_filter_id] + else + @display_name + end end def to_s diff --git a/libraries/aws_ec2_transit_gateway_attachment.rb b/libraries/aws_ec2_transit_gateway_attachment.rb index a6fa699fc..00a0dd678 100644 --- a/libraries/aws_ec2_transit_gateway_attachment.rb +++ b/libraries/aws_ec2_transit_gateway_attachment.rb @@ -14,21 +14,36 @@ def initialize(opts = {}) opts = { transit_gateway_attachment_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:transit_gateway_attachment_id]) - raise ArgumentError, "#{@__resource_name__}: transit_gateway_attachment_id must be provided" unless opts[:transit_gateway_attachment_id] && !opts[:transit_gateway_attachment_id].empty? + unless opts[:transit_gateway_attachment_id] && + !opts[:transit_gateway_attachment_id].empty? + raise ArgumentError, + "#{@__resource_name__}: transit_gateway_attachment_id must be provided" + end @display_name = opts[:transit_gateway_attachment_id] catch_aws_errors do - resp = @aws.compute_client.describe_transit_gateway_attachments({ transit_gateway_attachment_ids: [opts[:transit_gateway_attachment_id]] }) + resp = + @aws.compute_client.describe_transit_gateway_attachments( + { + transit_gateway_attachment_ids: [ + opts[:transit_gateway_attachment_id] + ] + } + ) @transit_gateway_attachments = resp.transit_gateway_attachments[0].to_h create_resource_methods(@transit_gateway_attachments) end end def resource_id - @transit_gateway_attachments ? @transit_gateway_attachments[:transit_gateway_attachment_id] : @display_name + if @transit_gateway_attachments + @transit_gateway_attachments[:transit_gateway_attachment_id] + else + @display_name + end end def transit_gateway_attachment_id - return nil unless exists? + return unless exists? @transit_gateway_attachments[:transit_gateway_attachment_id] end diff --git a/libraries/aws_ec2_transit_gateway_route_table.rb b/libraries/aws_ec2_transit_gateway_route_table.rb index e6a734a90..fbb0cdab9 100644 --- a/libraries/aws_ec2_transit_gateway_route_table.rb +++ b/libraries/aws_ec2_transit_gateway_route_table.rb @@ -14,10 +14,21 @@ def initialize(opts = {}) opts = { transit_gateway_route_table_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:transit_gateway_route_table_id]) - raise ArgumentError, "#{@__resource_name__}: transit_gateway_route_table_id must be provided" unless opts[:transit_gateway_route_table_id] && !opts[:transit_gateway_route_table_id].empty? + unless opts[:transit_gateway_route_table_id] && + !opts[:transit_gateway_route_table_id].empty? + raise ArgumentError, + "#{@__resource_name__}: transit_gateway_route_table_id must be provided" + end @display_name = opts[:transit_gateway_route_table_id] catch_aws_errors do - resp = @aws.compute_client.describe_transit_gateway_route_tables({ transit_gateway_route_table_ids: [opts[:transit_gateway_route_table_id]] }) + resp = + @aws.compute_client.describe_transit_gateway_route_tables( + { + transit_gateway_route_table_ids: [ + opts[:transit_gateway_route_table_id] + ] + } + ) @transit_gateway_route_tables = resp.transit_gateway_route_tables[0].to_h create_resource_methods(@transit_gateway_route_tables) end @@ -33,7 +44,11 @@ def exists? end def resource_id - @transit_gateway_route_tables ? @transit_gateway_route_tables[:transit_gateway_route_table_id] : @display_name + if @transit_gateway_route_tables + @transit_gateway_route_tables[:transit_gateway_route_table_id] + else + @display_name + end end def to_s diff --git a/libraries/aws_ec2_transit_gateway_route_table_association.rb b/libraries/aws_ec2_transit_gateway_route_table_association.rb index 60bc9138c..59070d9f3 100644 --- a/libraries/aws_ec2_transit_gateway_route_table_association.rb +++ b/libraries/aws_ec2_transit_gateway_route_table_association.rb @@ -16,10 +16,17 @@ def initialize(opts = {}) opts = { transit_gateway_route_table_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:transit_gateway_route_table_id]) - raise ArgumentError, "#{@__resource_name__}: transit_gateway_route_table_id must be provided" unless opts[:transit_gateway_route_table_id] && !opts[:transit_gateway_route_table_id].empty? + unless opts[:transit_gateway_route_table_id] && + !opts[:transit_gateway_route_table_id].empty? + raise ArgumentError, + "#{@__resource_name__}: transit_gateway_route_table_id must be provided" + end @display_name = opts[:transit_gateway_route_table_id] catch_aws_errors do - resp = aws.compute_client.get_transit_gateway_route_table_associations({ transit_gateway_route_table_id: @display_name }) + resp = + aws.compute_client.get_transit_gateway_route_table_associations( + { transit_gateway_route_table_id: @display_name } + ) @association = resp.associations[0].to_h create_resource_methods(@association) end diff --git a/libraries/aws_ec2_transit_gateway_route_table_propagation.rb b/libraries/aws_ec2_transit_gateway_route_table_propagation.rb index 6b6c5b74d..f430bbb33 100644 --- a/libraries/aws_ec2_transit_gateway_route_table_propagation.rb +++ b/libraries/aws_ec2_transit_gateway_route_table_propagation.rb @@ -15,19 +15,35 @@ class AWSEc2TransitGatewayRouteTablePropagation < AwsResourceBase def initialize(opts = {}) opts = { transit_gateway_route_table_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(transit_gateway_route_table_id transit_gateway_attachment_id)) - raise ArgumentError, "#{@__resource_name__}: transit_gateway_route_table_id must be provided" unless opts[:transit_gateway_route_table_id] && !opts[:transit_gateway_route_table_id].empty? - raise ArgumentError, "#{@__resource_name__}: transit_gateway_attachment_id must be provided" unless opts[:transit_gateway_attachment_id] && !opts[:transit_gateway_attachment_id].empty? + validate_parameters( + required: %i[transit_gateway_route_table_id transit_gateway_attachment_id] + ) + unless opts[:transit_gateway_route_table_id] && + !opts[:transit_gateway_route_table_id].empty? + raise ArgumentError, + "#{@__resource_name__}: transit_gateway_route_table_id must be provided" + end + unless opts[:transit_gateway_attachment_id] && + !opts[:transit_gateway_attachment_id].empty? + raise ArgumentError, + "#{@__resource_name__}: transit_gateway_attachment_id must be provided" + end @display_name = opts[:transit_gateway_attachment_id] filter = [ { name: "transit-gateway-attachment-id", - values: [opts[:transit_gateway_attachment_id]], - }, + values: [opts[:transit_gateway_attachment_id]] + } ] catch_aws_errors do - resp = @aws.compute_client.get_transit_gateway_route_table_propagations({ transit_gateway_route_table_id: opts[:transit_gateway_route_table_id], - filters: filter }) + resp = + @aws.compute_client.get_transit_gateway_route_table_propagations( + { + transit_gateway_route_table_id: + opts[:transit_gateway_route_table_id], + filters: filter + } + ) @resp = resp.transit_gateway_route_table_propagations[0].to_h create_resource_methods(@resp) end diff --git a/libraries/aws_ec2_volume_attachment.rb b/libraries/aws_ec2_volume_attachment.rb index e3e4cbafe..d18dfe245 100644 --- a/libraries/aws_ec2_volume_attachment.rb +++ b/libraries/aws_ec2_volume_attachment.rb @@ -14,10 +14,13 @@ def initialize(opts = {}) opts = { volume_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:volume_id]) - raise ArgumentError, "#{@__resource_name__}: volume_id must be provided" unless opts[:volume_id] && !opts[:volume_id].empty? + unless opts[:volume_id] && !opts[:volume_id].empty? + raise ArgumentError, "#{@__resource_name__}: volume_id must be provided" + end @display_name = opts[:volume_id] catch_aws_errors do - resp = @aws.compute_client.describe_volumes({ volume_ids: [opts[:volume_id]] }) + resp = + @aws.compute_client.describe_volumes({ volume_ids: [opts[:volume_id]] }) @res = resp.volumes[0].attachments[0].to_h create_resource_methods(@res) end diff --git a/libraries/aws_ec2_vpc_peering_connection.rb b/libraries/aws_ec2_vpc_peering_connection.rb index 29ceecc36..38eafc4d7 100644 --- a/libraries/aws_ec2_vpc_peering_connection.rb +++ b/libraries/aws_ec2_vpc_peering_connection.rb @@ -14,10 +14,17 @@ def initialize(opts = {}) opts = { vpc_peering_connection_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:vpc_peering_connection_id]) - raise ArgumentError, "#{@__resource_name__}: vpc_peering_connection_id must be provided" unless opts[:vpc_peering_connection_id] && !opts[:vpc_peering_connection_id].empty? + unless opts[:vpc_peering_connection_id] && + !opts[:vpc_peering_connection_id].empty? + raise ArgumentError, + "#{@__resource_name__}: vpc_peering_connection_id must be provided" + end @display_name = opts[:vpc_peering_connection_id] catch_aws_errors do - resp = @aws.compute_client.describe_vpc_peering_connections({ vpc_peering_connection_ids: [opts[:vpc_peering_connection_id]] }) + resp = + @aws.compute_client.describe_vpc_peering_connections( + { vpc_peering_connection_ids: [opts[:vpc_peering_connection_id]] } + ) @res = resp.vpc_peering_connections[0].to_h create_resource_methods(@res) end diff --git a/libraries/aws_ec2_vpn_gateway_route_propagation.rb b/libraries/aws_ec2_vpn_gateway_route_propagation.rb index 2ddfa3cc7..2a37dbb6d 100644 --- a/libraries/aws_ec2_vpn_gateway_route_propagation.rb +++ b/libraries/aws_ec2_vpn_gateway_route_propagation.rb @@ -18,7 +18,10 @@ def initialize(opts = {}) opts = { route_table_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:route_table_id]) - raise ArgumentError, "#{@__resource_name__}: route_table_id must be provided" unless opts[:route_table_id] && !opts[:route_table_id].empty? + unless opts[:route_table_id] && !opts[:route_table_id].empty? + raise ArgumentError, + "#{@__resource_name__}: route_table_id must be provided" + end @display_name = opts[:route_table_id] @route_arguments = { route_table_ids: [opts[:route_table_id]] } catch_aws_errors do diff --git a/libraries/aws_ecr.rb b/libraries/aws_ecr.rb index 05931e5b3..06ebdffbe 100644 --- a/libraries/aws_ecr.rb +++ b/libraries/aws_ecr.rb @@ -20,7 +20,7 @@ def initialize(opts = {}) catch_aws_errors do resp = @aws.ecr_client.describe_repositories(repository_names: [opts[:repository_name]]) - return nil if resp.repositories.nil? || resp.repositories.empty? + return if resp.repositories.nil? || resp.repositories.empty? repository = resp.repositories.first @repository_name = repository.repository_name @repository_arn = repository.repository_arn @@ -31,7 +31,7 @@ def initialize(opts = {}) end def images - return nil if !exists? + return if !exists? resp = nil catch_aws_errors do resp = @aws.ecr_client.describe_images(repository_name: @repository_name).image_details.first diff --git a/libraries/aws_ecr_image.rb b/libraries/aws_ecr_image.rb index 33aa55dad..d1c619e91 100644 --- a/libraries/aws_ecr_image.rb +++ b/libraries/aws_ecr_image.rb @@ -16,34 +16,50 @@ class AwsEcrImage < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(repository_name), require_any_of: %i(image_tag image_digest), allow: %i(registry_id)) + validate_parameters( + required: %i[repository_name], + require_any_of: %i[image_tag image_digest], + allow: %i[registry_id] + ) @display_name = opts.values.join(" ") # Validate repository_name. - pattern = %r{(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._\-][a-z0-9]+)*} + pattern = + %r{(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._\-][a-z0-9]+)*} matched_str = opts[:repository_name].match(pattern) - unless (opts[:repository_name] == matched_str[0]) && (matched_str.length == 1) && opts[:repository_name].length.between?(2, 256) - raise ArgumentError, "#{@__resource_name__}: `repository_name` is not in a valid format. " \ - "Please check the docs for more info "\ - "https://docs.aws.amazon.com/AmazonECR/latest/APIReference/API_DescribeRepositories.html" \ + unless (opts[:repository_name] == matched_str[0]) && + (matched_str.length == 1) && + opts[:repository_name].length.between?(2, 256) + raise ArgumentError, + "#{@__resource_name__}: `repository_name` is not in a valid format. " \ + "Please check the docs for more info " \ + "https://docs.aws.amazon.com/AmazonECR/latest/APIReference/API_DescribeRepositories.html" end # Validate image identifiers: # https://docs.aws.amazon.com/AmazonECR/latest/APIReference/API_ImageIdentifier.html - raise ArgumentError, "#{@__resource_name__}: `image_tag` must be maximum 300 characters long." if opts[:image_tag] && !opts[:image_tag].length.between?(1, 300) + if opts[:image_tag] && !opts[:image_tag].length.between?(1, 300) + raise ArgumentError, + "#{@__resource_name__}: `image_tag` must be maximum 300 characters long." + end - raise ArgumentError, "#{@__resource_name__}: `image_digest` must be a sha256 digest, e.g. 'sha256:aa..00'" if opts[:image_digest] && !/[a-zA-Z0-9\-_+.]+:[a-fA-F0-9]+/.match?(opts[:image_digest]) + if opts[:image_digest] && + !/[a-zA-Z0-9\-_+.]+:[a-fA-F0-9]+/.match?(opts[:image_digest]) + raise ArgumentError, + "#{@__resource_name__}: `image_digest` must be a sha256 digest, e.g. 'sha256:aa..00'" + end query_params = { repository_name: opts[:repository_name], - image_ids: [ - opts.select { |k, _v| k.to_s.start_with?("image") }, - ], + image_ids: [opts.select { |k, _v| k.to_s.start_with?("image") }] } # Validate registry_id. (Optional. If not provided, AWS account ID will be used by the AWS API.) if opts.key?(:registry_id) - raise ArgumentError, "#{@__resource_name__}: `registry_id` should be a string of 12 digits." unless /^[0-9]{12}$/.match?(opts[:registry_id]) + unless /^[0-9]{12}$/.match?(opts[:registry_id]) + raise ArgumentError, + "#{@__resource_name__}: `registry_id` should be a string of 12 digits." + end query_params[:registry_id] = opts[:registry_id] end @@ -60,7 +76,7 @@ def exists? def vulnerabilities # Create an array of vulnerabilities identified in the image after a scan - @vulns. - return unless exists? + return nil unless exists? # Do not try to create if vulnerability data exists. return @vulns unless @vulns.nil? # Use describe_image_scan_findings method: @@ -68,7 +84,7 @@ def vulnerabilities query_params = { repository_name: @opts[:repository_name], image_id: @opts.select { |k, _v| k.to_s.start_with?("image") }, - max_results: 1000, + max_results: 1000 } @scan_findings = [] loop do @@ -83,9 +99,7 @@ def vulnerabilities end # Convert AWS struct format to hash. @vulns = [] - @scan_findings.each do |vuln| - @vulns << vuln.to_h - end + @scan_findings.each { |vuln| @vulns << vuln.to_h } # Extract :attributes returned in scan_findings: # :attributes=>[{:key=>"package_version", :value=>"1.1.18-r3"}, # {:key=>"package_name", :value=>"musl"}, @@ -98,9 +112,7 @@ def vulnerabilities # :CVSS2_VECTOR=>"AV:N/AC:L/Au:N/C:P/I:P/A:P" # :CVSS2_SCORE=>"7.5" @vulns.each do |vuln| - vuln[:attributes].each do |attr| - vuln[attr[:key].to_sym] = attr[:value] - end + vuln[:attributes].each { |attr| vuln[attr[:key].to_sym] = attr[:value] } # Delete original :attributes item. vuln.delete(:attributes) end diff --git a/libraries/aws_ecr_repository.rb b/libraries/aws_ecr_repository.rb index d1309a73d..b3680ab2c 100644 --- a/libraries/aws_ecr_repository.rb +++ b/libraries/aws_ecr_repository.rb @@ -17,15 +17,19 @@ def initialize(opts = {}) opts = {} unless opts.is_a?(Hash) super(opts) - validate_parameters(required: %i(repository_name), allow: %i(registry_id)) + validate_parameters(required: %i[repository_name], allow: %i[registry_id]) # Validate repository_name. - pattern = %r{(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._\-][a-z0-9]+)*} + pattern = + %r{(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._\-][a-z0-9]+)*} matched_str = opts[:repository_name].match(pattern) - unless (opts[:repository_name] == matched_str[0]) && (matched_str.length == 1) && opts[:repository_name].length.between?(2, 256) - raise ArgumentError, "#{@__resource_name__}: `repository_name` is not in a valid format. " \ - "Please check the docs for more info "\ - "https://docs.aws.amazon.com/AmazonECR/latest/APIReference/API_DescribeRepositories.html" \ + unless (opts[:repository_name] == matched_str[0]) && + (matched_str.length == 1) && + opts[:repository_name].length.between?(2, 256) + raise ArgumentError, + "#{@__resource_name__}: `repository_name` is not in a valid format. " \ + "Please check the docs for more info " \ + "https://docs.aws.amazon.com/AmazonECR/latest/APIReference/API_DescribeRepositories.html" end @display_name = opts[:repository_name] @@ -33,7 +37,10 @@ def initialize(opts = {}) query_params[:repository_names] = [opts[:repository_name]] # Validate registry_id. (Optional. If not provided, AWS account ID will be used by the AWS API.) if opts.key?(:registry_id) - raise ArgumentError, "#{@__resource_name__}: `registry_id` should be a string of 12 digits." unless /^[0-9]{12}$/.match?(opts[:registry_id]) + unless /^[0-9]{12}$/.match?(opts[:registry_id]) + raise ArgumentError, + "#{@__resource_name__}: `registry_id` should be a string of 12 digits." + end query_params[:registry_id] = opts[:registry_id] end @@ -59,7 +66,10 @@ def resource_id def tags return unless exists? catch_aws_errors do - @resp_tags = @aws.ecr_client.list_tags_for_resource(resource_arn: @ecr_repo[:repository_arn]) + @resp_tags = + @aws.ecr_client.list_tags_for_resource( + resource_arn: @ecr_repo[:repository_arn] + ) end map_tags(@resp_tags.tags) end diff --git a/libraries/aws_ecrpublic_repository.rb b/libraries/aws_ecrpublic_repository.rb index 34804a14c..e6aa413b6 100644 --- a/libraries/aws_ecrpublic_repository.rb +++ b/libraries/aws_ecrpublic_repository.rb @@ -17,15 +17,19 @@ def initialize(opts = {}) opts = {} unless opts.is_a?(Hash) super(opts) - validate_parameters(required: %i(repository_name), allow: %i(registry_id)) + validate_parameters(required: %i[repository_name], allow: %i[registry_id]) # Validate repository_name. - pattern = %r{(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._\-][a-z0-9]+)*} + pattern = + %r{(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._\-][a-z0-9]+)*} matched_str = opts[:repository_name].match(pattern) - unless (opts[:repository_name] == matched_str[0]) && (matched_str.length == 1) && opts[:repository_name].length.between?(2, 256) - raise ArgumentError, "#{@__resource_name__}: `repository_name` is not in a valid format. " \ - "Please check the docs for more info "\ - "https://docs.aws.amazon.com/AmazonECR/latest/APIReference/API_DescribeRepositories.html" \ + unless (opts[:repository_name] == matched_str[0]) && + (matched_str.length == 1) && + opts[:repository_name].length.between?(2, 256) + raise ArgumentError, + "#{@__resource_name__}: `repository_name` is not in a valid format. " \ + "Please check the docs for more info " \ + "https://docs.aws.amazon.com/AmazonECR/latest/APIReference/API_DescribeRepositories.html" end @display_name = opts[:repository_name] @@ -33,7 +37,10 @@ def initialize(opts = {}) query_params[:repository_names] = [opts[:repository_name]] # Validate registry_id. (Optional. If not provided, AWS account ID will be used by the AWS API.) if opts.key?(:registry_id) - raise ArgumentError, "#{@__resource_name__}: `registry_id` should be a string of 12 digits." unless /^[0-9]{12}$/.match?(opts[:registry_id]) + unless /^[0-9]{12}$/.match?(opts[:registry_id]) + raise ArgumentError, + "#{@__resource_name__}: `registry_id` should be a string of 12 digits." + end query_params[:registry_id] = opts[:registry_id] end @@ -58,9 +65,12 @@ def to_s end def tags - return unless exists? + return nil unless exists? catch_aws_errors do - @resp_tags = @aws.ecrpublic_client.list_tags_for_resource(resource_arn: @ecr_repo[:repository_arn]) + @resp_tags = + @aws.ecrpublic_client.list_tags_for_resource( + resource_arn: @ecr_repo[:repository_arn] + ) end map_tags(@resp_tags.tags) end diff --git a/libraries/aws_ecs_service.rb b/libraries/aws_ecs_service.rb index 41f885882..e98b24287 100644 --- a/libraries/aws_ecs_service.rb +++ b/libraries/aws_ecs_service.rb @@ -12,19 +12,26 @@ class AWSECSService < AwsResourceBase def initialize(opts = {}) opts = { services: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(service), require_any_of: %i(cluster)) - raise ArgumentError, "#{@__resource_name__}: services must be provided" unless opts[:service] && !opts[:service].empty? - raise ArgumentError, "#{@__resource_name__}: cluster must be provided" unless opts[:cluster] && !opts[:cluster].empty? + validate_parameters(required: %i[service], require_any_of: %i[cluster]) + unless opts[:service] && !opts[:service].empty? + raise ArgumentError, "#{@__resource_name__}: services must be provided" + end + unless opts[:cluster] && !opts[:cluster].empty? + raise ArgumentError, "#{@__resource_name__}: cluster must be provided" + end @display_name = opts[:service] catch_aws_errors do - resp = @aws.ecs_client.describe_services({ cluster: opts[:cluster], services: [opts[:service]] }) + resp = + @aws.ecs_client.describe_services( + { cluster: opts[:cluster], services: [opts[:service]] } + ) @services = resp.services[0].to_h create_resource_methods(@services) end end def services - return nil unless exists? + return unless exists? @services[:services] end diff --git a/libraries/aws_ecs_task_definition.rb b/libraries/aws_ecs_task_definition.rb index 279f08a43..073cdaf3d 100644 --- a/libraries/aws_ecs_task_definition.rb +++ b/libraries/aws_ecs_task_definition.rb @@ -14,17 +14,23 @@ def initialize(opts = {}) opts = { task_definition: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:task_definition]) - raise ArgumentError, "#{@__resource_name__}: task_definition must be provided" unless opts[:task_definition] && !opts[:task_definition].empty? + unless opts[:task_definition] && !opts[:task_definition].empty? + raise ArgumentError, + "#{@__resource_name__}: task_definition must be provided" + end @display_name = opts[:task_definition] catch_aws_errors do - resp = @aws.ecs_client.describe_task_definition({ task_definition: opts[:task_definition] }) + resp = + @aws.ecs_client.describe_task_definition( + { task_definition: opts[:task_definition] } + ) @task_definition = resp.task_definition.to_h create_resource_methods(@task_definition) end end def task_definition - return nil unless exists? + return unless exists? @task_definition[:task_definition] end @@ -45,7 +51,9 @@ def container_definitions_repository_credentials end def container_definitions_repository_credentials_credentials_parameters - container_definitions.map(&:repository_credentials).map(&:credentials_parameter) + container_definitions.map(&:repository_credentials).map( + &:credentials_parameter + ) end def container_definitions_cpus @@ -161,15 +169,24 @@ def container_definitions_linux_parameters_capabilities_devices end def container_definitions_linux_parameters_capabilities_devices_host_paths - container_definitions.map(&:linux_parameters).map(&:devices).map(&:host_path) + container_definitions + .map(&:linux_parameters) + .map(&:devices) + .map(&:host_path) end def container_definitions_linux_parameters_capabilities_devices_container_paths - container_definitions.map(&:linux_parameters).map(&:devices).map(&:container_path) + container_definitions + .map(&:linux_parameters) + .map(&:devices) + .map(&:container_path) end def container_definitions_linux_parameters_capabilities_devices_permissions - container_definitions.map(&:linux_parameters).map(&:devices).map(&:permissions) + container_definitions + .map(&:linux_parameters) + .map(&:devices) + .map(&:permissions) end def container_definitions_linux_parameters_init_process_enabled @@ -185,7 +202,10 @@ def container_definitions_linux_parameters_tmpfs end def container_definitions_linux_parameters_tmpfs_container_paths - container_definitions.map(&:linux_parameters).map(&:tmpfs).map(&:container_path) + container_definitions + .map(&:linux_parameters) + .map(&:tmpfs) + .map(&:container_path) end def container_definitions_linux_parameters_tmpfs_sizes @@ -193,7 +213,10 @@ def container_definitions_linux_parameters_tmpfs_sizes end def container_definitions_linux_parameters_tmpfs_mount_options - container_definitions.map(&:linux_parameters).map(&:tmpfs).map(&:mount_options) + container_definitions + .map(&:linux_parameters) + .map(&:tmpfs) + .map(&:mount_options) end def container_definitions_linux_parameters_max_swaps @@ -329,11 +352,17 @@ def container_definitions_log_configurations_secret_options end def container_definitions_log_configurations_secret_options_names - container_definitions.map(&:log_configuration).map(&:secret_options).map(&:name) + container_definitions + .map(&:log_configuration) + .map(&:secret_options) + .map(&:name) end def container_definitions_log_configurations_secret_value_froms - container_definitions.map(&:log_configuration).map(&:secret_options).map(&:value_from) + container_definitions + .map(&:log_configuration) + .map(&:secret_options) + .map(&:value_from) end def container_definitions_health_checks @@ -457,11 +486,17 @@ def volumes_efs_volume_configuration_authorization_configs end def volumes_efs_volume_configuration_authorization_config_access_point_ids - volumes.map(&:efs_volume_configurations).map(&:authorization_config).map(&:access_point_id) + volumes + .map(&:efs_volume_configurations) + .map(&:authorization_config) + .map(&:access_point_id) end def volumes_efs_volume_configuration_authorization_config_iams - volumes.map(&:efs_volume_configurations).map(&:authorization_config).map(&:iam) + volumes + .map(&:efs_volume_configurations) + .map(&:authorization_config) + .map(&:iam) end def volumes_fsx_windows_file_server_volume_configurations @@ -469,23 +504,35 @@ def volumes_fsx_windows_file_server_volume_configurations end def volumes_fsx_windows_file_server_volume_configurations_file_system_ids - volumes.map(&:fsx_windows_file_server_volume_configuration).map(&:file_system_id) + volumes.map(&:fsx_windows_file_server_volume_configuration).map( + &:file_system_id + ) end def volumes_fsx_windows_file_server_volume_configurations_root_directories - volumes.map(&:fsx_windows_file_server_volume_configuration).map(&:root_directory) + volumes.map(&:fsx_windows_file_server_volume_configuration).map( + &:root_directory + ) end def volumes_fsx_windows_file_server_volume_configurations_authorization_configs - volumes.map(&:fsx_windows_file_server_volume_configuration).map(&:authorization_config) + volumes.map(&:fsx_windows_file_server_volume_configuration).map( + &:authorization_config + ) end def volumes_fsx_windows_file_server_volume_configurations_authorization_configs_credentials_parameters - volumes.map(&:fsx_windows_file_server_volume_configuration).map(&:authorization_config).map(&:credentials_parameter) + volumes + .map(&:fsx_windows_file_server_volume_configuration) + .map(&:authorization_config) + .map(&:credentials_parameter) end def volumes_fsx_windows_file_server_volume_configurations_authorization_configs_domains - volumes.map(&:fsx_windows_file_server_volume_configuration).map(&:authorization_config).map(&:domain) + volumes + .map(&:fsx_windows_file_server_volume_configuration) + .map(&:authorization_config) + .map(&:domain) end def requires_attributes_names diff --git a/libraries/aws_efs_mount_target.rb b/libraries/aws_efs_mount_target.rb index 4cfe2d1bf..2731097e9 100644 --- a/libraries/aws_efs_mount_target.rb +++ b/libraries/aws_efs_mount_target.rb @@ -13,10 +13,16 @@ def initialize(opts = {}) opts = { mount_target_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:mount_target_id]) - raise ArgumentError, "#{@__resource_name__}: mount_target_id must be provided" unless opts[:mount_target_id] && !opts[:mount_target_id].empty? + unless opts[:mount_target_id] && !opts[:mount_target_id].empty? + raise ArgumentError, + "#{@__resource_name__}: mount_target_id must be provided" + end @display_name = opts[:mount_target_id] catch_aws_errors do - resp = @aws.efs_client.describe_mount_targets({ mount_target_id: opts[:mount_target_id] }) + resp = + @aws.efs_client.describe_mount_targets( + { mount_target_id: opts[:mount_target_id] } + ) @mount_targets = resp.mount_targets[0].to_h create_resource_methods(@mount_targets) end diff --git a/libraries/aws_elasticloadbalancingv2_listener.rb b/libraries/aws_elasticloadbalancingv2_listener.rb index 8dc6df01c..d7bba469f 100644 --- a/libraries/aws_elasticloadbalancingv2_listener.rb +++ b/libraries/aws_elasticloadbalancingv2_listener.rb @@ -13,10 +13,16 @@ def initialize(opts = {}) opts = { listener_arn: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:listener_arn]) - raise ArgumentError, "#{@__resource_name__}: listener_arn must be provided" unless opts[:listener_arn] && !opts[:listener_arn].empty? + unless opts[:listener_arn] && !opts[:listener_arn].empty? + raise ArgumentError, + "#{@__resource_name__}: listener_arn must be provided" + end @display_name = opts[:listener_arn] catch_aws_errors do - resp = @aws.elb_client_v2.describe_listeners({ listener_arns: [opts[:listener_arn]] }) + resp = + @aws.elb_client_v2.describe_listeners( + { listener_arns: [opts[:listener_arn]] } + ) @listeners = resp.listeners[0].to_h create_resource_methods(@listeners) end diff --git a/libraries/aws_elasticloadbalancingv2_listener_certificate.rb b/libraries/aws_elasticloadbalancingv2_listener_certificate.rb index 9e569105b..5fd0fca9d 100644 --- a/libraries/aws_elasticloadbalancingv2_listener_certificate.rb +++ b/libraries/aws_elasticloadbalancingv2_listener_certificate.rb @@ -13,10 +13,16 @@ def initialize(opts = {}) opts = { listener_arn: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:listener_arn]) - raise ArgumentError, "#{@__resource_name__}: listener_arn must be provided" unless opts[:listener_arn] && !opts[:listener_arn].empty? + unless opts[:listener_arn] && !opts[:listener_arn].empty? + raise ArgumentError, + "#{@__resource_name__}: listener_arn must be provided" + end @display_name = opts[:listener_arn] catch_aws_errors do - resp = @aws.elb_client_v2.describe_listener_certificates({ listener_arn: opts[:listener_arn] }) + resp = + @aws.elb_client_v2.describe_listener_certificates( + { listener_arn: opts[:listener_arn] } + ) @listeners = resp.certificates[0].to_h create_resource_methods(@listeners) end diff --git a/libraries/aws_elasticloadbalancingv2_listener_rule.rb b/libraries/aws_elasticloadbalancingv2_listener_rule.rb index c4bae49a9..9e144428c 100644 --- a/libraries/aws_elasticloadbalancingv2_listener_rule.rb +++ b/libraries/aws_elasticloadbalancingv2_listener_rule.rb @@ -13,10 +13,13 @@ def initialize(opts = {}) opts = { rule_arns: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:rule_arns]) - raise ArgumentError, "#{@__resource_name__}: rule_arns must be provided" unless opts[:rule_arns] && !opts[:rule_arns].empty? + unless opts[:rule_arns] && !opts[:rule_arns].empty? + raise ArgumentError, "#{@__resource_name__}: rule_arns must be provided" + end @display_name = opts[:rule_arns] catch_aws_errors do - resp = @aws.elb_client_v2.describe_rules({ rule_arns: [opts[:rule_arns]] }) + resp = + @aws.elb_client_v2.describe_rules({ rule_arns: [opts[:rule_arns]] }) @listeners = resp.rules[0].to_h create_resource_methods(@listeners) end diff --git a/libraries/aws_elasticloadbalancingv2_target_group.rb b/libraries/aws_elasticloadbalancingv2_target_group.rb index 1a7d1780d..df0055855 100644 --- a/libraries/aws_elasticloadbalancingv2_target_group.rb +++ b/libraries/aws_elasticloadbalancingv2_target_group.rb @@ -13,10 +13,16 @@ def initialize(opts = {}) opts = { target_group_arn: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:target_group_arn]) - raise ArgumentError, "#{@__resource_name__}: target_group_arns must be provided" unless opts[:target_group_arn] && !opts[:target_group_arn].empty? + unless opts[:target_group_arn] && !opts[:target_group_arn].empty? + raise ArgumentError, + "#{@__resource_name__}: target_group_arns must be provided" + end @display_name = opts[:target_group_arn] catch_aws_errors do - resp = @aws.elb_client_v2.describe_target_groups({ target_group_arns: [opts[:target_group_arn]] }) + resp = + @aws.elb_client_v2.describe_target_groups( + { target_group_arns: [opts[:target_group_arn]] } + ) @target_groups = resp.target_groups[0].to_h create_resource_methods(@target_groups) end diff --git a/libraries/aws_elasticsearchservice_domain.rb b/libraries/aws_elasticsearchservice_domain.rb index ff3fcfded..fe70c7ca2 100644 --- a/libraries/aws_elasticsearchservice_domain.rb +++ b/libraries/aws_elasticsearchservice_domain.rb @@ -14,10 +14,15 @@ def initialize(opts = {}) opts = { domain_name: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:domain_name]) - raise ArgumentError, "#{@__resource_name__}: domain_name must be provided" unless opts[:domain_name] && !opts[:domain_name].empty? + unless opts[:domain_name] && !opts[:domain_name].empty? + raise ArgumentError, "#{@__resource_name__}: domain_name must be provided" + end @display_name = opts[:domain_name] catch_aws_errors do - resp = @aws.elasticsearch_service_client.describe_elasticsearch_domain({ domain_name: opts[:domain_name] }) + resp = + @aws.elasticsearch_service_client.describe_elasticsearch_domain( + { domain_name: opts[:domain_name] } + ) @domain_status = resp.domain_status.to_h create_resource_methods(@domain_status) end @@ -29,7 +34,7 @@ def domain_name end def resource_id - @domain_status? @domain_status[:domain_id]: "" + @domain_status ? @domain_status[:domain_id] : "" end def exists? diff --git a/libraries/aws_eventbridge_rule.rb b/libraries/aws_eventbridge_rule.rb index 693147e64..5487604a3 100644 --- a/libraries/aws_eventbridge_rule.rb +++ b/libraries/aws_eventbridge_rule.rb @@ -14,7 +14,9 @@ def initialize(opts = {}) opts = { name: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:name]) - raise ArgumentError, "#{@__resource_name__}: name must be provided" unless opts[:name] && !opts[:name].empty? + unless opts[:name] && !opts[:name].empty? + raise ArgumentError, "#{@__resource_name__}: name must be provided" + end @display_name = opts[:name] catch_aws_errors do resp = @aws.eventbridge_client.describe_rule({ name: opts[:name] }) diff --git a/libraries/aws_glue_crawler.rb b/libraries/aws_glue_crawler.rb index 2fac8adee..1e4641f53 100644 --- a/libraries/aws_glue_crawler.rb +++ b/libraries/aws_glue_crawler.rb @@ -14,7 +14,9 @@ def initialize(opts = {}) opts = { name: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:name]) - raise ArgumentError, "#{@__resource_name__}: name must be provided" unless opts[:name] && !opts[:name].empty? + unless opts[:name] && !opts[:name].empty? + raise ArgumentError, "#{@__resource_name__}: name must be provided" + end @display_name = opts[:name] catch_aws_errors do resp = @aws.glue_client.get_crawler({ name: opts[:name] }) @@ -24,7 +26,7 @@ def initialize(opts = {}) end def name - return nil unless exists? + return unless exists? @res[:name] end diff --git a/libraries/aws_glue_database.rb b/libraries/aws_glue_database.rb index 6f9077bd4..0e8bb2ed4 100644 --- a/libraries/aws_glue_database.rb +++ b/libraries/aws_glue_database.rb @@ -14,7 +14,9 @@ def initialize(opts = {}) opts = { name: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:name]) - raise ArgumentError, "#{@__resource_name__}: name must be provided" unless opts[:name] && !opts[:name].empty? + unless opts[:name] && !opts[:name].empty? + raise ArgumentError, "#{@__resource_name__}: name must be provided" + end @display_name = opts[:name] catch_aws_errors do resp = @aws.glue_client.get_database({ name: opts[:name] }) diff --git a/libraries/aws_iam_access_key.rb b/libraries/aws_iam_access_key.rb index f71397671..4b22e4ec5 100644 --- a/libraries/aws_iam_access_key.rb +++ b/libraries/aws_iam_access_key.rb @@ -29,12 +29,14 @@ def initialize(opts = {}) opts[:access_key_id] = opts.delete(:id) end - if opts[:access_key_id] && !/^AKIA[0-9A-Z]{16}$/.match?(opts[:access_key_id]) - raise ArgumentError, "#{@__resource_name__}: Incorrect format for provided Access Key ID" + if opts[:access_key_id] && + !/^AKIA[0-9A-Z]{16}$/.match?(opts[:access_key_id]) + raise ArgumentError, + "#{@__resource_name__}: Incorrect format for provided Access Key ID" end super(opts) - validate_parameters(require_any_of: %i(access_key_id username)) + validate_parameters(require_any_of: %i[access_key_id username]) @username = opts[:username] @access_key_id = opts[:access_key_id] @@ -47,13 +49,10 @@ def initialize(opts = {}) # Get all keys for the provided user. If no user provided, use current principal. # If an `access_key_id` has been provided, get only that key. - access_keys = resp.access_key_metadata.select do |key| - if access_key_id - key.access_key_id == access_key_id - else - true + access_keys = + resp.access_key_metadata.select do |key| + access_key_id ? key.access_key_id == access_key_id : true end - end return if access_keys.empty? if access_keys.count > 1 @@ -62,9 +61,9 @@ def initialize(opts = {}) end @access_key_id = access_keys[0].access_key_id - @username = access_keys[0].user_name - @create_date = access_keys[0].create_date - @status = access_keys[0].status + @username = access_keys[0].user_name + @create_date = access_keys[0].create_date + @status = access_keys[0].status end end @@ -87,11 +86,14 @@ def to_s def last_used_date return nil unless exists? - return @last_used_date if defined? @last_used_date + return @last_used_date if defined?(@last_used_date) catch_aws_errors do - @last_used_date = @aws.iam_client.get_access_key_last_used({ access_key_id: @access_key_id }) - .access_key_last_used - .last_used_date + @last_used_date = + @aws + .iam_client + .get_access_key_last_used({ access_key_id: @access_key_id }) + .access_key_last_used + .last_used_date end end end diff --git a/libraries/aws_iam_access_keys.rb b/libraries/aws_iam_access_keys.rb index ba4c4b441..af5bc4e1b 100644 --- a/libraries/aws_iam_access_keys.rb +++ b/libraries/aws_iam_access_keys.rb @@ -83,7 +83,7 @@ def get_keys def fetch_keys(username) access_keys = catch_aws_errors do - iam_client.list_access_keys(user_name: username) + iam_client.list_access_keys({ user_name: username }) rescue Aws::IAM::Errors::NoSuchEntity # Swallow - a miss on search results should return an empty table end @@ -96,7 +96,7 @@ def fetch_keys(username) access_key_hash[:inactive] = access_key_hash[:status] != "Active" access_key_hash[:created_hours_ago] = ((Time.now - access_key_hash[:create_date]) / (60*60)).to_i access_key_hash[:created_days_ago] = (access_key_hash[:created_hours_ago] / 24).to_i - access_key_hash[:user_created_date] = access_key_hash[:create_date] + access_key_hash[:user_created_date] = @_users.find { |user| user.user_name == access_key_hash[:username] }.create_date access_key_hash[:created_with_user] = (access_key_hash[:create_date] - access_key_hash[:user_created_date]).abs < 1.0/24.0 access_key_hash end @@ -104,8 +104,8 @@ def fetch_keys(username) end def last_used(row, _condition, _table) - @last_used ||= catch_aws_errors do - iam_client.get_access_key_last_used(access_key_id: row[:access_key_id]) + catch_aws_errors do + iam_client.get_access_key_last_used({ access_key_id: row[:access_key_id] }) .access_key_last_used end end @@ -114,22 +114,21 @@ def lazy_load_last_used_date(row, condition, table) row[:last_used_date] ||= last_used(row, condition, table).last_used_date end - def lazy_load_ever_used(row, condition, table) - row[:ever_used] = !lazy_load_never_used_time(row, condition, table) + def lazy_load_never_used_time(row, condition, table) + row[:never_used] ||= lazy_load_last_used_date(row, condition, table).nil? end - def lazy_load_never_used_time(row, condition, table) - row[:never_used] = lazy_load_last_used_date(row, condition, table).nil? + def lazy_load_ever_used(row, condition, table) + row[:ever_used] ||= !lazy_load_never_used_time(row, condition, table) end def lazy_load_last_used_hours_ago(row, condition, table) - return if lazy_load_never_used_time(row, condition, table) - + return row[:last_used_hours_ago] = nil if lazy_load_never_used_time(row, condition, table) row[:last_used_hours_ago] = ((Time.now - row[:last_used_date]) / (60*60)).to_i end def lazy_load_last_used_days_ago(row, condition, table) - return if lazy_load_never_used_time(row, condition, table) + return row[:last_used_days_ago] = nil if lazy_load_never_used_time(row, condition, table) if row[:last_used_hours_ago].nil? lazy_load_last_used_hours_ago(row, condition, table) end diff --git a/libraries/aws_iam_credential_report.rb b/libraries/aws_iam_credential_report.rb new file mode 100644 index 000000000..29fc4d044 --- /dev/null +++ b/libraries/aws_iam_credential_report.rb @@ -0,0 +1,79 @@ +require "csv" +require "aws_backend" + +class AwsIamCredentialReport < AwsCollectionResourceBase + name "aws_iam_credential_report" + desc "Lists all users in the AWS account and the status of their credentials." + + example " + describe aws_iam_credential_report.where(mfa_active: false) do + it { should_not exist } + end + " + + attr_reader :table + + FilterTable.create + .register_column(:user, field: :user) + .register_column(:arn, field: :arn) + .register_column(:user_creation_time, field: :user_creation_time) + .register_column(:password_enabled, field: :password_enabled) + .register_column(:password_last_used, field: :password_last_used) + .register_column(:password_last_changed, field: :password_last_changed) + .register_column(:password_next_rotation, field: :password_next_rotation) + .register_column(:mfa_active, field: :mfa_active) + .register_column(:access_key_1_active, field: :access_key_1_active) + .register_column(:access_key_1_last_rotated, field: :access_key_1_last_rotated) + .register_column(:access_key_1_last_used_date, field: :access_key_1_last_used_date) + .register_column(:access_key_1_last_used_region, field: :access_key_1_last_used_region) + .register_column(:access_key_1_last_used_service, field: :access_key_1_last_used_service) + .register_column(:access_key_2_active, field: :access_key_2_active) + .register_column(:access_key_2_last_rotated, field: :access_key_2_last_rotated) + .register_column(:access_key_2_last_used_date, field: :access_key_2_last_used_date) + .register_column(:access_key_2_last_used_region, field: :access_key_2_last_used_region) + .register_column(:access_key_2_last_used_service, field: :access_key_2_last_used_service) + .register_column(:cert_1_active, field: :cert_1_active) + .register_column(:cert_1_last_rotated, field: :cert_1_last_rotated) + .register_column(:cert_2_active, field: :cert_2_active) + .register_column(:cert_2_last_rotated, field: :cert_2_last_rotated) + .install_filter_methods_on_resource(self, :table) + + def initialize(opts = {}) + super(opts) + validate_parameters + @table = fetch_data + end + + def to_s + "IAM Credential Report" + end + + private + + def fetch_data + catch_aws_errors do + @aws.iam_client.generate_credential_report + begin + attempts ||= 0 + response = @aws.iam_client.get_credential_report + rescue Aws::IAM::Errors::ReportInProgress => e + if (attempts += 1) <= 5 + Inspec::Log.warn "AWS IAM Credential Report still being generated - attempt #{attempts}/5." + sleep 5 + retry + else + Inspec::Log.warn "AWS IAM Credential Report was not generated quickly enough." + raise e + end + end + report = CSV.parse(response.content, headers: true, header_converters: :symbol, converters: [:date_time, lambda { |field| + if field == "true" + true + else + field == "false" ? false : field + end + }]) + report.map(&:to_h) + end + end +end diff --git a/libraries/aws_iam_instance_profile.rb b/libraries/aws_iam_instance_profile.rb index 0dff67b6a..845d62524 100644 --- a/libraries/aws_iam_instance_profile.rb +++ b/libraries/aws_iam_instance_profile.rb @@ -14,10 +14,16 @@ def initialize(opts = {}) opts = { instance_profile_name: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:instance_profile_name]) - raise ArgumentError, "#{@__resource_name__}: instance_profile_name must be provided" unless opts[:instance_profile_name] && !opts[:instance_profile_name].empty? + unless opts[:instance_profile_name] && !opts[:instance_profile_name].empty? + raise ArgumentError, + "#{@__resource_name__}: instance_profile_name must be provided" + end @display_name = opts[:instance_profile_name] catch_aws_errors do - resp = @aws.iam_client.get_instance_profile({ instance_profile_name: opts[:instance_profile_name] }) + resp = + @aws.iam_client.get_instance_profile( + { instance_profile_name: opts[:instance_profile_name] } + ) @res = resp.instance_profile.to_h @arn = @res[:arn] create_resource_methods(@res) diff --git a/libraries/aws_iam_password_policy.rb b/libraries/aws_iam_password_policy.rb index 1ede00f6c..987eef54b 100644 --- a/libraries/aws_iam_password_policy.rb +++ b/libraries/aws_iam_password_policy.rb @@ -24,18 +24,18 @@ def initialize(opts = {}) end def minimum_password_length - return nil if !exists? + return if !exists? @policy.minimum_password_length end def max_password_age_in_days - return nil if !exists? + return if !exists? raise "this policy does not expire passwords" unless expire_passwords? @policy.max_password_age end def number_of_passwords_to_remember - return nil if !exists? + return if !exists? raise "this policy does not prevent password reuse" \ unless prevent_password_reuse? @policy.password_reuse_prevention diff --git a/libraries/aws_iam_service_linked_role_deletion_status.rb b/libraries/aws_iam_service_linked_role_deletion_status.rb index 9eec4aa21..6656f01d8 100644 --- a/libraries/aws_iam_service_linked_role_deletion_status.rb +++ b/libraries/aws_iam_service_linked_role_deletion_status.rb @@ -14,10 +14,16 @@ def initialize(opts = {}) opts = { deletion_task_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:deletion_task_id]) - raise ArgumentError, "#{@__resource_name__}: deletion_task_id must be provided" unless opts[:deletion_task_id] && !opts[:deletion_task_id].empty? + unless opts[:deletion_task_id] && !opts[:deletion_task_id].empty? + raise ArgumentError, + "#{@__resource_name__}: deletion_task_id must be provided" + end @display_name = opts[:deletion_task_id] catch_aws_errors do - resp = @aws.iam_client.get_service_linked_role_deletion_status({ deletion_task_id: opts[:deletion_task_id] }) + resp = + @aws.iam_client.get_service_linked_role_deletion_status( + { deletion_task_id: opts[:deletion_task_id] } + ) @res = resp.to_h create_resource_methods(@res) end @@ -29,7 +35,7 @@ def status end def resource_id - @res? @display_name: "" + @res ? @display_name : "" end def exists? diff --git a/libraries/aws_iam_ssh_public_key.rb b/libraries/aws_iam_ssh_public_key.rb index 462e1d96d..1ebece862 100644 --- a/libraries/aws_iam_ssh_public_key.rb +++ b/libraries/aws_iam_ssh_public_key.rb @@ -16,13 +16,27 @@ class AWSIAMSSHPublicKey < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(user_name ssh_public_key_id encoding)) - raise ArgumentError, "#{@__resource_name__}: user_name must be provided" unless opts[:user_name] && !opts[:user_name].empty? - raise ArgumentError, "#{@__resource_name__}: ssh_public_key_id must be provided" unless opts[:ssh_public_key_id] && !opts[:ssh_public_key_id].empty? - raise ArgumentError, "#{@__resource_name__}: encoding must be provided" unless opts[:encoding] && !opts[:encoding].empty? + validate_parameters(required: %i[user_name ssh_public_key_id encoding]) + unless opts[:user_name] && !opts[:user_name].empty? + raise ArgumentError, "#{@__resource_name__}: user_name must be provided" + end + unless opts[:ssh_public_key_id] && !opts[:ssh_public_key_id].empty? + raise ArgumentError, + "#{@__resource_name__}: ssh_public_key_id must be provided" + end + unless opts[:encoding] && !opts[:encoding].empty? + raise ArgumentError, "#{@__resource_name__}: encoding must be provided" + end @display_name = opts[:ssh_public_key_id] catch_aws_errors do - resp = @aws.iam_client.get_ssh_public_key({ user_name: opts[:user_name], ssh_public_key_id: opts[:ssh_public_key_id], encoding: opts[:encoding] }) + resp = + @aws.iam_client.get_ssh_public_key( + { + user_name: opts[:user_name], + ssh_public_key_id: opts[:ssh_public_key_id], + encoding: opts[:encoding] + } + ) @res = resp.ssh_public_key.to_h @user_name = @res[:user_name] @ssh_public_key_id = @res[:ssh_public_key_id] diff --git a/libraries/aws_internet_gateway.rb b/libraries/aws_internet_gateway.rb index 4c3305306..6a605eedb 100644 --- a/libraries/aws_internet_gateway.rb +++ b/libraries/aws_internet_gateway.rb @@ -16,27 +16,32 @@ class AwsInternetGateway < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(require_any_of: %i(id name)) + validate_parameters(require_any_of: %i[id name]) # Either id or name should be provided. if opts.key?(:id) && !opts.key?(:name) id = opts[:id] - format_error = "#{@__resource_name__}: `id` must be a string in the format of "\ - "'igw-' followed by 8 or 17 hexadecimal characters." + format_error = + "#{@__resource_name__}: `id` must be a string in the format of " \ + "'igw-' followed by 8 or 17 hexadecimal characters." pattern = /^igw-[0-9a-f]{8,17}$/ - raise ArgumentError, format_error unless id.match?(pattern) || id.length.between?(12, 21) + unless id.match?(pattern) || id.length.between?(12, 21) + raise ArgumentError, format_error + end query_params = { internet_gateway_ids: [id] } elsif opts.key?(:name) && !opts.key?(:id) name = opts[:name] - tag_error = "#{@__resource_name__}: `name` should be maximum 255 characters long and contain "\ - "letters, numbers, spaces and the following characters only: + - = . _ : / @" - raise ArgumentError, tag_error unless name.match?(%r{^[\w+\- =._:/@]{1,256}$}) && name.length.between?(1, 255) - query_params = { filters: [ - name: "tag:Name", - values: [name], - ] } + tag_error = + "#{@__resource_name__}: `name` should be maximum 255 characters long and contain " \ + "letters, numbers, spaces and the following characters only: + - = . _ : / @" + unless name.match?(%r{^[\w+\- =._:/@]{1,256}$}) && + name.length.between?(1, 255) + raise ArgumentError, tag_error + end + query_params = { filters: [name: "tag:Name", values: [name]] } else - raise ArgumentError, "#{@__resource_name__}: either `id` or `name` must be provided." + raise ArgumentError, + "#{@__resource_name__}: either `id` or `name` must be provided." end @display_name = opts.values.join(" ") @@ -52,9 +57,11 @@ def initialize(opts = {}) end # Fail resource, redirect users to plural resource if there are multiple resources with the same name tag. if gateways.length > 1 - fail_resource("#{@__resource_name__}: Multiple internet gateways were returned for the provided parameter:"\ - " `#{@display_name}`. If you wish to test multiple internet gateways, "\ - "please use the aws_internet_gateways resource.") + fail_resource( + "#{@__resource_name__}: Multiple internet gateways were returned for the provided parameter:" \ + " `#{@display_name}`. If you wish to test multiple internet gateways, " \ + "please use the aws_internet_gateways resource." + ) @failed_resource = true return end diff --git a/libraries/aws_lambda_alias.rb b/libraries/aws_lambda_alias.rb index 9f7844d93..be2a5aac2 100644 --- a/libraries/aws_lambda_alias.rb +++ b/libraries/aws_lambda_alias.rb @@ -12,12 +12,24 @@ class AWSLambdaAlias < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(function_name function_alias_name)) - raise ArgumentError, "#{@__resource_name__}: function_name must be provided" unless opts[:function_name] && !opts[:function_name].empty? - raise ArgumentError, "#{@__resource_name__}: function_alias_name must be provided" unless opts[:function_alias_name] && !opts[:function_alias_name].empty? + validate_parameters(required: %i[function_name function_alias_name]) + unless opts[:function_name] && !opts[:function_name].empty? + raise ArgumentError, + "#{@__resource_name__}: function_name must be provided" + end + unless opts[:function_alias_name] && !opts[:function_alias_name].empty? + raise ArgumentError, + "#{@__resource_name__}: function_alias_name must be provided" + end @display_name = opts[:function_alias_name] catch_aws_errors do - resp = @aws.lambda_client.get_alias({ function_name: opts[:function_name], name: opts[:function_alias_name] }) + resp = + @aws.lambda_client.get_alias( + { + function_name: opts[:function_name], + name: opts[:function_alias_name] + } + ) @res = resp.to_h create_resource_methods(@res) end diff --git a/libraries/aws_lambda_code_signing_config.rb b/libraries/aws_lambda_code_signing_config.rb index 0e8f62ecb..dd651cc0e 100644 --- a/libraries/aws_lambda_code_signing_config.rb +++ b/libraries/aws_lambda_code_signing_config.rb @@ -12,18 +12,25 @@ class AWSLambdaCodeSigningConfig < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(code_signing_config_arn)) - raise ArgumentError, "#{@__resource_name__}: code_signing_config_arn must be provided" unless opts[:code_signing_config_arn] && !opts[:code_signing_config_arn].empty? + validate_parameters(required: %i[code_signing_config_arn]) + unless opts[:code_signing_config_arn] && + !opts[:code_signing_config_arn].empty? + raise ArgumentError, + "#{@__resource_name__}: code_signing_config_arn must be provided" + end @display_name = opts[:code_signing_config_arn] catch_aws_errors do - resp = @aws.lambda_client.get_code_signing_config({ code_signing_config_arn: opts[:code_signing_config_arn] }) + resp = + @aws.lambda_client.get_code_signing_config( + { code_signing_config_arn: opts[:code_signing_config_arn] } + ) @res = resp.code_signing_config.to_h create_resource_methods(@res) end end def code_signing_config_arn - return nil unless exists? + return unless exists? @res[:code_signing_config_arn] end diff --git a/libraries/aws_lambda_event_invoke_config.rb b/libraries/aws_lambda_event_invoke_config.rb index a90dba54e..0b6f810fc 100644 --- a/libraries/aws_lambda_event_invoke_config.rb +++ b/libraries/aws_lambda_event_invoke_config.rb @@ -13,11 +13,17 @@ class AWSLambdaEventInvokeConfig < AwsResourceBase def initialize(opts = {}) opts = { function_name: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(function_name)) - raise ArgumentError, "#{@__resource_name__}: function_name must be provided" unless opts[:function_name] && !opts[:function_name].empty? + validate_parameters(required: %i[function_name]) + unless opts[:function_name] && !opts[:function_name].empty? + raise ArgumentError, + "#{@__resource_name__}: function_name must be provided" + end @display_name = opts[:function_name] catch_aws_errors do - resp = @aws.lambda_client.get_function_event_invoke_config({ function_name: opts[:function_name] }) + resp = + @aws.lambda_client.get_function_event_invoke_config( + { function_name: opts[:function_name] } + ) @res = resp.to_h create_resource_methods(@res) end diff --git a/libraries/aws_lambda_event_source_mapping.rb b/libraries/aws_lambda_event_source_mapping.rb index c222ae774..c504ae544 100644 --- a/libraries/aws_lambda_event_source_mapping.rb +++ b/libraries/aws_lambda_event_source_mapping.rb @@ -14,7 +14,9 @@ def initialize(opts = {}) opts = { uuid: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:uuid]) - raise ArgumentError, "#{@__resource_name__}: uuid must be provided" unless opts[:uuid] && !opts[:uuid].empty? + unless opts[:uuid] && !opts[:uuid].empty? + raise ArgumentError, "#{@__resource_name__}: uuid must be provided" + end @display_name = opts[:uuid] catch_aws_errors do resp = @aws.lambda_client.get_event_source_mapping({ uuid: opts[:uuid] }) diff --git a/libraries/aws_lambda_layer_version_permission.rb b/libraries/aws_lambda_layer_version_permission.rb index cc7a0e81c..d6132e13a 100644 --- a/libraries/aws_lambda_layer_version_permission.rb +++ b/libraries/aws_lambda_layer_version_permission.rb @@ -13,12 +13,23 @@ class AWSLambdaLayerVersionPermission < AwsResourceBase def initialize(opts = {}) opts = { layer_name: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(layer_name version_number)) - raise ArgumentError, "#{@__resource_name__}: layer_name must be provided" unless opts[:layer_name] && !opts[:layer_name].empty? - raise ArgumentError, "#{@__resource_name__}: version_number must be provided" unless opts[:version_number] + validate_parameters(required: %i[layer_name version_number]) + unless opts[:layer_name] && !opts[:layer_name].empty? + raise ArgumentError, "#{@__resource_name__}: layer_name must be provided" + end + unless opts[:version_number] + raise ArgumentError, + "#{@__resource_name__}: version_number must be provided" + end @display_name = opts[:layer_name] catch_aws_errors do - resp = @aws.lambda_client.get_layer_version_policy({ layer_name: opts[:layer_name], version_number: opts[:version_number] }) + resp = + @aws.lambda_client.get_layer_version_policy( + { + layer_name: opts[:layer_name], + version_number: opts[:version_number] + } + ) @res = resp.to_h create_resource_methods(@res) end diff --git a/libraries/aws_lambda_version.rb b/libraries/aws_lambda_version.rb index c0f1abf89..aafbabd5a 100644 --- a/libraries/aws_lambda_version.rb +++ b/libraries/aws_lambda_version.rb @@ -12,11 +12,19 @@ class AWSLambdaVersion < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(layer_name version_number)) - raise ArgumentError, "#{@__resource_name__}: layer_name must be provided" unless opts[:layer_name] && !opts[:layer_name].empty? + validate_parameters(required: %i[layer_name version_number]) + unless opts[:layer_name] && !opts[:layer_name].empty? + raise ArgumentError, "#{@__resource_name__}: layer_name must be provided" + end @display_name = opts[:layer_name] catch_aws_errors do - resp = @aws.lambda_client.get_layer_version({ layer_name: opts[:layer_name], version_number: opts[:version_number] }) + resp = + @aws.lambda_client.get_layer_version( + { + layer_name: opts[:layer_name], + version_number: opts[:version_number] + } + ) @res = resp.to_h create_resource_methods(@res) end diff --git a/libraries/aws_launch_configuration.rb b/libraries/aws_launch_configuration.rb index 5ec214e2c..54dcfefbb 100644 --- a/libraries/aws_launch_configuration.rb +++ b/libraries/aws_launch_configuration.rb @@ -20,7 +20,7 @@ def initialize(opts = {}) catch_aws_errors do resp = @aws.service_client.describe_launch_configurations(launch_configuration_names: [opts[:launch_configuration_name]]) - return nil if resp.launch_configurations.nil? || resp.launch_configurations.empty? + return if resp.launch_configurations.nil? || resp.launch_configurations.empty? configuration = resp.launch_configurations[0] @name = configuration[:launch_configuration_name] @arn = configuration[:launch_configuration_arn] diff --git a/libraries/aws_logs_metric_filter.rb b/libraries/aws_logs_metric_filter.rb index f4f033b50..0bb19d298 100644 --- a/libraries/aws_logs_metric_filter.rb +++ b/libraries/aws_logs_metric_filter.rb @@ -14,10 +14,15 @@ def initialize(opts = {}) opts = { filter_name: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:filter_name]) - raise ArgumentError, "#{@__resource_name__}: filter_name must be provided" unless opts[:filter_name] && !opts[:filter_name].empty? + unless opts[:filter_name] && !opts[:filter_name].empty? + raise ArgumentError, "#{@__resource_name__}: filter_name must be provided" + end @display_name = opts[:filter_name] catch_aws_errors do - resp = @aws.cloudwatchlogs_client.describe_metric_filters({ filter_name_prefix: opts[:filter_name] }) + resp = + @aws.cloudwatchlogs_client.describe_metric_filters( + { filter_name_prefix: opts[:filter_name] } + ) @metric_filters = resp.metric_filters[0].to_h @filter_name = @metric_filters[:filter_name] @log_group_name = @metric_filters[:log_group_name] diff --git a/libraries/aws_mq_broker.rb b/libraries/aws_mq_broker.rb index 5ddfe09ef..995d67352 100644 --- a/libraries/aws_mq_broker.rb +++ b/libraries/aws_mq_broker.rb @@ -14,7 +14,9 @@ def initialize(opts = {}) opts = { broker_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:broker_id]) - raise ArgumentError, "#{@__resource_name__}: broker_id must be provided" unless opts[:broker_id] && !opts[:broker_id].empty? + unless opts[:broker_id] && !opts[:broker_id].empty? + raise ArgumentError, "#{@__resource_name__}: broker_id must be provided" + end @display_name = opts[:broker_id] resp = @aws.mq_client.describe_broker({ broker_id: opts[:broker_id] }) @brokers = resp.to_h @@ -27,7 +29,7 @@ def broker_id end def resource_id - @brokers? @brokers[:broker_id] : @display_name + @brokers ? @brokers[:broker_id] : @display_name end def exists? diff --git a/libraries/aws_mq_configuration.rb b/libraries/aws_mq_configuration.rb index 069dff7e6..d5a30286a 100644 --- a/libraries/aws_mq_configuration.rb +++ b/libraries/aws_mq_configuration.rb @@ -12,11 +12,17 @@ class AWSMQConfiguration < AwsResourceBase def initialize(opts = {}) opts = { configuration_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(configuration_id)) - raise ArgumentError, "#{@__resource_name__}: configuration_id must be provided" if opts[:configuration_id].blank? + validate_parameters(required: %i[configuration_id]) + if opts[:configuration_id].blank? + raise ArgumentError, + "#{@__resource_name__}: configuration_id must be provided" + end @display_name = opts[:configuration_id] catch_aws_errors do - resp = @aws.mq_client.describe_configuration({ configuration_id: opts[:configuration_id] }) + resp = + @aws.mq_client.describe_configuration( + { configuration_id: opts[:configuration_id] } + ) @configurations = resp.to_h @arn = @configurations[:arn] create_resource_methods(@configurations) @@ -24,7 +30,7 @@ def initialize(opts = {}) end def resource_id - return unless exists? + return nil unless exists? @arn || @display_name end diff --git a/libraries/aws_network_firewall_firewall.rb b/libraries/aws_network_firewall_firewall.rb index dc3b7eb6c..b4ba5ae23 100644 --- a/libraries/aws_network_firewall_firewall.rb +++ b/libraries/aws_network_firewall_firewall.rb @@ -14,10 +14,16 @@ def initialize(opts = {}) opts = { firewall_name: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:firewall_name]) - raise ArgumentError, "#{@__resource_name__}: firewall_name must be provided" unless opts[:firewall_name] && !opts[:firewall_name].empty? + unless opts[:firewall_name] && !opts[:firewall_name].empty? + raise ArgumentError, + "#{@__resource_name__}: firewall_name must be provided" + end @display_name = opts[:firewall_name] catch_aws_errors do - resp = @aws.network_firewall_client.describe_firewall({ firewall_name: opts[:firewall_name] }) + resp = + @aws.network_firewall_client.describe_firewall( + { firewall_name: opts[:firewall_name] } + ) @res = resp.to_h @firewall_arn = @res[:firewall][:firewall_arn] create_resource_methods(@res) diff --git a/libraries/aws_network_firewall_firewall_policy.rb b/libraries/aws_network_firewall_firewall_policy.rb index ae71e423c..354052cc2 100644 --- a/libraries/aws_network_firewall_firewall_policy.rb +++ b/libraries/aws_network_firewall_firewall_policy.rb @@ -14,10 +14,16 @@ def initialize(opts = {}) opts = { firewall_policy_name: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:firewall_policy_name]) - raise ArgumentError, "#{@__resource_name__}: firewall_policy_name must be provided" unless opts[:firewall_policy_name] && !opts[:firewall_policy_name].empty? + unless opts[:firewall_policy_name] && !opts[:firewall_policy_name].empty? + raise ArgumentError, + "#{@__resource_name__}: firewall_policy_name must be provided" + end @display_name = opts[:firewall_policy_name] catch_aws_errors do - resp = @aws.network_firewall_client.describe_firewall_policy({ firewall_policy_name: opts[:firewall_policy_name] }) + resp = + @aws.network_firewall_client.describe_firewall_policy( + { firewall_policy_name: opts[:firewall_policy_name] } + ) @res = resp.to_h @firewall_policy_arn = @res[:firewall_policy_arn] create_resource_methods(@res) diff --git a/libraries/aws_network_firewall_logging_configuration.rb b/libraries/aws_network_firewall_logging_configuration.rb index 3eef38fc5..3ee17c35c 100644 --- a/libraries/aws_network_firewall_logging_configuration.rb +++ b/libraries/aws_network_firewall_logging_configuration.rb @@ -14,10 +14,16 @@ def initialize(opts = {}) opts = { firewall_name: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:firewall_name]) - raise ArgumentError, "#{@__resource_name__}: firewall_name must be provided" unless opts[:firewall_name] && !opts[:firewall_name].empty? + unless opts[:firewall_name] && !opts[:firewall_name].empty? + raise ArgumentError, + "#{@__resource_name__}: firewall_name must be provided" + end @display_name = opts[:firewall_name] catch_aws_errors do - resp = @aws.network_firewall_client.describe_logging_configuration({ firewall_name: opts[:firewall_name] }) + resp = + @aws.network_firewall_client.describe_logging_configuration( + { firewall_name: opts[:firewall_name] } + ) @res = resp.to_h create_resource_methods(@res) end @@ -29,7 +35,7 @@ def firewall_name end def resource_id - @res? @res[:firewall_arn]: "" + @res ? @res[:firewall_arn] : "" end def exists? @@ -45,7 +51,9 @@ def logging_configuration_log_destination_configs_log_type end def logging_configuration_log_destination_configs_log_destination_type - logging_configuration.map(&:log_destination_configs).map(&:log_destination_type) + logging_configuration.map(&:log_destination_configs).map( + &:log_destination_type + ) end def logging_configuration_log_destination_configs_log_destination diff --git a/libraries/aws_network_firewall_rule_group.rb b/libraries/aws_network_firewall_rule_group.rb index 6bb98514e..1b56f832b 100644 --- a/libraries/aws_network_firewall_rule_group.rb +++ b/libraries/aws_network_firewall_rule_group.rb @@ -14,10 +14,16 @@ def initialize(opts = {}) opts = { rule_group_arn: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:rule_group_arn]) - raise ArgumentError, "#{@__resource_name__}: rule_group_arn must be provided" unless opts[:rule_group_arn] && !opts[:rule_group_arn].empty? + unless opts[:rule_group_arn] && !opts[:rule_group_arn].empty? + raise ArgumentError, + "#{@__resource_name__}: rule_group_arn must be provided" + end @display_name = opts[:rule_group_arn] catch_aws_errors do - resp = @aws.network_firewall_client.describe_rule_group({ rule_group_arn: opts[:rule_group_arn] }) + resp = + @aws.network_firewall_client.describe_rule_group( + { rule_group_arn: opts[:rule_group_arn] } + ) @res = resp.to_h create_resource_methods(@res) end @@ -29,7 +35,7 @@ def rule_group_arn end def resource_id - @res? @res[:rule_group_response][:rule_group_arn]: @display_name + @res ? @res[:rule_group_response][:rule_group_arn] : @display_name end def exists? diff --git a/libraries/aws_network_manager_customer_gateway_association.rb b/libraries/aws_network_manager_customer_gateway_association.rb index 0407a3296..46b469cc0 100644 --- a/libraries/aws_network_manager_customer_gateway_association.rb +++ b/libraries/aws_network_manager_customer_gateway_association.rb @@ -14,12 +14,24 @@ def initialize(opts = {}) opts = { global_network_id: opts } if opts.is_a?(String) opts = { customer_gateway_arn: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(global_network_id customer_gateway_arn)) - raise ArgumentError, "#{@__resource_name__}: global_network_id must be provided" unless opts[:global_network_id] && !opts[:global_network_id].empty? - raise ArgumentError, "#{@__resource_name__}: customer_gateway_arn must be provided" unless opts[:customer_gateway_arn] && !opts[:customer_gateway_arn].empty? + validate_parameters(required: %i[global_network_id customer_gateway_arn]) + unless opts[:global_network_id] && !opts[:global_network_id].empty? + raise ArgumentError, + "#{@__resource_name__}: global_network_id must be provided" + end + unless opts[:customer_gateway_arn] && !opts[:customer_gateway_arn].empty? + raise ArgumentError, + "#{@__resource_name__}: customer_gateway_arn must be provided" + end @display_name = opts[:customer_gateway_arn] catch_aws_errors do - resp = @aws.network_manager_client.get_customer_gateway_associations({ global_network_id: opts[:global_network_id], customer_gateway_arns: [opts[:customer_gateway_arn]] }) + resp = + @aws.network_manager_client.get_customer_gateway_associations( + { + global_network_id: opts[:global_network_id], + customer_gateway_arns: [opts[:customer_gateway_arn]] + } + ) @res = resp.customer_gateway_associations[0].to_h create_resource_methods(@res) end @@ -31,7 +43,7 @@ def customer_gateway_arn end def resource_id - @res? @res[:customer_gateway_arn]: @display_name + @res ? @res[:customer_gateway_arn] : @display_name end def exists? diff --git a/libraries/aws_network_manager_device.rb b/libraries/aws_network_manager_device.rb index 19dd6a489..863834be0 100644 --- a/libraries/aws_network_manager_device.rb +++ b/libraries/aws_network_manager_device.rb @@ -13,11 +13,19 @@ class AWSNetworkManagerDevice < AwsResourceBase def initialize(opts = {}) opts = { global_network_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(device_id global_network_id)) - raise ArgumentError, "#{@__resource_name__}: device_id must be provided" unless opts[:device_id] && !opts[:device_id].empty? + validate_parameters(required: %i[device_id global_network_id]) + unless opts[:device_id] && !opts[:device_id].empty? + raise ArgumentError, "#{@__resource_name__}: device_id must be provided" + end @display_name = opts[:device_id] catch_aws_errors do - resp = @aws.network_manager_client.get_devices({ device_ids: [opts[:device_id]], global_network_id: opts[:global_network_id] }) + resp = + @aws.network_manager_client.get_devices( + { + device_ids: [opts[:device_id]], + global_network_id: opts[:global_network_id] + } + ) @res = resp.devices[0].to_h create_resource_methods(@res) end @@ -29,7 +37,7 @@ def device_id end def resource_id - @res? @res[:device_id]: @display_name + @res ? @res[:device_id] : @display_name end def exists? diff --git a/libraries/aws_network_manager_global_network.rb b/libraries/aws_network_manager_global_network.rb index 56c67adad..af796386a 100644 --- a/libraries/aws_network_manager_global_network.rb +++ b/libraries/aws_network_manager_global_network.rb @@ -14,10 +14,16 @@ def initialize(opts = {}) opts = { global_network_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:global_network_id]) - raise ArgumentError, "#{@__resource_name__}: global_network_id must be provided" unless opts[:global_network_id] && !opts[:global_network_id].empty? + unless opts[:global_network_id] && !opts[:global_network_id].empty? + raise ArgumentError, + "#{@__resource_name__}: global_network_id must be provided" + end @display_name = opts[:global_network_id] catch_aws_errors do - resp = @aws.network_manager_client.describe_global_networks({ global_network_ids: [opts[:global_network_id]] }) + resp = + @aws.network_manager_client.describe_global_networks( + { global_network_ids: [opts[:global_network_id]] } + ) @res = resp.global_networks[0].to_h create_resource_methods(@res) end @@ -29,7 +35,7 @@ def global_network_id end def resource_id - @res? @res[:global_network_id]: @display_name + @res ? @res[:global_network_id] : @display_name end def exists? diff --git a/libraries/aws_ram_resource_share.rb b/libraries/aws_ram_resource_share.rb index 7c56be5ad..5ee9dae6a 100644 --- a/libraries/aws_ram_resource_share.rb +++ b/libraries/aws_ram_resource_share.rb @@ -11,14 +11,28 @@ class AWSRAMResourceShare < AwsResourceBase " def initialize(opts = {}) - opts = { resource_owner: opts, resource_share_arn: opts } if opts.is_a?(String) + opts = { resource_owner: opts, resource_share_arn: opts } if opts.is_a?( + String + ) super(opts) - validate_parameters(required: %i(resource_owner resource_share_arn)) - raise ArgumentError, "#{@__resource_name__}: resource_owner must be provided" unless opts[:resource_owner] && !opts[:resource_owner].empty? - raise ArgumentError, "#{@__resource_name__}: resource_share_arn must be provided" unless opts[:resource_share_arn] && !opts[:resource_share_arn].empty? + validate_parameters(required: %i[resource_owner resource_share_arn]) + unless opts[:resource_owner] && !opts[:resource_owner].empty? + raise ArgumentError, + "#{@__resource_name__}: resource_owner must be provided" + end + unless opts[:resource_share_arn] && !opts[:resource_share_arn].empty? + raise ArgumentError, + "#{@__resource_name__}: resource_share_arn must be provided" + end @display_name = opts[:resource_share_arn] catch_aws_errors do - resp = @aws.ram_client.get_resource_shares({ resource_owner: opts[:resource_owner], resource_share_arns: [opts[:resource_share_arn]] }) + resp = + @aws.ram_client.get_resource_shares( + { + resource_owner: opts[:resource_owner], + resource_share_arns: [opts[:resource_share_arn]] + } + ) @res = resp.resource_shares[0].to_h create_resource_methods(@res) end diff --git a/libraries/aws_rds_db_cluster_snapshot.rb b/libraries/aws_rds_db_cluster_snapshot.rb index a7de8acb0..82a460ffa 100644 --- a/libraries/aws_rds_db_cluster_snapshot.rb +++ b/libraries/aws_rds_db_cluster_snapshot.rb @@ -13,14 +13,18 @@ class AWSRDSDBClusterSnapShot < AwsResourceBase def initialize(opts = {}) opts = { db_cluster_snapshot_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(db_cluster_snapshot_id)) - raise ArgumentError, "#{@__resource_name__}: db_cluster_snapshot_id must be provided" unless opts[:db_cluster_snapshot_id] && !opts[:db_cluster_snapshot_id].empty? + validate_parameters(required: %i[db_cluster_snapshot_id]) + unless opts[:db_cluster_snapshot_id] && + !opts[:db_cluster_snapshot_id].empty? + raise ArgumentError, + "#{@__resource_name__}: db_cluster_snapshot_id must be provided" + end @display_name = opts[:db_cluster_snapshot_id] filter = [ { name: "db-cluster-snapshot-id", - values: [opts[:db_cluster_snapshot_id]], - }, + values: [opts[:db_cluster_snapshot_id]] + } ] catch_aws_errors do resp = @aws.rds_client.describe_db_cluster_snapshots({ filters: filter }) diff --git a/libraries/aws_rds_db_proxy.rb b/libraries/aws_rds_db_proxy.rb index a73694e10..e06432756 100644 --- a/libraries/aws_rds_db_proxy.rb +++ b/libraries/aws_rds_db_proxy.rb @@ -12,11 +12,17 @@ class AWSRDSProxy < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(db_proxy_name)) - raise ArgumentError, "#{@__resource_name__}: db_proxy_name must be provided" unless opts[:db_proxy_name] && !opts[:db_proxy_name].empty? + validate_parameters(required: %i[db_proxy_name]) + unless opts[:db_proxy_name] && !opts[:db_proxy_name].empty? + raise ArgumentError, + "#{@__resource_name__}: db_proxy_name must be provided" + end @display_name = opts[:db_proxy_name] catch_aws_errors do - resp = @aws.rds_client.describe_db_proxies({ db_proxy_name: opts[:db_proxy_name] }) + resp = + @aws.rds_client.describe_db_proxies( + { db_proxy_name: opts[:db_proxy_name] } + ) @res = resp.db_proxies[0].to_h @db_proxy_arn = @res[:db_proxy_arn] create_resource_methods(@res) diff --git a/libraries/aws_rds_db_proxy_endpoint.rb b/libraries/aws_rds_db_proxy_endpoint.rb index 54540d636..dbe5b634c 100644 --- a/libraries/aws_rds_db_proxy_endpoint.rb +++ b/libraries/aws_rds_db_proxy_endpoint.rb @@ -12,12 +12,25 @@ class AWSRDSProxyEndpoint < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(db_proxy_name db_proxy_endpoint_name)) - raise ArgumentError, "#{@__resource_name__}: db_proxy_name must be provided" unless opts[:db_proxy_name] && !opts[:db_proxy_name].empty? - raise ArgumentError, "#{@__resource_name__}: db_proxy_endpoint_name must be provided" unless opts[:db_proxy_endpoint_name] && !opts[:db_proxy_endpoint_name].empty? + validate_parameters(required: %i[db_proxy_name db_proxy_endpoint_name]) + unless opts[:db_proxy_name] && !opts[:db_proxy_name].empty? + raise ArgumentError, + "#{@__resource_name__}: db_proxy_name must be provided" + end + unless opts[:db_proxy_endpoint_name] && + !opts[:db_proxy_endpoint_name].empty? + raise ArgumentError, + "#{@__resource_name__}: db_proxy_endpoint_name must be provided" + end @display_name = opts[:db_proxy_endpoint_name] catch_aws_errors do - resp = @aws.rds_client.describe_db_proxy_endpoints({ db_proxy_name: opts[:db_proxy_name], db_proxy_endpoint_name: opts[:db_proxy_endpoint_name] }) + resp = + @aws.rds_client.describe_db_proxy_endpoints( + { + db_proxy_name: opts[:db_proxy_name], + db_proxy_endpoint_name: opts[:db_proxy_endpoint_name] + } + ) @res = resp.db_proxy_endpoints[0].to_h @db_proxy_endpoint_arn = @res[:db_proxy_endpoint_arn] create_resource_methods(@res) diff --git a/libraries/aws_rds_db_security_group.rb b/libraries/aws_rds_db_security_group.rb index 91059fe8a..d69c9ac48 100644 --- a/libraries/aws_rds_db_security_group.rb +++ b/libraries/aws_rds_db_security_group.rb @@ -12,11 +12,18 @@ class AWSRDSDBSecurityGroup < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(db_security_group_name)) - raise ArgumentError, "#{@__resource_name__}: db_security_group_name must be provided" unless opts[:db_security_group_name] && !opts[:db_security_group_name].empty? + validate_parameters(required: %i[db_security_group_name]) + unless opts[:db_security_group_name] && + !opts[:db_security_group_name].empty? + raise ArgumentError, + "#{@__resource_name__}: db_security_group_name must be provided" + end @display_name = opts[:db_security_group_name] catch_aws_errors do - resp = @aws.rds_client.describe_db_security_groups({ db_security_group_name: opts[:db_security_group_name] }) + resp = + @aws.rds_client.describe_db_security_groups( + { db_security_group_name: opts[:db_security_group_name] } + ) @res = resp.db_security_groups[0].to_h @db_security_group_arn = @res[:db_security_group_arn] create_resource_methods(@res) diff --git a/libraries/aws_rds_event_subscription.rb b/libraries/aws_rds_event_subscription.rb index 7e40e6581..0b0beac3e 100644 --- a/libraries/aws_rds_event_subscription.rb +++ b/libraries/aws_rds_event_subscription.rb @@ -12,18 +12,24 @@ class AWSRDSEventSubscription < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(subscription_name)) - raise ArgumentError, "#{@__resource_name__}: subscription_name must be provided" unless opts[:subscription_name] && !opts[:subscription_name].empty? + validate_parameters(required: %i[subscription_name]) + unless opts[:subscription_name] && !opts[:subscription_name].empty? + raise ArgumentError, + "#{@__resource_name__}: subscription_name must be provided" + end @display_name = opts[:subscription_name] catch_aws_errors do - resp = @aws.rds_client.describe_event_subscriptions({ subscription_name: opts[:subscription_name] }) + resp = + @aws.rds_client.describe_event_subscriptions( + { subscription_name: opts[:subscription_name] } + ) @res = resp.event_subscriptions_list[0].to_h create_resource_methods(@res) end end def resource_id - "#{@res? @res[:customer_aws_id]: ""}_#{@res? @res[:cust_subscription_id]: ""}" + "#{@res ? @res[:customer_aws_id] : ""}_#{@res ? @res[:cust_subscription_id] : ""}" end def subscription_name diff --git a/libraries/aws_rds_global_cluster.rb b/libraries/aws_rds_global_cluster.rb index 29cb1b136..aa64ca810 100644 --- a/libraries/aws_rds_global_cluster.rb +++ b/libraries/aws_rds_global_cluster.rb @@ -12,11 +12,18 @@ class AWSRDSGlobalCluster < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(global_cluster_identifier)) - raise ArgumentError, "#{@__resource_name__}: global_cluster_identifier must be provided" unless opts[:global_cluster_identifier] && !opts[:global_cluster_identifier].empty? + validate_parameters(required: %i[global_cluster_identifier]) + unless opts[:global_cluster_identifier] && + !opts[:global_cluster_identifier].empty? + raise ArgumentError, + "#{@__resource_name__}: global_cluster_identifier must be provided" + end @display_name = opts[:global_cluster_identifier] catch_aws_errors do - resp = @aws.rds_client.describe_global_clusters({ global_cluster_identifier: opts[:global_cluster_identifier] }) + resp = + @aws.rds_client.describe_global_clusters( + { global_cluster_identifier: opts[:global_cluster_identifier] } + ) @res = resp.global_clusters[0].to_h @global_cluster_resource_id = @res[:global_cluster_resource_id] create_resource_methods(@res) diff --git a/libraries/aws_redshift_cluster_parameter_group.rb b/libraries/aws_redshift_cluster_parameter_group.rb index bee0498e2..24cfc5ff1 100644 --- a/libraries/aws_redshift_cluster_parameter_group.rb +++ b/libraries/aws_redshift_cluster_parameter_group.rb @@ -13,10 +13,16 @@ def initialize(opts = {}) opts = { parameter_group_name: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:parameter_group_name]) - raise ArgumentError, "#{@__resource_name__}: parameter_group_name must be provided" unless opts[:parameter_group_name] && !opts[:parameter_group_name].empty? + unless opts[:parameter_group_name] && !opts[:parameter_group_name].empty? + raise ArgumentError, + "#{@__resource_name__}: parameter_group_name must be provided" + end @display_name = opts[:parameter_group_name] catch_aws_errors do - resp = @aws.redshift_client.describe_cluster_parameter_groups({ parameter_group_name: opts[:parameter_group_name] }) + resp = + @aws.redshift_client.describe_cluster_parameter_groups( + { parameter_group_name: opts[:parameter_group_name] } + ) @parameter_groups = resp.parameter_groups[0].to_h @parameter_group_name = (@parameter_groups[:parameter_group_name]).to_s create_resource_methods(@parameter_groups) diff --git a/libraries/aws_route53_record_set.rb b/libraries/aws_route53_record_set.rb index 68dbe73cf..cc755e40d 100644 --- a/libraries/aws_route53_record_set.rb +++ b/libraries/aws_route53_record_set.rb @@ -12,13 +12,25 @@ class AWSRoute53RecordSet < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(hosted_zone_id start_record_name)) - raise ArgumentError, "#{@__resource_name__}: hosted_zone_id must be provided" unless opts[:hosted_zone_id] && !opts[:hosted_zone_id].empty? - raise ArgumentError, "#{@__resource_name__}: start_record_name must be provided" unless opts[:start_record_name] && !opts[:start_record_name].empty? + validate_parameters(required: %i[hosted_zone_id start_record_name]) + unless opts[:hosted_zone_id] && !opts[:hosted_zone_id].empty? + raise ArgumentError, + "#{@__resource_name__}: hosted_zone_id must be provided" + end + unless opts[:start_record_name] && !opts[:start_record_name].empty? + raise ArgumentError, + "#{@__resource_name__}: start_record_name must be provided" + end @hosted_zone_id = opts[:hosted_zone_id] @start_record_name = opts[:start_record_name] catch_aws_errors do - resp = @aws.route53_client.list_resource_record_sets({ hosted_zone_id: opts[:hosted_zone_id], start_record_name: opts[:name] }) + resp = + @aws.route53_client.list_resource_record_sets( + { + hosted_zone_id: opts[:hosted_zone_id], + start_record_name: opts[:name] + } + ) @res = resp.resource_record_sets[0].to_h create_resource_methods(@res) end @@ -30,7 +42,7 @@ def hosted_zone_id end def resource_id - "#{@res? @hosted_zone_id: ""}_#{@res? @start_record_name: ""}" + "#{@res ? @hosted_zone_id : ""}_#{@res ? @start_record_name : ""}" end def exists? diff --git a/libraries/aws_route53resolver_resolver_endpoint.rb b/libraries/aws_route53resolver_resolver_endpoint.rb index c577c55c3..7d1781275 100644 --- a/libraries/aws_route53resolver_resolver_endpoint.rb +++ b/libraries/aws_route53resolver_resolver_endpoint.rb @@ -13,11 +13,17 @@ class AWSRoute53ResolverResolverEndpoint < AwsResourceBase def initialize(opts = {}) opts = { resolver_endpoint_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(resolver_endpoint_id)) - raise ArgumentError, "#{@__resource_name__}: resolver_endpoint_id must be provided" unless opts[:resolver_endpoint_id] && !opts[:resolver_endpoint_id].empty? + validate_parameters(required: %i[resolver_endpoint_id]) + unless opts[:resolver_endpoint_id] && !opts[:resolver_endpoint_id].empty? + raise ArgumentError, + "#{@__resource_name__}: resolver_endpoint_id must be provided" + end @display_name = opts[:resolver_endpoint_id] catch_aws_errors do - resp = @aws.route53resolver_client.get_resolver_endpoint({ resolver_endpoint_id: opts[:resolver_endpoint_id] }) + resp = + @aws.route53resolver_client.get_resolver_endpoint( + { resolver_endpoint_id: opts[:resolver_endpoint_id] } + ) @res = resp.resolver_endpoint.to_h create_resource_methods(@res) end @@ -29,7 +35,7 @@ def resolver_endpoint_id end def resource_id - @res? @res[:id]: @display_name + @res ? @res[:id] : @display_name end def exists? diff --git a/libraries/aws_route53resolver_resolver_rule.rb b/libraries/aws_route53resolver_resolver_rule.rb index 4ea4a3cef..644e9af39 100644 --- a/libraries/aws_route53resolver_resolver_rule.rb +++ b/libraries/aws_route53resolver_resolver_rule.rb @@ -13,11 +13,17 @@ class AWSRoute53ResolverResolverRule < AwsResourceBase def initialize(opts = {}) opts = { resolver_rule_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(resolver_rule_id)) - raise ArgumentError, "#{@__resource_name__}: resolver_rule_id must be provided" unless opts[:resolver_rule_id] && !opts[:resolver_rule_id].empty? + validate_parameters(required: %i[resolver_rule_id]) + unless opts[:resolver_rule_id] && !opts[:resolver_rule_id].empty? + raise ArgumentError, + "#{@__resource_name__}: resolver_rule_id must be provided" + end @display_name = opts[:resolver_rule_id] catch_aws_errors do - resp = @aws.route53resolver_client.get_resolver_rule({ resolver_rule_id: opts[:resolver_rule_id] }) + resp = + @aws.route53resolver_client.get_resolver_rule( + { resolver_rule_id: opts[:resolver_rule_id] } + ) @res = resp.resolver_rule.to_h create_resource_methods(@res) end @@ -29,7 +35,7 @@ def resolver_rule_id end def resource_id - @res? @res[:id]: @display_name + @res ? @res[:id] : @display_name end def exists? diff --git a/libraries/aws_route53resolver_resolver_rule_association.rb b/libraries/aws_route53resolver_resolver_rule_association.rb index 8ffa0f9e1..f95e9409c 100644 --- a/libraries/aws_route53resolver_resolver_rule_association.rb +++ b/libraries/aws_route53resolver_resolver_rule_association.rb @@ -13,23 +13,30 @@ class AWSRoute53ResolverResolverRuleAssociation < AwsResourceBase def initialize(opts = {}) opts = { resolver_rule_association_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(resolver_rule_association_id)) - raise ArgumentError, "#{@__resource_name__}: resource_share_arn must be provided" unless opts[:resolver_rule_association_id] && !opts[:resolver_rule_association_id].empty? + validate_parameters(required: %i[resolver_rule_association_id]) + unless opts[:resolver_rule_association_id] && + !opts[:resolver_rule_association_id].empty? + raise ArgumentError, + "#{@__resource_name__}: resource_share_arn must be provided" + end @display_name = opts[:resolver_rule_association_id] catch_aws_errors do - resp = @aws.route53resolver_client.get_resolver_rule_association({ resolver_rule_association_id: opts[:resolver_rule_association_id] }) + resp = + @aws.route53resolver_client.get_resolver_rule_association( + { resolver_rule_association_id: opts[:resolver_rule_association_id] } + ) @res = resp.resolver_rule_association.to_h create_resource_methods(@res) end end def resolver_rule_association_id - return nil unless exists? + return unless exists? @res[:id] end def resource_id - @res? @res[:id]: @display_name + @res ? @res[:id] : @display_name end def exists? diff --git a/libraries/aws_s3_access_point.rb b/libraries/aws_s3_access_point.rb index 39c9944bd..257dc35c5 100644 --- a/libraries/aws_s3_access_point.rb +++ b/libraries/aws_s3_access_point.rb @@ -14,12 +14,19 @@ def initialize(opts = {}) opts = { bucket_name: opts } if opts.is_a?(String) opts = { metrics_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(bucket_name metrics_id)) - raise ArgumentError, "#{@__resource_name__}: bucket_name must be provided" unless opts[:bucket_name] && !opts[:bucket_name].empty? - raise ArgumentError, "#{@__resource_name__}: metrics_id must be provided" unless opts[:metrics_id] && !opts[:metrics_id].empty? + validate_parameters(required: %i[bucket_name metrics_id]) + unless opts[:bucket_name] && !opts[:bucket_name].empty? + raise ArgumentError, "#{@__resource_name__}: bucket_name must be provided" + end + unless opts[:metrics_id] && !opts[:metrics_id].empty? + raise ArgumentError, "#{@__resource_name__}: metrics_id must be provided" + end @display_name = opts[:metrics_id] catch_aws_errors do - resp = @aws.storage_client.get_bucket_metrics_configuration({ bucket: opts[:bucket_name], id: opts[:metrics_id] }) + resp = + @aws.storage_client.get_bucket_metrics_configuration( + { bucket: opts[:bucket_name], id: opts[:metrics_id] } + ) @resp = resp.metrics_configuration.to_h create_resource_methods(@resp) end diff --git a/libraries/aws_secretsmanager_secret.rb b/libraries/aws_secretsmanager_secret.rb index fc2163e02..7556b54a5 100644 --- a/libraries/aws_secretsmanager_secret.rb +++ b/libraries/aws_secretsmanager_secret.rb @@ -13,11 +13,16 @@ class AWSSecretsManagerSecret < AwsResourceBase def initialize(opts = {}) opts = { secret_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(secret_id)) - raise ArgumentError, "#{@__resource_name__}: secret_id must be provided" unless opts[:secret_id] && !opts[:secret_id].empty? + validate_parameters(required: %i[secret_id]) + unless opts[:secret_id] && !opts[:secret_id].empty? + raise ArgumentError, "#{@__resource_name__}: secret_id must be provided" + end @display_name = opts[:secret_id] catch_aws_errors do - resp = @aws.secretsmanager_client.describe_secret({ secret_id: opts[:secret_id] }) + resp = + @aws.secretsmanager_client.describe_secret( + { secret_id: opts[:secret_id] } + ) @res = resp.to_h create_resource_methods(@res) end diff --git a/libraries/aws_security_group.rb b/libraries/aws_security_group.rb index ede6c7023..28f3c610d 100644 --- a/libraries/aws_security_group.rb +++ b/libraries/aws_security_group.rb @@ -231,11 +231,11 @@ def allow__match_protocol(rule, criteria) def match_ipv4_or_6_range(rule, criteria) if criteria.key?(:ipv4_range) query = criteria[:ipv4_range] - query = [query] unless query.is_a?(Array) + query = Array(query) ranges = rule[:ip_ranges].map { |rng| rng[:cidr_ip] } else # IPv6 query = criteria[:ipv6_range] - query = [query] unless query.is_a?(Array) + query = Array(query) ranges = rule[:ipv_6_ranges].map { |rng| rng[:cidr_ipv_6] } end diff --git a/libraries/aws_securityhub_hub.rb b/libraries/aws_securityhub_hub.rb index c9dcdc020..d67da7045 100644 --- a/libraries/aws_securityhub_hub.rb +++ b/libraries/aws_securityhub_hub.rb @@ -14,7 +14,9 @@ def initialize(opts = {}) opts = { hub_arn: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:hub_arn]) - raise ArgumentError, "#{@__resource_hub_arn__}: hub_arn must be provided" unless opts[:hub_arn] && !opts[:hub_arn].empty? + unless opts[:hub_arn] && !opts[:hub_arn].empty? + raise ArgumentError, "#{@__resource_hub_arn__}: hub_arn must be provided" + end @display_name = opts[:hub_arn] catch_aws_errors do resp = @aws.securityhub_client.describe_hub({ hub_arn: opts[:hub_arn] }) diff --git a/libraries/aws_servicecatalog_cloud_formation_product.rb b/libraries/aws_servicecatalog_cloud_formation_product.rb index 2b9af0524..955b008c9 100644 --- a/libraries/aws_servicecatalog_cloud_formation_product.rb +++ b/libraries/aws_servicecatalog_cloud_formation_product.rb @@ -14,12 +14,18 @@ def initialize(opts = {}) opts = { name: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:name]) - raise ArgumentError, "#{@__resource_name__}: name must be provided" unless opts[:name] && !opts[:name].empty? + unless opts[:name] && !opts[:name].empty? + raise ArgumentError, "#{@__resource_name__}: name must be provided" + end @display_name = opts[:name] catch_aws_errors do - resp = @aws.servicecatalog_client.describe_product_as_admin({ name: opts[:name] }) + resp = + @aws.servicecatalog_client.describe_product_as_admin( + { name: opts[:name] } + ) @res = resp.to_h - @product_view_detail_product_view_summary_id = @res[:product_view_detail][:product_view_summary][:id] + @product_view_detail_product_view_summary_id = + @res[:product_view_detail][:product_view_summary][:id] create_resource_methods(@res) end end diff --git a/libraries/aws_servicecatalog_portfolio_principal_association.rb b/libraries/aws_servicecatalog_portfolio_principal_association.rb index e99d0597b..4c42e2b1a 100644 --- a/libraries/aws_servicecatalog_portfolio_principal_association.rb +++ b/libraries/aws_servicecatalog_portfolio_principal_association.rb @@ -14,10 +14,16 @@ def initialize(opts = {}) opts = { portfolio_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:portfolio_id]) - raise ArgumentError, "#{@__resource_name__}: portfolio_id must be provided" unless opts[:portfolio_id] && !opts[:portfolio_id].empty? + unless opts[:portfolio_id] && !opts[:portfolio_id].empty? + raise ArgumentError, + "#{@__resource_name__}: portfolio_id must be provided" + end @display_name = opts[:portfolio_id] catch_aws_errors do - resp = @aws.servicecatalog_client.list_principals_for_portfolio({ portfolio_id: opts[:portfolio_id] }) + resp = + @aws.servicecatalog_client.list_principals_for_portfolio( + { portfolio_id: opts[:portfolio_id] } + ) @res = resp.principals[0].to_h @principal_arn = @res[:principal_arn] create_resource_methods(@res) diff --git a/libraries/aws_servicecatalog_portfolio_product_association.rb b/libraries/aws_servicecatalog_portfolio_product_association.rb index 125f5d153..edc58cbde 100644 --- a/libraries/aws_servicecatalog_portfolio_product_association.rb +++ b/libraries/aws_servicecatalog_portfolio_product_association.rb @@ -14,10 +14,15 @@ def initialize(opts = {}) opts = { product_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:product_id]) - raise ArgumentError, "#{@__resource_name__}: product_id must be provided" unless opts[:product_id] && !opts[:product_id].empty? + unless opts[:product_id] && !opts[:product_id].empty? + raise ArgumentError, "#{@__resource_name__}: product_id must be provided" + end @display_name = opts[:product_id] catch_aws_errors do - resp = @aws.servicecatalog_client.list_portfolios_for_product({ product_id: opts[:product_id] }) + resp = + @aws.servicecatalog_client.list_portfolios_for_product( + { product_id: opts[:product_id] } + ) @res = resp.portfolio_details[0].to_h @arn = @res[:arn] create_resource_methods(@res) @@ -29,7 +34,7 @@ def resource_id end def product_id - return nil unless exists? + return unless exists? @res[:product_id] end diff --git a/libraries/aws_ses_receipt_rule.rb b/libraries/aws_ses_receipt_rule.rb index 8d71e04ba..28a734919 100644 --- a/libraries/aws_ses_receipt_rule.rb +++ b/libraries/aws_ses_receipt_rule.rb @@ -12,12 +12,20 @@ class AWSSESReceiptRule < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(rule_set_name rule_name)) - raise ArgumentError, "#{@__resource_name__}: rule_set_name must be provided" unless opts[:rule_set_name] && !opts[:rule_set_name].empty? - raise ArgumentError, "#{@__resource_name__}: rule_name must be provided" unless opts[:rule_name] && !opts[:rule_name].empty? + validate_parameters(required: %i[rule_set_name rule_name]) + unless opts[:rule_set_name] && !opts[:rule_set_name].empty? + raise ArgumentError, + "#{@__resource_name__}: rule_set_name must be provided" + end + unless opts[:rule_name] && !opts[:rule_name].empty? + raise ArgumentError, "#{@__resource_name__}: rule_name must be provided" + end @display_name = opts[:rule_name] catch_aws_errors do - resp = @aws.ses_client.describe_receipt_rule({ rule_set_name: opts[:rule_set_name], rule_name: opts[:rule_name] }) + resp = + @aws.ses_client.describe_receipt_rule( + { rule_set_name: opts[:rule_set_name], rule_name: opts[:rule_name] } + ) @res = resp.rule.to_h create_resource_methods(@res) end diff --git a/libraries/aws_ses_receipt_rule_set.rb b/libraries/aws_ses_receipt_rule_set.rb index 4ad178bba..967967069 100644 --- a/libraries/aws_ses_receipt_rule_set.rb +++ b/libraries/aws_ses_receipt_rule_set.rb @@ -12,11 +12,17 @@ class AWSSESReceiptRuleSet < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(rule_set_name)) - raise ArgumentError, "#{@__resource_name__}: rule_set_name must be provided" unless opts[:rule_set_name] && !opts[:rule_set_name].empty? + validate_parameters(required: %i[rule_set_name]) + unless opts[:rule_set_name] && !opts[:rule_set_name].empty? + raise ArgumentError, + "#{@__resource_name__}: rule_set_name must be provided" + end @display_name = opts[:rule_set_name] catch_aws_errors do - resp = @aws.ses_client.describe_receipt_rule_set({ rule_set_name: opts[:rule_set_name] }) + resp = + @aws.ses_client.describe_receipt_rule_set( + { rule_set_name: opts[:rule_set_name] } + ) @res = resp.rules[0].to_h create_resource_methods(@res) end diff --git a/libraries/aws_ses_template.rb b/libraries/aws_ses_template.rb index 292177e5d..973199c8b 100644 --- a/libraries/aws_ses_template.rb +++ b/libraries/aws_ses_template.rb @@ -12,11 +12,15 @@ class AWSSESTemplate < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(template_name)) - raise ArgumentError, "#{@__resource_name__}: template_name must be provided" unless opts[:template_name] && !opts[:template_name].empty? + validate_parameters(required: %i[template_name]) + unless opts[:template_name] && !opts[:template_name].empty? + raise ArgumentError, + "#{@__resource_name__}: template_name must be provided" + end @display_name = opts[:template_name] catch_aws_errors do - resp = @aws.ses_client.get_template({ template_name: opts[:template_name] }) + resp = + @aws.ses_client.get_template({ template_name: opts[:template_name] }) @res = resp.template.to_h create_resource_methods(@res) end diff --git a/libraries/aws_signer_signing_profile.rb b/libraries/aws_signer_signing_profile.rb index fb0570346..d166bbce7 100644 --- a/libraries/aws_signer_signing_profile.rb +++ b/libraries/aws_signer_signing_profile.rb @@ -13,11 +13,17 @@ class AWSSignerSigningProfile < AwsResourceBase def initialize(opts = {}) opts = { profile_name: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(profile_name)) - raise ArgumentError, "#{@__resource_name__}: profile_name must be provided" unless opts[:profile_name] && !opts[:profile_name].empty? + validate_parameters(required: %i[profile_name]) + unless opts[:profile_name] && !opts[:profile_name].empty? + raise ArgumentError, + "#{@__resource_name__}: profile_name must be provided" + end @display_name = opts[:profile_name] catch_aws_errors do - resp = @aws.signer_client.get_signing_profile({ profile_name: opts[:profile_name] }) + resp = + @aws.signer_client.get_signing_profile( + { profile_name: opts[:profile_name] } + ) @res = resp.to_h create_resource_methods(@res) end diff --git a/libraries/aws_ssm_maintenance_window.rb b/libraries/aws_ssm_maintenance_window.rb index bee5c564f..636a96e17 100644 --- a/libraries/aws_ssm_maintenance_window.rb +++ b/libraries/aws_ssm_maintenance_window.rb @@ -12,18 +12,21 @@ class AWSSESMaintenanceWindow < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(window_id)) - raise ArgumentError, "#{@__resource_name__}: window_id must be provided" unless opts[:window_id] && !opts[:window_id].empty? + validate_parameters(required: %i[window_id]) + unless opts[:window_id] && !opts[:window_id].empty? + raise ArgumentError, "#{@__resource_name__}: window_id must be provided" + end @display_name = opts[:window_id] catch_aws_errors do - resp = @aws.ssm_client.get_maintenance_window({ window_id: opts[:window_id] }) + resp = + @aws.ssm_client.get_maintenance_window({ window_id: opts[:window_id] }) @res = resp.to_h create_resource_methods(@res) end end def resource_id - @res? @res[:window_id]: @display_name + @res ? @res[:window_id] : @display_name end def window_id diff --git a/libraries/aws_ssm_maintenance_window_target.rb b/libraries/aws_ssm_maintenance_window_target.rb index 17da61ecf..c090c9140 100644 --- a/libraries/aws_ssm_maintenance_window_target.rb +++ b/libraries/aws_ssm_maintenance_window_target.rb @@ -12,18 +12,21 @@ class AWSSESMaintenanceWindowTarget < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(window_id window_target_id)) - raise ArgumentError, "#{@__resource_name__}: window_id must be provided" unless opts[:window_id] && !opts[:window_id].empty? - raise ArgumentError, "#{@__resource_name__}: window_target_id must be provided" unless opts[:window_target_id] && !opts[:window_target_id].empty? - filter = [ - { - key: "WindowTargetId", - values: [opts[:window_target_id]], - }, - ] + validate_parameters(required: %i[window_id window_target_id]) + unless opts[:window_id] && !opts[:window_id].empty? + raise ArgumentError, "#{@__resource_name__}: window_id must be provided" + end + unless opts[:window_target_id] && !opts[:window_target_id].empty? + raise ArgumentError, + "#{@__resource_name__}: window_target_id must be provided" + end + filter = [{ key: "WindowTargetId", values: [opts[:window_target_id]] }] @display_name = opts[:window_target_id] catch_aws_errors do - resp = @aws.ssm_client.describe_maintenance_window_targets({ window_id: opts[:window_id], filters: filter }) + resp = + @aws.ssm_client.describe_maintenance_window_targets( + { window_id: opts[:window_id], filters: filter } + ) @res = resp.targets[0].to_h @window_id = @res[:window_id] @window_target_id = @res[:window_target_id] diff --git a/libraries/aws_ssm_maintenance_window_task.rb b/libraries/aws_ssm_maintenance_window_task.rb index 44ff8ec66..111538956 100644 --- a/libraries/aws_ssm_maintenance_window_task.rb +++ b/libraries/aws_ssm_maintenance_window_task.rb @@ -12,18 +12,21 @@ class AWSSESMaintenanceWindowTask < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(window_id window_task_id)) - raise ArgumentError, "#{@__resource_name__}: window_id must be provided" unless opts[:window_id] && !opts[:window_id].empty? - raise ArgumentError, "#{@__resource_name__}: window_task_id must be provided" unless opts[:window_task_id] && !opts[:window_task_id].empty? - filter = [ - { - key: "WindowTaskId", - values: [opts[:window_task_id]], - }, - ] + validate_parameters(required: %i[window_id window_task_id]) + unless opts[:window_id] && !opts[:window_id].empty? + raise ArgumentError, "#{@__resource_name__}: window_id must be provided" + end + unless opts[:window_task_id] && !opts[:window_task_id].empty? + raise ArgumentError, + "#{@__resource_name__}: window_task_id must be provided" + end + filter = [{ key: "WindowTaskId", values: [opts[:window_task_id]] }] @display_name = opts[:window_task_id] catch_aws_errors do - resp = @aws.ssm_client.describe_maintenance_window_tasks({ window_id: opts[:window_id], filters: filter }) + resp = + @aws.ssm_client.describe_maintenance_window_tasks( + { window_id: opts[:window_id], filters: filter } + ) @res = resp.tasks[0].to_h @window_id = @res[:window_id] @window_task_id = @res[:window_task_id] diff --git a/libraries/aws_ssm_patch_baseline.rb b/libraries/aws_ssm_patch_baseline.rb index ce9e7cebb..67d7e7ac0 100644 --- a/libraries/aws_ssm_patch_baseline.rb +++ b/libraries/aws_ssm_patch_baseline.rb @@ -20,11 +20,14 @@ class AWSSESPatchBaseline < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(baseline_id)) - raise ArgumentError, "#{@__resource_name__}: baseline_id must be provided" unless opts[:baseline_id] && !opts[:baseline_id].empty? + validate_parameters(required: %i[baseline_id]) + unless opts[:baseline_id] && !opts[:baseline_id].empty? + raise ArgumentError, "#{@__resource_name__}: baseline_id must be provided" + end @display_name = opts[:baseline_id] catch_aws_errors do - resp = @aws.ssm_client.get_patch_baseline({ baseline_id: opts[:baseline_id] }) + resp = + @aws.ssm_client.get_patch_baseline({ baseline_id: opts[:baseline_id] }) @res = resp.to_h @baseline_id = @res[:baseline_id] @name = @res[:name] @@ -54,15 +57,26 @@ def patch_filter_values end def patch_filter_groups - approval_rules.map(&:patch_rules).map(&:patch_filter_group).map(&:patch_filters) + approval_rules + .map(&:patch_rules) + .map(&:patch_filter_group) + .map(&:patch_filters) end def patch_filter_group_keys - approval_rules.map(&:patch_rules).map(&:patch_filter_group).map(&:patch_filters).map(&:key) + approval_rules + .map(&:patch_rules) + .map(&:patch_filter_group) + .map(&:patch_filters) + .map(&:key) end def patch_filter_group_values - approval_rules.map(&:patch_rules).map(&:patch_filter_group).map(&:patch_filters).map(&:values) + approval_rules + .map(&:patch_rules) + .map(&:patch_filter_group) + .map(&:patch_filters) + .map(&:values) end def compliance_levels diff --git a/libraries/aws_stepfunctions_activity.rb b/libraries/aws_stepfunctions_activity.rb index d62618c29..8e62de1b8 100644 --- a/libraries/aws_stepfunctions_activity.rb +++ b/libraries/aws_stepfunctions_activity.rb @@ -12,11 +12,17 @@ class AWSStepFunctionsActivity < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(activity_arn)) - raise ArgumentError, "#{@__resource_name__}: activity_arn must be provided" unless opts[:activity_arn] && !opts[:activity_arn].empty? + validate_parameters(required: %i[activity_arn]) + unless opts[:activity_arn] && !opts[:activity_arn].empty? + raise ArgumentError, + "#{@__resource_name__}: activity_arn must be provided" + end @display_name = opts[:activity_arn] catch_aws_errors do - resp = @aws.states_client.describe_activity({ activity_arn: opts[:activity_arn] }) + resp = + @aws.states_client.describe_activity( + { activity_arn: opts[:activity_arn] } + ) @res = resp.to_h create_resource_methods(@res) end diff --git a/libraries/aws_stepfunctions_state_machine.rb b/libraries/aws_stepfunctions_state_machine.rb index ce704ef89..438ac1c7e 100644 --- a/libraries/aws_stepfunctions_state_machine.rb +++ b/libraries/aws_stepfunctions_state_machine.rb @@ -13,11 +13,17 @@ class AWSStepFunctionsStateMachine < AwsResourceBase def initialize(opts = {}) opts = { state_machine_arn: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(state_machine_arn)) - raise ArgumentError, "#{@__resource_name__}: state_machine_arn must be provided" unless opts[:state_machine_arn] && !opts[:state_machine_arn].empty? + validate_parameters(required: %i[state_machine_arn]) + unless opts[:state_machine_arn] && !opts[:state_machine_arn].empty? + raise ArgumentError, + "#{@__resource_name__}: state_machine_arn must be provided" + end @display_name = opts[:state_machine_arn] catch_aws_errors do - resp = @aws.states_client.describe_state_machine({ state_machine_arn: opts[:state_machine_arn] }) + resp = + @aws.states_client.describe_state_machine( + { state_machine_arn: opts[:state_machine_arn] } + ) @res = resp.to_h create_resource_methods(@res) end diff --git a/libraries/aws_synthetics_canary.rb b/libraries/aws_synthetics_canary.rb index 15ad21a89..b104f983f 100644 --- a/libraries/aws_synthetics_canary.rb +++ b/libraries/aws_synthetics_canary.rb @@ -12,8 +12,10 @@ class AWSSyntheticsCanary < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(name)) - raise ArgumentError, "#{@__resource_name__}: name must be provided" unless opts[:name] && !opts[:name].empty? + validate_parameters(required: %i[name]) + unless opts[:name] && !opts[:name].empty? + raise ArgumentError, "#{@__resource_name__}: name must be provided" + end @display_name = opts[:name] catch_aws_errors do resp = @aws.synthetics_client.get_canary({ name: opts[:name] }) @@ -23,7 +25,7 @@ def initialize(opts = {}) end def name - return nil unless exists? + return unless exists? @res[:name] end diff --git a/libraries/aws_transfer_user.rb b/libraries/aws_transfer_user.rb index f2d8de829..bf1a0d474 100644 --- a/libraries/aws_transfer_user.rb +++ b/libraries/aws_transfer_user.rb @@ -11,12 +11,19 @@ class AWSTransferUser < AwsResourceBase def initialize(opts = {}) super(opts) - validate_parameters(required: %i(server_id user_name)) - raise ArgumentError, "#{@__resource_name__}: server_id must be provided" unless opts[:server_id] && !opts[:server_id].empty? - raise ArgumentError, "#{@__resource_name__}: user_name must be provided" unless opts[:user_name] && !opts[:user_name].empty? + validate_parameters(required: %i[server_id user_name]) + unless opts[:server_id] && !opts[:server_id].empty? + raise ArgumentError, "#{@__resource_name__}: server_id must be provided" + end + unless opts[:user_name] && !opts[:user_name].empty? + raise ArgumentError, "#{@__resource_name__}: user_name must be provided" + end @user_name = opts[:user_name] catch_aws_errors do - resp = @aws.transfer_client.describe_user({ server_id: opts[:server_id], user_name: opts[:user_name] }) + resp = + @aws.transfer_client.describe_user( + { server_id: opts[:server_id], user_name: opts[:user_name] } + ) @res = resp.user.to_h @res[:server_id] = resp.server_id create_resource_methods(@res) diff --git a/libraries/aws_transit_gateway.rb b/libraries/aws_transit_gateway.rb index d777f656b..64eea6e5e 100644 --- a/libraries/aws_transit_gateway.rb +++ b/libraries/aws_transit_gateway.rb @@ -20,7 +20,7 @@ def initialize(opts = {}) catch_aws_errors do resp = @aws.compute_client.describe_transit_gateways(transit_gateway_ids: [opts[:transit_gateway_id]]) - return nil if resp.transit_gateways.nil? || resp.transit_gateways.empty? + return if resp.transit_gateways.nil? || resp.transit_gateways.empty? transit_gateway = resp.transit_gateways.first @transit_gateway_arn = transit_gateway.transit_gateway_arn @transit_gateway_id = transit_gateway.transit_gateway_id diff --git a/libraries/aws_transit_gateway_connect.rb b/libraries/aws_transit_gateway_connect.rb index ab53aa00f..c11673765 100644 --- a/libraries/aws_transit_gateway_connect.rb +++ b/libraries/aws_transit_gateway_connect.rb @@ -14,10 +14,21 @@ def initialize(opts = {}) opts = { transit_gateway_attachment_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:transit_gateway_attachment_id]) - raise ArgumentError, "#{@__resource_name__}: transit_gateway_attachment_id must be provided" unless opts[:transit_gateway_attachment_id] && !opts[:transit_gateway_attachment_id].empty? + unless opts[:transit_gateway_attachment_id] && + !opts[:transit_gateway_attachment_id].empty? + raise ArgumentError, + "#{@__resource_name__}: transit_gateway_attachment_id must be provided" + end @display_name = opts[:transit_gateway_attachment_id] catch_aws_errors do - resp = @aws.compute_client.describe_transit_gateway_connects({ transit_gateway_attachment_ids: [opts[:transit_gateway_attachment_id]] }) + resp = + @aws.compute_client.describe_transit_gateway_connects( + { + transit_gateway_attachment_ids: [ + opts[:transit_gateway_attachment_id] + ] + } + ) @transit_gateway_connects = resp.transit_gateway_connects[0].to_h create_resource_methods(@transit_gateway_connects) end @@ -33,7 +44,11 @@ def exists? end def resource_id - @transit_gateway_connects ? @transit_gateway_connects[:transit_gateway_attachment_id] : @display_name + if @transit_gateway_connects + @transit_gateway_connects[:transit_gateway_attachment_id] + else + @display_name + end end def to_s diff --git a/libraries/aws_transit_gateway_multicast_domain.rb b/libraries/aws_transit_gateway_multicast_domain.rb index 86ce410f5..9db5b1fb7 100644 --- a/libraries/aws_transit_gateway_multicast_domain.rb +++ b/libraries/aws_transit_gateway_multicast_domain.rb @@ -18,11 +18,23 @@ def initialize(opts = {}) opts = { transit_gateway_multicast_domain_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:transit_gateway_multicast_domain_id]) - raise ArgumentError, "#{@__resource_name__}: transit_gateway_multicast_domain_id must be provided" unless opts[:transit_gateway_multicast_domain_id] && !opts[:transit_gateway_multicast_domain_id].empty? + unless opts[:transit_gateway_multicast_domain_id] && + !opts[:transit_gateway_multicast_domain_id].empty? + raise ArgumentError, + "#{@__resource_name__}: transit_gateway_multicast_domain_id must be provided" + end @display_name = opts[:transit_gateway_multicast_domain_id] catch_aws_errors do - resp = @aws.compute_client.describe_transit_gateway_multicast_domains({ transit_gateway_multicast_domain_ids: [opts[:transit_gateway_multicast_domain_id]] }) - @transit_gateway_multicast_domains = resp.transit_gateway_multicast_domains[0].to_h + resp = + @aws.compute_client.describe_transit_gateway_multicast_domains( + { + transit_gateway_multicast_domain_ids: [ + opts[:transit_gateway_multicast_domain_id] + ] + } + ) + @transit_gateway_multicast_domains = + resp.transit_gateway_multicast_domains[0].to_h create_resource_methods(@transit_gateway_multicast_domains) end end @@ -33,11 +45,16 @@ def transit_gateway_multicast_domain_id end def exists? - !@transit_gateway_multicast_domains.nil? && !@transit_gateway_multicast_domains.empty? + !@transit_gateway_multicast_domains.nil? && + !@transit_gateway_multicast_domains.empty? end def resource_id - @transit_gateway_multicast_domains ? @transit_gateway_multicast_domains[:transit_gateway_multicast_domain_id] : @display_name + if @transit_gateway_multicast_domains + @transit_gateway_multicast_domains[:transit_gateway_multicast_domain_id] + else + @display_name + end end def to_s diff --git a/libraries/aws_transit_gateway_multicast_domain_association.rb b/libraries/aws_transit_gateway_multicast_domain_association.rb index f33e5c5ea..be56271f9 100644 --- a/libraries/aws_transit_gateway_multicast_domain_association.rb +++ b/libraries/aws_transit_gateway_multicast_domain_association.rb @@ -17,11 +17,22 @@ class AWSTransitGatewayMulticastDomainAssociation < AwsResourceBase def initialize(opts = {}) super(opts) validate_parameters(required: [:transit_gateway_multicast_domain_id]) - raise ArgumentError, "#{@__resource_name__}: transit_gateway_multicast_domain_id must be provided" unless opts[:transit_gateway_multicast_domain_id] && !opts[:transit_gateway_multicast_domain_id].empty? + unless opts[:transit_gateway_multicast_domain_id] && + !opts[:transit_gateway_multicast_domain_id].empty? + raise ArgumentError, + "#{@__resource_name__}: transit_gateway_multicast_domain_id must be provided" + end @display_name = opts[:transit_gateway_multicast_domain_id] catch_aws_errors do - resp = @aws.compute_client.get_transit_gateway_multicast_domain_associations({ transit_gateway_multicast_domain_id: opts[:transit_gateway_multicast_domain_id] }) - @multicast_domain_associations = resp.multicast_domain_associations[0].to_h + resp = + @aws.compute_client.get_transit_gateway_multicast_domain_associations( + { + transit_gateway_multicast_domain_id: + opts[:transit_gateway_multicast_domain_id] + } + ) + @multicast_domain_associations = + resp.multicast_domain_associations[0].to_h create_resource_methods(@multicast_domain_associations) end end @@ -32,11 +43,16 @@ def transit_gateway_multicast_domain_id end def exists? - !@multicast_domain_associations.nil? && !@multicast_domain_associations.empty? + !@multicast_domain_associations.nil? && + !@multicast_domain_associations.empty? end def resource_id - @multicast_domain_associations ? @multicast_domain_associations[:transit_gateway_multicast_domain_id] : @display_name + if @multicast_domain_associations + @multicast_domain_associations[:transit_gateway_multicast_domain_id] + else + @display_name + end end def to_s diff --git a/libraries/aws_transit_gateway_multicast_group_member.rb b/libraries/aws_transit_gateway_multicast_group_member.rb index 7e0121d1a..7e956c892 100644 --- a/libraries/aws_transit_gateway_multicast_group_member.rb +++ b/libraries/aws_transit_gateway_multicast_group_member.rb @@ -18,10 +18,20 @@ def initialize(opts = {}) opts = { transit_gateway_multicast_domain_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:transit_gateway_multicast_domain_id]) - raise ArgumentError, "#{@__resource_name__}: transit_gateway_multicast_domain_id must be provided" unless opts[:transit_gateway_multicast_domain_id] && !opts[:transit_gateway_multicast_domain_id].empty? + unless opts[:transit_gateway_multicast_domain_id] && + !opts[:transit_gateway_multicast_domain_id].empty? + raise ArgumentError, + "#{@__resource_name__}: transit_gateway_multicast_domain_id must be provided" + end @display_name = opts[:transit_gateway_multicast_domain_id] catch_aws_errors do - resp = @aws.compute_client.search_transit_gateway_multicast_groups({ transit_gateway_multicast_domain_id: opts[:transit_gateway_multicast_domain_id] }) + resp = + @aws.compute_client.search_transit_gateway_multicast_groups( + { + transit_gateway_multicast_domain_id: + opts[:transit_gateway_multicast_domain_id] + } + ) @multicast_groups = resp.multicast_groups[0].to_h create_resource_methods(@multicast_groups) end @@ -37,7 +47,11 @@ def exists? end def resource_id - @multicast_groups ? @multicast_groups[:transit_gateway_multicast_domain_id] : @display_name + if @multicast_groups + @multicast_groups[:transit_gateway_multicast_domain_id] + else + @display_name + end end def to_s diff --git a/libraries/aws_transit_gateway_multicast_group_source.rb b/libraries/aws_transit_gateway_multicast_group_source.rb index 3a6c23e04..60b7fc49d 100644 --- a/libraries/aws_transit_gateway_multicast_group_source.rb +++ b/libraries/aws_transit_gateway_multicast_group_source.rb @@ -18,10 +18,20 @@ def initialize(opts = {}) opts = { transit_gateway_multicast_domain_id: opts } if opts.is_a?(String) super(opts) validate_parameters(required: [:transit_gateway_multicast_domain_id]) - raise ArgumentError, "#{@__resource_name__}: transit_gateway_multicast_domain_id must be provided" unless opts[:transit_gateway_multicast_domain_id] && !opts[:transit_gateway_multicast_domain_id].empty? + unless opts[:transit_gateway_multicast_domain_id] && + !opts[:transit_gateway_multicast_domain_id].empty? + raise ArgumentError, + "#{@__resource_name__}: transit_gateway_multicast_domain_id must be provided" + end @display_name = opts[:transit_gateway_multicast_domain_id] catch_aws_errors do - resp = @aws.compute_client.search_transit_gateway_multicast_groups({ transit_gateway_multicast_domain_id: opts[:transit_gateway_multicast_domain_id] }) + resp = + @aws.compute_client.search_transit_gateway_multicast_groups( + { + transit_gateway_multicast_domain_id: + opts[:transit_gateway_multicast_domain_id] + } + ) @multicast_groups = resp.multicast_groups[0].to_h create_resource_methods(@multicast_groups) end @@ -37,7 +47,11 @@ def exists? end def resource_id - @multicast_groups ? @multicast_groups[:transit_gateway_multicast_domain_id] : @display_name + if @multicast_groups + @multicast_groups[:transit_gateway_multicast_domain_id] + else + @display_name + end end def to_s diff --git a/libraries/aws_waf_byte_match_set.rb b/libraries/aws_waf_byte_match_set.rb index ff02f7968..5ca8299d0 100644 --- a/libraries/aws_waf_byte_match_set.rb +++ b/libraries/aws_waf_byte_match_set.rb @@ -13,11 +13,17 @@ class AWSWAFByteMatchSet < AwsResourceBase 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? + validate_parameters(required: %i[byte_match_set_id]) + unless opts[:byte_match_set_id] && !opts[:byte_match_set_id].empty? + raise ArgumentError, + "#{@__resource_name__}: byte_match_set_id must be provided" + end @display_name = opts[:byte_match_set_id] catch_aws_errors do - resp = @aws.waf_client.get_byte_match_set({ byte_match_set_id: opts[:byte_match_set_id] }) + resp = + @aws.waf_client.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 diff --git a/libraries/aws_waf_ip_set.rb b/libraries/aws_waf_ip_set.rb index f652062e1..5de550afd 100644 --- a/libraries/aws_waf_ip_set.rb +++ b/libraries/aws_waf_ip_set.rb @@ -13,8 +13,10 @@ class AWSWAFIPSet < AwsResourceBase 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? + validate_parameters(required: %i[ip_set_id]) + unless opts[:ip_set_id] && !opts[:ip_set_id].empty? + raise ArgumentError, "#{@__resource_name__}: ip_set_id must be provided" + end @display_name = opts[:ip_set_id] catch_aws_errors do resp = @aws.waf_client.get_ip_set({ ip_set_id: opts[:ip_set_id] }) diff --git a/libraries/aws_waf_rule.rb b/libraries/aws_waf_rule.rb index 66d8599fd..954914961 100644 --- a/libraries/aws_waf_rule.rb +++ b/libraries/aws_waf_rule.rb @@ -13,8 +13,10 @@ class AWSWAFRule < AwsResourceBase 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? + validate_parameters(required: %i[rule_id]) + unless opts[:rule_id] && !opts[:rule_id].empty? + raise ArgumentError, "#{@__resource_name__}: rule_id must be provided" + end @display_name = opts[:rule_id] catch_aws_errors do resp = @aws.waf_client.get_rule({ rule_id: opts[:rule_id] }) diff --git a/libraries/aws_waf_size_constraint_set.rb b/libraries/aws_waf_size_constraint_set.rb index cd7a22327..7d34fc609 100644 --- a/libraries/aws_waf_size_constraint_set.rb +++ b/libraries/aws_waf_size_constraint_set.rb @@ -13,11 +13,18 @@ class AWSWAFSizeConstraintSet < AwsResourceBase 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? + validate_parameters(required: %i[size_constraint_set_id]) + unless opts[:size_constraint_set_id] && + !opts[:size_constraint_set_id].empty? + raise ArgumentError, + "#{@__resource_name__}: size_constraint_set_id must be provided" + end @display_name = opts[:size_constraint_set_id] catch_aws_errors do - resp = @aws.waf_client.get_size_constraint_set({ size_constraint_set_id: opts[:size_constraint_set_id] }) + resp = + @aws.waf_client.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 diff --git a/libraries/aws_waf_sql_injection_match_set.rb b/libraries/aws_waf_sql_injection_match_set.rb index 40adc2f32..4eaba1380 100644 --- a/libraries/aws_waf_sql_injection_match_set.rb +++ b/libraries/aws_waf_sql_injection_match_set.rb @@ -13,11 +13,18 @@ class AWSWAFSQLInjectionMatchSet < AwsResourceBase def initialize(opts = {}) opts = { sql_injection_match_set_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(sql_injection_match_set_id)) - raise ArgumentError, "#{@__resource_name__}: sql_injection_match_set_id must be provided" unless opts[:sql_injection_match_set_id] && !opts[:sql_injection_match_set_id].empty? + validate_parameters(required: %i[sql_injection_match_set_id]) + unless opts[:sql_injection_match_set_id] && + !opts[:sql_injection_match_set_id].empty? + raise ArgumentError, + "#{@__resource_name__}: sql_injection_match_set_id must be provided" + end @display_name = opts[:sql_injection_match_set_id] catch_aws_errors do - resp = @aws.waf_client.get_sql_injection_match_set({ sql_injection_match_set_id: opts[:sql_injection_match_set_id] }) + resp = + @aws.waf_client.get_sql_injection_match_set( + { sql_injection_match_set_id: opts[:sql_injection_match_set_id] } + ) @resp = resp.sql_injection_match_set.to_h create_resource_methods(@resp) end diff --git a/libraries/aws_waf_web_acl.rb b/libraries/aws_waf_web_acl.rb index 789165a24..3d700264f 100644 --- a/libraries/aws_waf_web_acl.rb +++ b/libraries/aws_waf_web_acl.rb @@ -13,8 +13,10 @@ class AWSWAFWebACL < AwsResourceBase def initialize(opts = {}) opts = { web_acl_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(web_acl_id)) - raise ArgumentError, "#{@__resource_name__}: web_acl_id must be provided" unless opts[:web_acl_id] && !opts[:web_acl_id].empty? + validate_parameters(required: %i[web_acl_id]) + unless opts[:web_acl_id] && !opts[:web_acl_id].empty? + raise ArgumentError, "#{@__resource_name__}: web_acl_id must be provided" + end @display_name = opts[:web_acl_id] catch_aws_errors do resp = @aws.waf_client.get_web_acl({ web_acl_id: opts[:web_acl_id] }) diff --git a/libraries/aws_waf_xss_match_set.rb b/libraries/aws_waf_xss_match_set.rb index 4c1d7964f..7eb4a63a4 100644 --- a/libraries/aws_waf_xss_match_set.rb +++ b/libraries/aws_waf_xss_match_set.rb @@ -13,11 +13,17 @@ class AWSWAFXSSMatchSet < AwsResourceBase def initialize(opts = {}) opts = { xss_match_set_id: opts } if opts.is_a?(String) super(opts) - validate_parameters(required: %i(xss_match_set_id)) - raise ArgumentError, "#{@__resource_name__}: xss_match_set_id must be provided" unless opts[:xss_match_set_id] && !opts[:xss_match_set_id].empty? + validate_parameters(required: %i[xss_match_set_id]) + unless opts[:xss_match_set_id] && !opts[:xss_match_set_id].empty? + raise ArgumentError, + "#{@__resource_name__}: xss_match_set_id must be provided" + end @display_name = opts[:xss_match_set_id] catch_aws_errors do - resp = @aws.waf_client.get_xss_match_set({ xss_match_set_id: opts[:xss_match_set_id] }) + resp = + @aws.waf_client.get_xss_match_set( + { xss_match_set_id: opts[:xss_match_set_id] } + ) @resp = resp.xss_match_set.to_h create_resource_methods(@resp) end