blufin-lib 1.7.3 → 1.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/core/aws.rb +33 -2
  3. data/lib/version.rb +1 -1
  4. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1ec1457a15378d9f5080b5ec64fb9b95065e4b0
4
- data.tar.gz: 35a135254e439143706ee3edb126aca97cad1b68
3
+ metadata.gz: d670802e60811a458378ed20b28ee75b7691f1d6
4
+ data.tar.gz: 4b7ed248efce868e4d904003a7028749ff2b68e2
5
5
  SHA512:
6
- metadata.gz: bace4811e8ebee0304c4e26898913e331388af631151f1bbd2b192e18a8b66b864bd8ff73fab92d77120b91dcb9d45356869f33aaf6b918360e0289b587e6d0e
7
- data.tar.gz: '058b1449de28f55ab3fa1647df97a62276c4a53a114c30474d3bcab7a808fe7392fa9654ca7ca82331527bd45d1ab16dd5df46509e07c298fcf2b0cce6d951a9'
6
+ metadata.gz: c0319aec4d945f390446cef58804bbaadcad7dd6e8d0d02dfef375745ed2903b1e662b6b94d83f926489a65412f6f40a42f46c2123be2f94db39e10c1a1a0cd4
7
+ data.tar.gz: e015f083e35a9255eeffd566997d6e8fca1b90f7c8a0e6a362fa3aed998ccf800eb92544cac27361a276333051cd8f306a5b7b987c231dfb244266c6e34968c6
data/lib/core/aws.rb CHANGED
@@ -2,6 +2,37 @@ module Blufin
2
2
 
3
3
  module AWS
4
4
 
5
+ S3_EXCLUDE = "--exclude '.DS_Store' --exclude '*/.DS_Store' --exclude '*.icloud' --exclude '*/*.icloud'"
6
+
7
+ # Uploads a file (or path) to S3. If path, will upload recursively (which is mandatory with s3 sync command).
8
+ # @return string (S3 URL).
9
+ def self.upload_s3_data(bucket_name, bucket_path, file_or_path, profile: nil, region: nil, is_file: false, dryrun: false)
10
+ raise RuntimeError, 'profile cannot be nil.' if profile.nil?
11
+ raise RuntimeError, 'region cannot be nil.' if region.nil?
12
+ raise RuntimeError, "File or path not found: #{file_or_path}" unless Blufin::Files::file_exists(file_or_path)
13
+ file_or_path = File.expand_path(file_or_path)
14
+ bucket_path = Blufin::Strings::remove_surrounding_slashes(bucket_path).strip
15
+ bucket_path_s3 = bucket_path.length > 0 ? "/#{bucket_path}" : ''
16
+ s3_url = "s3://#{bucket_name}#{bucket_path_s3}"
17
+ begin
18
+ if is_file
19
+ cmd = "aws s3 cp #{file_or_path} #{s3_url} --region #{region}#{App::AWS::get_profile_for_cli}"
20
+ else
21
+ cmd = "aws s3 sync #{file_or_path} #{s3_url} --delete --region #{region}#{App::AWS::get_profile_for_cli}"
22
+ end
23
+ if dryrun
24
+ cmd = "#{cmd} --dryrun"
25
+ Blufin::Terminal::info('Performing Dry Run:', Blufin::Terminal::format_command(cmd))
26
+ system("#{cmd} #{S3_EXCLUDE} --exclude '*.blank*'")
27
+ else
28
+ raise RuntimeError unless Blufin::Terminal::execute("#{cmd} #{S3_EXCLUDE} --exclude '*.blank*'", verbose: true, text: cmd)
29
+ end
30
+ s3_url
31
+ rescue
32
+ Blufin::Terminal::error("Unable to download from S3 bucket: #{Blufin::Terminal::format_highlight(s3_url)}", "Either the bucket doesn't exist, you don't have permissions or something else is wrong.", true, false)
33
+ end
34
+ end
35
+
5
36
  # Pulls a file from S3 and saves it to the /tmp folder.
6
37
  # To avoid making multiple calls, caching is turned on by default.
7
38
  # @return string (path to tmp file).
@@ -18,7 +49,7 @@ module Blufin
18
49
  tmp_location = "/tmp/awx-s3-cache-#{bucket_name}#{bucket_path_tmp}"
19
50
  # If path/file exists and we're using cached values, simply return.
20
51
  if file.nil?
21
- return tmp_location if Blufin::Files::path_exists(tmp_location) && use_cache && Blufin::Files::get_files_in_dir(tmp_location).any?
52
+ return tmp_location if Blufin::Files::path_exists(tmp_location) && use_cache
22
53
  else
23
54
  return tmp_location if Blufin::Files::file_exists(tmp_location) && use_cache
24
55
  end
@@ -34,7 +65,7 @@ module Blufin
34
65
  rescue
35
66
  system("rm -rf #{tmp_location}") if file.nil?
36
67
  system("rm #{tmp_location}") unless file.nil?
37
- Blufin::Terminal::error("Unable to download from S3 bucket: #{Blufin::Terminal::format_highlight("s3://#{bucket_name}#{bucket_path_s3}")}", "Either the bucket doesn't exist, you don't have permissions or something else is wrong...", true, false)
68
+ Blufin::Terminal::error("Unable to download from S3 bucket: #{Blufin::Terminal::format_highlight("s3://#{bucket_name}#{bucket_path_s3}")}", "Either the bucket doesn't exist, you don't have permissions or something else is wrong.", true, false)
38
69
  end
39
70
 
40
71
  end
data/lib/version.rb CHANGED
@@ -1 +1 @@
1
- BLUFIN_LIB_VERSION = '1.7.3'
1
+ BLUFIN_LIB_VERSION = '1.7.4'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blufin-lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.3
4
+ version: 1.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Albert Rannetsperger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-08 00:00:00.000000000 Z
11
+ date: 2019-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 2.1.0
33
+ version: 2.2.0
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
- version: 2.1.0
40
+ version: 2.2.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: kwalify
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  version: '0'
168
168
  requirements: []
169
169
  rubyforge_project:
170
- rubygems_version: 2.5.1
170
+ rubygems_version: 2.6.12
171
171
  signing_key:
172
172
  specification_version: 4
173
173
  summary: Blufin Lib