aws-ssm-console 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3d22ed651af6a689c6fcbd4428eb3bf4a3a7dc1d
4
+ data.tar.gz: ad8fc23bf150f006c7b7743892c0004f303e9940
5
+ SHA512:
6
+ metadata.gz: 7a7f399ea4cccbced13b7b6dd61196e21de3f06beb150da03a594f3475ca83f0da88bbfdeb7c0961a6f43358ec74d08f4d3b8212f421b199907a897e8710748c
7
+ data.tar.gz: 54f262d4115ad16ec88747b43184fc7cd2c5f0d66e22b4cce8a84a35c83b81d08a5dee773c92a7dd5fd5fb02d4c3a9aafa71cde8b83591474da0608dc5b95202
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in aws-ssm-console.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Masataka Suzuki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Aws::Ssm::Console
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'aws-ssm-console'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install aws-ssm-console
18
+
19
+ ## Usage
20
+
21
+ ### Configuration
22
+
23
+ You should configure some environment variables to use AWS SDK.
24
+
25
+ - `AWS_REGION`
26
+ - `AWS_ACCESS_KEY_ID`
27
+ - `AWS_SECRET_ACCESS_KEY`
28
+
29
+ ### Run Command
30
+
31
+ ```
32
+ $ bin/aws-ssm-console --instance-ids=i-xxxx,i-yyyy,...
33
+ >>
34
+ ```
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+
40
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/koshigoe/aws-ssm-console.
45
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -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 'aws-sdk-core'
5
+ require 'aws/ssm/console/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'aws-ssm-console'
9
+ spec.version = Aws::SSM::Console::VERSION
10
+ spec.authors = ['koshigoe']
11
+ spec.email = ['koshigoeb@gmail.com']
12
+ spec.license = 'MIT'
13
+
14
+ spec.summary = 'REPL for AWS SSM.'
15
+ spec.description = 'REPL for AWS SSM.'
16
+ spec.homepage = 'https://github.com/koshigoe/aws-ssm-console'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.12'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.0'
26
+
27
+ spec.add_dependency 'aws-sdk', '~> 2.6'
28
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'aws/ssm/console'
5
+ require 'optparse'
6
+
7
+ options = {}
8
+ OptionParser.new do |opt|
9
+ opt.on('--instance-ids id,id,...', Array) { |v| options[:instance_ids] = v }
10
+
11
+ opt.parse!(ARGV)
12
+ end
13
+
14
+ raise ArgumentError, '--instance-ids is required' unless options[:instance_ids]
15
+
16
+ Aws::SSM::Console.run(options[:instance_ids])
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "aws/ssm/console"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,19 @@
1
+ require 'aws-sdk'
2
+ require 'aws/ssm/console/version'
3
+ require 'aws/ssm/console/runner'
4
+ require 'aws/ssm/console/command'
5
+ require 'aws/ssm/console/printer'
6
+
7
+ module Aws
8
+ module SSM
9
+ module Console
10
+ def self.client
11
+ @client ||= Aws::SSM::Client.new
12
+ end
13
+
14
+ def self.run(instance_ids)
15
+ Aws::SSM::Console::Runner.new(instance_ids).run
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ module Aws
2
+ module SSM
3
+ module Console
4
+ class Command
5
+ attr_reader :start_timeout, :execution_timeout, :instance_ids
6
+
7
+ DEFAULT_START_TIMEOUT = 30
8
+ DEFAULT_EXECUTION_TIMEOUT = 3600
9
+
10
+ def initialize(instance_ids:, start_timeout: DEFAULT_START_TIMEOUT, execution_timeout: DEFAULT_EXECUTION_TIMEOUT)
11
+ @instance_ids = instance_ids
12
+ @start_timeout = start_timeout
13
+ @execution_timeout = execution_timeout
14
+ end
15
+
16
+ def invoke(command)
17
+ response = Aws::SSM::Console.client.send_command(
18
+ document_name: 'AWS-RunShellScript',
19
+ instance_ids: instance_ids,
20
+ timeout_seconds: start_timeout,
21
+ parameters: {
22
+ commands: [command],
23
+ executionTimeout: [execution_timeout.to_s],
24
+ }
25
+ )
26
+ Aws::SSM::Console::Printer.new(response).print
27
+ rescue Aws::SSM::Errors::ServiceError
28
+ # TODO: error handling
29
+ raise
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,48 @@
1
+ module Aws
2
+ module SSM
3
+ module Console
4
+ class Printer
5
+ attr_reader :command, :command_id, :instance_ids
6
+
7
+ def initialize(response)
8
+ @command = response.command.parameters['commands'][0]
9
+ @command_id = response.command.command_id
10
+ @instance_ids = response.command.instance_ids
11
+ end
12
+
13
+ def print
14
+ puts 'Running %{command}' % { command: command }
15
+
16
+ wait do
17
+ outputs do |instance_id, status, output|
18
+ puts "[%{instance_id}] %<status>10s: %{command}\n%{output}" % { instance_id: instance_id, status: status, command: command, output: output}
19
+ end
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def wait(time: 1)
26
+ loop do
27
+ response = Aws::SSM::Console.client.list_command_invocations(command_id: command_id)
28
+ break unless response.command_invocations.any? { |x| %w(Pending InProgress).include?(x.status) }
29
+ sleep(time)
30
+ end
31
+
32
+ yield if block_given?
33
+ end
34
+
35
+ def outputs
36
+ instance_ids.each do |instance_id|
37
+ response = Aws::SSM::Console.client.list_command_invocations(command_id: command_id, instance_id: instance_id, details: true)
38
+ response.command_invocations.each do |invocation|
39
+ invocation.command_plugins.map do |command_plugin|
40
+ yield(instance_id, command_plugin.status, command_plugin.output.split("\n").map { |x| "\t#{x}" }.join("\n"))
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,26 @@
1
+ require 'readline'
2
+
3
+ module Aws
4
+ module SSM
5
+ module Console
6
+ class Runner
7
+ attr_reader :command
8
+
9
+ def initialize(instance_ids)
10
+ @command = Aws::SSM::Console::Command.new(instance_ids: instance_ids)
11
+ end
12
+
13
+ def run
14
+ stty_save = `stty -g`.chomp
15
+ trap('INT') { system 'stty', stty_save; exit }
16
+
17
+ loop do
18
+ cmd = Readline.readline('>> ', true)
19
+ break unless cmd
20
+ command.invoke(cmd)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ module Aws
2
+ module SSM
3
+ module Console
4
+ VERSION = '0.1.0'.freeze
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aws-ssm-console
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - koshigoe
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aws-sdk
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.6'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.6'
69
+ description: REPL for AWS SSM.
70
+ email:
71
+ - koshigoeb@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - aws-ssm-console.gemspec
84
+ - bin/aws-ssm-console
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/aws/ssm/console.rb
88
+ - lib/aws/ssm/console/command.rb
89
+ - lib/aws/ssm/console/printer.rb
90
+ - lib/aws/ssm/console/runner.rb
91
+ - lib/aws/ssm/console/version.rb
92
+ homepage: https://github.com/koshigoe/aws-ssm-console
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.5.1
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: REPL for AWS SSM.
116
+ test_files: []