Module: Cumulus::SecurityGroups::Loader
- Includes:
- Common::BaseLoader
- Defined in:
- lib/security/loader/Loader.rb
Overview
Public: Load Security Group assets
Constant Summary collapse
- @@groups_dir =
Configuration.instance.security.groups_directory
- @@rules_dir =
Configuration.instance.security.rules_directory
- @@subnet_files =
Configuration.instance.security.subnet_files
Class Method Summary collapse
-
.groups ⇒ Object
Public: Load all the security group configurations as SecurityGroupConfig objects.
-
.rule(rule_name) ⇒ Object
Public: Load a single static rule.
-
.subnet_group(name) ⇒ Object
Public: Get the local definition of a subnet group.
Methods included from Common::BaseLoader
load_file, resource, resources, template
Class Method Details
.groups ⇒ Object
Public: Load all the security group configurations as SecurityGroupConfig objects
Returns an array of SecurityGroupConfig
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/security/loader/Loader.rb', line 20 def Loader.groups # List all the directories to load groups from each vpc vpc_dirs = Dir.entries(@@groups_dir).reject { |f| f == "." or f == ".."}.select { |f| File.directory?(File.join(@@groups_dir, f)) } vpc_groups = vpc_dirs.map do |d| aws_vpc = EC2::named_vpcs[d] if aws_vpc.nil? puts Colors.red("No VPC named #{d} exists") exit StatusCodes::EXCEPTION end Common::BaseLoader.resources(File.join(@@groups_dir, d)) do |file_name, json| name = "#{aws_vpc.name}/#{file_name}" SecurityGroupConfig.new(name, aws_vpc.vpc_id, json) end end.flatten non_vpc_groups = Common::BaseLoader.resources(@@groups_dir) do |file_name, json| SecurityGroupConfig.new(file_name, nil, json) end if !EC2::supports_ec2_classic and !non_vpc_groups.empty? puts "Ignoring Non-VPC Security Groups because your account does not support them" non_vpc_groups = [] end vpc_groups + non_vpc_groups end |
.rule(rule_name) ⇒ Object
Public: Load a single static rule
Returns the static rule as json
53 54 55 |
# File 'lib/security/loader/Loader.rb', line 53 def Loader.rule(rule_name) Common::BaseLoader.resource(rule_name, @@rules_dir) { |_, json| json } end |
.subnet_group(name) ⇒ Object
Public: Get the local definition of a subnet group.
name - the name of the subnet group to get
Returns an array of ip addresses that is empty if there is no subnet group with that name
62 63 64 65 66 67 68 |
# File 'lib/security/loader/Loader.rb', line 62 def Loader.subnet_group(name) if self.subnet_groups[name].nil? raise "Could not find subnet #{name}" else self.subnet_groups[name] end end |