Sha256: fc8c7b4ce67bda325f544c85b350f48132993f4a3b8262504f5833f5e6b7e2e1

Contents?: true

Size: 1.75 KB

Versions: 37

Compression:

Stored size: 1.75 KB

Contents

class AwsSecurityGroups < Inspec.resource(1)
  name 'aws_security_groups'
  desc 'Verifies settings for AWS Security Groups in bulk'
  example <<-EOX
    # Verify that you have security groups defined
    describe aws_security_groups do
      it { should exist }
    end

    # Verify you have more than the default security group
    describe aws_security_groups do
      its('entries.count') { should be > 1 }
    end
EOX
  supports platform: 'aws'

  include AwsPluralResourceMixin

  # Underlying FilterTable implementation.
  filter = FilterTable.create
  filter.register_custom_matcher(:exists?) { |x| !x.entries.empty? }
  filter.register_column(:group_ids, field: :group_id)
  filter.install_filter_methods_on_resource(self, :table)

  def to_s
    'EC2 Security Groups'
  end

  private

  def validate_params(raw_criteria)
    unless raw_criteria.is_a? Hash
      raise 'Unrecognized criteria for fetching Security Groups. ' \
            "Use 'criteria: value' format."
    end

    # No criteria yet
    unless raw_criteria.empty?
      raise ArgumentError, 'aws_ec2_security_groups does not currently accept resource parameters.'
    end
    raw_criteria
  end

  def fetch_from_api
    @table = []
    backend = BackendFactory.create(inspec_runner)
    backend.describe_security_groups({}).security_groups.each do |sg_info|
      @table.push({
                    group_id: sg_info.group_id,
        group_name: sg_info.group_name,
        vpc_id: sg_info.vpc_id,
                  })
    end
  end

  class Backend
    class AwsClientApi < AwsBackendBase
      BackendFactory.set_default_backend self
      self.aws_client_class = Aws::EC2::Client

      def describe_security_groups(query)
        aws_service_client.describe_security_groups(query)
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
inspec-3.7.1 lib/resources/aws/aws_security_groups.rb
inspec-3.6.6 lib/resources/aws/aws_security_groups.rb
inspec-3.6.4 lib/resources/aws/aws_security_groups.rb
inspec-2.3.28 lib/resources/aws/aws_security_groups.rb
inspec-3.6.2 lib/resources/aws/aws_security_groups.rb
inspec-3.5.0 lib/resources/aws/aws_security_groups.rb
inspec-3.4.1 lib/resources/aws/aws_security_groups.rb
inspec-3.3.14 lib/resources/aws/aws_security_groups.rb
inspec-3.2.6 lib/resources/aws/aws_security_groups.rb
inspec-3.1.3 lib/resources/aws/aws_security_groups.rb
inspec-3.0.64 lib/resources/aws/aws_security_groups.rb
inspec-3.0.61 lib/resources/aws/aws_security_groups.rb
inspec-3.0.52 lib/resources/aws/aws_security_groups.rb
inspec-3.0.46 lib/resources/aws/aws_security_groups.rb
inspec-3.0.25 lib/resources/aws/aws_security_groups.rb
inspec-3.0.12 lib/resources/aws/aws_security_groups.rb
inspec-3.0.9 lib/resources/aws/aws_security_groups.rb
inspec-3.0.0 lib/resources/aws/aws_security_groups.rb
inspec-2.3.24 lib/resources/aws/aws_security_groups.rb
inspec-2.3.23 lib/resources/aws/aws_security_groups.rb