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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/Rakefile +6 -0
- data/aws-ssm-console.gemspec +28 -0
- data/bin/aws-ssm-console +16 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/aws/ssm/console.rb +19 -0
- data/lib/aws/ssm/console/command.rb +34 -0
- data/lib/aws/ssm/console/printer.rb +48 -0
- data/lib/aws/ssm/console/runner.rb +26 -0
- data/lib/aws/ssm/console/version.rb +7 -0
- metadata +116 -0
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
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
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,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
|
data/bin/aws-ssm-console
ADDED
@@ -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,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
|
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: []
|