lex-ssh 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 54411d088fc2c86e4dc4307af92d0926d30209f2436d17d4dda4c5d82aaca882
4
- data.tar.gz: 88b360219dafe6628a962185c4e2844b57d60b884a759534d17662f810bfbdb7
3
+ metadata.gz: b2bb57872bee5cc75e4a9473c5b07512807e247f4b4efd2b28d7194307672a25
4
+ data.tar.gz: 74704ae18bc7bebd25d3d22e23b7281536dcade1296169654639037fe18fbd66
5
5
  SHA512:
6
- metadata.gz: 61a88165cef8514b90669ac51468b08577a55edce5b1430460ddf460a8594d8db6314719a537a7e382a3fed813ec713b72f02b7feac023daece499bee46fc091
7
- data.tar.gz: ce2d16a46fcd44eddcc85a86ec74c4ffc6f5d517c39222ee184d19e898c8f0be03e36174c8dbb1da9113f5a598fe8ad8cb8258b0ddb27ed0c84637269925a14f
6
+ metadata.gz: '06931bf6372eb719331c816ab10ab7eb1a1a23a10c3a9b2e7336d9eddc08a0c7dc350b07fa03cd4991c891c942dc078007ffa8008f3aedf5c162af32a2a5f64b'
7
+ data.tar.gz: 771a072383605088115f64432ceaa50baf42c937e70f65c713f4b8d7f3035fcabd2542438725481398db91203f6fb96503c519822c0f460fa6ffb004f1ca9c2d
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,17 @@
1
+ Layout/LineLength:
2
+ Max: 120
3
+ Metrics/MethodLength:
4
+ Max: 30
5
+ Metrics/ClassLength:
6
+ Max: 1500
7
+ Metrics/BlockLength:
8
+ Max: 50
9
+ Metrics/AbcSize:
10
+ Max: 30
11
+ Style/Documentation:
12
+ Enabled: false
13
+ AllCops:
14
+ TargetRubyVersion: 2.5
15
+ NewCops: enable
16
+ Style/FrozenStringLiteralComment:
17
+ Enabled: false
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at matthewdiverson@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in legion-extensions-ssh.gemspec
4
+ gemspec
@@ -0,0 +1,62 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lex-ssh (0.1.1)
5
+ bcrypt_pbkdf
6
+ ed25519
7
+ net-ssh
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ ast (2.4.1)
13
+ bcrypt_pbkdf (1.0.1)
14
+ diff-lcs (1.4.4)
15
+ ed25519 (1.2.4)
16
+ net-ssh (6.1.0)
17
+ parallel (1.19.2)
18
+ parser (2.7.2.0)
19
+ ast (~> 2.4.1)
20
+ rainbow (3.0.0)
21
+ rake (13.0.1)
22
+ regexp_parser (1.8.2)
23
+ rexml (3.2.4)
24
+ rspec (3.10.0)
25
+ rspec-core (~> 3.10.0)
26
+ rspec-expectations (~> 3.10.0)
27
+ rspec-mocks (~> 3.10.0)
28
+ rspec-core (3.10.0)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-expectations (3.10.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.10.0)
33
+ rspec-mocks (3.10.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.10.0)
36
+ rspec-support (3.10.0)
37
+ rubocop (1.1.0)
38
+ parallel (~> 1.10)
39
+ parser (>= 2.7.1.5)
40
+ rainbow (>= 2.2.2, < 4.0)
41
+ regexp_parser (>= 1.8)
42
+ rexml
43
+ rubocop-ast (>= 1.0.1)
44
+ ruby-progressbar (~> 1.7)
45
+ unicode-display_width (>= 1.4.0, < 2.0)
46
+ rubocop-ast (1.1.0)
47
+ parser (>= 2.7.1.5)
48
+ ruby-progressbar (1.10.1)
49
+ unicode-display_width (1.7.0)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ bundler (>= 2)
56
+ lex-ssh!
57
+ rake
58
+ rspec
59
+ rubocop
60
+
61
+ BUNDLED WITH
62
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Esity
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ # Legion::Extensions::Ssh
2
+
3
+ This gem connects Legion to *nix servers via SSH
@@ -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,69 @@
1
+ image: ruby:2.7
2
+
3
+ pipelines:
4
+ tags:
5
+ "v*":
6
+ - step:
7
+ name: Rubocop
8
+ caches:
9
+ - bundler
10
+ script:
11
+ - gem install rubocop
12
+ - gem update rubocop
13
+ - rubocop
14
+ - step:
15
+ name: RSpec
16
+ caches:
17
+ - bundler
18
+ script:
19
+ - gem install bundler
20
+ - gem update bundler
21
+ - bundle update
22
+ - bundle exec rspec
23
+ - step:
24
+ name: Push to RubyGems
25
+ deployment: RubyGems
26
+ script:
27
+ - gem install bundler gem-release rspec
28
+ - bundle install
29
+ - (umask 077 ; echo $gem_creds | base64 --decode > ~/.gem/credentials)
30
+ - gem release
31
+ artifacts:
32
+ - pkg/**
33
+ branches:
34
+ master:
35
+ - step:
36
+ caches:
37
+ - bundler
38
+ script:
39
+ - gem install rubocop
40
+ - gem update rubocop
41
+ - rubocop
42
+ - step:
43
+ caches:
44
+ - bundler
45
+ script:
46
+ - gem install bundler
47
+ - gem update bundler
48
+ - bundle update
49
+ - bundle exec rspec
50
+ develop:
51
+ - step:
52
+ caches:
53
+ - bundler
54
+ script:
55
+ - gem install rubocop
56
+ - gem update rubocop
57
+ - rubocop
58
+ - step:
59
+ caches:
60
+ - bundler
61
+ script:
62
+ - gem install bundler
63
+ - gem update bundler
64
+ - bundle update
65
+ - bundle exec rspec
66
+
67
+ definitions:
68
+ caches:
69
+ bundler: /usr/local/bundle
@@ -0,0 +1,34 @@
1
+ require_relative 'lib/legion/extensions/ssh/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'lex-ssh'
5
+ spec.version = Legion::Extensions::Ssh::VERSION
6
+ spec.authors = ['Esity']
7
+ spec.email = ['matthewdiverson@gmail.com']
8
+
9
+ spec.summary = 'LEX::SSH'
10
+ spec.description = 'LEX::SSH'
11
+ spec.homepage = 'https://bitbucket.org/legion-io/lex-ssh'
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
14
+
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = 'https://bitbucket.org/legion-io/lex-ssh'
17
+ spec.metadata['documentation_uri'] = 'https://legionio.atlassian.net/wiki/spaces/LEX/pages/614891551'
18
+ spec.metadata['changelog_uri'] = 'https://legionio.atlassian.net/wiki/spaces/LEX/pages/612270160'
19
+ spec.metadata['bug_tracker_uri'] = 'https://bitbucket.org/legion-io/lex-ssh/issues'
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_development_dependency 'bundler', '>= 2'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'rspec'
29
+ spec.add_development_dependency 'rubocop'
30
+
31
+ spec.add_dependency 'bcrypt_pbkdf'
32
+ spec.add_dependency 'ed25519'
33
+ spec.add_dependency 'net-ssh'
34
+ end
@@ -0,0 +1,9 @@
1
+ require 'legion/extensions/ssh/version'
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Ssh
6
+ extend Legion::Extensions::Core if Legion::Extensions.const_defined? :Core
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,31 @@
1
+ require 'net/ssh'
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Ssh
6
+ module Helpers
7
+ module Connection
8
+ def session(server:, user: 'root', **opts)
9
+ hash = {}
10
+ if opts.key? :password
11
+ hash[:password] = opts[:password]
12
+ elsif opts.key? :key_data
13
+ hash[:key_data] = opts[:key_data]
14
+ elsif opts.key? :keys
15
+ hash[:keys] = opts[:keys]
16
+ end
17
+ hash[:non_interactive] = opts.key?(:non_interactive) ? opts[:non_interactive] : true
18
+ hash[:passphrase] = opts[:passphrase] if opts.key? :passphrase
19
+ hash[:timeout] = opts.key(:timeout) ? opts[:timeout] : 5
20
+
21
+ Net::SSH.start(server, user, **hash)
22
+ end
23
+
24
+ def detect_os(session)
25
+ session.exec!('lsb_release -a')
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ module Legion
2
+ module Extensions
3
+ module Ssh
4
+ module Runners
5
+ module Command
6
+ include Legion::Extensions::Ssh::Helpers::Connection
7
+
8
+ def run(command:, server:, user: 'root', **opts)
9
+ session = session(server: server, user: user, **opts)
10
+ results = session.exec!(command)
11
+ { success: results.exitstatus.zero?, results: results, server: server }
12
+ end
13
+
14
+ def run_mulitple(commands:, server:, user: 'root', **opts)
15
+ session = session(server: server, user: user, **opts)
16
+ final_results = []
17
+
18
+ commands.each do |command|
19
+ results = session.exec!(command)
20
+ final_results.push({ success: results.exitstatus.zero?, results: results })
21
+ end
22
+ final_results
23
+ end
24
+
25
+ include Legion::Extensions::Helpers::Lex
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,27 @@
1
+ module Legion
2
+ module Extensions
3
+ module Ssh
4
+ module Runners
5
+ module State
6
+ include Legion::Extensions::Ssh::Helpers::Connection
7
+
8
+ def reboot(server:, user: 'root', delay: 0, **opts)
9
+ session = session(server: server, user: user, **opts)
10
+ command = delay.zero? ? 'shutdown -r now' : "shutdown -r +#{delay}"
11
+ results = session.exec!(command)
12
+ { success: results.exitstatus.zero?, results: results, server: server, delay: delay }
13
+ end
14
+
15
+ def shutdown(server:, user: 'root', delay: 0, **opts)
16
+ session = session(server: server, user: user, **opts)
17
+ command = delay.zero? ? 'shutdown -h now' : "shutdown -h +#{delay}"
18
+ results = session.exec!(command)
19
+ { success: results.exitstatus.zero?, results: results, server: server, delay: delay }
20
+ end
21
+
22
+ include Legion::Extensions::Helpers::Lex
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ module Legion
2
+ module Extensions
3
+ module Ssh
4
+ VERSION = '0.1.1'.freeze
5
+ end
6
+ end
7
+ end
metadata CHANGED
@@ -1,15 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lex-ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esity
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-30 00:00:00.000000000 Z
11
+ date: 2020-11-02 00:00:00.000000000 Z
12
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: '2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
13
69
  - !ruby/object:Gem::Dependency
14
70
  name: bcrypt_pbkdf
15
71
  requirement: !ruby/object:Gem::Requirement
@@ -58,7 +114,23 @@ email:
58
114
  executables: []
59
115
  extensions: []
60
116
  extra_rdoc_files: []
61
- files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".rubocop.yml"
121
+ - CODE_OF_CONDUCT.md
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bitbucket-pipelines.yml
128
+ - lex-ssh.gemspec
129
+ - lib/legion/extensions/ssh.rb
130
+ - lib/legion/extensions/ssh/helpers/connection.rb
131
+ - lib/legion/extensions/ssh/runners/command.rb
132
+ - lib/legion/extensions/ssh/runners/state.rb
133
+ - lib/legion/extensions/ssh/version.rb
62
134
  homepage: https://bitbucket.org/legion-io/lex-ssh
63
135
  licenses:
64
136
  - MIT