superluminal 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gitignore +50 -0
- data/.rspec +1 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +116 -0
- data/LICENSE.txt +20 -0
- data/README.mdown +21 -0
- data/Rakefile +60 -0
- data/VERSION +1 -0
- data/bin/superluminal +40 -0
- data/example/superluminal.yaml +15 -0
- data/example/templates/s3/bucket.yaml +13 -0
- data/example/templates/s3/contents.yaml +12 -0
- data/lib/superluminal/iam.rb +55 -0
- data/lib/superluminal/s3.rb +27 -0
- data/lib/superluminal/settings.rb +17 -0
- data/lib/superluminal/vpc.rb +103 -0
- data/lib/superluminal.rb +4 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/superluminal_spec.rb +7 -0
- metadata +237 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c0b22a4f63bda3366d1974fcad9571163d7d2f40
|
4
|
+
data.tar.gz: 65c301144844b12009c7874fb5d6c671c4024cf4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4029e4220df72f3b1c2a5c28880e248573bb517a5797c08f4bb9fc93854a430d913a82e79235f3af90f48ea840a34de81dbd579c40d579efe7b89fa607061f74
|
7
|
+
data.tar.gz: 0d1b2f280b665c688fc5b799bc913921cd667d2a337ea01ff073a48b4fea3472c3cb481c2fc2417b74a78fdc29d9f4a8d1a953fd40246ef276cfedcbda316d3f
|
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
coverage.data
|
4
|
+
|
5
|
+
# rdoc generated
|
6
|
+
rdoc
|
7
|
+
|
8
|
+
# yard generated
|
9
|
+
doc
|
10
|
+
.yardoc
|
11
|
+
|
12
|
+
# bundler
|
13
|
+
.bundle
|
14
|
+
vendor
|
15
|
+
|
16
|
+
# jeweler generated
|
17
|
+
pkg
|
18
|
+
|
19
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
20
|
+
#
|
21
|
+
# * Create a file at ~/.gitignore
|
22
|
+
# * Include files you want ignored
|
23
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
24
|
+
#
|
25
|
+
# After doing this, these files will be ignored in all your git projects,
|
26
|
+
# saving you from having to 'pollute' every project you touch with them
|
27
|
+
#
|
28
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
29
|
+
#
|
30
|
+
# For MacOS:
|
31
|
+
#
|
32
|
+
#.DS_Store
|
33
|
+
|
34
|
+
# For TextMate
|
35
|
+
#*.tmproj
|
36
|
+
#tmtags
|
37
|
+
|
38
|
+
# For emacs:
|
39
|
+
#*~
|
40
|
+
#\#*
|
41
|
+
#.\#*
|
42
|
+
|
43
|
+
# For vim:
|
44
|
+
#*.swp
|
45
|
+
|
46
|
+
# For redcar:
|
47
|
+
#.redcar
|
48
|
+
|
49
|
+
# For rubinius:
|
50
|
+
#*.rbc
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem 'aws-sdk'
|
7
|
+
gem 'commander'
|
8
|
+
gem 'settingslogic'
|
9
|
+
gem 'terminal-announce'
|
10
|
+
|
11
|
+
# Add dependencies to develop your gem here.
|
12
|
+
# Include everything needed to run rake, tests, features, etc.
|
13
|
+
group :development do
|
14
|
+
gem "rspec", "~> 2.8.0"
|
15
|
+
gem "yard", "~> 0.7"
|
16
|
+
gem "rdoc", "~> 3.12"
|
17
|
+
gem "bundler", "~> 1.0"
|
18
|
+
gem "jeweler", "~> 2.0.1"
|
19
|
+
gem "simplecov", ">= 0"
|
20
|
+
gem "reek", "~> 1.2.8"
|
21
|
+
gem "roodi", "~> 2.1.0"
|
22
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.3.8)
|
5
|
+
aws-sdk (2.1.4)
|
6
|
+
aws-sdk-resources (= 2.1.4)
|
7
|
+
aws-sdk-core (2.1.4)
|
8
|
+
jmespath (~> 1.0)
|
9
|
+
aws-sdk-resources (2.1.4)
|
10
|
+
aws-sdk-core (= 2.1.4)
|
11
|
+
builder (3.2.2)
|
12
|
+
commander (4.3.4)
|
13
|
+
highline (~> 1.7.2)
|
14
|
+
contracts (0.10)
|
15
|
+
descendants_tracker (0.0.4)
|
16
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
17
|
+
diff-lcs (1.1.3)
|
18
|
+
docile (1.1.5)
|
19
|
+
faraday (0.9.1)
|
20
|
+
multipart-post (>= 1.2, < 3)
|
21
|
+
git (1.2.9.1)
|
22
|
+
github_api (0.12.3)
|
23
|
+
addressable (~> 2.3)
|
24
|
+
descendants_tracker (~> 0.0.4)
|
25
|
+
faraday (~> 0.8, < 0.10)
|
26
|
+
hashie (>= 3.3)
|
27
|
+
multi_json (>= 1.7.5, < 2.0)
|
28
|
+
nokogiri (~> 1.6.3)
|
29
|
+
oauth2
|
30
|
+
hashie (3.4.2)
|
31
|
+
highline (1.7.2)
|
32
|
+
jeweler (2.0.1)
|
33
|
+
builder
|
34
|
+
bundler (>= 1.0)
|
35
|
+
git (>= 1.2.5)
|
36
|
+
github_api
|
37
|
+
highline (>= 1.6.15)
|
38
|
+
nokogiri (>= 1.5.10)
|
39
|
+
rake
|
40
|
+
rdoc
|
41
|
+
jmespath (1.0.2)
|
42
|
+
multi_json (~> 1.0)
|
43
|
+
json (1.8.3)
|
44
|
+
jwt (1.5.1)
|
45
|
+
mini_portile (0.6.2)
|
46
|
+
multi_json (1.11.2)
|
47
|
+
multi_xml (0.5.5)
|
48
|
+
multipart-post (2.0.0)
|
49
|
+
nokogiri (1.6.6.2)
|
50
|
+
mini_portile (~> 0.6.0)
|
51
|
+
oauth2 (1.0.0)
|
52
|
+
faraday (>= 0.8, < 0.10)
|
53
|
+
jwt (~> 1.0)
|
54
|
+
multi_json (~> 1.3)
|
55
|
+
multi_xml (~> 0.5)
|
56
|
+
rack (~> 1.2)
|
57
|
+
rack (1.6.4)
|
58
|
+
rainbow (2.0.0)
|
59
|
+
rake (10.4.2)
|
60
|
+
rdoc (3.12.2)
|
61
|
+
json (~> 1.4)
|
62
|
+
reek (1.2.13)
|
63
|
+
ripper_ruby_parser (~> 0.0.7)
|
64
|
+
ruby2ruby (~> 1.2.5)
|
65
|
+
ruby_parser (~> 2.0)
|
66
|
+
sexp_processor (~> 3.0)
|
67
|
+
ripper_ruby_parser (0.0.8)
|
68
|
+
sexp_processor (~> 3.0)
|
69
|
+
roodi (2.1.0)
|
70
|
+
ruby_parser
|
71
|
+
rspec (2.8.0)
|
72
|
+
rspec-core (~> 2.8.0)
|
73
|
+
rspec-expectations (~> 2.8.0)
|
74
|
+
rspec-mocks (~> 2.8.0)
|
75
|
+
rspec-core (2.8.0)
|
76
|
+
rspec-expectations (2.8.0)
|
77
|
+
diff-lcs (~> 1.1.2)
|
78
|
+
rspec-mocks (2.8.0)
|
79
|
+
ruby2ruby (1.2.5)
|
80
|
+
ruby_parser (~> 2.0)
|
81
|
+
sexp_processor (~> 3.0)
|
82
|
+
ruby_parser (2.3.1)
|
83
|
+
sexp_processor (~> 3.0)
|
84
|
+
settingslogic (2.0.9)
|
85
|
+
sexp_processor (3.2.0)
|
86
|
+
simplecov (0.10.0)
|
87
|
+
docile (~> 1.1.0)
|
88
|
+
json (~> 1.8)
|
89
|
+
simplecov-html (~> 0.10.0)
|
90
|
+
simplecov-html (0.10.0)
|
91
|
+
terminal-announce (1.0.0)
|
92
|
+
bundler
|
93
|
+
contracts
|
94
|
+
rainbow
|
95
|
+
thread_safe (0.3.5)
|
96
|
+
yard (0.8.7.6)
|
97
|
+
|
98
|
+
PLATFORMS
|
99
|
+
ruby
|
100
|
+
|
101
|
+
DEPENDENCIES
|
102
|
+
aws-sdk
|
103
|
+
bundler (~> 1.0)
|
104
|
+
commander
|
105
|
+
jeweler (~> 2.0.1)
|
106
|
+
rdoc (~> 3.12)
|
107
|
+
reek (~> 1.2.8)
|
108
|
+
roodi (~> 2.1.0)
|
109
|
+
rspec (~> 2.8.0)
|
110
|
+
settingslogic
|
111
|
+
simplecov
|
112
|
+
terminal-announce
|
113
|
+
yard (~> 0.7)
|
114
|
+
|
115
|
+
BUNDLED WITH
|
116
|
+
1.10.5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015 Chris Olstrom
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.mdown
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Superluminal
|
2
|
+
============
|
3
|
+
|
4
|
+
Superluminal is a tool for managing AWS infrastructure, built on ```aws-sdk```. It is intended for use alongside Ansible.
|
5
|
+
|
6
|
+
Background
|
7
|
+
----------
|
8
|
+
|
9
|
+
Ansible does a pretty good job of handling AWS, but there are cases where features either haven't been implemented yet, or are very cumbersome to manage.
|
10
|
+
|
11
|
+
1. While there is a method for putting an object in an S3 Bucket, there is no method for creating a bucket.
|
12
|
+
2. There is no method for creating an IAM role, or defining a User Policy for one.
|
13
|
+
3. There is no method to create peering between VPCs.
|
14
|
+
|
15
|
+
License
|
16
|
+
-------
|
17
|
+
[MIT](https://tldrlegal.com/license/mit-license)
|
18
|
+
|
19
|
+
Contributors
|
20
|
+
------------
|
21
|
+
* [Chris Olstrom](https://colstrom.github.io/) | [e-mail](mailto:chris@olstrom.com) | [Twitter](https://twitter.com/ChrisOlstrom)
|
data/Rakefile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = "superluminal"
|
18
|
+
gem.homepage = "http://github.com/colstrom/superluminal"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Picking up where Ansible falls down.}
|
21
|
+
gem.description = %Q{Fills in some gaps in Ansible's functionality. Handles creation of IAM Roles, S3 Buckets, and VPC Peering.}
|
22
|
+
gem.email = "chris@olstrom.com"
|
23
|
+
gem.authors = ["Chris Olstrom"]
|
24
|
+
gem.files = `git ls-files`.split("\n")
|
25
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
26
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
27
|
+
gem.require_paths = ['lib']
|
28
|
+
# dependencies defined in Gemfile
|
29
|
+
end
|
30
|
+
Jeweler::RubygemsDotOrgTasks.new
|
31
|
+
|
32
|
+
require 'rspec/core'
|
33
|
+
require 'rspec/core/rake_task'
|
34
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
35
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Code coverage detail"
|
39
|
+
task :simplecov do
|
40
|
+
ENV['COVERAGE'] = "true"
|
41
|
+
Rake::Task['spec'].execute
|
42
|
+
end
|
43
|
+
|
44
|
+
require 'reek/rake/task'
|
45
|
+
Reek::Rake::Task.new do |t|
|
46
|
+
t.fail_on_error = true
|
47
|
+
t.verbose = false
|
48
|
+
t.source_files = 'lib/**/*.rb'
|
49
|
+
end
|
50
|
+
|
51
|
+
require 'roodi'
|
52
|
+
require 'roodi_task'
|
53
|
+
RoodiTask.new do |t|
|
54
|
+
t.verbose = false
|
55
|
+
end
|
56
|
+
|
57
|
+
task :default => :spec
|
58
|
+
|
59
|
+
require 'yard'
|
60
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.8.0
|
data/bin/superluminal
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'commander'
|
4
|
+
require 'superluminal'
|
5
|
+
|
6
|
+
Commander.configure do
|
7
|
+
program :name, 'Superluminal'
|
8
|
+
program :version, '0.8.0'
|
9
|
+
program :description, 'Picking up where Ansible falls down.'
|
10
|
+
program :help, 'Author', 'Chris Olstrom <chris@olstrom.com>'
|
11
|
+
|
12
|
+
default_command :bootstrap
|
13
|
+
|
14
|
+
command :bootstrap do |command|
|
15
|
+
command.syntax = 'bootstrap --project <project name>'
|
16
|
+
command.description = 'Sets up project-specific IAM role and S3 buckets'
|
17
|
+
command.option '--project STRING', String, 'Name of the project'
|
18
|
+
command.option '--environment STRING', String, 'Environment to create buckets for' # TODO: Make this do something.
|
19
|
+
command.action do |_args, options|
|
20
|
+
abort 'Missing parameter --project' unless options.project
|
21
|
+
IdentityAccessManagement.create_user "project-#{ options.project }"
|
22
|
+
IdentityAccessManagement.apply_policies to_user: "project-#{ options.project }", for_project: options.project
|
23
|
+
SimpleStorageService.create_buckets options.project, Settings.environments
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
command :peering do |command|
|
28
|
+
command.syntax = 'peering --from <vpc> --to <vpc>'
|
29
|
+
command.description = 'Handles VPC peering and routing'
|
30
|
+
command.option '--from STRING', String, 'Name of the VPC to initiate peering'
|
31
|
+
command.option '--to STRING', String, 'Name of VPC to peer with'
|
32
|
+
command.option '--region STRING', String, "AWS Region (defaults to #{ Settings.default_region })"
|
33
|
+
command.action do |_args, options|
|
34
|
+
options.default region: Settings.default_region
|
35
|
+
abort 'Both --from and --to are required for peering.' unless options.from && options.to
|
36
|
+
with_api = VirtualPrivateCloud.api options.region
|
37
|
+
VirtualPrivateCloud.attempt_peering from_vpc: options.from, to_vpc: options.to
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
---
|
2
|
+
Metadata:
|
3
|
+
resource_suffix: ''
|
4
|
+
Version: "2012-10-17"
|
5
|
+
Statement:
|
6
|
+
- Effect: "Allow"
|
7
|
+
Action:
|
8
|
+
- "s3:ListBucket"
|
9
|
+
- "s3:GetBucketAcl"
|
10
|
+
- "s3:GetBucketVersioning"
|
11
|
+
- "s3:GetBucketLocation"
|
12
|
+
- "s3:ListBucketMultipartUploads"
|
13
|
+
Resource: []
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
require 'multi_json'
|
3
|
+
require 'terminal-announce'
|
4
|
+
require_relative 'settings'
|
5
|
+
|
6
|
+
# Module for dealing with IAM.
|
7
|
+
module IdentityAccessManagement
|
8
|
+
def self.api(region = Settings.default_region)
|
9
|
+
@api ||= Aws::IAM::Client.new region: region
|
10
|
+
end
|
11
|
+
|
12
|
+
module UserPolicy
|
13
|
+
def self.from_template(template, project: nil, settings: nil)
|
14
|
+
policy = YAML.load_file "#{ settings.template_path }/#{ template }.yaml"
|
15
|
+
policy['Statement'].each do |statement|
|
16
|
+
statement['Resource'] = settings.environments.map do |environment|
|
17
|
+
"arn:aws:s3:::#{ settings.s3.namespace }-#{ project }-#{ environment.name }#{ policy['Metadata']['resource_suffix'] }"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
policy.delete 'Metadata'
|
21
|
+
return MultiJson.encode policy
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.generate(project_name, settings, templates: ['s3/bucket', 's3/contents'])
|
25
|
+
templates.map do |template|
|
26
|
+
{ name: template.gsub(/\//, '-'),
|
27
|
+
document: from_template(template, project: project_name, settings: settings)
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.upload(policy, named: nil, for_user: nil)
|
33
|
+
IdentityAccessManagement.api.put_user_policy(
|
34
|
+
user_name: for_user,
|
35
|
+
policy_name: named,
|
36
|
+
policy_document: policy
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.create_user(user_name)
|
42
|
+
api.create_user user_name: user_name
|
43
|
+
Announce.success "#{ user_name } created."
|
44
|
+
rescue Aws::IAM::Errors::EntityAlreadyExists
|
45
|
+
Announce.success "#{ user_name } already exists."
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.apply_policies(to_user: nil, for_project: nil)
|
49
|
+
policies = UserPolicy.generate(for_project, Settings)
|
50
|
+
policies.each do |policy|
|
51
|
+
UserPolicy.upload policy[:document], named: policy[:name], for_user: to_user
|
52
|
+
Announce.success "Applied policy #{ policy[:name] } to #{ to_user }."
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
require 'terminal-announce'
|
3
|
+
require_relative 'settings'
|
4
|
+
|
5
|
+
# Module for dealing with S3.
|
6
|
+
module SimpleStorageService
|
7
|
+
def self.connect(region: Settings.default_region)
|
8
|
+
Aws::S3::Client.new region: region
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.create_buckets(project, environments = Settings.environments)
|
12
|
+
environments.each do |environment|
|
13
|
+
with_api = connect region: environment.region
|
14
|
+
bucket_name = "#{ project }-#{ environment.name }"
|
15
|
+
create_bucket "#{ Settings.s3.namespace }-#{ bucket_name }", with_api: with_api
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.create_bucket(bucket_name, with_api: connect)
|
20
|
+
with_api.create_bucket bucket: bucket_name
|
21
|
+
Announce.success "#{ bucket_name } created."
|
22
|
+
rescue Aws::S3::Errors::BucketAlreadyExists
|
23
|
+
Announce.failure "#{ bucket_name } already exists."
|
24
|
+
rescue Aws::S3::Errors::BucketAlreadyOwnedByYou
|
25
|
+
Announce.info "#{ bucket_name } is already owned by this account."
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'settingslogic'
|
2
|
+
require 'terminal-announce'
|
3
|
+
|
4
|
+
# Singleton for loading configs from common paths.
|
5
|
+
class Settings < Settingslogic
|
6
|
+
config_paths = %w(/etc /usr/local/etc ~/.config .)
|
7
|
+
|
8
|
+
config_paths.each do |config_path|
|
9
|
+
config_file = File.expand_path "#{ config_path }/superluminal.yaml"
|
10
|
+
source config_file if File.exist? config_file
|
11
|
+
end
|
12
|
+
|
13
|
+
load!
|
14
|
+
rescue Errno::ENOENT
|
15
|
+
Announce.failure "Unable to locate configuration in #{ config_paths }."
|
16
|
+
abort
|
17
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
require_relative 'settings'
|
3
|
+
|
4
|
+
# Module for dealing with VPCs
|
5
|
+
module VirtualPrivateCloud
|
6
|
+
def self.api(region = Settings.default_region)
|
7
|
+
@api ||= Aws::EC2::Client.new region: region
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.find_vpcs_by_project(project)
|
11
|
+
api.describe_vpcs(
|
12
|
+
filters: [
|
13
|
+
{ name: 'tag:Project', values: [project] }
|
14
|
+
]
|
15
|
+
).vpcs
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.find_vpcs(where: 'project', named:)
|
19
|
+
method("find_vpcs_by_#{ where }").call(named)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.first_vpc(where: 'project', named:)
|
23
|
+
find_vpcs(where: where, named: named).first
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.attempt_peering(from_vpc:, to_vpc:)
|
27
|
+
abort "VPC not found: #{from_vpc}" unless from = first_vpc(named: from_vpc)
|
28
|
+
abort "VPC not found: #{to_vpc}" unless to = first_vpc(named: to_vpc)
|
29
|
+
create_peering from: from, to: to
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.create_peering(from:, to:)
|
33
|
+
peering_id = request_peering from.vpc_id, to.vpc_id
|
34
|
+
approve_peering_request with_id: peering_id
|
35
|
+
create_routes from, to, using_connection: peering_id
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.request_peering(from_vpc, to_vpc)
|
39
|
+
response = api.create_vpc_peering_connection vpc_id: from_vpc, peer_vpc_id: to_vpc
|
40
|
+
request_id = response.vpc_peering_connection.vpc_peering_connection_id
|
41
|
+
Announce.success "Request #{ request_id } to peer #{ from_vpc } with #{ to_vpc }." # TODO: Use names, not IDs! Tags should *mean* something.
|
42
|
+
assign_name "#{ from_vpc }-#{ to_vpc }", to: request_id # TODO: Assigning tags is not requesting peering. This line does not belong here.
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.approve_peering_request(with_id:)
|
46
|
+
api.accept_vpc_peering_connection vpc_peering_connection_id: with_id
|
47
|
+
Announce.success "Approved peering request #{ with_id }."
|
48
|
+
rescue Aws::EC2::Errors::VpcPeeringConnectionAlreadyExists
|
49
|
+
Announce.success "Redundant peering request #{ with_id }, deleting."
|
50
|
+
delete_peering_request with_id
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.delete_peering_request(request_id)
|
54
|
+
api.delete_vpc_peering_connection vpc_peering_connection_id: request_id
|
55
|
+
Announce.success "Peering request #{ request_id } deleted."
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.find_route_tables_by_peering(peering_id)
|
59
|
+
api.describe_route_tables(
|
60
|
+
filters: [
|
61
|
+
{ name: 'route.vpc-peering-connection-id', values: [peering_id] }
|
62
|
+
]
|
63
|
+
).route_tables
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.find_route_tables_by_vpc(vpc_id)
|
67
|
+
api.describe_route_tables(
|
68
|
+
filters: [
|
69
|
+
{ name: 'vpc-id', values: [vpc_id] },
|
70
|
+
{ name: 'association.main', values: ['false'] }
|
71
|
+
]
|
72
|
+
).route_tables
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.find_route_tables(where: 'vpc', **options)
|
76
|
+
method("find_route_tables_by_#{ where }").call options[where.to_sym]
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.create_routes(from_vpc, to_vpc, using_connection:)
|
80
|
+
create_route from_vpc, to_vpc, using_connection
|
81
|
+
create_route to_vpc, from_vpc, using_connection
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.create_route(from, to, peering_id)
|
85
|
+
route_tables = find_route_tables where: 'vpc', vpc: from.vpc_id
|
86
|
+
route_tables.each do |route_table|
|
87
|
+
api.create_route(
|
88
|
+
route_table_id: route_table.route_table_id,
|
89
|
+
destination_cidr_block: to.cidr_block,
|
90
|
+
vpc_peering_connection_id: peering_id
|
91
|
+
)
|
92
|
+
end
|
93
|
+
Announce.success "Routes created from #{ from.vpc_id } to #{ to.vpc_id } using #{ peering_id }."
|
94
|
+
rescue Aws::EC2::Errors::RouteAlreadyExists
|
95
|
+
Announce.success "Already have a route connecting #{ from.vpc_id } to #{ to.vpc_id } using #{ peering_id }."
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.assign_name(name, to:)
|
99
|
+
api.create_tags resources: [to], tags: [{ key: 'Name', value: name }]
|
100
|
+
Announce.success "Assigned tag #{ name } to #{ to }."
|
101
|
+
return to
|
102
|
+
end
|
103
|
+
end
|
data/lib/superluminal.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
module SimpleCov::Configuration
|
4
|
+
def clean_filters
|
5
|
+
@filters = []
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.configure do
|
10
|
+
clean_filters
|
11
|
+
load_adapter 'test_frameworks'
|
12
|
+
end
|
13
|
+
|
14
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
15
|
+
add_filter "/.rvm/"
|
16
|
+
end
|
17
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
18
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
19
|
+
|
20
|
+
require 'rspec'
|
21
|
+
require 'superluminal'
|
22
|
+
|
23
|
+
# Requires supporting files with custom matchers and macros, etc,
|
24
|
+
# in ./support/ and its subdirectories.
|
25
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
26
|
+
|
27
|
+
RSpec.configure do |config|
|
28
|
+
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,237 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: superluminal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Olstrom
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: commander
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: settingslogic
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: terminal-announce
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.8.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.8.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.7'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.7'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rdoc
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.12'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.12'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: bundler
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: jeweler
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 2.0.1
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 2.0.1
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: reek
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 1.2.8
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 1.2.8
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: roodi
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 2.1.0
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 2.1.0
|
181
|
+
description: Fills in some gaps in Ansible's functionality. Handles creation of IAM
|
182
|
+
Roles, S3 Buckets, and VPC Peering.
|
183
|
+
email: chris@olstrom.com
|
184
|
+
executables:
|
185
|
+
- superluminal
|
186
|
+
extensions: []
|
187
|
+
extra_rdoc_files:
|
188
|
+
- LICENSE.txt
|
189
|
+
- README.mdown
|
190
|
+
files:
|
191
|
+
- ".document"
|
192
|
+
- ".gitignore"
|
193
|
+
- ".rspec"
|
194
|
+
- Gemfile
|
195
|
+
- Gemfile.lock
|
196
|
+
- LICENSE.txt
|
197
|
+
- README.mdown
|
198
|
+
- Rakefile
|
199
|
+
- VERSION
|
200
|
+
- bin/superluminal
|
201
|
+
- example/superluminal.yaml
|
202
|
+
- example/templates/s3/bucket.yaml
|
203
|
+
- example/templates/s3/contents.yaml
|
204
|
+
- lib/superluminal.rb
|
205
|
+
- lib/superluminal/iam.rb
|
206
|
+
- lib/superluminal/s3.rb
|
207
|
+
- lib/superluminal/settings.rb
|
208
|
+
- lib/superluminal/vpc.rb
|
209
|
+
- spec/spec_helper.rb
|
210
|
+
- spec/superluminal_spec.rb
|
211
|
+
homepage: http://github.com/colstrom/superluminal
|
212
|
+
licenses:
|
213
|
+
- MIT
|
214
|
+
metadata: {}
|
215
|
+
post_install_message:
|
216
|
+
rdoc_options: []
|
217
|
+
require_paths:
|
218
|
+
- lib
|
219
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
220
|
+
requirements:
|
221
|
+
- - ">="
|
222
|
+
- !ruby/object:Gem::Version
|
223
|
+
version: '0'
|
224
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
225
|
+
requirements:
|
226
|
+
- - ">="
|
227
|
+
- !ruby/object:Gem::Version
|
228
|
+
version: '0'
|
229
|
+
requirements: []
|
230
|
+
rubyforge_project:
|
231
|
+
rubygems_version: 2.4.8
|
232
|
+
signing_key:
|
233
|
+
specification_version: 4
|
234
|
+
summary: Picking up where Ansible falls down.
|
235
|
+
test_files:
|
236
|
+
- spec/spec_helper.rb
|
237
|
+
- spec/superluminal_spec.rb
|