mist_aws 0.1.0 → 0.1.9

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: ecbfb2c243c78f6e0b31be95db7ba6f10abe271f
4
- data.tar.gz: 8f10d71ae5f7c1ae0a29aec510bbeea1d8506c65
3
+ metadata.gz: b9419905aff1664dee2756b700fe04fd7225424f
4
+ data.tar.gz: dcb97d1e1a911fcc97972857b27e2a7ec52a010b
5
5
  SHA512:
6
- metadata.gz: 7137a1ecf189cecbf4ee81b43a263ecf97db5798e4e096f3b319b9706357bca2e417f40eb6259ceac0ddc2d33696e3405a745757d7a6c5765263b01404ad20dc
7
- data.tar.gz: 40ac0d83153c646e93cce36f9a23c223eccf373fa65f6c3f27011fdfc997de034a801589c1408abad43a260948bf5c87aa3ae01089b61cb22921b4eddcdcec78
6
+ metadata.gz: df24fcd6de9bbe28917e0e695404e27435f09b6257d2e3f43d368b7f1767269ab4b2980123202eb9ab68b7f914e0cc1c2ae2fa72d3cc2e758e80a95eb06b4d7a
7
+ data.tar.gz: c836a04cb7fdb8e959ac63068058bd306941cd1dac9112f6ce96d9e6105fd467b997c5ac479ac17ac21398d5900c1f29150eff343f75a2abd511c2162685607e
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Uses the [ruby aws-sdk v2](https://github.com/aws/aws-sdk-core-ruby) [Resource Interface](https://github.com/aws/aws-sdk-core-ruby#resource-interfaces) to create some use specific higher level functionality.
4
4
 
5
- > NOTE: Currently the only object implemented is IAM for creating / deleting instance roles
5
+ > NOTE: Currently the only object implemented is Iam for creating / deleting instance roles and an Ec2 for working with Security Groups
6
6
 
7
7
 
8
8
  ## Installation
@@ -47,6 +47,8 @@ mist_aws = ::MistAws::Iam.new(profile_name: "my_profile_name", region: "us-east-
47
47
  role = mist_aws.create_iam_role(role_name, role_policy_name, role_policy_document, instance_profile_name)
48
48
  ```
49
49
 
50
+ See yard docs for more info.
51
+
50
52
  ## Contributing
51
53
 
52
54
  I would be very interested in feedback on things that could be done
@@ -0,0 +1,86 @@
1
+ require 'aws-sdk'
2
+ require 'logger'
3
+
4
+ module MistAws
5
+ class Ec2
6
+
7
+ # These are read-only accessor and are initializeds by initialize method
8
+ attr_reader :profile_name
9
+ attr_reader :credentials
10
+ attr_reader :region
11
+ attr_reader :logger
12
+ attr_reader :iam
13
+ attr_reader :ec2_client
14
+ attr_reader :ec2
15
+
16
+ def initialize(opts={})
17
+ # Ruby 1.9 backwards compatability
18
+ opts = {profile_name: nil, region: nil, logger: ::Logger.new(STDERR)}.merge(opts)
19
+ opts.each do |key, value|
20
+ instance_variable_set "@#{key}", value
21
+ end
22
+
23
+ @iam = Iam.new(opts)
24
+ @ec2_client = Aws::EC2::Client.new(credentials: @iam.credentials, region: @iam.region)
25
+ @ec2 = Aws::EC2::Resource.new(client: @ec2_client)
26
+
27
+ end
28
+
29
+ def get_security_group(group_name, vpc_id)
30
+ ec2_client.describe_security_groups(filters: [{ name: "vpc-id", values: [vpc_id]}]).security_groups.detect { |g| g.group_name == group_name }
31
+ end
32
+
33
+ def get_security_group_id(group_name, vpc_id)
34
+ if (group = get_security_group(group_name, vpc_id))
35
+ group.group_id
36
+ else
37
+ nil
38
+ end
39
+ end
40
+
41
+ def security_group_exists?(group_name, vpc_id)
42
+ get_security_group(group_name, vpc_id)
43
+ end
44
+
45
+ def delete_security_group(group_name, vpc_id)
46
+ group_id = get_security_group_id(group_name, vpc_id)
47
+ ec2_client.delete_security_group(group_id: group_id) if group_id
48
+ end
49
+
50
+ def create_security_group(group_name, vpc_id, description=group_name)
51
+ begin
52
+ ec2_client.create_security_group(group_name: group_name, vpc_id: vpc_id, description: description)
53
+ rescue Aws::EC2::Errors::InvalidGroupDuplicate
54
+ end
55
+ # Seem to need to fetch it to get a valid security group struct
56
+ get_security_group(group_name, vpc_id)
57
+ end
58
+
59
+ # Note the keys for opts must be strings not symbols
60
+ def authorize_security_group_ingress(opts={})
61
+ begin
62
+ ec2_client.authorize_security_group_ingress(opts)
63
+ rescue Aws::EC2::Errors::InvalidPermissionDuplicate
64
+ end
65
+ end
66
+
67
+ def create_vpc(cdr_block)
68
+ result = ec2_client.describe_vpcs(filters: [{ name: "cidr", values: [cdr_block]}])
69
+ if result.vpcs == []
70
+ ec2_client.create_vpc(cidr_block: cdr_block).vpc
71
+ else
72
+ result.vpcs.first
73
+ end
74
+ end
75
+
76
+ def delete_vpc(vpc_id)
77
+ begin
78
+ ec2_client.delete_vpc(vpc_id: vpc_id)
79
+ rescue Aws::EC2::Errors::InvalidVpcIDNotFound
80
+ nil
81
+ end
82
+ end
83
+
84
+ end
85
+ end
86
+
@@ -1,3 +1,3 @@
1
1
  module MistAws
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.9"
3
3
  end
data/lib/mist_aws.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "mist_aws/version"
2
2
  require "mist_aws/iam"
3
+ require "mist_aws/ec2"
3
4
 
4
5
  module MistAws
5
6
  # Your code goes here...
data/mist_aws.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = MistAws::VERSION
9
9
  spec.authors = ["Robert J. Berger"]
10
10
  spec.email = ["rberger@mistsys.com"]
11
- spec.summary = %q{Wrapper around aws-sdk for higher level use}
12
- spec.description = %q{Wrapper around aws-sdk for higher level use. So far only supports IAM Role create/delete}
11
+ spec.summary = %q{Wrapper around aws-sdk V2 for higher level use}
12
+ spec.description = %q{Wrapper around aws-sdk V2 Resource api for higher level use. So far only supports IAM Role create/delete}
13
13
  spec.homepage = "https://github.com/mistsys/mist_aws"
14
14
  spec.license = "MIT"
15
15
 
@@ -0,0 +1,66 @@
1
+ # These tests actually hit AWS and are not mocked
2
+
3
+ require 'spec_helper'
4
+ require 'json'
5
+
6
+ include MistAws
7
+
8
+ describe "Live tests on AWS (not mocked)" do
9
+ describe Ec2 do
10
+ PRE = "trsh_#{ENV['USER']}"
11
+ let(:profile_name) { 'mistsys' }
12
+ let(:region) { 'us-east-1' }
13
+ let(:cdr_block) { "192.168.99.0/24" }
14
+ let(:test_group) { "#{PRE}_test_group" }
15
+ let(:credentials) { ::Aws::SharedCredentials.new(profile_name: profile_name) }
16
+ let(:ec2_client) { ::Aws::EC2::Client.new(credentials: credentials, region: region) }
17
+ let(:my_mist_aws) { ::MistAws::Ec2.new(profile_name: profile_name, region: region) }
18
+ let!(:vpc) { my_mist_aws.create_vpc(cdr_block) }
19
+ let!(:vpc_id) { vpc.vpc_id }
20
+
21
+ it 'has a version number' do
22
+ expect(MistAws::VERSION).not_to be nil
23
+ end
24
+
25
+ describe '#security_group_exists?' do
26
+ before(:each) do
27
+ my_mist_aws.delete_security_group(test_group, vpc_id)
28
+ end
29
+
30
+ after(:each) do
31
+ my_mist_aws.delete_security_group(test_group, vpc_id)
32
+ end
33
+
34
+ it 'is falsy when it does not exist' do
35
+ expect(my_mist_aws.security_group_exists?(test_group, vpc_id)).to be_falsy
36
+ end
37
+
38
+ it 'is truthy when it does exist' do
39
+ my_mist_aws.create_security_group(test_group, vpc_id)
40
+ expect(my_mist_aws.security_group_exists?(test_group, vpc_id)).to be_truthy
41
+ end
42
+ end
43
+
44
+ describe '#authorize_security_group_ingress' do
45
+ let (:my_security_group) { my_mist_aws.create_security_group(test_group, vpc_id) }
46
+ let (:my_security_group_id) { my_security_group.group_id }
47
+
48
+ after(:each) do
49
+ my_mist_aws.delete_security_group(test_group, vpc_id)
50
+ end
51
+
52
+ it 'should not blow up' do
53
+ opts = {
54
+ group_id: my_security_group_id,
55
+ ip_protocol: "tcp",
56
+ from_port: 22,
57
+ to_port: 22,
58
+ cidr_ip: "0.0.0.0/0"
59
+ }
60
+ expect {
61
+ my_mist_aws.authorize_security_group_ingress(opts)
62
+ }.not_to raise_error
63
+ end
64
+ end
65
+ end
66
+ end
@@ -7,7 +7,7 @@ include MistAws
7
7
 
8
8
  describe "Live tests on AWS (not mocked)" do
9
9
  describe Iam do
10
- PRE = "trsh"
10
+ PRE = "trsh_#{ENV['USER']}"
11
11
  let(:profile_name) { 'mistsys' }
12
12
  let(:region) { 'us-east-1' }
13
13
  let(:role_name) { "#{PRE}_my_role" }
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mist_aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert J. Berger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-14 00:00:00.000000000 Z
11
+ date: 2014-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,8 +122,8 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
- description: Wrapper around aws-sdk for higher level use. So far only supports IAM
126
- Role create/delete
125
+ description: Wrapper around aws-sdk V2 Resource api for higher level use. So far only
126
+ supports IAM Role create/delete
127
127
  email:
128
128
  - rberger@mistsys.com
129
129
  executables: []
@@ -138,12 +138,14 @@ files:
138
138
  - README.md
139
139
  - Rakefile
140
140
  - lib/mist_aws.rb
141
+ - lib/mist_aws/ec2.rb
141
142
  - lib/mist_aws/iam.rb
142
143
  - lib/mist_aws/version.rb
143
144
  - mist_aws.gemspec
144
- - spec/mist_aws_live_spec.rb
145
- - spec/mist_aws_spec.rb
146
- - spec/policy_document.txt
145
+ - spec/ec2/live_spec.rb
146
+ - spec/iam/live_spec.rb
147
+ - spec/iam/mocked_spec.rb
148
+ - spec/iam/policy_document.txt
147
149
  - spec/spec_helper.rb
148
150
  homepage: https://github.com/mistsys/mist_aws
149
151
  licenses:
@@ -165,13 +167,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
167
  version: '0'
166
168
  requirements: []
167
169
  rubyforge_project:
168
- rubygems_version: 2.2.2
170
+ rubygems_version: 2.4.3
169
171
  signing_key:
170
172
  specification_version: 4
171
- summary: Wrapper around aws-sdk for higher level use
173
+ summary: Wrapper around aws-sdk V2 for higher level use
172
174
  test_files:
173
- - spec/mist_aws_live_spec.rb
174
- - spec/mist_aws_spec.rb
175
- - spec/policy_document.txt
175
+ - spec/ec2/live_spec.rb
176
+ - spec/iam/live_spec.rb
177
+ - spec/iam/mocked_spec.rb
178
+ - spec/iam/policy_document.txt
176
179
  - spec/spec_helper.rb
177
180
  has_rdoc: