opsworks 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in opsworks.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Adam Lindberg
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Opsworks
2
+
3
+ Command line interface for Amazon OpsWorks.
4
+
5
+ ## Commands
6
+
7
+ * `ssh` Generate and update SSH configuration files
8
+
9
+ ## Configuration
10
+
11
+ This gem uses the same configuration file as the [AWS CLI][aws_cli]
12
+
13
+ Add the following section to the file pointed out by the `AWS_CONFIG_FILE`
14
+ environment variable:
15
+
16
+ [opsworks]
17
+ stack-id=<MY STACK ID>
18
+ ssh-user=<MY SSH USER NAME>
19
+
20
+ The stack ID can be found in the stack settings, under _OpsWorks ID_. The
21
+ `ssh-user` flag should be set to the username you want to use when logging in
22
+ remotely, most probably the user name from your _My Settings_ page on OpsWorks.
23
+
24
+ ## Installation
25
+
26
+ Install for use on the command line:
27
+
28
+ $ gem install opsworks
29
+
30
+ Then run `opsworks`:
31
+
32
+ $ opsworks --help
33
+
34
+ To use the gem in a project, add this to your `Gemfile`:
35
+
36
+ gem 'opsworks'
37
+
38
+ And then execute:
39
+
40
+ $ bundle
41
+
42
+
43
+ ## Usage
44
+
45
+ TODO: Write usage instructions here
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create new Pull Request
54
+
55
+ [aws_cli]: http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html "Amazon AWS CLI"
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/opsworks ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path(
5
+ "../../Gemfile",
6
+ Pathname.new(__FILE__).realpath,
7
+ )
8
+
9
+ require 'rubygems'
10
+ require 'bundler/setup'
11
+
12
+ require 'opsworks/cli'
13
+
14
+ OpsWorks::CLI.start
15
+
data/lib/opsworks.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "opsworks/version"
2
+ require "opsworks/config"
3
+ require "opsworks/commands/ssh"
4
+
5
+ class String
6
+ def unindent
7
+ gsub(/^#{self[/\A\s*/]}/, '')
8
+ end
9
+ end
10
+
11
+ module Opsworks
12
+ end
@@ -0,0 +1,42 @@
1
+ require 'trollop'
2
+ require 'opsworks'
3
+
4
+ class OpsWorks::CLI
5
+ def self.start
6
+ spec = Gem::Specification::load(File.expand_path(
7
+ "../../../opsworks.gemspec",
8
+ Pathname.new(__FILE__).realpath,
9
+ ))
10
+
11
+ commands = %w(ssh)
12
+
13
+ global_opts = Trollop::options do
14
+ version "opsworks #{spec.version} (c) #{spec.authors.join(", ")}"
15
+ banner <<-EOS.unindent
16
+ usage: opsworks [COMMAND] [OPTIONS...]
17
+
18
+ #{spec.summary}
19
+
20
+ Commands
21
+ ssh #{OpsWorks::Commands::SSH.banner}
22
+
23
+ For help with specific commands, run:
24
+ opsworks COMMAND -h/--help
25
+
26
+ Options:
27
+ EOS
28
+ stop_on commands
29
+ end
30
+
31
+ command = ARGV.shift
32
+ command_opts = case command
33
+ when "ssh"
34
+ OpsWorks::Commands::SSH.run
35
+ when nil
36
+ Trollop::die "no command specified"
37
+ else
38
+ Trollop::die "unknown command: #{command}"
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,87 @@
1
+ require 'aws-sdk'
2
+ require 'awesome_print'
3
+ require 'trollop'
4
+
5
+ require 'opsworks'
6
+
7
+ SSH_PREFIX = "# --- OpsWorks ---"
8
+ SSH_POSTFIX = "# --- End of OpsWorks ---\n\n"
9
+
10
+ module OpsWorks::Commands
11
+ class SSH
12
+ def self.banner
13
+ "Generate and update SSH configuration files"
14
+ end
15
+
16
+ def self.run
17
+ options = Trollop::options do
18
+ banner <<-EOS.unindent
19
+ #{SSH.banner}
20
+
21
+ Options:
22
+ EOS
23
+ opt :update, "Update ~/.ssh/config directly"
24
+ opt :backup, "Backup old SSH config before updating"
25
+ opt :quiet, "Use SSH LogLevel quiet", default: true
26
+ opt :key_checking,
27
+ "Check SSH host keys (this can be annoying since dynamic " <<
28
+ "instances often change IP number)", short: 'c', default: false
29
+ end
30
+
31
+ config = OpsWorks.config
32
+
33
+ client = AWS::OpsWorks::Client.new
34
+
35
+ result = client.describe_instances(stack_id: config.stack_id)
36
+ instances = result.instances.select { |i| i[:status] == "online" }
37
+
38
+ instances.map! do |instance|
39
+ ip = instance[:public_ip] || instance[:elastic_ip]
40
+ parameters = {
41
+ "Host" => "#{instance[:hostname]} #{ip}",
42
+ "HostName" => ip,
43
+ "User" => config.ssh_user_name,
44
+ }
45
+ parameters.merge!({
46
+ "StrictHostKeyChecking" => "no",
47
+ "UserKnownHostsFile" => "/dev/null",
48
+ }) unless options[:host_checking]
49
+ parameters["LogLevel"] = "quiet" if options[:quiet]
50
+ parameters.map{ |param| param.join(" ") }.join("\n ")
51
+ end
52
+
53
+ new_contents = "\n" << SSH_PREFIX
54
+ new_contents << instances.join("\n")
55
+ new_contents << "\n" << SSH_POSTFIX
56
+
57
+ if options[:update]
58
+ ssh_config = "#{ENV['HOME']}/.ssh/config"
59
+ old_contents = File.read(ssh_config)
60
+
61
+ if options[:backup]
62
+ base_name = ssh_config + ".backup"
63
+ if File.exists? base_name
64
+ number = 0
65
+ file_name = "#{base_name}-#{number}"
66
+ while File.exists? file_name
67
+ file_name = "#{base_name}-#{number += 1}"
68
+ end
69
+ else
70
+ file_name = base_name
71
+ end
72
+ File.open(file_name, "w") { |file| file.puts old_contents }
73
+ end
74
+
75
+ File.open(ssh_config, "w") do |file|
76
+ file.puts old_contents.gsub(/#{SSH_PREFIX}.*#{SSH_POSTFIX}/m, '')
77
+ file.puts new_contents
78
+ end
79
+
80
+ puts "Successfully updated #{ssh_config} with " <<
81
+ "#{instances.length} instances!"
82
+ else
83
+ puts new_contents.strip
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,24 @@
1
+ require 'inifile'
2
+
3
+ module OpsWorks
4
+ def self.config
5
+ @config ||= Config.new
6
+ end
7
+
8
+ class Config
9
+ attr_reader :stack_id, :ssh_user_name
10
+
11
+ def initialize
12
+ ini = IniFile.load(ENV["AWS_CONFIG_FILE"])
13
+
14
+ aws_config = ini['default']
15
+ AWS.config(
16
+ access_key_id: aws_config["aws_access_key_id"],
17
+ secret_access_key: aws_config["aws_secret_access_key"],
18
+ )
19
+
20
+ @stack_id = ini['opsworks']['stack-id']
21
+ @ssh_user_name = ini['opsworks']['ssh-user-name']
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Opsworks
2
+ VERSION = "0.0.1"
3
+ end
data/opsworks.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'opsworks/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "opsworks"
8
+ spec.version = Opsworks::VERSION
9
+ spec.authors = ["Adam Lindberg"]
10
+ spec.email = ["hello@alind.io"]
11
+ spec.description = %q{Amazon OpsWorks CLI}
12
+ spec.summary = %q{Command line interface for Amazon OpsWorks}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "inifile", "~> 2.0.2"
22
+ spec.add_dependency "aws-sdk", "~> 1.11.3"
23
+ spec.add_dependency "trollop", "~> 2.0"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "awesome_print"
28
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opsworks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam Lindberg
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: inifile
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: aws-sdk
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.11.3
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.11.3
46
+ - !ruby/object:Gem::Dependency
47
+ name: trollop
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.3'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: awesome_print
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Amazon OpsWorks CLI
111
+ email:
112
+ - hello@alind.io
113
+ executables:
114
+ - opsworks
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - bin/opsworks
124
+ - lib/opsworks.rb
125
+ - lib/opsworks/cli.rb
126
+ - lib/opsworks/commands/ssh.rb
127
+ - lib/opsworks/config.rb
128
+ - lib/opsworks/version.rb
129
+ - opsworks.gemspec
130
+ homepage: ''
131
+ licenses:
132
+ - MIT
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ segments:
144
+ - 0
145
+ hash: 695574961303516982
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ segments:
153
+ - 0
154
+ hash: 695574961303516982
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 1.8.25
158
+ signing_key:
159
+ specification_version: 3
160
+ summary: Command line interface for Amazon OpsWorks
161
+ test_files: []