holepunch 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee112b10944d69873e6fcf50a0b1536a5adfb88c
4
- data.tar.gz: f40ac7918db97e6fd64470b40358fe344d456380
3
+ metadata.gz: 835de8629ab48100eb2c3d3dd5e0ecb36b2df16a
4
+ data.tar.gz: b237f089c115c345dccb9fd76cd27c6cdc1b0608
5
5
  SHA512:
6
- metadata.gz: 4330a09b9e4e9fc291c3910395bb160bf97a94ba52404113eb6cee6386fe9a9ceadbfd60296c8f5e2efd83f389ae80978d1ec764afee411bc919447e3ae93764
7
- data.tar.gz: 828ad00eb16a838923cd72be646348ac4745bee98bdadd19d4faf7c07d5a5322db96edba8cfd06881b40755c7346ca81b41bd458b5dc7718264b56fb24ba2cab
6
+ metadata.gz: f46ed832177b63432c5c977be97fe14430f1b5f5bee5e795b8167de6f95397bd3ae45f044ddfa18066e016b19903b925c79161f351ddbf5bf160ef06fb848926
7
+ data.tar.gz: 537fb43dc6c40dc3b733ed5b8213031d4c9791c2e74c3897902d992aba074eead37c0a2d23a6b7b08d650ba52c63ec87c42196a9ef55cc5e5edad1f6be84828d
@@ -36,6 +36,47 @@ module HolePunch
36
36
  class ServiceDoesNotExistError < HolePunchError; end
37
37
 
38
38
  class << self
39
+ # Applies the given SecurityGroups file to EC2.
40
+ #
41
+ # @param filename [String] the path to the SecurityGroups file
42
+ # @param env [String, nil] the environment
43
+ # @param opts [Hash] additional options
44
+ #
45
+ # @option opts [String] :aws_access_key_id the AWS access key id
46
+ # @option opts [String] :aws_secret_access_key the AWS secret access key
47
+ # @option opts [String] :aws_region the AWS region
48
+ def apply(filename, env, opts = {})
49
+ definition = Definition.build(filename, env)
50
+ ec2 = EC2.new(opts)
51
+ ec2.apply(definition)
52
+ end
53
+
54
+ # Tests if a list of security groups are all defined in the SecurityGroups
55
+ # file.
56
+ #
57
+ # @param filename [String] the path to the SecurityGroups file
58
+ # @param env [String, nil] the environment
59
+ # @param groups [Array<String>] the list of security groups to check
60
+ def defined?(filename, env, groups)
61
+ definition = Definition.build(filename, env)
62
+ groups.all? do |group_id|
63
+ definition.groups.include?(group_id)
64
+ end
65
+ end
66
+
67
+ # Checks a list of security groups against the SecurityGroups file and
68
+ # returns an array of the groups that are undefined.
69
+ #
70
+ # @param filename [String] the path to the SecurityGroups file
71
+ # @param env [String, nil] the environment
72
+ # @param groups [Array<String>] the list of security groups to check
73
+ def select_undefined(filename, env, groups)
74
+ definition = Definition.build(filename, env)
75
+ groups.reject do |group_id|
76
+ definition.groups.include?(group_id)
77
+ end
78
+ end
79
+
39
80
  # Examines the given SecurityGroups file for the given service and returns
40
81
  # a list of the security groups that make up that service.
41
82
  #
@@ -55,10 +96,12 @@ module HolePunch
55
96
  # private helpers
56
97
  #
57
98
 
99
+ # @private
58
100
  def cidr?(value)
59
101
  value.to_s =~ /\d+\.\d+\.\d+\.\d+\/\d+/
60
102
  end
61
103
 
104
+ # @private
62
105
  def read_file(file)
63
106
  content = File.open(file, 'rb') do |io|
64
107
  io.read
@@ -49,14 +49,11 @@ module HolePunch
49
49
  Logger.fatal("AWS Region not defined. Use --aws-region or AWS_REGION") if options[:'aws-region'].nil?
50
50
  Logger.verbose = options[:verbose]
51
51
 
52
- definition = Definition.build(options[:file], options[:env])
53
- ec2 = EC2.new({
54
- access_key_id: options[:'aws-access-key'],
55
- secret_access_key: options[:'aws-secret-access-key'],
56
- region: options[:'aws-region'],
52
+ HolePunch.apply(options[:file], options[:env], {
53
+ aws_access_key_id: options[:'aws-access-key'],
54
+ aws_secret_access_key: options[:'aws-secret-access-key'],
55
+ aws_region: options[:'aws-region'],
57
56
  })
58
- ec2.apply(definition)
59
-
60
57
  rescue EnvNotDefinedError => e
61
58
  Logger.fatal('You have security groups that use an environment, but you did not specify one. See --help')
62
59
  rescue HolePunchError => e
@@ -27,24 +27,22 @@ module HolePunch
27
27
 
28
28
  def initialize(opts = {})
29
29
  opts = {
30
- access_key_id: ENV['AWS_ACCESS_KEY_ID'],
31
- secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
32
- region: ENV['AWS_REGION'],
30
+ aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
31
+ aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
32
+ aws_region: ENV['AWS_REGION'],
33
33
  }.merge(opts)
34
34
 
35
- AWS.config(opts)
35
+ AWS.config({
36
+ access_key_id: opts[:aws_access_key_id],
37
+ secret_access_key: opts[:aws_secret_access_key],
38
+ region: opts[:aws_region],
39
+ })
36
40
 
37
41
  @ec2 = AWS::EC2.new
38
- @region = @ec2.regions[opts[:region]]
42
+ @region = @ec2.regions[opts[:aws_region]]
39
43
  end
40
44
 
41
45
  def apply(definition)
42
- if definition.env.nil?
43
- Logger.log("Creating security groups in '#{@region.name}' region")
44
- else
45
- Logger.log("Creating security groups for '#{definition.env}' environment in '#{@region.name}' region")
46
- end
47
-
48
46
  # get the security group data from the AWS servers
49
47
  fetch!
50
48
 
@@ -19,5 +19,5 @@
19
19
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
20
  #
21
21
  module HolePunch
22
- VERSION = '1.1.0'
22
+ VERSION = '1.2.0'
23
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: holepunch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Scott
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-01 00:00:00.000000000 Z
12
+ date: 2014-07-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -163,6 +163,7 @@ description: |
163
163
  group 'my-service' do
164
164
  ping '10.0.0.0/16'
165
165
  end
166
+ ```
166
167
 
167
168
  It can be useful to describe groups of security groups you plan to launch
168
169
  instances with by using the `service` declaration.