holepunch 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 835de8629ab48100eb2c3d3dd5e0ecb36b2df16a
4
- data.tar.gz: b237f089c115c345dccb9fd76cd27c6cdc1b0608
3
+ metadata.gz: 8a08441876887342e6570fd07d22796ca946409b
4
+ data.tar.gz: 2be013a42dbca64d9ee952082bb855846950292c
5
5
  SHA512:
6
- metadata.gz: f46ed832177b63432c5c977be97fe14430f1b5f5bee5e795b8167de6f95397bd3ae45f044ddfa18066e016b19903b925c79161f351ddbf5bf160ef06fb848926
7
- data.tar.gz: 537fb43dc6c40dc3b733ed5b8213031d4c9791c2e74c3897902d992aba074eead37c0a2d23a6b7b08d650ba52c63ec87c42196a9ef55cc5e5edad1f6be84828d
6
+ metadata.gz: f072b9211e176a12c861cf3e163e8d171392927a3238849108e8a906154a5a373f2dadd823abc34718fc2512229bdc7cecb22dc77d8dd82c0833b023be3c3557
7
+ data.tar.gz: 309dd74b73a0ad8ee8cf89c55c6b3d0c6e1a458dd9e1a72d84e634462ff4f5854f690a52080822d9684cfd52d04acbafd33360f7bb1cd7295cfd09129cd7ddfb
@@ -46,7 +46,7 @@ module HolePunch
46
46
  # @option opts [String] :aws_secret_access_key the AWS secret access key
47
47
  # @option opts [String] :aws_region the AWS region
48
48
  def apply(filename, env, opts = {})
49
- definition = Definition.build(filename, env)
49
+ definition = DSL.evaluate(filename, env)
50
50
  ec2 = EC2.new(opts)
51
51
  ec2.apply(definition)
52
52
  end
@@ -58,7 +58,7 @@ module HolePunch
58
58
  # @param env [String, nil] the environment
59
59
  # @param groups [Array<String>] the list of security groups to check
60
60
  def defined?(filename, env, groups)
61
- definition = Definition.build(filename, env)
61
+ definition = DSL.evaluate(filename, env)
62
62
  groups.all? do |group_id|
63
63
  definition.groups.include?(group_id)
64
64
  end
@@ -71,7 +71,7 @@ module HolePunch
71
71
  # @param env [String, nil] the environment
72
72
  # @param groups [Array<String>] the list of security groups to check
73
73
  def select_undefined(filename, env, groups)
74
- definition = Definition.build(filename, env)
74
+ definition = DSL.evaluate(filename, env)
75
75
  groups.reject do |group_id|
76
76
  definition.groups.include?(group_id)
77
77
  end
@@ -86,7 +86,7 @@ module HolePunch
86
86
  #
87
87
  # @return [Array<String>] the list of security group names
88
88
  def service_groups(filename, env, name)
89
- definition = Definition.build(filename, env)
89
+ definition = DSL.evaluate(filename, env)
90
90
  service = definition.services[name]
91
91
  raise ServiceDoesNotExistError, "service '#{name}' not found" if service.nil?
92
92
  service.groups
@@ -30,17 +30,19 @@ module HolePunch
30
30
 
31
31
  default_task :apply
32
32
 
33
- option :'aws-access-key', aliases: :A, type: :string, default: ENV['AWS_ACCESS_KEY_ID'], desc:
33
+ option :'aws-access-key', aliases: :A, type: :string, default: ENV['AWS_ACCESS_KEY_ID'], desc:
34
34
  'Your AWS Access Key ID'
35
- option :'aws-secret-access-key', aliases: :k, type: :string, default: ENV['AWS_SECRET_ACCESS_KEY'], desc:
35
+ option :'aws-secret-access-key', aliases: :k, type: :string, default: ENV['AWS_SECRET_ACCESS_KEY'], desc:
36
36
  'Your AWS API Secret Access Key'
37
- option :'aws-region', aliases: :r, type: :string, default: ENV['AWS_REGION'], desc:
37
+ option :'aws-region', aliases: :r, type: :string, default: ENV['AWS_REGION'], desc:
38
38
  'Your AWS region'
39
- option :env, aliases: :e, type: :string, desc:
39
+ option :'aws-vpc-id', aliases: :c, type: :string, desc:
40
+ 'Set the VPC ID (for VPC security groups)'
41
+ option :env, aliases: :e, type: :string, desc:
40
42
  'Set the environment'
41
- option :file, aliases: :f, type: :string, default: "#{Dir.pwd}/SecurityGroups", desc:
43
+ option :file, aliases: :f, type: :string, default: "#{Dir.pwd}/SecurityGroups", desc:
42
44
  'The location of the SecurityGroups file to use'
43
- option :verbose, aliases: :v, type: :boolean, desc:
45
+ option :verbose, aliases: :v, type: :boolean, desc:
44
46
  'Enable verbose output'
45
47
  desc 'apply [OPTIONS]', 'apply the defined security groups to ec2'
