sink3 0.0.2 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8e315e3d1e4c3a2244abd5567acd62f367ee165d
4
- data.tar.gz: 86b0c67187540a7f6bf97d7896ef79622d9198a6
2
+ SHA256:
3
+ metadata.gz: c38fc1886885c4b540758bfe360fbb3b104e42a58cf09089665e070aa748c116
4
+ data.tar.gz: df4199bae369d7186ba4337d0789e33a332c6ac925dcd3ae2d85ae9c4aa5df3c
5
5
  SHA512:
6
- metadata.gz: b960028f69435bce624b5f046588fcdddd16898002dbc85b024574386c18d3821fb6d55c9f118bf640dbf71c5df763a628080d6a70366d767fd1041d10ebafc5
7
- data.tar.gz: 33038b991198e05f23b1340b36899b98cbadf2fb3dc16d5bd4acec9520f919a173fc4e43e2d1dcfa0cb6b994bb79f22d5a8125bbc3375a59a5b8c782938fceaa
6
+ metadata.gz: 61e0348ecb5cf342f3de7e69ff208fa6dc82f65a62572180cd157bc5a7cf910b9b176b66034e44815c0bc0574e9510484f9bd3a08c070d4fd3fb8f1b9d76c19f
7
+ data.tar.gz: 435085e039823346909ae1494acc924024a525d4a2a99c3c02f3bb1bd198e75fb90e8128a6a1da4343983eed571adc9f533559623fb2b847037ab9acbcf34f8d
data/lib/sink3.rb CHANGED
@@ -15,6 +15,10 @@ module Sink3
15
15
 
16
16
  class Configuration
17
17
  attr_accessor :delete_after_upload
18
+ attr_accessor :skip_overwrite
19
+ attr_accessor :skip_date_partition
20
+ attr_accessor :verbose
21
+ attr_accessor :skip_full_path
18
22
 
19
23
  def delete_after_upload
20
24
  !!@delete_after_upload
data/lib/sink3/main.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'thor'
2
2
  require 'dotenv'
3
- require 'aws-sdk'
3
+ require 'aws-sdk-v1'
4
4
 
5
5
  lib = File.expand_path('../..', __FILE__)
6
6
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
@@ -9,22 +9,40 @@ require 'sink3/path_crawler'
9
9
 
10
10
  module Sink3
11
11
  class Main < Thor
12
- option :delete, type: :boolean
13
-
12
+ #
14
13
  # option :path, :required => true
15
- desc "Send file to S3", "Send files to S3 in write only mode"
14
+ desc "send", "Send files to S3 in write only mode"
16
15
 
17
- def send(path)
18
- configure
19
- path = Pathname.new(path)
20
- raise "specified path does not exist" unless path.exist?
16
+ option :delete, type: :boolean, desc: "delete origin file on succesful send"
17
+ option :skip_overwrite, type: :boolean, desc: "skip sending file if exists"
18
+ option :verbose, type: :boolean, desc: "verbose"
19
+ option :skip_date_partition, type: :boolean, desc: "remove YYYY-MM-DD remote prefix"
20
+ option :skip_full_path, type: :boolean, desc: "don't archive file with full path prefix"
21
21
 
22
+ def send(*paths)
23
+ configure
22
24
  # overwrite hostname if configured
23
25
  Dotenv.overload('~/.sink3cfg')
26
+
24
27
  validate_env
25
28
 
26
- prefix = path.realdirpath.basename
27
- Sink3::PathCrawler.new(path, prefix).start
29
+ prefix = nil
30
+ [paths].flatten.each do |path|
31
+ path = Pathname.new(path)
32
+
33
+ raise "specified path does not exist" unless path.exist?
34
+ unless Sink3.config.skip_full_path
35
+ if (path.file?)
36
+ prefix = path.realdirpath.parent
37
+ puts "prefix is #{prefix}" if Sink3.config.verbose
38
+ else
39
+ prefix = path.realdirpath.parent.parent
40
+ puts "prefix is not set" if Sink3.config.verbose
41
+ end
42
+ end
43
+
44
+ Sink3::PathCrawler.new(path, prefix).start
45
+ end
28
46
  end
29
47
 
30
48
  private
@@ -34,6 +52,10 @@ module Sink3
34
52
 
35
53
  Sink3.configure do |config|
36
54
  config.delete_after_upload = options[:delete]
55
+ config.skip_overwrite = options[:skip_overwrite]
56
+ config.verbose = options[:verbose]
57
+ config.skip_date_partition = options[:skip_date_partition]
58
+ config.skip_full_path = options[:skip_full_path]
37
59
  end
38
60
  end
39
61
 
@@ -44,10 +44,27 @@ module Sink3
44
44
  s3.buckets[ENV['BUCKET']]
45
45
  end
46
46
 
47
+ def check_exists remote_file
48
+ remote_file.exists?
49
+ rescue AWS::S3::Errors::Forbidden
50
+ # expect this error to be returned when file exists
51
+ # and we don't have access to read the file
52
+ true
53
+ end
54
+
47
55
  def send_to_remote
48
- remote_path = "#{ENV['HOSTNAME'].strip}/#{formatted_date}/#{prefix_and_path}"
56
+ remote_path = "#{ENV['HOSTNAME'].strip}/#{formatted_date}#{prefix_and_path}"
49
57
  remote_file = bucket.objects[remote_path]
50
- remote_file.write(@path)
58
+ if Sink3.config.skip_overwrite
59
+ if ! check_exists(remote_file)
60
+ puts "remote file does not exist #{remote_path}" if Sink3.config.verbose
61
+ remote_file.write(@path)
62
+ else
63
+ puts "skpping overwrite of #{remote_path}" if Sink3.config.verbose
64
+ end
65
+ else
66
+ remote_file.write(@path)
67
+ end
51
68
 
52
69
  if Sink3.config.delete_after_upload?
53
70
  FileUtils.rm @path
@@ -55,7 +72,11 @@ module Sink3
55
72
  end
56
73
 
57
74
  def formatted_date
58
- Time.now.strftime "%Y-%m-%d"
75
+ if !Sink3.config.skip_date_partition
76
+ return "#{Time.now.strftime "%Y-%m-%d"}/"
77
+ else
78
+ return ""
79
+ end
59
80
  end
60
81
 
61
82
  def prefix_and_path
data/lib/sink3/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sink3
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sink3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabrizio Regini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-22 00:00:00.000000000 Z
11
+ date: 2021-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-v1
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.61.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.61.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dotenv
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.11.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.11.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: thor
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.19.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.19.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.5'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.5'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: Sink3 is an S3 backup designed to work with write-only keys.
@@ -88,8 +88,8 @@ executables:
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
- - .gitignore
92
- - .rspec
91
+ - ".gitignore"
92
+ - ".rspec"
93
93
  - Gemfile
94
94
  - LICENSE.txt
95
95
  - README.md
@@ -116,17 +116,16 @@ require_paths:
116
116
  - lib
117
117
  required_ruby_version: !ruby/object:Gem::Requirement
118
118
  requirements:
119
- - - '>='
119
+ - - ">="
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  requirements:
124
- - - '>='
124
+ - - ">="
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
127
  requirements: []
128
- rubyforge_project:
129
- rubygems_version: 2.2.1
128
+ rubygems_version: 3.0.8
130
129
  signing_key:
131
130
  specification_version: 4
132
131
  summary: S3 backup designed for servers