s3_cat 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: aa1e3d093e5a0b49a4c1eb70ff86dac6d4760ef942314716b678cf1fc0c78521
4
+ data.tar.gz: 91b4c3a44eae7a20e99bd05c22e31a97e6759d2581185306e90547d508ce2f35
5
+ SHA512:
6
+ metadata.gz: a2047c4290c0baf67ce77c73e2631aa1895e1e1d55954234751006f41496806db88aef999e8290f247497ee8a9059cdd6668124704f45f43c089decb9e37c129
7
+ data.tar.gz: 38c7f0f7baca36c2852fe07a0fc79010f048df9e36408bf5b59de9349b8f9f7f52e1c984782d5fa453591d095a4af22e1efd9c3ebe7390616d755d7edf284da1
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 's3_cat'
5
+
6
+ unless ARGV.size == 1
7
+ puts 'usage: s3-cat <s3_url>'
8
+ exit(1)
9
+ end
10
+
11
+ url, = ARGV
12
+
13
+ parser = S3Cat::S3UrlParser.new
14
+ lister = S3Cat::FileLister.new
15
+ reader = S3Cat::FileReader.new
16
+
17
+ bucket, prefix = parser.parse_url(url)
18
+ files = lister.list_files(bucket, prefix)
19
+ reader.read_files(bucket, files, STDOUT)
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aws-sdk-s3'
4
+
5
+ require 's3_cat/version'
6
+
7
+ require 's3_cat/s3_url_parser'
8
+ require 's3_cat/file_lister'
9
+ require 's3_cat/file_reader'
10
+
11
+ module S3Cat
12
+ class Error < StandardError; end
13
+
14
+ def self.s3_client
15
+ @s3_client ||= Aws::S3::Client.new
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module S3Cat
4
+ class FileLister
5
+ def initialize(s3_client: S3Cat.s3_client)
6
+ @s3_client = s3_client
7
+ end
8
+
9
+ def list_files(bucket, prefix)
10
+ Enumerator.new do |y|
11
+ continuation_token = nil
12
+
13
+ loop do
14
+ response = s3_client.list_objects_v2(bucket: bucket, prefix: prefix, continuation_token: continuation_token)
15
+
16
+ response.contents.map(&:key).each { |key| y << key }
17
+
18
+ break unless response.is_truncated
19
+
20
+ continuation_token = response.continuation_token
21
+ end
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :s3_client
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module S3Cat
4
+ class FileReader
5
+ def initialize(s3_client: S3Cat.s3_client)
6
+ @s3_client = s3_client
7
+ end
8
+
9
+ def read_files(bucket, files, output_stream)
10
+ files.each do |file|
11
+ s3_client.get_object(bucket: bucket, key: file) do |chunk|
12
+ output_stream.write(chunk)
13
+ end
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :s3_client
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module S3Cat
4
+ class S3UrlParser
5
+ S3_URL_PATTERN = %r{^s3://(?<bucket>\S+?)/(?<key>\S+)?$}.freeze
6
+
7
+ def parse_url(s3_url)
8
+ matched_data = S3_URL_PATTERN.match(s3_url)
9
+
10
+ [matched_data['bucket'], matched_data['key']]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module S3Cat
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,35 @@
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 's3_cat/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 's3_cat'
9
+ spec.version = S3Cat::VERSION
10
+ spec.author = 'Marek Mateja'
11
+
12
+ spec.summary = 'Concatenate and print S3 files recursively'
13
+ spec.description = 'Command line utility for searching multiple S3 files'
14
+ spec.homepage = 'https://github.com/mmateja/s3-cat'
15
+ spec.license = 'MIT'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = spec.homepage
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z s3_cat.gemspec bin/s3-cat lib/`.split("\x0")
24
+ end
25
+ spec.bindir = 'bin'
26
+ spec.executables = %w[s3-cat]
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_dependency 'aws-sdk-s3', '~> 1'
30
+
31
+ spec.add_development_dependency 'bundler', '~> 2.0'
32
+ spec.add_development_dependency 'rake', '~> 12.0', '>= 12.3.3'
33
+ spec.add_development_dependency 'rspec', '~> 3.0'
34
+ spec.add_development_dependency 'rubocop', '~> 0.84.0'
35
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: s3_cat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marek Mateja
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-s3
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 12.3.3
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '12.0'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 12.3.3
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rubocop
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.84.0
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.84.0
89
+ description: Command line utility for searching multiple S3 files
90
+ email:
91
+ executables:
92
+ - s3-cat
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - bin/s3-cat
97
+ - lib/s3_cat.rb
98
+ - lib/s3_cat/file_lister.rb
99
+ - lib/s3_cat/file_reader.rb
100
+ - lib/s3_cat/s3_url_parser.rb
101
+ - lib/s3_cat/version.rb
102
+ - s3_cat.gemspec
103
+ homepage: https://github.com/mmateja/s3-cat
104
+ licenses:
105
+ - MIT
106
+ metadata:
107
+ homepage_uri: https://github.com/mmateja/s3-cat
108
+ source_code_uri: https://github.com/mmateja/s3-cat
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubygems_version: 3.1.2
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Concatenate and print S3 files recursively
128
+ test_files: []