46
48
  def apply
@@ -53,6 +55,7 @@ module HolePunch
53
55
  aws_access_key_id: options[:'aws-access-key'],
54
56
  aws_secret_access_key: options[:'aws-secret-access-key'],
55
57
  aws_region: options[:'aws-region'],
58
+ aws_vpc_id: options[:'aws-vpc-id'],
56
59
  })
57
60
  rescue EnvNotDefinedError => e
58
61
  Logger.fatal('You have security groups that use an environment, but you did not specify one. See --help')
@@ -72,7 +75,7 @@ module HolePunch
72
75
  def service(name = nil)
73
76
  Logger.verbose = options[:verbose]
74
77
 
75
- definition = Definition.build(options[:file], options[:env])
78
+ definition = DSL.evaluate(options[:file], options[:env])
76
79
 
77
80
  if options[:list]
78
81
  definition.services.keys.sort.each do |name|
@@ -70,18 +70,7 @@ module HolePunch
70
70
  attr_reader :groups
71
71
  attr_reader :services
72
72
 
73
- class << self
74
- def build(file, env)
75
- filename = Pathname.new(file).expand_path
76
- unless filename.file?
77
- raise SecurityGroupsFileNotFoundError, "#{filename} not found"
78
- end
79
-
80
- DSL.evaluate(file, env)
81
- end
82
- end
83
-
84
- def initialize(env = nil)
73
+ def initialize(env)
85
74
  @env = env
86
75
  @groups = {}
87
76
  @services = {}
@@ -71,7 +71,7 @@ module HolePunch
71
71
 
72
72
  def icmp(*sources)
73
73
  sources << '0.0.0.0/0' if sources.empty?
74
- @model.ingresses << Permission.new(:icmp, nil, sources.flatten)
74
+ @model.ingresses << Permission.new(:icmp, 0, sources.flatten)
75
75
  end
76
76
  alias_method :ping, :icmp
77
77
 
@@ -88,6 +88,11 @@ module HolePunch
88
88
 
89
89
  class DSL < BaseDSL
90
90
  def self.evaluate(filename, env)
91
+ path = Pathname.new(filename).expand_path
92
+ unless path.file?
93
+ raise SecurityGroupsFileNotFoundError, "#{filename} not found"
94
+ end
95
+
91
96
  DSL.new(env).eval_dsl(filename)
92
97
  end
93
98
 
@@ -40,6 +40,7 @@ module HolePunch
40
40
 
41
41
  @ec2 = AWS::EC2.new
42
42
  @region = @ec2.regions[opts[:aws_region]]
43
+ @vpc_id = opts[:aws_vpc_id]
43
44
  end
44
45
 
45
46
  def apply(definition)
@@ -59,7 +60,7 @@ module HolePunch
59
60
  ec2_group = find(id)
60
61
  if ec2_group.nil?
61
62
  Logger.log(:create, id)
62
- ec2_group = create(id, group.desc)
63
+ ec2_group = create(id, group.desc, @vpc_id)
63
64
  end
64
65
  ec2_groups[id] = ec2_group
65
66
  end
@@ -82,7 +83,7 @@ module HolePunch
82
83
  end
83
84
  end
84
85
  unless revoke_sources.empty?
85
- Logger.log("revoke #{ec2_perm.protocol}", "#{id} #{sources_list_to_s(revoke_sources)}")
86
+ Logger.log("revoke #{ec2_perm.protocol}", "#{id} #{sources_list_to_s(revoke_sources)} #{ec2_perm.port_range}")
86
87
  ec2_group.revoke_ingress(ec2_perm.protocol, ec2_perm.port_range, *revoke_sources)
87
88
  end
88
89
  end
@@ -106,7 +107,7 @@ module HolePunch
106
107
  end
107
108
  end
108
109
  unless new_sources.empty?
109
- Logger.log(perm.type, "#{id} #{sources_list_to_s(new_sources)}")
110
+ Logger.log(perm.type, "#{id} #{sources_list_to_s(new_sources)} #{perm.ports}")
110
111
  ec2_group.authorize_ingress(perm.type, perm.ports, *new_sources)
111
112
  end
112
113
  end
@@ -116,11 +117,13 @@ module HolePunch
116
117
 
117
118
  private
118
119
  def fetch!
119
- @groups = @region.security_groups.to_a
120
+ @groups = @region.security_groups.to_a.keep_if do |region|
121
+ !@vpc_id == !region.vpc_id
122
+ end
120
123
  end
121
124
 
122
- def create(name, description)
123
- group = @region.security_groups.create(name, description: description)
125
+ def create(name, description, vpc)
126
+ group = @region.security_groups.create(name, description: description, vpc: vpc)
124
127
  @groups << group
125
128
  group
126
129
  end
@@ -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.2.0'
22
+ VERSION = '1.3.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.2.0
4
+ version: 1.3.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-08 00:00:00.000000000 Z
12
+ date: 2015-01-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor