vagrant-aws-iam-decoder 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +19 -0
  5. data/CHANGELOG.md +96 -0
  6. data/Gemfile +12 -0
  7. data/LICENSE +8 -0
  8. data/README.md +326 -0
  9. data/Rakefile +22 -0
  10. data/dummy.box +0 -0
  11. data/example_box/README.md +13 -0
  12. data/example_box/metadata.json +3 -0
  13. data/lib/vagrant-aws-iam-decoder.rb +18 -0
  14. data/lib/vagrant-aws/action.rb +210 -0
  15. data/lib/vagrant-aws/action/connect_aws.rb +48 -0
  16. data/lib/vagrant-aws/action/elb_deregister_instance.rb +24 -0
  17. data/lib/vagrant-aws/action/elb_register_instance.rb +24 -0
  18. data/lib/vagrant-aws/action/is_created.rb +18 -0
  19. data/lib/vagrant-aws/action/is_stopped.rb +18 -0
  20. data/lib/vagrant-aws/action/message_already_created.rb +16 -0
  21. data/lib/vagrant-aws/action/message_not_created.rb +16 -0
  22. data/lib/vagrant-aws/action/message_will_not_destroy.rb +16 -0
  23. data/lib/vagrant-aws/action/package_instance.rb +192 -0
  24. data/lib/vagrant-aws/action/read_ssh_info.rb +53 -0
  25. data/lib/vagrant-aws/action/read_state.rb +38 -0
  26. data/lib/vagrant-aws/action/run_instance.rb +396 -0
  27. data/lib/vagrant-aws/action/start_instance.rb +81 -0
  28. data/lib/vagrant-aws/action/stop_instance.rb +28 -0
  29. data/lib/vagrant-aws/action/terminate_instance.rb +51 -0
  30. data/lib/vagrant-aws/action/timed_provision.rb +21 -0
  31. data/lib/vagrant-aws/action/wait_for_state.rb +41 -0
  32. data/lib/vagrant-aws/action/warn_networks.rb +19 -0
  33. data/lib/vagrant-aws/config.rb +601 -0
  34. data/lib/vagrant-aws/errors.rb +43 -0
  35. data/lib/vagrant-aws/plugin.rb +73 -0
  36. data/lib/vagrant-aws/provider.rb +50 -0
  37. data/lib/vagrant-aws/util/elb.rb +58 -0
  38. data/lib/vagrant-aws/util/timer.rb +17 -0
  39. data/lib/vagrant-aws/version.rb +5 -0
  40. data/locales/en.yml +161 -0
  41. data/spec/spec_helper.rb +1 -0
  42. data/spec/vagrant-aws/config_spec.rb +395 -0
  43. data/templates/metadata.json.erb +3 -0
  44. data/templates/vagrant-aws_package_Vagrantfile.erb +5 -0
  45. data/vagrant-aws-iam-decoder.gemspec +62 -0
  46. metadata +163 -0
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec/core/rake_task'
4
+
5
+ # Immediately sync all stdout so that tools like buildbot can
6
+ # immediately load in the output.
7
+ $stdout.sync = true
8
+ $stderr.sync = true
9
+
10
+ # Change to the directory of this file.
11
+ Dir.chdir(File.expand_path("../", __FILE__))
12
+
13
+ # This installs the tasks that help with gem creation and
14
+ # publishing.
15
+ Bundler::GemHelper.install_tasks
16
+
17
+ # Install the `spec` task so that we can run tests.
18
+ RSpec::Core::RakeTask.new(:spec) do |t|
19
+ t.rspec_opts = "--order defined"
20
+ end
21
+ # Default task is to run the unit tests
22
+ task :default => :spec
data/dummy.box ADDED
Binary file
@@ -0,0 +1,13 @@
1
+ # Vagrant AWS Example Box
2
+
3
+ Vagrant providers each require a custom provider-specific box format.
4
+ This folder shows the example contents of a box for the `aws` provider.
5
+ To turn this into a box:
6
+
7
+ ```
8
+ $ tar cvzf aws.box ./metadata.json ./Vagrantfile
9
+ ```
10
+
11
+ This box works by using Vagrant's built-in Vagrantfile merging to setup
12
+ defaults for AWS. These defaults can easily be overwritten by higher-level
13
+ Vagrantfiles (such as project root Vagrantfiles).
@@ -0,0 +1,3 @@
1
+ {
2
+ "provider": "aws"
3
+ }
@@ -0,0 +1,18 @@
1
+ require "pathname"
2
+
3
+ require "vagrant-aws/plugin"
4
+
5
+ module VagrantPlugins
6
+ module AWS
7
+ lib_path = Pathname.new(File.expand_path("../vagrant-aws", __FILE__))
8
+ autoload :Action, lib_path.join("action")
9
+ autoload :Errors, lib_path.join("errors")
10
+
11
+ # This returns the path to the source of this plugin.
12
+ #
13
+ # @return [Pathname]
14
+ def self.source_root
15
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,210 @@
1
+ require "pathname"
2
+
3
+ require "vagrant/action/builder"
4
+
5
+ module VagrantPlugins
6
+ module AWS
7
+ module Action
8
+ # Include the built-in modules so we can use them as top-level things.
9
+ include Vagrant::Action::Builtin
10
+
11
+ def self.action_package
12
+ Vagrant::Action::Builder.new.tap do |b|
13
+ b.use Call, IsCreated do |env, b2|
14
+ if !env[:result]
15
+ b2.use MessageNotCreated
16
+ next
17
+ end
18
+
19
+ # Connect to AWS and then Create a package from the server instance
20
+ b2.use ConnectAWS
21
+ b2.use PackageInstance
22
+ end
23
+ end
24
+ end
25
+
26
+ # This action is called to halt the remote machine.
27
+ def self.action_halt
28
+ Vagrant::Action::Builder.new.tap do |b|
29
+ b.use ConfigValidate
30
+ b.use Call, IsCreated do |env, b2|
31
+ if !env[:result]
32
+ b2.use MessageNotCreated
33
+ next
34
+ end
35
+
36
+ b2.use ConnectAWS
37
+ b2.use StopInstance
38
+ end
39
+ end
40
+ end
41
+
42
+ # This action is called to terminate the remote machine.
43
+ def self.action_destroy
44
+ Vagrant::Action::Builder.new.tap do |b|
45
+ b.use Call, DestroyConfirm do |env, b2|
46
+ if env[:result]
47
+ b2.use ConfigValidate
48
+ b2.use Call, IsCreated do |env2, b3|
49
+ if !env2[:result]
50
+ b3.use MessageNotCreated
51
+ next
52
+ end
53
+
54
+ b3.use ConnectAWS
55
+ b3.use ElbDeregisterInstance
56
+ b3.use ProvisionerCleanup, :before if defined?(ProvisionerCleanup)
57
+ b3.use TerminateInstance
58
+ end
59
+ else
60
+ b2.use MessageWillNotDestroy
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ # This action is called when `vagrant provision` is called.
67
+ def self.action_provision
68
+ Vagrant::Action::Builder.new.tap do |b|
69
+ b.use ConfigValidate
70
+ b.use Call, IsCreated do |env, b2|
71
+ if !env[:result]
72
+ b2.use MessageNotCreated
73
+ next
74
+ end
75
+
76
+ b2.use Provision
77
+ end
78
+ end
79
+ end
80
+
81
+ # This action is called to read the SSH info of the machine. The
82
+ # resulting state is expected to be put into the `:machine_ssh_info`
83
+ # key.
84
+ def self.action_read_ssh_info
85
+ Vagrant::Action::Builder.new.tap do |b|
86
+ b.use ConfigValidate
87
+ b.use ConnectAWS
88
+ b.use ReadSSHInfo
89
+ end
90
+ end
91
+
92
+ # This action is called to read the state of the machine. The
93
+ # resulting state is expected to be put into the `:machine_state_id`
94
+ # key.
95
+ def self.action_read_state
96
+ Vagrant::Action::Builder.new.tap do |b|
97
+ b.use ConfigValidate
98
+ b.use ConnectAWS
99
+ b.use ReadState
100
+ end
101
+ end
102
+
103
+ # This action is called to SSH into the machine.
104
+ def self.action_ssh
105
+ Vagrant::Action::Builder.new.tap do |b|
106
+ b.use ConfigValidate
107
+ b.use Call, IsCreated do |env, b2|
108
+ if !env[:result]
109
+ b2.use MessageNotCreated
110
+ next
111
+ end
112
+
113
+ b2.use SSHExec
114
+ end
115
+ end
116
+ end
117
+
118
+ def self.action_ssh_run
119
+ Vagrant::Action::Builder.new.tap do |b|
120
+ b.use ConfigValidate
121
+ b.use Call, IsCreated do |env, b2|
122
+ if !env[:result]
123
+ b2.use MessageNotCreated
124
+ next
125
+ end
126
+
127
+ b2.use SSHRun
128
+ end
129
+ end
130
+ end
131
+
132
+ def self.action_prepare_boot
133
+ Vagrant::Action::Builder.new.tap do |b|
134
+ b.use Provision
135
+ b.use SyncedFolders
136
+ b.use WarnNetworks
137
+ b.use ElbRegisterInstance
138
+ end
139
+ end
140
+
141
+ # This action is called to bring the box up from nothing.
142
+ def self.action_up
143
+ Vagrant::Action::Builder.new.tap do |b|
144
+ b.use HandleBox
145
+ b.use ConfigValidate
146
+ b.use BoxCheckOutdated
147
+ b.use ConnectAWS
148
+ b.use Call, IsCreated do |env1, b1|
149
+ if env1[:result]
150
+ b1.use Call, IsStopped do |env2, b2|
151
+ if env2[:result]
152
+ b2.use action_prepare_boot
153
+ b2.use StartInstance # restart this instance
154
+ else
155
+ b2.use MessageAlreadyCreated # TODO write a better message
156
+ end
157
+ end
158
+ else
159
+ b1.use action_prepare_boot
160
+ b1.use RunInstance # launch a new instance
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ def self.action_reload
167
+ Vagrant::Action::Builder.new.tap do |b|
168
+ b.use ConfigValidate
169
+ b.use ConnectAWS
170
+ b.use Call, IsCreated do |env, b2|
171
+ if !env[:result]
172
+ b2.use MessageNotCreated
173
+ next
174
+ end
175
+
176
+ b2.use action_halt
177
+ b2.use Call, WaitForState, :stopped, 120 do |env2, b3|
178
+ if env2[:result]
179
+ b3.use action_up
180
+ else
181
+ # TODO we couldn't reach :stopped, what now?
182
+ end
183
+ end
184
+ end
185
+ end
186
+ end
187
+
188
+ # The autoload farm
189
+ action_root = Pathname.new(File.expand_path("../action", __FILE__))
190
+ autoload :ConnectAWS, action_root.join("connect_aws")
191
+ autoload :IsCreated, action_root.join("is_created")
192
+ autoload :IsStopped, action_root.join("is_stopped")
193
+ autoload :MessageAlreadyCreated, action_root.join("message_already_created")
194
+ autoload :MessageNotCreated, action_root.join("message_not_created")
195
+ autoload :MessageWillNotDestroy, action_root.join("message_will_not_destroy")
196
+ autoload :PackageInstance, action_root.join("package_instance")
197
+ autoload :ReadSSHInfo, action_root.join("read_ssh_info")
198
+ autoload :ReadState, action_root.join("read_state")
199
+ autoload :RunInstance, action_root.join("run_instance")
200
+ autoload :StartInstance, action_root.join("start_instance")
201
+ autoload :StopInstance, action_root.join("stop_instance")
202
+ autoload :TerminateInstance, action_root.join("terminate_instance")
203
+ autoload :TimedProvision, action_root.join("timed_provision") # some plugins now expect this action to exist
204
+ autoload :WaitForState, action_root.join("wait_for_state")
205
+ autoload :WarnNetworks, action_root.join("warn_networks")
206
+ autoload :ElbRegisterInstance, action_root.join("elb_register_instance")
207
+ autoload :ElbDeregisterInstance, action_root.join("elb_deregister_instance")
208
+ end
209
+ end
210
+ end
@@ -0,0 +1,48 @@
1
+ require "fog"
2
+ require "log4r"
3
+
4
+ module VagrantPlugins
5
+ module AWS
6
+ module Action
7
+ # This action connects to AWS, verifies credentials work, and
8
+ # puts the AWS connection object into the `:aws_compute` key
9
+ # in the environment.
10
+ class ConnectAWS
11
+ def initialize(app, env)
12
+ @app = app
13
+ @logger = Log4r::Logger.new("vagrant_aws::action::connect_aws")
14
+ end
15
+
16
+ def call(env)
17
+ # Get the region we're going to booting up in
18
+ region = env[:machine].provider_config.region
19
+
20
+ # Get the configs
21
+ region_config = env[:machine].provider_config.get_region_config(region)
22
+
23
+ # Build the fog config
24
+ fog_config = {
25
+ :provider => :aws,
26
+ :region => region
27
+ }
28
+ if region_config.use_iam_profile
29
+ fog_config[:use_iam_profile] = true
30
+ else
31
+ fog_config[:aws_access_key_id] = region_config.access_key_id
32
+ fog_config[:aws_secret_access_key] = region_config.secret_access_key
33
+ fog_config[:aws_session_token] = region_config.session_token
34
+ end
35
+
36
+ fog_config[:endpoint] = region_config.endpoint if region_config.endpoint
37
+ fog_config[:version] = region_config.version if region_config.version
38
+
39
+ @logger.info("Connecting to AWS...")
40
+ env[:aws_compute] = Fog::Compute.new(fog_config)
41
+ env[:aws_elb] = Fog::AWS::ELB.new(fog_config.except(:provider, :endpoint))
42
+
43
+ @app.call(env)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,24 @@
1
+ require 'vagrant-aws/util/elb'
2
+
3
+ module VagrantPlugins
4
+ module AWS
5
+ module Action
6
+ # This registers instance in ELB
7
+ class ElbDeregisterInstance
8
+ include ElasticLoadBalancer
9
+
10
+ def initialize(app, env)
11
+ @app = app
12
+ @logger = Log4r::Logger.new("vagrant_aws::action::elb_deregister_instance")
13
+ end
14
+
15
+ def call(env)
16
+ if elb_name = env[:machine].provider_config.elb
17
+ deregister_instance env, elb_name, env[:machine].id
18
+ end
19
+ @app.call(env)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'vagrant-aws/util/elb'
2
+
3
+ module VagrantPlugins
4
+ module AWS
5
+ module Action
6
+ # This registers instance in ELB
7
+ class ElbRegisterInstance
8
+ include ElasticLoadBalancer
9
+
10
+ def initialize(app, env)
11
+ @app = app
12
+ @logger = Log4r::Logger.new("vagrant_aws::action::elb_register_instance")
13
+ end
14
+
15
+ def call(env)
16
+ @app.call(env)
17
+ if elb_name = env[:machine].provider_config.elb
18
+ register_instance env, elb_name, env[:machine].id
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module AWS
3
+ module Action
4
+ # This can be used with "Call" built-in to check if the machine
5
+ # is created and branch in the middleware.
6
+ class IsCreated
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ env[:result] = env[:machine].state.id != :not_created
13
+ @app.call(env)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module AWS
3
+ module Action
4
+ # This can be used with "Call" built-in to check if the machine
5
+ # is stopped and branch in the middleware.
6
+ class IsStopped
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ env[:result] = env[:machine].state.id == :stopped
13
+ @app.call(env)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module AWS
3
+ module Action
4
+ class MessageAlreadyCreated
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_aws.already_status", :status => "created"))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module AWS
3
+ module Action
4
+ class MessageNotCreated
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_aws.not_created"))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end