Sha256: c556d5e0ca93101e7d46f0c88547594b69a729cf208d037f31c1bba7892614ba

Contents?: true

Size: 1.91 KB

Versions: 7

Compression:

Stored size: 1.91 KB

Contents

module EC2
  class SecurityGroup
    attr_accessor :security_group_id

    def initialize(ec2)
      @config = ec2.config
      @gateway = ec2.gateway
      group_name = @config.security_group_name
      description = @config.security_group_description
      vpc_id = @config.vpc_id
      @security_group = {
          group_name: group_name,
          description: description,
          vpc_id: vpc_id,
      }
      @authorize_egress = {
          ip_permissions: [
              {
                  ip_protocol: "tcp",
                  from_port: 22,
                  to_port: 22,
                  ip_ranges: [
                      {
                          cidr_ip: "0.0.0.0/0",
                      },
                  ],
              },
          ],
      }
      @authorize_ingress = {
          ip_permissions: [
              {
                  ip_protocol: "tcp",
                  from_port: 22,
                  to_port: 22,
                  ip_ranges: [
                      {
                          cidr_ip: "0.0.0.0/0",
                      },
                  ],
              },
              {
                  ip_protocol: "icmp",
                  from_port: -1,
                  to_port: -1,
                  ip_ranges: [
                      {
                          cidr_ip: "0.0.0.0/0",
                      },
                  ],
              },
          ],
      }
      @security_group_id = get_group_id
    end

    def create
      if @security_group_id.nil?
        id = @gateway.create_security_group(@security_group)
        @gateway.authorize_egress(id,@authorize_egress)
        @gateway.authorize_ingress(id,@authorize_ingress)
        @security_group_id = id
      end
    end

    def delete
      @gateway.delete_security_group(@security_group_id) unless @security_group_id.nil?
    end

    private
    def get_group_id
      @gateway.get_group_id(@security_group)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
etude_for_aws-0.7.10 lib/etude_for_aws/ec2/security_group.rb
etude_for_aws-0.7.9 lib/etude_for_aws/ec2/security_group.rb
etude_for_aws-0.7.8 lib/etude_for_aws/ec2/security_group.rb
etude_for_aws-0.7.7 lib/etude_for_aws/ec2/security_group.rb
etude_for_aws-0.7.6 lib/etude_for_aws/ec2/security_group.rb
etude_for_aws-0.7.5 lib/etude_for_aws/ec2/security_group.rb
etude_for_aws-0.7.4 lib/etude_for_aws/ec2/security_group.rb