Class: Jets::CLI::Waf::Info

Inherits:
Base show all
Includes:
AwsServices
Defined in:
lib/jets/cli/waf/info.rb

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods included from AwsServices

#apigateway, #aws_options, #cfn, #codebuild, #dynamodb, #lambda_client, #logs, #s3, #s3_resource, #sns, #sqs, #ssm, #sts, #wafv2

Methods included from AwsServices::StackStatus

#output_value, #stack_exists?

Methods included from AwsServices::GlobalMemoist

included, #reset_cache!

Methods inherited from Base

#stack_name

Methods inherited from Base

#initialize, #paginate, #paging_params, rescue_api_error

Methods included from Util::Logging

#log

Methods included from Api

#api, #api_key

Constructor Details

This class inherits a constructor from Jets::CLI::Base

Instance Method Details

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jets/cli/waf/info.rb', line 9

def run
  ENV["AWS_REGION"] = "us-east-1" # wafv2 only works in us-east-1

  web_acl_summary = web_acl_summaries.find do |i|
    web_acl_name == i.name
  end

  unless web_acl_summary
    puts "Web ACL not found: #{web_acl_name}"
    return
  end

  resp = wafv2.get_web_acl(
    id: web_acl_summary.id,
    name: web_acl_summary.name,
    scope: "CLOUDFRONT"
  )
  web_acl = resp.web_acl
  present(web_acl)
end

#web_acl_nameObject



5
6
7
# File 'lib/jets/cli/waf/info.rb', line 5

def web_acl_name
  @options[:name] || Jets::CLI::Waf.waf_name
end

#web_acl_summariesObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jets/cli/waf/info.rb', line 30

def web_acl_summaries
  Enumerator.new do |y|
    next_token = :start
    while next_token
      params = {}
      params[:next_token] = next_token if next_token && next_token != :start
      params[:scope] = "CLOUDFRONT"
      resp = wafv2.list_web_acls(params)
      y.yield resp.web_acls # acl summaries
      # Looks like if there's only 1 page next_token is not even availablel
      break unless resp.respond_to?(:next_token)
      next_token = resp.next_token
    end
  end.lazy.flat_map { |i| i }
end