docker-api 1.30.1 → 1.30.2
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.
- checksums.yaml +4 -4
- data/lib/docker/util.rb +19 -4
- data/lib/docker/version.rb +1 -1
- data/spec/docker/util_spec.rb +16 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e2975a50b698d9d6a2a5fdaecd477f160677427
|
4
|
+
data.tar.gz: e652feb4204f7e52d5877a388820dfd5a31c13e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab26e9e3ba3f505ad0ac1ebb8b594913128473f7d7900c35886d867f041ba2dad1259162cdda3ce4bd51634107a44736667c82f3205f5d804f2ca35f0808ea63
|
7
|
+
data.tar.gz: 4e5d8807fa2a6942662dea8a7e29e0fcc93deb4aa15fa097f29a9f265f765b961920df6276efc60c1e021d4d88fc9df81c35ab7c3aa90e7e61188e0381c644a6
|
data/lib/docker/util.rb
CHANGED
@@ -119,8 +119,12 @@ module Docker::Util
|
|
119
119
|
def create_tar(hash = {})
|
120
120
|
output = StringIO.new
|
121
121
|
Gem::Package::TarWriter.new(output) do |tar|
|
122
|
-
hash.each do |file_name,
|
123
|
-
|
122
|
+
hash.each do |file_name, file_details|
|
123
|
+
permissions = file_details.is_a?(Hash) ? file_details[:permissions] : 0640
|
124
|
+
tar.add_file(file_name, permissions) do |tar_file|
|
125
|
+
content = file_details.is_a?(Hash) ? file_details[:content] : file_details
|
126
|
+
tar_file.write(content)
|
127
|
+
end
|
124
128
|
end
|
125
129
|
end
|
126
130
|
output.tap(&:rewind).string
|
@@ -203,15 +207,26 @@ module Docker::Util
|
|
203
207
|
basename = File.basename(local_path)
|
204
208
|
if File.directory?(local_path)
|
205
209
|
tar = create_dir_tar(local_path)
|
206
|
-
file_hash[basename] =
|
210
|
+
file_hash[basename] = {
|
211
|
+
content: tar.read,
|
212
|
+
permissions: filesystem_permissions(local_path)
|
213
|
+
}
|
207
214
|
tar.close
|
208
215
|
FileUtils.rm(tar.path)
|
209
216
|
else
|
210
|
-
file_hash[basename] =
|
217
|
+
file_hash[basename] = {
|
218
|
+
content: File.read(local_path, mode: 'rb'),
|
219
|
+
permissions: filesystem_permissions(local_path)
|
220
|
+
}
|
211
221
|
end
|
212
222
|
end
|
213
223
|
end
|
214
224
|
|
225
|
+
def filesystem_permissions(path)
|
226
|
+
mode = sprintf("%o", File.stat(path).mode)
|
227
|
+
mode[(mode.length - 3)...mode.length].to_i(8)
|
228
|
+
end
|
229
|
+
|
215
230
|
def build_auth_header(credentials)
|
216
231
|
credentials = credentials.to_json if credentials.is_a?(Hash)
|
217
232
|
encoded_creds = Base64.encode64(credentials).gsub(/\n/, '')
|
data/lib/docker/version.rb
CHANGED
data/spec/docker/util_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'tempfile'
|
2
3
|
|
3
4
|
describe Docker::Util do
|
4
5
|
subject { described_class }
|
@@ -151,4 +152,19 @@ describe Docker::Util do
|
|
151
152
|
end
|
152
153
|
end
|
153
154
|
end
|
155
|
+
|
156
|
+
describe '.filesystem_permissions' do
|
157
|
+
it 'returns the permissions on a file' do
|
158
|
+
file = Tempfile.new('test_file')
|
159
|
+
file.close
|
160
|
+
expected_permissions = 0600
|
161
|
+
File.chmod(expected_permissions, file.path)
|
162
|
+
|
163
|
+
actual_permissions = subject.filesystem_permissions(file.path)
|
164
|
+
|
165
|
+
file.unlink
|
166
|
+
expect(actual_permissions).to eql(expected_permissions)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
154
170
|
end
|