nucleus 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/CHANGELOG.md +18 -4
  4. data/README.md +28 -40
  5. data/Rakefile +137 -137
  6. data/config/nucleus_config.rb +0 -4
  7. data/lib/nucleus/adapter_resolver.rb +115 -115
  8. data/lib/nucleus/adapters/buildpack_translator.rb +79 -79
  9. data/lib/nucleus/adapters/v1/cloud_control/application.rb +108 -108
  10. data/lib/nucleus/adapters/v1/cloud_control/authentication.rb +27 -27
  11. data/lib/nucleus/adapters/v1/cloud_control/cloud_control.rb +153 -153
  12. data/lib/nucleus/adapters/v1/cloud_control/domains.rb +68 -68
  13. data/lib/nucleus/adapters/v1/cloud_control/logs.rb +103 -103
  14. data/lib/nucleus/adapters/v1/cloud_control/vars.rb +88 -88
  15. data/lib/nucleus/adapters/v1/cloud_foundry_v2/domains.rb +149 -149
  16. data/lib/nucleus/adapters/v1/cloud_foundry_v2/logs.rb +303 -303
  17. data/lib/nucleus/adapters/v1/cloud_foundry_v2/services.rb +286 -286
  18. data/lib/nucleus/adapters/v1/heroku/heroku.rb +2 -2
  19. data/lib/nucleus/adapters/v1/heroku/logs.rb +108 -108
  20. data/lib/nucleus/core/adapter_authentication_inductor.rb +0 -2
  21. data/lib/nucleus/core/adapter_extensions/auth/http_basic_auth_client.rb +37 -37
  22. data/lib/nucleus/core/adapter_extensions/http_client.rb +177 -177
  23. data/lib/nucleus/core/common/files/archive_extractor.rb +112 -112
  24. data/lib/nucleus/core/common/files/archiver.rb +91 -91
  25. data/lib/nucleus/core/common/logging/request_log_formatter.rb +48 -48
  26. data/lib/nucleus/core/error_messages.rb +127 -127
  27. data/lib/nucleus/core/models/abstract_model.rb +29 -29
  28. data/lib/nucleus/scripts/load_dependencies.rb +0 -1
  29. data/lib/nucleus/scripts/setup_config.rb +28 -28
  30. data/lib/nucleus/version.rb +3 -3
  31. data/nucleus.gemspec +10 -12
  32. data/spec/factories/models.rb +63 -61
  33. data/spec/integration/api/auth_spec.rb +58 -58
  34. data/spec/test_suites.rake +31 -31
  35. data/spec/unit/common/helpers/auth_helper_spec.rb +73 -73
  36. data/spec/unit/common/oauth2_auth_client_spec.rb +1 -1
  37. data/tasks/compatibility.rake +113 -113
  38. data/tasks/evaluation.rake +162 -162
  39. metadata +16 -30
