Skip to content

Commit

Permalink
Initial Creation (#1)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthew Newell <[email protected]>
  • Loading branch information
wheatevo and wheatevo authored Mar 10, 2021
1 parent d79abe0 commit 2d3c90a
Show file tree
Hide file tree
Showing 29 changed files with 2,821 additions and 30 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,25 @@ jobs:
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7.2
- name: Run the default task
- name: Run unit tests and code linting
run: |
gem install bundler -v 2.2.9
bundle install
bundle exec rake
bundle exec yard
- name: Deploy documentation
if: github.ref == 'refs/heads/main'
uses: crazy-max/[email protected]
with:
target_branch: gh-pages
build_dir: doc
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Release Gem
if: contains(github.ref, 'refs/tags/v')
uses: dawidd6/[email protected]
with:
github_token: ${{secrets.GITHUB_TOKEN}}
api_key: ${{secrets.RUBYGEMS_API_KEY}}
30 changes: 29 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
AllCops:
TargetRubyVersion: 2.4
NewCops: enable

Style/StringLiterals:
Enabled: true
Expand All @@ -10,4 +11,31 @@ Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes

Layout/LineLength:
Max: 120
Max: 150

Metrics/ClassLength:
Max: 250

Metrics/BlockLength:
Exclude:
- spec/**/*.rb
- remotus.gemspec
- lib/remotus/ssh_connection.rb

Metrics/AbcSize:
Max: 25
Exclude:
- lib/remotus/ssh_connection.rb

Metrics/MethodLength:
Max: 20
Exclude:
- lib/remotus/ssh_connection.rb

Metrics/CyclomaticComplexity:
Exclude:
- lib/remotus/ssh_connection.rb

Metrics/PerceivedComplexity:
Exclude:
- lib/remotus/ssh_connection.rb
6 changes: 0 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,3 @@ source "https://rubygems.org"

# Specify your gem's dependencies in remotus.gemspec
gemspec

gem "rake", "~> 13.0"

gem "rspec", "~> 3.0"

gem "rubocop", "~> 1.7"
103 changes: 103 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
PATH
remote: .
specs:
remotus (0.1.0)
connection_pool (~> 2.2)
net-scp (~> 3.0)
net-ssh (~> 6.1)
winrm (~> 2.3)
winrm-fs (~> 1.3)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
builder (3.2.4)
connection_pool (2.2.3)
diff-lcs (1.4.4)
erubi (1.10.0)
ffi (1.15.0)
gssapi (1.3.1)
ffi (>= 1.0.1)
gyoku (1.3.1)
builder (>= 2.1.2)
httpclient (2.8.3)
little-plugger (1.1.4)
logging (2.3.0)
little-plugger (~> 1.1)
multi_json (~> 1.14)
multi_json (1.15.0)
net-scp (3.0.0)
net-ssh (>= 2.6.5, < 7.0.0)
net-ssh (6.1.0)
nori (2.6.0)
parallel (1.20.1)
parser (3.0.0.0)
ast (~> 2.4.1)
rainbow (3.0.0)
rake (13.0.3)
regexp_parser (2.1.1)
rexml (3.2.4)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
rubocop (1.11.0)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.2.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.4.1)
parser (>= 2.7.1.5)
rubocop-rake (0.5.1)
rubocop
rubocop-rspec (2.2.0)
rubocop (~> 1.0)
rubocop-ast (>= 1.1.0)
ruby-progressbar (1.11.0)
rubyntlm (0.6.3)
rubyzip (2.3.0)
unicode-display_width (2.0.0)
winrm (2.3.6)
builder (>= 2.1.2)
erubi (~> 1.8)
gssapi (~> 1.2)
gyoku (~> 1.0)
httpclient (~> 2.2, >= 2.2.0.2)
logging (>= 1.6.1, < 3.0)
nori (~> 2.0)
rubyntlm (~> 0.6.0, >= 0.6.3)
winrm-fs (1.3.5)
erubi (~> 1.8)
logging (>= 1.6.1, < 3.0)
rubyzip (~> 2.0)
winrm (~> 2.0)
yard (0.9.26)

PLATFORMS
x86_64-linux

DEPENDENCIES
rake (~> 13.0)
remotus!
rspec (~> 3.0)
rubocop (~> 1.7)
rubocop-rake (~> 0.5)
rubocop-rspec (~> 2.2)
yard (~> 0.9)

BUNDLED WITH
2.2.9
83 changes: 78 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Remotus

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/remotus`. To experiment with that code, run `bin/console` for an interactive prompt.

TODO: Delete this and the text above, and describe your gem
Remotus provides a simple ruby interface for pooling remote SSH and WinRM connections and managing remote credentials. Custom authentication stores may be added to allow remote credentials to be automatically retrieved.

## Installation

Expand All @@ -22,7 +20,82 @@ Or install it yourself as:

## Usage

TODO: Write usage instructions here
```ruby
# Initialize a new connection pool to remotehost.local and auto-determine whether to use SSH or WinRM
connection = Remotus.connect("remotehost.local")

# Initialize a new connection pool to remotehost.local with a defined protocol and port
connection = Remotus.connect("remotehost.local", proto: :ssh, port: 2222)

# Create a credential for the new connection pool
connection.credential = Remotus::Auth::Credential.new("username", "password")

# Run a command on the remote host
result = connection.run("hostname")

result.command
# => "hostname"

result.stdout
# => "remotehost.local\n"

result.stderr
# => ""

result.output
# => "remotehost.local\n"

result.exit_code
# => 0

# Run a command on the remote host with sudo (Linux only, requires password to be specified)
result = connection.run("ls /root", sudo: true)

# Run a script on the remote host
connection.run_script("/local/script.sh", "/remote/path/script.sh")

# Run a script on the remote host with arguments
connection.run_script("/local/script.sh", "/remote/path/script.sh", "arg1", "arg2")

# Upload a file to the remote host
connection.upload("/local/file.txt", "/remote/path/file.txt")

# Download a file from the remote host
connection.download("/remote/path/file.txt", "/local/file.txt")
```

Full documentation is available in the [Remotus GitHub Pages](https://wheatevo.github.io/remotus/).

### Extending Remotus

Remotus may be extended by adding more authentication stores to gather remote credential data from centralized services.

#### Authentication Stores

More authentication stores may be added by creating a new class that inherits from `Remotus::Auth::Store` and implementing the `credential` method. The `credential` method should receive a `Remotus::SshConnection` or `Remotus::WinrmConnection` and an options hash and return a `Remotus::Auth::Credential` or `nil` if no credential can be found.

Once a new authentication store has been defined, ensure it is used by Remotus by adding it to `Remotus::Auth.stores`.

```ruby
# Define a new authentication store that returns "<hostname>_password" for any connection
#
# This is for demonstration purposes only, please do not use any password with your hostname or "password" in it :)
require "remotus"

class SimpleStore < Remotus::Auth::Store
def credential(connection, **options)
"#{connection.host}_password"
end
end

# Add the authentication store to the array of existing authentication stores
Remotus::Auth.stores << SimpleStore.new

# Use the authentication store
connection = Remotus.connect("remotehost.local", proto: :ssh)
Remotus::Auth.credential(connection)
# => "remotehost.local_password"
```

## Development

Expand All @@ -32,7 +105,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/remotus.
Bug reports and pull requests are welcome on GitHub at https://github.com/wheatevo/remotus.

## License

Expand Down
Loading

0 comments on commit 2d3c90a

Please sign in to comment.