s3lite 0.0.0.pre.1

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: 2bf1286511e5661990746ae9aed7bc451eebfee26db29dd379dfdebda542681e
4
+ data.tar.gz: b11c193adf9c2eb039e3abf797c4f1ab90bc7ce0fb4a95567773f6f325588832
5
+ SHA512:
6
+ metadata.gz: 2fd6dd1ecbfb090c6296ea4e105aec354ecedc548c9c0979f2649d6ccb5984dc349ad381f77960034f1214149cdfb7ab63f0d72a2a408992fa5cae56864fb49a
7
+ data.tar.gz: cb14fc6a1e911e2d89002f3147cc166a1962ff88c6675577cb2d7948270f4d6c60428221b39b0913663fdacc098d1bab45659a3f5c334e6a53ec2fa5af565565
data/.gitignore ADDED
@@ -0,0 +1,12 @@
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
+ s3lite-*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in s3lite.gemspec
6
+ gemspec
7
+
8
+ group :test do
9
+ gem 'webmock'
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ s3lite (0.0.0.pre.1)
5
+ aws-sdk-s3 (~> 1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.5.2)
11
+ public_suffix (>= 2.0.2, < 4.0)
12
+ aws-partitions (1.73.0)
13
+ aws-sdk-core (3.17.1)
14
+ aws-partitions (~> 1.0)
15
+ aws-sigv4 (~> 1.0)
16
+ jmespath (~> 1.0)
17
+ aws-sdk-kms (1.5.0)
18
+ aws-sdk-core (~> 3)
19
+ aws-sigv4 (~> 1.0)
20
+ aws-sdk-s3 (1.8.2)
21
+ aws-sdk-core (~> 3)
22
+ aws-sdk-kms (~> 1)
23
+ aws-sigv4 (~> 1.0)
24
+ aws-sigv4 (1.0.2)
25
+ coderay (1.1.2)
26
+ crack (0.4.3)
27
+ safe_yaml (~> 1.0.0)
28
+ diff-lcs (1.3)
29
+ hashdiff (0.3.7)
30
+ jmespath (1.3.1)
31
+ method_source (0.9.0)
32
+ pry (0.11.3)
33
+ coderay (~> 1.1.0)
34
+ method_source (~> 0.9.0)
35
+ public_suffix (3.0.2)
36
+ rake (10.5.0)
37
+ rspec (3.7.0)
38
+ rspec-core (~> 3.7.0)
39
+ rspec-expectations (~> 3.7.0)
40
+ rspec-mocks (~> 3.7.0)
41
+ rspec-core (3.7.1)
42
+ rspec-support (~> 3.7.0)
43
+ rspec-expectations (3.7.0)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.7.0)
46
+ rspec-mocks (3.7.0)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.7.0)
49
+ rspec-support (3.7.1)
50
+ safe_yaml (1.0.4)
51
+ webmock (3.3.0)
52
+ addressable (>= 2.3.6)
53
+ crack (>= 0.3.2)
54
+ hashdiff
55
+
56
+ PLATFORMS
57
+ ruby
58
+
59
+ DEPENDENCIES
60
+ bundler (~> 1.16)
61
+ pry (~> 0.11)
62
+ rake (~> 10.0)
63
+ rspec (~> 3.0)
64
+ s3lite!
65
+ webmock
66
+
67
+ BUNDLED WITH
68
+ 1.16.1
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # S3lite
2
+
3
+ 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/s3lite`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 's3lite'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install s3lite
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/s3lite.
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 's3lite'
5
+ require 'irb'
6
+ S3lite.aws_key = ENV['AWS_ACCESS_KEY_ID']
7
+ S3lite.aws_secret_key = ENV['AWS_SECRET_ACCESS_KEY']
8
+ S3lite.s3_bucket = ENV['S3_BUCKET']
9
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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,37 @@
1
+ module S3lite::Base
2
+ attr_accessor :last_backup_at
3
+ include S3lite::S3
4
+
5
+ def backup(raise_error: false)
6
+ s3_put(path: s3_path, body: to_json)
7
+ rescue => e
8
+ raise e if raise_error
9
+ false
10
+ end
11
+
12
+ def backup!
13
+ backup(raise_error: true)
14
+ end
15
+
16
+ def latest
17
+ obj = s3_get(s3_path)
18
+ body = obj.body.read
19
+ json = S3lite::Parse.json(body)
20
+ json[:last_backup_at] = obj.last_modified
21
+ self.class.new(json)
22
+ rescue Aws::S3::Errors::AccessDenied, Aws::S3::Errors::NotFound
23
+ nil
24
+ end
25
+
26
+ def backedup?
27
+ to_json == latest.to_json
28
+ end
29
+
30
+ def s3_path
31
+ if defined?(Rails)
32
+ "#{Rails.env}/#{self.class.to_s.parameterize}/#{id}"
33
+ else
34
+ "#{self.class}/#{id}"
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,10 @@
1
+ module S3lite::Parse
2
+ class << self
3
+ def json(txt)
4
+ case txt.class.to_s
5
+ when 'String' then JSON.parse(txt, symbolize_names: true)
6
+ when 'Hash', 'Array' then json(txt.to_json)
7
+ end
8
+ end
9
+ end
10
+ end
data/lib/s3lite/s3.rb ADDED
@@ -0,0 +1,30 @@
1
+ module S3lite::S3
2
+ def s3_get(path)
3
+ s3_resource_object(path).get
4
+ end
5
+
6
+ def s3_list(bucket)
7
+ s3_resource.bucket(bucket)
8
+ end
9
+
10
+ def s3_put(path:, body:)
11
+ s3_resource_object(path).put(body: body)
12
+ end
13
+
14
+ private
15
+
16
+ def s3_resource_object(path)
17
+ raise 'No AWS S3 Bucket Set' if S3lite.s3_bucket.nil?
18
+ s3_resource.bucket(S3lite.s3_bucket).object(path)
19
+ end
20
+
21
+ def s3_resource
22
+ raise 'No AWS Access Key Set' if S3lite.aws_key.nil?
23
+ raise 'No AWS Secret Access Key Set' if S3lite.aws_secret_key.nil?
24
+ Aws::S3::Resource.new(
25
+ region: S3lite.region || 'us-east-1',
26
+ access_key_id: S3lite.aws_key,
27
+ secret_access_key: S3lite.aws_secret_key
28
+ )
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module S3lite
2
+ VERSION = '0.0.0-1'.freeze
3
+ end
data/lib/s3lite.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 's3lite/version'
2
+
3
+ module S3lite
4
+ class << self
5
+ attr_accessor :s3_bucket, :region, :aws_key, :aws_secret_key
6
+ end
7
+ end
data/s3lite.gemspec ADDED
@@ -0,0 +1,35 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'aws-sdk-s3'
5
+
6
+ require 's3lite'
7
+ require 's3lite/parse'
8
+ require 's3lite/s3'
9
+ require 's3lite/base'
10
+
11
+ Gem::Specification.new do |spec|
12
+ spec.name = 's3lite'
13
+ spec.version = S3lite::VERSION
14
+ spec.authors = ['David Richey']
15
+ spec.email = ['daveyrichey@gmail.com']
16
+
17
+ spec.summary = 'S3 Framework to backup SQLite database to S3'
18
+ spec.description = 'S3 Framework to backup SQLite database to S3'
19
+ spec.homepage = 'http://www.google.com'
20
+ spec.license = 'MIT'
21
+
22
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
23
+ f.match(%r{^(test|spec|features)/})
24
+ end
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_development_dependency 'bundler', '~> 1.16'
30
+ spec.add_development_dependency 'pry', '~> 0.11'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rspec', '~> 3.0'
33
+
34
+ spec.add_dependency 'aws-sdk-s3', '~> 1'
35
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: s3lite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.pre.1
5
+ platform: ruby
6
+ authors:
7
+ - David Richey
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: aws-sdk-s3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1'
83
+ description: S3 Framework to backup SQLite database to S3
84
+ email:
85
+ - daveyrichey@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/s3lite.rb
100
+ - lib/s3lite/base.rb
101
+ - lib/s3lite/parse.rb
102
+ - lib/s3lite/s3.rb
103
+ - lib/s3lite/version.rb
104
+ - s3lite.gemspec
105
+ homepage: http://www.google.com
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
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: 1.3.1
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.7.6
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: S3 Framework to backup SQLite database to S3
129
+ test_files: []