@@ -1,112 +1,112 @@
1
- module Nucleus
2
- class ArchiveExtractor
3
- def initialize(exclude_git = true)
4
- @exclude_git = exclude_git
5
- end
6
-
7
- # Extract the file to the destination path.
8
- # The compression format indicates which method must be used to extract the archive.
9
- # @param [IO] file in-memory archive file to extract
10
- # @param [String] destination_path where the archive is going to be extracted to
11
- # @param [String] compression_format represented by well-known file extensions, e.g. zip or tar.gz
12
- # @raise [StandardError] if the compression_format is not supported and can't be extracted
13
- # @return [Integer] number of extracted files
14
- def extract(file, destination_path, compression_format)
15
- compression_method = compression_format_method_name(compression_format)
16
- fail StandardError, 'Unsupported compression format' unless respond_to?(compression_method, true)
17
-
18
- # be sure that directory exists
19
- FileUtils.mkdir_p(destination_path, verbose: false)
20
-
21
- begin
22
- send(compression_method, file, destination_path)
23
- rescue Zip::Error, Zlib::GzipFile::Error
24
- raise API::Errors::ApplicationArchiveError, "Failed to extract #{compression_format} archive"
25
- end
26
- end
27
-
28
- # Checks if the compression format is supported and an archive of this type could be extracted.
29
- # @param [String] compression_format represented by well-known file extensions, e.g. zip or tar.gz
30
- # @return [Boolean] true if format is supported, false if not
31
- def supports?(compression_format)
32
- compression_method = compression_format_method_name(compression_format)
33
- respond_to?(compression_method, true)
34
- end
35
-
36
- private
37
-
38
- def compression_format_method_name(compression_format)
39
- "un_#{compression_format.downcase.gsub(/\./, '_').underscore}".to_sym
40
- end
41
-
42
- def un_zip(file, destination_path)
43
- extracted = 0
44
- Zip::File.open(file) do |zip_file|
45
- # Handle entries one by one
46
- zip_file.each do |entry|
47
- next if @exclude_git && entry.name.start_with?('.git')
48
- dest = File.join(destination_path, entry.name)
49
- if entry.name_is_directory?
50
- FileUtils.mkdir_p(dest) unless File.exist?(dest)
51
- else
52
- # make sure parent directory exists
53
- FileUtils.mkdir_p(File.expand_path('..', dest))
54
-
55
- entry.extract(dest) unless File.exist?(dest)
56
- # increase count
57
- extracted += 1
58
- end
59
- end
60
- end
61
- extracted
62
- end
63
-
64
- def un_tar_gz(file, destination_path)
65
- extracted = 0
66
- # unzip the archive into the repo, closes resource automatically
67
- # Thanks to Draco Ater: http://stackoverflow.com/a/19139114/1009436
68
- Gem::Package::TarReader.new(Zlib::GzipReader.open(file)) do |tar|
69
- dest = nil
70
- tar.each do |entry|
71
- # Process Longlinks and skip to next entry
72
- if entry.full_name == '././@LongLink'
73
- dest = File.join(destination_path, entry.read.strip)
74
- next
75
- end
76
-
77
- # Process default entry types (dir, file, symlink)
78
- full_name = entry.full_name.sub(%r{(\.\/)?}, '')
79
- dest ||= File.join(destination_path, full_name)
80
- next if tar_git_entry? full_name
81
- if entry.directory?
82
- write_tar_dir_entry(entry, dest)
83
- elsif entry.file?
84
- write_tar_file_entry(entry, dest)
85
- # increase count
86
- extracted += 1
87
- elsif entry.header.typeflag == '2'
88
- # handle symlinks
89
- File.symlink(entry.header.linkname, dest)
90
- end
91
- dest = nil
92
- end
93
- end
94
- end
95
- alias_method :un_tgz, :un_tar_gz
96
-
97
- def tar_git_entry?(full_name)
98
- @exclude_git && (full_name.start_with?('._.git') || full_name.start_with?('.git'))
99
- end
100
-
101
- def write_tar_file_entry(entry, dest)
102
- FileUtils.rm_rf(dest) if File.directory?(dest)
103
- File.open(dest, 'wb') { |f| f.print entry.read }
104
- FileUtils.chmod(entry.header.mode, dest, verbose: false)
105
- end
106
-
107
- def write_tar_dir_entry(entry, dest)
108
- File.delete(dest) if File.file?(dest)
109
- FileUtils.mkdir_p(dest, mode: entry.header.mode, verbose: false)
110
- end
111
- end
112
- end
1
+ module Nucleus
2
+ class ArchiveExtractor
3
+ def initialize(exclude_git = true)
4
+ @exclude_git = exclude_git
5
+ end
6
+
7
+ # Extract the file to the destination path.
8
+ # The compression format indicates which method must be used to extract the archive.
9
+ # @param [IO] file in-memory archive file to extract
10
+ # @param [String] destination_path where the archive is going to be extracted to
11
+ # @param [String] compression_format represented by well-known file extensions, e.g. zip or tar.gz
12
+ # @raise [StandardError] if the compression_format is not supported and can't be extracted
13
+ # @return [Integer] number of extracted files
14
+ def extract(file, destination_path, compression_format)
15
+ compression_method = compression_format_method_name(compression_format)
16
+ fail StandardError, 'Unsupported compression format' unless respond_to?(compression_method, true)
17
+
18
+ # be sure that directory exists
19
+ FileUtils.mkdir_p(destination_path, verbose: false)
20
+
21
+ begin
22
+ send(compression_method, file, destination_path)
23
+ rescue Zip::Error, Zlib::GzipFile::Error
24
+ raise API::Errors::ApplicationArchiveError, "Failed to extract #{compression_format} archive"
25
+ end
26
+ end
27
+
28
+ # Checks if the compression format is supported and an archive of this type could be extracted.
29
+ # @param [String] compression_format represented by well-known file extensions, e.g. zip or tar.gz
30
+ # @return [Boolean] true if format is supported, false if not
31
+ def supports?(compression_format)
32
+ compression_method = compression_format_method_name(compression_format)
33
+ respond_to?(compression_method, true)
34
+ end
35
+
36
+ private
37
+
38
+ def compression_format_method_name(compression_format)
39
+ "un_#{compression_format.downcase.tr('.', '_').underscore}".to_sym
40
+ end
41
+
42
+ def un_zip(file, destination_path)
43
+ extracted = 0
44
+ Zip::File.open(file) do |zip_file|
45
+ # Handle entries one by one
46
+ zip_file.each do |entry|
47
+ next if @exclude_git && entry.name.start_with?('.git')
48
+ dest = File.join(destination_path, entry.name)
49
+ if entry.name_is_directory?
50
+ FileUtils.mkdir_p(dest) unless File.exist?(dest)
51
+ else
52
+ # make sure parent directory exists
53
+ FileUtils.mkdir_p(File.expand_path('..', dest))
54
+
55
+ entry.extract(dest) unless File.exist?(dest)
56
+ # increase count
57
+ extracted += 1
58
+ end
59
+ end
60
+ end
61
+ extracted
62
+ end
63
+
64
+ def un_tar_gz(file, destination_path)
65
+ extracted = 0
66
+ # unzip the archive into the repo, closes resource automatically
67
+ # Thanks to Draco Ater: http://stackoverflow.com/a/19139114/1009436
68
+ Gem::Package::TarReader.new(Zlib::GzipReader.open(file)) do |tar|
69
+ dest = nil
70
+ tar.each do |entry|
71
+ # Process Longlinks and skip to next entry
72
+ if entry.full_name == '././@LongLink'
73
+ dest = File.join(destination_path, entry.read.strip)
74
+ next
75
+ end
76
+
77
+ # Process default entry types (dir, file, symlink)
78
+ full_name = entry.full_name.sub(%r{(\.\/)?}, '')
79
+ dest ||= File.join(destination_path, full_name)
80
+ next if tar_git_entry? full_name
81
+ if entry.directory?
82
+ write_tar_dir_entry(entry, dest)
83
+ elsif entry.file?
84
+ write_tar_file_entry(entry, dest)
85
+ # increase count
86
+ extracted += 1
87
+ elsif entry.header.typeflag == '2'
88
+ # handle symlinks
89
+ File.symlink(entry.header.linkname, dest)
90
+ end
91
+ dest = nil
92
+ end
93
+ end
94
+ end
95
+ alias un_tgz un_tar_gz
96
+
97
+ def tar_git_entry?(full_name)
98
+ @exclude_git && full_name.start_with?('._.git', '.git')
99
+ end
100
+
101
+ def write_tar_file_entry(entry, dest)
102
+ FileUtils.rm_rf(dest) if File.directory?(dest)
103
+ File.open(dest, 'wb') { |f| f.print entry.read }
104
+ FileUtils.chmod(entry.header.mode, dest, verbose: false)
105
+ end
106
+
107
+ def write_tar_dir_entry(entry, dest)
108
+ File.delete(dest) if File.file?(dest)
109
+ FileUtils.mkdir_p(dest, mode: entry.header.mode, verbose: false)
110
+ end
111
+ end
112
+ end
@@ -1,91 +1,91 @@
1
- module Nucleus
2
- class Archiver
3
- def initialize(exclude_git = true)
4
- @exclude_git = exclude_git
5
- end
6
-
7
- # Compress the files of the path into an archive, using the compression format,
8
- # which indicates which method must be used to compress the archive.
9
- # @param [String] path which directory's contents are going to be compressed into the archive
10
- # @param [String] compression_format represented by well-known file extensions, e.g. zip or tar.gz
11
- # @raise [StandardError] if the compression_format is not supported and the directory can't be compressed
12
- # @return [StringIO] compressed data of the given input path
13
- def compress(path, compression_format)
14
- compression_method = compression_format.downcase.gsub(/\./, '_').underscore.to_sym
15
- fail StandardError,
16
- "Unsupported compression format #{compression_format}" unless self.respond_to?(compression_method, true)
17
- send(compression_method, path)
18
- end
19
-
20
- private
21
-
22
- def tar(path)
23
- string_io = StringIO.new('')
24
- Gem::Package::TarWriter.new(string_io) do |tar|
25
- Find.find(path) do |file|
26
- # do not include the git files
27
- next if @exclude_git && file.start_with?("#{path}/.git")
28
-
29
- mode = File.stat(file).mode
30
- relative_file = file.sub(%r{^#{Regexp.escape path}\/?}, '')
31
-
32
- if File.directory?(file)
33
- tar.mkdir relative_file, mode
34
- else
35
- tar.add_file relative_file, mode do |tf|
36
- File.open(file, 'rb') { |f| tf.write f.read }
37
- end
38
- end
39
- end
40
- end
41
- string_io.rewind
42
- string_io
43
- end
44
-
45
- def tar_gz(path)
46
- tar_file = tar(path)
47
- begin
48
- gz = StringIO.new('')
49
- z = Zlib::GzipWriter.new(gz)
50
- z.write tar_file.string
51
- ensure
52
- z.close unless z.nil?
53
- end
54
-
55
- # z was closed to write the gzip footer, so
56
- # now we need a new StringIO
57
- StringIO.new gz.string
58
- end
59
-
60
- def zip(path)
61
- string_io = Zip::OutputStream.write_buffer do |zio|
62
- Find.find(path) do |file|
63
- # do not process directories && do not include the Git DB files
64
- next if File.directory?(file) || (@exclude_git && file.start_with?("#{path}/.git"))
65
-
66
- relative_file = file.sub(%r{^#{Regexp.escape path}\/?}, '')
67
- zio.put_next_entry(relative_file)
68
- File.open(file, 'rb') do |f|
69
- zio.write f.read
70
- end
71
- end
72
- end
73
- string_io.rewind
74
- string_io
75
- end
76
-
77
- def write_zip_entries(path, sub_path, io)
78
- search_path = File.join(path, sub_path)
79
- Find.find(path) do |file|
80
- zip_file_path = file.sub(%r{^#{Regexp.escape search_path}\/?}, '')
81
- next if @exclude_git && zip_file_path.start_with?('.git')
82
- if File.directory?(file)
83
- io.mkdir(zip_file_path)
84
- write_zip_entries(path, zip_file_path, io)
85
- else
86
- io.get_output_stream(zip_file_path) { |f| f.print(File.open(file, 'rb').read) }
87
- end
88
- end
89
- end
90
- end
91
- end
1
+ module Nucleus
2
+ class Archiver
3
+ def initialize(exclude_git = true)
4
+ @exclude_git = exclude_git
5
+ end
6
+
7
+ # Compress the files of the path into an archive, using the compression format,
8
+ # which indicates which method must be used to compress the archive.
9
+ # @param [String] path which directory's contents are going to be compressed into the archive
10
+ # @param [String] compression_format represented by well-known file extensions, e.g. zip or tar.gz
11
+ # @raise [StandardError] if the compression_format is not supported and the directory can't be compressed
12
+ # @return [StringIO] compressed data of the given input path
13
+ def compress(path, compression_format)
14
+ compression_method = compression_format.downcase.tr('.', '_').underscore.to_sym
15
+ fail StandardError,
16
+ "Unsupported compression format #{compression_format}" unless respond_to?(compression_method, true)
17
+ send(compression_method, path)
18
+ end
19
+
20
+ private
21
+
22
+ def tar(path)
23
+ string_io = StringIO.new('')
24
+ Gem::Package::TarWriter.new(string_io) do |tar|
25
+ Find.find(path) do |file|
26
+ # do not include the git files
27
+ next if @exclude_git && file.start_with?("#{path}/.git")
28
+
29
+ mode = File.stat(file).mode
30
+ relative_file = file.sub(%r{^#{Regexp.escape path}\/?}, '')
31
+
32
+ if File.directory?(file)
33
+ tar.mkdir relative_file, mode
34
+ else
35
+ tar.add_file relative_file, mode do |tf|
36
+ File.open(file, 'rb') { |f| tf.write f.read }
37
+ end
38
+ end
39
+ end
40
+ end
41
+ string_io.rewind
42
+ string_io
43
+ end
44
+
45
+ def tar_gz(path)
46
+ tar_file = tar(path)
47
+ begin
48
+ gz = StringIO.new('')
49
+ z = Zlib::GzipWriter.new(gz)
50
+ z.write tar_file.string
51
+ ensure
52
+ z.close unless z.nil?
53
+ end
54
+
55
+ # z was closed to write the gzip footer, so
56
+ # now we need a new StringIO
57
+ StringIO.new gz.string
58
+ end
59
+
60
+ def zip(path)
61
+ string_io = Zip::OutputStream.write_buffer do |zio|
62
+ Find.find(path) do |file|
63
+ # do not process directories && do not include the Git DB files
64
+ next if File.directory?(file) || (@exclude_git && file.start_with?("#{path}/.git"))
65
+
66
+ relative_file = file.sub(%r{^#{Regexp.escape path}\/?}, '')
67
+ zio.put_next_entry(relative_file)
68
+ File.open(file, 'rb') do |f|
69
+ zio.write f.read
70
+ end
71
+ end
72
+ end
73
+ string_io.rewind
74
+ string_io
75
+ end
76
+
77
+ def write_zip_entries(path, sub_path, io)
78
+ search_path = File.join(path, sub_path)
79
+ Find.find(path) do |file|
80
+ zip_file_path = file.sub(%r{^#{Regexp.escape search_path}\/?}, '')
81
+ next if @exclude_git && zip_file_path.start_with?('.git')
82
+ if File.directory?(file)
83
+ io.mkdir(zip_file_path)
84
+ write_zip_entries(path, zip_file_path, io)
85
+ else
86
+ io.get_output_stream(zip_file_path) { |f| f.print(File.open(file, 'rb').read) }
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -1,48 +1,48 @@
1
- require 'English'
2
-
3
- module Nucleus
4
- module Logging
5
- class Formatter
6
- FORMAT = "%s, %38s [%s#%d] %5s -- %s: %s\n"
7
-
8
- attr_accessor :datetime_format
9
-
10
- def initialize
11
- @datetime_format = nil
12
- end
13
-
14
- def call(severity, time, progname, msg)
15
- if Thread.current[:nucleus_request_id].nil?
16
- # if there is no request id, then fill up the space
17
- request_part = "[#{'*' * 36}]"
18
- else
19
- request_part = "[#{Thread.current[:nucleus_request_id]}]"
20
- end
21
-
22
- format(FORMAT, severity[0..0], request_part, format_datetime(time),
23
- $PID, severity, progname, msg2str(msg))
24
- end
25
-
26
- private
27
-
28
- def format_datetime(time)
29
- if @datetime_format.nil?
30
- format(time.strftime('%Y-%m-%dT%H:%M:%S.') << '%06d ', time.usec)
31
- else
32
- time.strftime(@datetime_format)
33
- end
34
- end
35
-
36
- def msg2str(msg)
37
- case msg
38
- when ::String
39
- msg
40
- when ::Exception
41
- "#{msg.message} (#{msg.class})\n" << (msg.backtrace || []).join("\n")
42
- else
43
- msg.inspect
44
- end
45
- end
46
- end
47
- end
48
- end
1
+ require 'English'
2
+
3
+ module Nucleus
4
+ module Logging
5
+ class Formatter
6
+ FORMAT = "%s, %38s [%s#%d] %5s -- %s: %s\n".freeze
7
+
8
+ attr_accessor :datetime_format
9
+
10
+ def initialize
11
+ @datetime_format = nil
12
+ end
13
+
14
+ def call(severity, time, progname, msg)
15
+ request_part = if Thread.current[:nucleus_request_id].nil?
16
+ # if there is no request id, then fill up the space
17
+ "[#{'*' * 36}]"
18
+ else
19
+ "[#{Thread.current[:nucleus_request_id]}]"
20
+ end
21
+
22
+ format(FORMAT, severity[0..0], request_part, format_datetime(time),
23
+ $PID, severity, progname, msg2str(msg))
24
+ end
25
+
26
+ private
27
+
28
+ def format_datetime(time)
29
+ if @datetime_format.nil?
30
+ format(time.strftime('%Y-%m-%dT%H:%M:%S.') << '%06d ', time.usec)
31
+ else
32
+ time.strftime(@datetime_format)
33
+ end
34
+ end
35
+
36
+ def msg2str(msg)
37
+ case msg
38
+ when ::String
39
+ msg
40
+ when ::Exception
41
+ "#{msg.message} (#{msg.class})\n" << (msg.backtrace || []).join("\n")
42
+ else
43
+ msg.inspect
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end