remote_marshal 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: 95af049cc6fd1d033f5ff94f615d995664f31e85
4
+ data.tar.gz: e95ec13bbce6f3edecfc88a064cd4aff176e8f19
5
+ SHA512:
6
+ metadata.gz: a041cf5e2bdb19e098782125683ee14839d2a42e6686da8b4f6982a222d5e3b64b97a439eab58fa5ced0c7e2c80bb6081450c4a250dce365303c0e49da4fc932
7
+ data.tar.gz: 62a36ffdd74cc20906d3ed010f716d18428d61cb5e4ef3d5a61192ce03ef64323f533a0c1277de2ce1ee30a52f8ca6fb7e7c00d75a1ee8a7889b6465f677fbd7
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ *.swp
3
+ .ruby-version
4
+ .bundle
5
+ .DS_Store
6
+ pkg
7
+ vendor/bundle
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in remote_marshal.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 TODO: Write your name
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,44 @@
1
+ # RemoteMarshal
2
+
3
+ RemoteMarshal is a library for Marshal on SSH.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'remote_marshal'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install remote_marshal
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ remote = RemoteMarshal.new('example.com', 'username', keys: ['~/.ssh/some_key_here'])
25
+
26
+ p remote.eval { Dir.glob('/some/directory/**/*') }
27
+ # => [exit-status, return value(some ruby object) or stderror(String)]
28
+ ```
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
33
+
34
+ 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).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/remote_marshal. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
39
+
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
44
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "remote_marshal"
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,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module RemoteMarshal
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,97 @@
1
+ require "remote_marshal/version"
2
+
3
+ class RemoteMarshal
4
+ def initialize(host, user, options)
5
+ @ssh = create_ssh(host, user, options)
6
+ end
7
+
8
+ def eval(&block)
9
+ command = block.to_source(strip_enclosure: true)
10
+
11
+ call { |dir| marshal(StringIO.new(command), File.join(dir, token)) }
12
+ end
13
+
14
+ def file(filename)
15
+ call { |dir| marshal(filename, File.join(dir, File.basename(filename))) }
16
+ end
17
+
18
+ def exec!(command)
19
+ status, output, error = nil, [], []
20
+
21
+ @ssh.call do |ssh|
22
+ channel = ssh.open_channel do |chan|
23
+ chan.exec command do |ch, success|
24
+ raise command unless success
25
+
26
+ ch.on_data { |_, data| output << data }
27
+ ch.on_extended_data { |_, _, data| error << data }
28
+ ch.on_request('exit-status') { |_, data| status = data.read_long }
29
+ end
30
+ end
31
+
32
+ channel.wait
33
+ end
34
+
35
+ [status, (status == 0 ? output : error).join]
36
+ end
37
+
38
+ %i(upload! download!).each do |name|
39
+ define_method(name) do |src, dst|
40
+ @ssh.call { |ssh| ssh.scp.public_send(name, src, dst) }
41
+ end
42
+ end
43
+
44
+ def test?(name, options)
45
+ exec!(%([ #{option} #{name} ])
46
+ end
47
+
48
+ private
49
+
50
+ def call(&block)
51
+ status, output = mktmpdir
52
+
53
+ return [status, output] unless status == 0
54
+
55
+ dir = output.chomp
56
+ ret = block.(dir)
57
+ status, output = remove_entry_secure(dir)
58
+
59
+ return [status, output] unless status == 0
60
+
61
+ status, output = *ret
62
+
63
+ return [status, output] unless status == 0
64
+
65
+ [status, Marshal.load(output.chomp)]
66
+ end
67
+
68
+ def mktmpdir
69
+ exec!("ruby -r tmpdir -e 'puts Dir.mktmpdir'")
70
+ end
71
+
72
+ def remove_entry_secure(dir)
73
+ exec!(%(ruby -r fileutils -e "FileUtils.remove_entry_secure '#{dir}'"))
74
+ end
75
+
76
+ def token
77
+ seed = ([Time.now] + (1..10).map { rand.to_s }).join('--')
78
+
79
+ Digest::SHA1.hexdigest(seed)
80
+ end
81
+
82
+ def marshal(src, dst)
83
+ upload!(src, dst)
84
+
85
+ exec!("ruby -e 'puts Marshal.dump(eval(open(ARGV[0], &:read)))' #{dst}")
86
+ end
87
+
88
+ def create_ssh(host, user, options)
89
+ lambda do |&block|
90
+ Net::SSH.start(host, user, options) do |ssh|
91
+ block.(ssh)
92
+
93
+ ssh.loop
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'remote_marshal/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "remote_marshal"
8
+ spec.version = RemoteMarshal::VERSION
9
+ spec.authors = ["daisuko"]
10
+ spec.email = ["striker.daisuko@gmail.com"]
11
+
12
+ spec.summary = %q{A library for Marshal on SSH}
13
+ spec.homepage = "https://github.com/daisuko/remote_marshal"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'net-ssh'
22
+ spec.add_dependency 'net-scp'
23
+ spec.add_dependency 'sourcify'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: remote_marshal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - daisuko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-ssh
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: net-scp
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: sourcify
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description:
84
+ email:
85
+ - striker.daisuko@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - CODE_OF_CONDUCT.md
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/remote_marshal.rb
99
+ - lib/remote_marshal/version.rb
100
+ - remote_marshal.gemspec
101
+ homepage: https://github.com/daisuko/remote_marshal
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.5.1
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: A library for Marshal on SSH
125
+ test_files: []