koine-filesystem-adapters-sftp 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b8070488cea7cee5d94b3efff51ae11ee391db86acba9ce308d9ed7d71e8547a
4
+ data.tar.gz: dea3bfbad0c357c7f06977dd7d8728754cba77ace79ca3044ff4b2f112c3c758
5
+ SHA512:
6
+ metadata.gz: 96b3e15f17aa1eccdc04ebf6610a76fcea2f1e8bd6146739d4eca7e44822b059a0d60f3bcba2a1e1f972bdbcd5560a2d29ae8f99ed447e2466c1f074b58b4e3a
7
+ data.tar.gz: df6fead8e1b0982b7f1c6233d23e20be2423a1e4c2aa87d9fb59bc57c3339627e65ca148b9ecfb42fc8b0acc8a2665172f267c35c3ffa0da5536a89c24ab8c42
@@ -0,0 +1,13 @@
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
12
+ /Gemfile.lock
13
+ /spec/fixtures/sandbox
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,66 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+
5
+ Metrics/BlockLength:
6
+ Exclude:
7
+ - 'spec/**/*'
8
+
9
+ Metrics/MethodLength:
10
+ Exclude:
11
+ - 'db/migrate/**.rb'
12
+
13
+ Layout/LineLength:
14
+ Max: 100
15
+ Exclude:
16
+ - 'db/seeds.rb'
17
+
18
+ Style/Documentation:
19
+ Enabled: false
20
+
21
+ Style/GuardClause:
22
+ Enabled: false
23
+
24
+ Style/IfUnlessModifier:
25
+ Enabled: false
26
+
27
+ Layout/MultilineMethodCallIndentation:
28
+ EnforcedStyle: indented
29
+
30
+ Layout/MultilineOperationIndentation:
31
+ Enabled: true
32
+ EnforcedStyle: indented
33
+
34
+ Layout/FirstArrayElementIndentation:
35
+ EnforcedStyle: consistent
36
+
37
+ Naming/RescuedExceptionsVariableName:
38
+ PreferredName: 'exception'
39
+
40
+ Style/FormatStringToken:
41
+ EnforcedStyle: template
42
+
43
+ RSpec:
44
+ Exclude:
45
+ - 'spec/factories/**/*'
46
+
47
+ RSpec/ExampleLength:
48
+ Max: 10
49
+
50
+ RSpec/MultipleExpectations:
51
+ Enabled: false
52
+
53
+ AllCops:
54
+ Exclude:
55
+ - 'node_modules/**/*'
56
+ - 'script/**/*'
57
+ - 'log/**/*'
58
+ - 'docker/**/*'
59
+ - 'doc/**/*'
60
+ - 'bin/**/*'
61
+ - 'Rakefile'
62
+ - 'config.ru'
63
+ - 'config/**/*'
64
+ - 'db/schema.rb'
65
+ - 'node_modules/**/*'
66
+ - 'vendor/**/*'
@@ -0,0 +1,11 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.5
6
+ before_install: gem install bundler -v 2.1.4
7
+
8
+ script:
9
+ - RAILS_ENV=test bundle exec rspec
10
+ - bundle exec rubocop --version
11
+ - bundle exec rubocop -a
@@ -0,0 +1,6 @@
1
+ Change log
2
+ -----------------
3
+
4
+ ### 0.1.0
5
+
6
+ Minimal Local Filesystem Storage. Many methods are not implemented yet
@@ -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 marcelo.jacobus@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,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in koine-filesystem.gemspec
6
+ gemspec
7
+
8
+ gem 'awesome_print'
9
+ gem 'coveralls', '~> 0.8.23'
10
+ gem 'rake', '~> 12.0'
11
+ gem 'reek'
12
+ gem 'rspec', '~> 3.0'
13
+ gem 'rubocop', '0.79.0'
14
+ gem 'rubocop-performance'
15
+ gem 'rubocop-rspec'
16
+ gem 'simplecov', '~> 0.16.1'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Marcelo Jacobus
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,63 @@
1
+ # Koine::Filesystem::Adapters::Sftp
2
+
3
+
4
+ - [Net::SFTP](https://github.com/net-ssh/net-sftp) adapter for [Koine::Filesystem](https://github.com/mjacobus/koine-file_system)
5
+
6
+ [![Build Status](https://travis-ci.org/mjacobus/koine-filesystem-adapters-sftp.svg?branch=master)](https://travis-ci.org/mjacobus/koine-filesystem-adapters-sftp)
7
+ [![Coverage Status](https://coveralls.io/repos/github/mjacobus/koine-filesystem-adapters-sftp/badge.svg?branch=master)](https://coveralls.io/github/mjacobus/koine-filesystem-adapters-sftp?branch=master)
8
+ [![Maintainability](https://api.codeclimate.com/v1/badges/ae41e3facbadaabaa463/maintainability)](https://codeclimate.com/github/mjacobus/koine-filesystem-adapters-sftp/maintainability)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'koine-filesystem-adapters-sftp'
16
+
17
+ require 'koine/filesystem/adapters/sftp'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle install
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install koine-filesystem-adapters-sftp
27
+
28
+ ## Usage
29
+
30
+ Check the [Net::SFTP.start](http://net-ssh.github.io/net-sftp/) start options for more details.
31
+
32
+ ```ruby
33
+ require 'koine/filesystem'
34
+ require 'koine/filesystem/adapters/sftp'
35
+
36
+ adapter = Koine::Filesystem::Adapters::Sftp.new(
37
+ hostname: 'localhost',
38
+ username: 'foo',
39
+ password: 'foo',
40
+ port: 2222,
41
+ )
42
+
43
+ fs = Koine::Filesystem::Filesystem.new(adapter)
44
+ ```
45
+
46
+ ## Development
47
+
48
+ 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.
49
+
50
+ 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).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mjacobus/koine-filesystem-adapters-sftp. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/mjacobus/koine-filesystem-adapters-sftp/blob/master/CODE_OF_CONDUCT.md).
55
+
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
60
+
61
+ ## Code of Conduct
62
+
63
+ Everyone interacting in the Koine::Filesystem project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mjacobus/koine-filesystem-adapters-sftp/blob/master/CODE_OF_CONDUCT.md).
@@ -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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "koine/filesystem"
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(__FILE__)
@@ -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
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'koine-filesystem-adapters-sftp'
5
+ spec.version = '0.1.0' # please change it in lib/koine/filesystem/adapters/sftp.rb:9
6
+ spec.authors = ['Marcelo Jacobus']
7
+ spec.email = ['marcelo.jacobus@gmail.com']
8
+
9
+ spec.summary = 'File System abstraction'
10
+ spec.description = 'File System abstraction'
11
+ spec.homepage = 'https://github.com/mjacobus/koine-filesystem-adapters-sftp'
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
14
+
15
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/mjacobus/koine-filesystem-adapters-sftp'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/mjacobus/koine-filesystem-adapters-sftp/blob/CHANGELOG'
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_dependency 'koine-filesystem', '~> 0.1.1'
31
+ spec.add_dependency 'net-sftp', '~> 2.1'
32
+ end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'koine/filesystem'
4
+ require 'net/sftp'
5
+
6
+ module Koine
7
+ module Filesystem
8
+ module Adapters
9
+ VERSION = '1.0.1' # please change koine-filesystem-adapters-sftp.gemspec:5
10
+
11
+ class Sftp < Base
12
+ # @param [Hash] options a hash containing the same options as Net::SFTP.start
13
+ # method plus username and password @see http://net-ssh.github.io/net-sftp/
14
+ #
15
+ # @option options [The Net::SFTP::Session] :session if not given it tries to
16
+ # create a new one from the options
17
+ # @option options [String] :hostname the ftp hostname
18
+ # @option options [String] :username the ftp hostname
19
+ # @option options [String] :password the ftp password
20
+ def initialize(options)
21
+ if options[:session]
22
+ @session = options.delete(:session)
23
+ else
24
+ @hostname = options.delete(:hostname)
25
+ @username = options.delete(:username)
26
+ @options = options
27
+ end
28
+ end
29
+
30
+ def list(path = nil, recursive: false)
31
+ path = format_path(path, '.')
32
+ matcher = format_matcher(recursive)
33
+
34
+ entries = []
35
+
36
+ session.dir.glob(path, matcher) do |item|
37
+ if item.name == '.' || item.name == '..'
38
+ next
39
+ end
40
+
41
+ entries << from_result(item, path)
42
+ end
43
+
44
+ entries
45
+ end
46
+
47
+ private
48
+
49
+ def session
50
+ @session ||= Net::SFTP.start(@hostname, @username, @options)
51
+ end
52
+
53
+ # rubocop:disable Metrics/AbcSize
54
+ def from_result(item, dir)
55
+ file_path = "#{dir}/#{item.name}".delete_prefix('.').delete_prefix('/')
56
+
57
+ {
58
+ path: file_path,
59
+ type: item.directory? ? 'dir' : 'file',
60
+ extension: item.directory? ? nil : file_path.split('.').last,
61
+ filename: File.basename(file_path),
62
+ dirname: format_path(File.dirname(file_path).delete_prefix('.')),
63
+ timestamp: Time.at(item.attributes.mtime),
64
+ size: item.attributes.size
65
+ }
66
+ end
67
+ # rubocop:enable Metrics/AbcSize
68
+
69
+ def format_path(path, default = '')
70
+ path = path.to_s
71
+ .delete_prefix('.')
72
+ .delete_prefix('/')
73
+ .delete_suffix('/')
74
+ .strip
75
+
76
+ if path.empty?
77
+ path = default
78
+ end
79
+
80
+ path
81
+ end
82
+
83
+ def format_matcher(recursive)
84
+ if recursive
85
+ return '**/*'
86
+ end
87
+
88
+ '*'
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ path=`pwd`/tmp
4
+ echo $path
5
+
6
+ docker run \
7
+ -v $path:/home/ftpuser \
8
+ -p 2222:22 -d atmoz/sftp \
9
+ ftpuser:ftppassword:$UID
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: koine-filesystem-adapters-sftp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marcelo Jacobus
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-07-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: koine-filesystem
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: net-sftp
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ description: File System abstraction
42
+ email:
43
+ - marcelo.jacobus@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".rubocop.yml"
51
+ - ".travis.yml"
52
+ - CHANGELOG
53
+ - CODE_OF_CONDUCT.md
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - bin/console
59
+ - bin/setup
60
+ - koine-filesystem-adapters-sftp.gemspec
61
+ - lib/koine/filesystem/adapters/sftp.rb
62
+ - scripts/start_sftp
63
+ homepage: https://github.com/mjacobus/koine-filesystem-adapters-sftp
64
+ licenses:
65
+ - MIT
66
+ metadata:
67
+ allowed_push_host: https://rubygems.org
68
+ homepage_uri: https://github.com/mjacobus/koine-filesystem-adapters-sftp
69
+ source_code_uri: https://github.com/mjacobus/koine-filesystem-adapters-sftp
70
+ changelog_uri: https://github.com/mjacobus/koine-filesystem-adapters-sftp/blob/CHANGELOG
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 2.3.0
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.0.3
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: File System abstraction
90
+ test_files: []