Module: HolePunch

Defined in:
lib/holepunch/logger.rb,
lib/holepunch.rb,
lib/holepunch/cli.rb,
lib/holepunch/dsl.rb,
lib/holepunch/ec2.rb,
lib/holepunch/version.rb,
lib/holepunch/definition.rb

Overview

Copyright © 2014 Undead Labs, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Defined Under Namespace

Modules: Logger Classes: BaseDSL, CLI, DSL, Definition, EC2, EnvNotDefinedError, GroupDSL, GroupDoesNotExistError, GroupError, HolePunchError, LoggerOutputStdio, Permission, SecurityGroup, SecurityGroupsFileError, SecurityGroupsFileNotFoundError, Service, ServiceDSL, ServiceDoesNotExistError

Constant Summary collapse

VERSION =
'1.3.0'

Class Method Summary collapse

Class Method Details

.apply(filename, env, opts = {}) ⇒ Object

Applies the given SecurityGroups file to EC2.

Parameters:

  • filename (String)

    the path to the SecurityGroups file

  • env (String, nil)

    the environment

  • opts (Hash) (defaults to: {})

    additional options

Options Hash (opts):

  • :aws_access_key_id (String)

    the AWS access key id

  • :aws_secret_access_key (String)

    the AWS secret access key

  • :aws_region (String)

    the AWS region



48
49
50
51
52
# File 'lib/holepunch.rb', line 48

def apply(filename, env, opts = {})
  definition = DSL.evaluate(filename, env)
  ec2 = EC2.new(opts)
  ec2.apply(definition)
end

.cidr?(value) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/holepunch.rb', line 100

def cidr?(value)
  value.to_s =~ /\d+\.\d+\.\d+\.\d+\/\d+/
end

.defined?(filename, env, groups) ⇒ Boolean

Tests if a list of security groups are all defined in the SecurityGroups file.

Parameters:

  • filename (String)

    the path to the SecurityGroups file

  • env (String, nil)

    the environment

  • groups (Array<String>)

    the list of security groups to check

Returns:

  • (Boolean)


60
61
62
63
64
65
# File 'lib/holepunch.rb', line 60

def defined?(filename, env, groups)
  definition = DSL.evaluate(filename, env)
  groups.all? do |group_id|
    definition.groups.include?(group_id)
  end
end

.read_file(file) ⇒ Object



105
106
107
108
109
# File 'lib/holepunch.rb', line 105

def read_file(file)
  content = File.open(file, 'rb') do |io|
    io.read
  end
end

.select_undefined(filename, env, groups) ⇒ Object

Checks a list of security groups against the SecurityGroups file and returns an array of the groups that are undefined.

Parameters:

  • filename (String)

    the path to the SecurityGroups file

  • env (String, nil)

    the environment

  • groups (Array<String>)

    the list of security groups to check



73
74
75
76
77
78
# File 'lib/holepunch.rb', line 73

def select_undefined(filename, env, groups)
  definition = DSL.evaluate(filename, env)
  groups.reject do |group_id|
    definition.groups.include?(group_id)
  end
end

.service_groups(filename, env, name) ⇒ Array<String>

Examines the given SecurityGroups file for the given service and returns a list of the security groups that make up that service.

Parameters:

  • filename (String)

    the path to the SecurityGroups file

  • env (String, nil)

    the environment

  • name (String)

    the name of the service to query

Returns:

  • (Array<String>)

    the list of security group names

Raises:



88
89
90
91
92
93
# File 'lib/holepunch.rb', line 88

def service_groups(filename, env, name)
  definition = DSL.evaluate(filename, env)
  service = definition.services[name]
  raise ServiceDoesNotExistError, "service '#{name}' not found" if service.nil?
  service.groups
end