s3grep 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
+ SHA256:
3
+ metadata.gz: 7155353e97cda7850ee2e53dddd2d03e0951b426a9c3fec3408b8f2b2f91b7bb
4
+ data.tar.gz: 6debc36f79d05e27787ffd5eff62373c51e2d9e314b8eb71a7b06b681bbfea6d
5
+ SHA512:
6
+ metadata.gz: 06a4120d12ac5dc6aaaf13b14cb08fe19a7ba2594e193920ea9c9d2376896049f6c61cc2976a0968126b00ee78a3750e7645a315f9d307428ac2629ef57ba8e6
7
+ data.tar.gz: a5d0c0d85be34326b73517cdfc9ef0106e1c068665b02ca9bd64719ba60aae7c1c94ac67930bd05e0bc1970e9130b18306a2d84540e717665f4dd8935859d41b
data/.gitignore ADDED
@@ -0,0 +1,57 @@
1
+ *~
2
+ *.gem
3
+ *.rbc
4
+ /.config
5
+ /coverage/
6
+ /InstalledFiles
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/examples.txt
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ /tmp/
13
+
14
+ # Used by dotenv library to load environment variables.
15
+ # .env
16
+
17
+ # Ignore Byebug command history file.
18
+ .byebug_history
19
+
20
+ ## Specific to RubyMotion:
21
+ .dat*
22
+ .repl_history
23
+ build/
24
+ *.bridgesupport
25
+ build-iPhoneOS/
26
+ build-iPhoneSimulator/
27
+
28
+ ## Specific to RubyMotion (use of CocoaPods):
29
+ #
30
+ # We recommend against adding the Pods directory to your .gitignore. However
31
+ # you should judge for yourself, the pros and cons are mentioned at:
32
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
33
+ #
34
+ # vendor/Pods/
35
+
36
+ ## Documentation cache and generated files:
37
+ /.yardoc/
38
+ /_yardoc/
39
+ /doc/
40
+ /rdoc/
41
+
42
+ ## Environment normalization:
43
+ /.bundle/
44
+ /vendor/bundle
45
+ /lib/bundler/man/
46
+
47
+ # for a library or gem, you might want to ignore these files since the code is
48
+ # intended to run in multiple environments; otherwise, check them in:
49
+ # Gemfile.lock
50
+ # .ruby-version
51
+ # .ruby-gemset
52
+
53
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
54
+ .rvmrc
55
+
56
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
57
+ # .rubocop-https?--*
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ s3grep
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.0
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'http://rubygems.org'
4
+
5
+ gem 'aws-sdk-s3'
data/Gemfile.lock ADDED
@@ -0,0 +1,29 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ aws-eventstream (1.2.0)
5
+ aws-partitions (1.571.0)
6
+ aws-sdk-core (3.130.0)
7
+ aws-eventstream (~> 1, >= 1.0.2)
8
+ aws-partitions (~> 1, >= 1.525.0)
9
+ aws-sigv4 (~> 1.1)
10
+ jmespath (~> 1.0)
11
+ aws-sdk-kms (1.55.0)
12
+ aws-sdk-core (~> 3, >= 3.127.0)
13
+ aws-sigv4 (~> 1.1)
14
+ aws-sdk-s3 (1.113.0)
15
+ aws-sdk-core (~> 3, >= 3.127.0)
16
+ aws-sdk-kms (~> 1)
17
+ aws-sigv4 (~> 1.4)
18
+ aws-sigv4 (1.4.0)
19
+ aws-eventstream (~> 1, >= 1.0.2)
20
+ jmespath (1.6.1)
21
+
22
+ PLATFORMS
23
+ x86_64-darwin-21
24
+
25
+ DEPENDENCIES
26
+ aws-sdk-s3
27
+
28
+ BUNDLED WITH
29
+ 2.3.3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 dougyouch
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # s3grep
2
+
3
+ Search through S3 files without downloading them.
4
+
5
+ # Basic Usage
6
+
7
+ Search for a pattern in a S3 file.
8
+
9
+ example:
10
+ ```
11
+ s3grep Bob s3://exammple.com/users.csv
12
+ ```
13
+
14
+ Outputs S3 file with line number and the matching line.
data/bin/s3grep ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 's3grep'
4
+
5
+ regex = Regexp.new(ARGV[0])
6
+ s3_url = ARGV[1]
7
+
8
+ S3Grep::Search.search(s3_url, Aws::S3::Client.new, regex) do |line_number, line|
9
+ puts "#{s3_url}:#{line_number} #{line}"
10
+ end
@@ -0,0 +1,40 @@
1
+ require 'aws-sdk-s3'
2
+
3
+ module S3Grep
4
+ class Search
5
+ attr_reader :s3_url,
6
+ :aws_s3_client
7
+
8
+ def initialize(s3_url, aws_s3_client)
9
+ @s3_url = s3_url
10
+ @aws_s3_client = aws_s3_client
11
+ end
12
+
13
+ def self.search(s3_url, aws_s3_client, regex, &block)
14
+ new(s3_url, aws_s3_client).search(regex, &block)
15
+ end
16
+
17
+ def search(regex)
18
+ body = s3_object.body
19
+
20
+ line_number = 0
21
+ body.each do |line|
22
+ line_number += 1
23
+ next unless line.match?(regex)
24
+
25
+ yield line_number, line
26
+ end
27
+ end
28
+
29
+ def s3_object
30
+ uri = URI(s3_url)
31
+
32
+ aws_s3_client.get_object(
33
+ {
34
+ bucket: uri.host,
35
+ key: uri.path[1..-1]
36
+ }
37
+ )
38
+ end
39
+ end
40
+ end
data/lib/s3grep.rb ADDED
@@ -0,0 +1,3 @@
1
+ module S3Grep
2
+ autoload :Search, 's3grep/search'
3
+ end
data/s3grep.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 's3grep'
5
+ s.version = '0.1.0'
6
+ s.licenses = ['MIT']
7
+ s.summary = 'Search through S3 files'
8
+ s.description = 'Tools for searching files on S3'
9
+ s.authors = ['Doug Youch']
10
+ s.email = 'dougyouch@gmail.com'
11
+ s.homepage = 'https://github.com/dougyouch/s3grep'
12
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
13
+ s.bindir = 'bin'
14
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+
16
+ s.add_runtime_dependency 'aws-sdk-s3'
17
+ end
data/script/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH << File.expand_path('../lib', __dir__)
5
+ require 's3grep'
6
+ require 'irb'
7
+ IRB.start(__FILE__)
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: s3grep
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Doug Youch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-03-29 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: '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
+ description: Tools for searching files on S3
28
+ email: dougyouch@gmail.com
29
+ executables:
30
+ - s3grep
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".ruby-gemset"
36
+ - ".ruby-version"
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENSE
40
+ - README.md
41
+ - bin/s3grep
42
+ - lib/s3grep.rb
43
+ - lib/s3grep/search.rb
44
+ - s3grep.gemspec
45
+ - script/console
46
+ homepage: https://github.com/dougyouch/s3grep
47
+ licenses:
48
+ - MIT
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubygems_version: 3.3.3
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: Search through S3 files
69
+ test_files: []