executo 0.3.12

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
+ SHA256:
3
+ metadata.gz: 918d5ac389754c1f27b8f8f4f299fe188e3c73f4f7ef12a8a3a186d1ebcb2c9f
4
+ data.tar.gz: 70add86102029bc613886c60e7eae2e18e0d21198f0ed936c9ef14192aa65565
5
+ SHA512:
6
+ metadata.gz: e98b92d408bc2fade981fd061734402fc9a43f2d352c451bbb2de3e53a564273251772fa352f266d317a24b76c09b27916d562b18d00442198de940b84719bf6
7
+ data.tar.gz: 20807577dc4a072a526b784d6743b2365a2d5b02bc511009994c826a4cf6eca3a9c45d0f85dda5542ea78b1445c7a4aa71e6757f91dd31b6241c7e1c6895b50c
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,30 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ TargetRubyVersion: 2.7
4
+ Exclude:
5
+ - "doc/**/*"
6
+ - "log/**/*"
7
+
8
+ Metrics:
9
+ Enabled: false
10
+
11
+ Style/PercentLiteralDelimiters:
12
+ PreferredDelimiters:
13
+ "%": "[]"
14
+ "%i": "[]"
15
+ "%q": "[]"
16
+ "%Q": "[]"
17
+ "%r": "[]"
18
+ "%s": "[]"
19
+ "%w": "[]"
20
+ "%W": "[]"
21
+ "%x": "[]"
22
+
23
+ Style/Documentation:
24
+ Enabled: false
25
+
26
+ Style/ClassAndModuleChildren:
27
+ Enabled: false
28
+
29
+ Layout/LineLength:
30
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.2
7
+ before_install: gem install bundler -v 1.17.2
@@ -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 tom@degrunt.nl. 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 [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in executo.gemspec
6
+ gem 'pry'
7
+
8
+ gemspec
9
+
10
+ gem "ruby-lsp", "~> 0.2.0", :group => :development
11
+ gem "solargraph"
data/Gemfile.lock ADDED
@@ -0,0 +1,181 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ executo (0.3.12)
5
+ active_attr (>= 0.15)
6
+ activejob (> 7.0.0)
7
+ activemodel (> 7.0.0)
8
+ activesupport (> 7.0.0)
9
+ redis (< 5)
10
+ sidekiq (> 5.1, < 7.0)
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ actionpack (7.0.4)
16
+ actionview (= 7.0.4)
17
+ activesupport (= 7.0.4)
18
+ rack (~> 2.0, >= 2.2.0)
19
+ rack-test (>= 0.6.3)
20
+ rails-dom-testing (~> 2.0)
21
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
22
+ actionview (7.0.4)
23
+ activesupport (= 7.0.4)
24
+ builder (~> 3.1)
25
+ erubi (~> 1.4)
26
+ rails-dom-testing (~> 2.0)
27
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
28
+ active_attr (0.15.4)
29
+ actionpack (>= 3.0.2, < 7.1)
30
+ activemodel (>= 3.0.2, < 7.1)
31
+ activesupport (>= 3.0.2, < 7.1)
32
+ activejob (7.0.4)
33
+ activesupport (= 7.0.4)
34
+ globalid (>= 0.3.6)
35
+ activemodel (7.0.4)
36
+ activesupport (= 7.0.4)
37
+ activesupport (7.0.4)
38
+ concurrent-ruby (~> 1.0, >= 1.0.2)
39
+ i18n (>= 1.6, < 2)
40
+ minitest (>= 5.1)
41
+ tzinfo (~> 2.0)
42
+ ast (2.4.2)
43
+ auxilium (3.0.24)
44
+ actionpack (> 5.1)
45
+ activemodel (> 5.1)
46
+ activesupport (> 5.1)
47
+ pundit (> 2)
48
+ responders (> 3)
49
+ rolify (> 5)
50
+ backport (1.2.0)
51
+ benchmark (0.2.0)
52
+ builder (3.2.4)
53
+ coderay (1.1.3)
54
+ concurrent-ruby (1.1.10)
55
+ connection_pool (2.3.0)
56
+ crass (1.0.6)
57
+ diff-lcs (1.5.0)
58
+ e2mmap (0.1.0)
59
+ erubi (1.11.0)
60
+ globalid (1.0.0)
61
+ activesupport (>= 5.0)
62
+ i18n (1.12.0)
63
+ concurrent-ruby (~> 1.0)
64
+ jaro_winkler (1.5.4)
65
+ json (2.6.2)
66
+ kramdown (2.4.0)
67
+ rexml
68
+ kramdown-parser-gfm (1.1.0)
69
+ kramdown (~> 2.0)
70
+ language_server-protocol (3.17.0.0)
71
+ loofah (2.19.0)
72
+ crass (~> 1.0.2)
73
+ nokogiri (>= 1.5.9)
74
+ method_source (1.0.0)
75
+ minitest (5.16.3)
76
+ nokogiri (1.13.9-arm64-darwin)
77
+ racc (~> 1.4)
78
+ nokogiri (1.13.9-x86_64-darwin)
79
+ racc (~> 1.4)
80
+ parallel (1.22.1)
81
+ parser (3.1.2.1)
82
+ ast (~> 2.4.1)
83
+ prettier_print (0.1.0)
84
+ pry (0.14.1)
85
+ coderay (~> 1.1)
86
+ method_source (~> 1.0)
87
+ pundit (2.2.0)
88
+ activesupport (>= 3.0.0)
89
+ racc (1.6.0)
90
+ rack (2.2.4)
91
+ rack-test (2.0.2)
92
+ rack (>= 1.3)
93
+ rails-dom-testing (2.0.3)
94
+ activesupport (>= 4.2.0)
95
+ nokogiri (>= 1.6)
96
+ rails-html-sanitizer (1.4.3)
97
+ loofah (~> 2.3)
98
+ railties (7.0.4)
99
+ actionpack (= 7.0.4)
100
+ activesupport (= 7.0.4)
101
+ method_source
102
+ rake (>= 12.2)
103
+ thor (~> 1.0)
104
+ zeitwerk (~> 2.5)
105
+ rainbow (3.1.1)
106
+ rake (13.0.6)
107
+ redis (4.8.0)
108
+ regexp_parser (2.5.0)
109
+ responders (3.0.1)
110
+ actionpack (>= 5.0)
111
+ railties (>= 5.0)
112
+ reverse_markdown (2.1.1)
113
+ nokogiri
114
+ rexml (3.2.5)
115
+ rolify (6.0.0)
116
+ rubocop (1.35.1)
117
+ json (~> 2.3)
118
+ parallel (~> 1.10)
119
+ parser (>= 3.1.2.1)
120
+ rainbow (>= 2.2.2, < 4.0)
121
+ regexp_parser (>= 1.8, < 3.0)
122
+ rexml (>= 3.2.5, < 4.0)
123
+ rubocop-ast (>= 1.20.1, < 2.0)
124
+ ruby-progressbar (~> 1.7)
125
+ unicode-display_width (>= 1.4.0, < 3.0)
126
+ rubocop-ast (1.21.0)
127
+ parser (>= 3.1.1.0)
128
+ ruby-lsp (0.2.4)
129
+ language_server-protocol
130
+ sorbet-runtime
131
+ syntax_tree (>= 2.4)
132
+ ruby-progressbar (1.11.0)
133
+ sidekiq (6.5.8)
134
+ connection_pool (>= 2.2.5, < 3)
135
+ rack (~> 2.0)
136
+ redis (>= 4.5.0, < 5)
137
+ solargraph (0.47.2)
138
+ backport (~> 1.2)
139
+ benchmark
140
+ bundler (>= 1.17.2)
141
+ diff-lcs (~> 1.4)
142
+ e2mmap
143
+ jaro_winkler (~> 1.5)
144
+ kramdown (~> 2.3)
145
+ kramdown-parser-gfm (~> 1.1)
146
+ parser (~> 3.0)
147
+ reverse_markdown (>= 1.0.5, < 3)
148
+ rubocop (>= 0.52)
149
+ thor (~> 1.0)
150
+ tilt (~> 2.0)
151
+ yard (~> 0.9, >= 0.9.24)
152
+ sorbet-runtime (0.5.10386)
153
+ syntax_tree (3.5.0)
154
+ prettier_print
155
+ thor (1.2.1)
156
+ tilt (2.0.11)
157
+ tzinfo (2.0.5)
158
+ concurrent-ruby (~> 1.0)
159
+ unicode-display_width (2.2.0)
160
+ webrick (1.7.0)
161
+ yard (0.9.28)
162
+ webrick (~> 1.7.0)
163
+ zeitwerk (2.6.6)
164
+
165
+ PLATFORMS
166
+ arm64-darwin-21
167
+ arm64-darwin-22
168
+ x86_64-darwin-21
169
+
170
+ DEPENDENCIES
171
+ auxilium (~> 3)
172
+ executo!
173
+ minitest (> 5.0)
174
+ pry
175
+ rake (> 10.0)
176
+ rubocop
177
+ ruby-lsp (~> 0.2.0)
178
+ solargraph
179
+
180
+ BUNDLED WITH
181
+ 2.3.16
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Tom de Grunt
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.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Executo
2
+
3
+ Unix command execution from Rails. Jobs can be executed on remote servers, as long as they run executo.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'executo'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install executo
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ Executo.publish('localhost', 'ls', ['-al'])
25
+ ```
26
+
27
+ ## Development
28
+
29
+ Run worker using `sidekiq -r ./boot.rb -C sidekiq.yml`
30
+ Run active-job worker using `sidekiq -r ./boot_activejob.rb`
31
+
32
+ Publish jobs using:
33
+
34
+ ```ruby
35
+ Executo.publish('localhost', 'ls', ['-al'])
36
+ ```
37
+
38
+ You can publish jobs encrypted as well, which means that the command and parameters, but also passed options are encrypted before sent to the server (sidekiq/redis).
39
+ They are only decrypted in memory for the command te be executed. Job options are never encrypted.
40
+ This is ideal if you don't want email addresses or passwords to be littered over log files or in the redis database.
41
+
42
+ Publish encrypted jobs using:
43
+
44
+ ```ruby
45
+ Executo.publish('localhost', 'ls', ['-al'], encrypt: true)
46
+ ```
47
+
48
+ Schedule for a host:
49
+
50
+ ```ruby
51
+ Executo.schedule('localhost', [
52
+ ['30 * * * *', { class_name: '', arguments: {} }]
53
+ ])
54
+ ```
55
+
56
+ ## Contributing
57
+
58
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/executo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
59
+
60
+ ## License
61
+
62
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
63
+
64
+ ## Code of Conduct
65
+
66
+ Everyone interacting in the Executo project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/entdec/executo/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+ require 'bundler/gem_tasks'
5
+ require 'rake/testtask'
6
+
7
+ Bundler.setup
8
+
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'test'
11
+ t.libs << 'lib'
12
+ t.test_files = FileList['test/**/*_test.rb']
13
+ end
14
+
15
+ task default: :test
16
+
17
+ # Adds the Auxilium semver task
18
+ spec = Gem::Specification.find_by_name 'auxilium'
19
+ load "#{spec.gem_dir}/lib/tasks/semver.rake"
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'bundler'
6
+ Bundler.require
7
+ require 'executo'
8
+ require File.join(Dir.pwd, 'boot.rb')
9
+
10
+ Executo.setup do |config|
11
+ config.redis = { url: 'redis://localhost:6379/1' }
12
+ config.active_job_redis = { url: 'redis://localhost:6379/0' }
13
+ end
14
+
15
+ Pry.start
data/bin/executo ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler'
5
+ Bundler.setup
6
+ require 'executo'
7
+ require File.join(Dir.pwd, 'boot.rb')
8
+
9
+ Executo.publish(ARGV[0], ARGV[1..-1].join(' '))
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
data/bin/sidekiq ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'sidekiq' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path('bundle', __dir__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
+
29
+ load Gem.bin_path('sidekiq', 'sidekiq')
data/bin/sidekiqctl ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'sidekiqctl' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path('bundle', __dir__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
+
29
+ load Gem.bin_path('sidekiq', 'sidekiqctl')
data/boot.rb ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+ Bundler.require
5
+ require 'executo'
6
+ require 'net/http'
7
+ require 'uri'
8
+
9
+ Sidekiq.strict_args!
10
+
11
+ Executo.setup do |config|
12
+ config.redis = { url: 'redis://localhost:6379/1' }
13
+ config.active_job_redis = { url: 'redis://localhost:6379/0' }
14
+ end
15
+
16
+ Sidekiq.configure_server do |config|
17
+ config.redis = Executo.config.redis
18
+ config.logger = Executo.config.logger.tagged('Sidekiq')
19
+ end
data/boot_activejob.rb ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+ require 'executo'
5
+ require 'active_job'
6
+ require 'pry'
7
+
8
+ class LsProcessService < Executo::FeedbackProcessService
9
+ arguments :now
10
+
11
+ def perform
12
+ stdout&.each do |line|
13
+ logger.info line
14
+ end
15
+ end
16
+ end
17
+
18
+ Executo.setup do |config|
19
+ config.redis = { url: 'redis://localhost:6379/1' }
20
+ config.active_job_redis = { url: 'redis://localhost:6379/0' }
21
+ end
22
+
23
+ ActiveJob::Base.logger = Executo.config.logger.tagged('ActiveJob')
24
+ ActiveJob::Base.logger.level = Logger::WARN
25
+
26
+ Sidekiq.configure_server do |config|
27
+ config.logger = Executo.config.logger.tagged('Sidekiq')
28
+ config.logger.level = Logger::WARN
29
+ config.redis = { url: 'redis://localhost:6379/0' }
30
+ end
data/executo.gemspec ADDED
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'executo/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'executo'
9
+ spec.version = Executo::VERSION
10
+ spec.authors = ['Tom de Grunt']
11
+ spec.email = ['tom@degrunt.nl']
12
+
13
+ spec.summary = 'Executes commands on remote servers'
14
+ spec.description = 'Executes commands on remote servers'
15
+ spec.homepage = 'https://github.com/entdec/excecuto'
16
+ spec.license = 'MIT'
17
+
18
+ spec.metadata['rubygems_mfa_required'] = 'true'
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/entdec/excecuto'
21
+ spec.metadata['changelog_uri'] = 'https://github.com/entdec/excecuto'
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = 'bin'
29
+ spec.executables = 'executo'
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_dependency 'active_attr', '>= 0.15'
33
+ spec.add_dependency 'activejob', '> 7.0.0'
34
+ spec.add_dependency 'activemodel', '> 7.0.0'
35
+ spec.add_dependency 'activesupport', '> 7.0.0'
36
+ spec.add_dependency 'sidekiq', '> 5.1', '< 7.0'
37
+ spec.add_dependency 'redis', '< 5'
38
+
39
+ spec.add_development_dependency 'auxilium', '~> 3'
40
+ spec.add_development_dependency 'minitest', '> 5.0'
41
+ spec.add_development_dependency 'pry'
42
+ spec.add_development_dependency 'rake', '> 10.0'
43
+ spec.add_development_dependency 'rubocop'
44
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
4
+ require 'shellwords'
5
+
6
+ module Executo
7
+ class CLI
8
+ class << self
9
+ def run(cmd, stdout:, stderr:, stdin_content: [], stdin_newlines: true, shell_escape: true)
10
+ raise 'cmd must be an array of Strings.' unless array_of_strings?(cmd)
11
+ raise 'stdout must be a Proc.' unless stdout.is_a?(Proc)
12
+ raise 'stderr must be a Proc.' unless stderr.is_a?(Proc)
13
+ raise 'stdin_content must be an Array of Strings.' unless array_of_strings?(stdin_content)
14
+
15
+ computed_cmd = escaped_command(cmd, shell_escape: shell_escape)
16
+ Executo.logger.debug "computed cmd: #{computed_cmd}"
17
+ Open3.popen3(computed_cmd) do |stdin_stream, stdout_stream, stderr_stream, thread|
18
+ threads = []
19
+ threads << write_stream(stdin_stream, stdin_content, newlines: stdin_newlines)
20
+ threads << read_stream(stdout_stream, stdout)
21
+ threads << read_stream(stderr_stream, stderr)
22
+ threads << thread
23
+
24
+ threads.each(&:join)
25
+ thread.value
26
+ end
27
+ end
28
+
29
+ def escaped_command(command, shell_escape: true)
30
+ return command.join unless shell_escape
31
+
32
+ command.shelljoin
33
+ end
34
+
35
+ def write_stream(stream, content, newlines: true)
36
+ Thread.new do
37
+ content.each do |input_line|
38
+ stream.write(input_line)
39
+ stream.write("\n") if input_line[-1] != "\n" && newlines
40
+ end
41
+ rescue Errno::EPIPE
42
+ nil
43
+ ensure
44
+ stream.close
45
+ end
46
+ end
47
+
48
+ def read_stream(stream, callback)
49
+ Thread.new do
50
+ until (line = stream.gets).nil?
51
+ callback.call(line)
52
+ end
53
+ rescue IOError
54
+ # ignore
55
+ end
56
+ end
57
+
58
+ def array_of_strings?(array)
59
+ array.is_a?(Array) && array.all? { |c| c.is_a?(String) }
60
+ end
61
+ end
62
+ end
63
+ end