omc 0.0.2 → 0.0.3

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: dc3cffe813d70187f7415b6ee368a1355301cbb4
4
- data.tar.gz: 188d8b778d92830e879a016968529ebd133cdd70
3
+ metadata.gz: 40766a4dd46b353e2b9bfdd9cc5628f83845d90b
4
+ data.tar.gz: 591dc4424274502ba89c3a1c487745ac19293955
5
5
  SHA512:
6
- metadata.gz: 2f36c9dff7a20e16e2bb17718c55d6b548ba336fcc67ae1337f7743fa2ec27d34205dbe2b04a6fd1e21ab6a9d798a1b687aebda9b46f7701a34874ba1498fd88
7
- data.tar.gz: afaf005acb4df2b401b1015d57109009e98fabe957509772f70aadfbd38f094399c2186997762cdd6947e94d952adf3fab7a3797b7a7d294b65027829c4edfcb
6
+ metadata.gz: 0d280a904f65b44571e6a4f9c45f6b5ae34f6c26b921e95eff6df3395adc3007443893b9a5bf7afd3d75fdcef9cb44666fbeaefcf64389bd602c14efd225d1f3
7
+ data.tar.gz: db7927aca1c1e0a498bdfd73b4454549b29d984ef39aef69aebe06bb31c5f39cccd0f3653dd0b697d870be4167ea27f7e4b19e1fb6fe14e705fcfb4fd4ec8b3e
data/lib/omc.rb CHANGED
@@ -2,5 +2,4 @@ require "omc/version"
2
2
  require "omc/cli"
3
3
 
4
4
  module Omc
5
- # Your code goes here...
6
5
  end
@@ -1,30 +1,30 @@
1
1
  require 'thor'
2
2
  require 'aws_cred_vault'
3
3
  require 'aws-sdk'
4
+ require "omc/stack_command"
4
5
 
5
6
  module Omc
6
7
  class Cli < Thor
7
8
  desc 'ssh', 'Connect to an instance on a stack on an account'
8
- def ssh(account, stack)
9
- iam_account = vault.account account
10
- user = iam_account.users.first
11
- ops = ::AWS::OpsWorks::Client.new user.credentials
9
+ def ssh(account_name, stack)
10
+ command = StackCommand.new(user(account), stack)
11
+ command.ssh
12
+ end
12
13
 
13
- ops_stack = get_by_name ops.describe_stacks[:stacks], stack
14
- instances = ops.describe_instances(stack_id: ops_stack[:stack_id])[:instances]
15
- instance = instances.first
16
- system "ssh #{user.name}@#{instance[:public_ip]}"
14
+ desc 'console', 'Run a rails console on the given stack'
15
+ def console(account, stack)
16
+ command = StackCommand.new(user(account), stack)
17
+ command.console
17
18
  end
18
19
 
19
20
  private
20
- def vault
21
- AwsCredVault::Toml.new File.join(ENV['HOME'], '.aws_cred_vault')
21
+ def user(account)
22
+ iam_account = vault.account(account) || abort("Account #{account.inspect} not configured")
23
+ iam_account.users.first || abort("No users configured under #{account.inspect}")
22
24
  end
23
25
 
24
- def get_by_name collection, name
25
- collection.detect do |x|
26
- x[:name] == name
27
- end || abort("Can't find #{name.inspect} among #{collection.map{|x| x[:name] }.inspect}")
26
+ def vault
27
+ AwsCredVault::Toml.new File.join(ENV['HOME'], '.aws_cred_vault')
28
28
  end
29
29
  end
30
30
  end
@@ -0,0 +1,48 @@
1
+ require 'aws-sdk'
2
+
3
+ module Omc
4
+ class StackCommand
5
+ def initialize user, stack_name
6
+ @user = user
7
+ @stack_name = stack_name
8
+ end
9
+
10
+ def ssh
11
+ exec "ssh", ssh_host
12
+ end
13
+
14
+ def console
15
+ app = applications.first
16
+ exec 'ssh', '-t', ssh_host, "sudo su deploy -c 'cd /srv/www/#{app[:name]}/current && RAILS_ENV=#{app[:attributes]['RailsEnv']} bundle exec rails c'"
17
+ end
18
+
19
+ private
20
+ def applications
21
+ ops.describe_apps(stack_id: stack[:stack_id])[:apps]
22
+ end
23
+
24
+ def instance
25
+ instances = ops.describe_instances(stack_id: stack[:stack_id])[:instances]
26
+ instances.reject!{|i| i[:status] != "online" }
27
+ instance = instances.first || abort("No running instances")
28
+ end
29
+
30
+ def ssh_host
31
+ "#{@user.name}@#{instance[:public_ip]}"
32
+ end
33
+
34
+ def ops
35
+ @ops ||= ::AWS::OpsWorks::Client.new @user.credentials
36
+ end
37
+
38
+ def stack
39
+ @stack ||= get_by_name ops.describe_stacks[:stacks], @stack_name
40
+ end
41
+
42
+ def get_by_name collection, name
43
+ collection.detect do |x|
44
+ x[:name] == name
45
+ end || abort("Can't find #{name.inspect} among #{collection.map{|x| x[:name] }.inspect}")
46
+ end
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module Omc
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clarke Brunsdon
@@ -96,6 +96,7 @@ files:
96
96
  - bin/omc
97
97
  - lib/omc.rb
98
98
  - lib/omc/cli.rb
99
+ - lib/omc/stack_command.rb
99
100
  - lib/omc/version.rb
100
101
  - omc.gemspec
101
102
  homepage: http://github.com/freerunningtech/omc