studio_api 3.1.4 → 3.2.0
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.
- data/VERSION +1 -1
- data/lib/studio_api/file.rb +15 -10
- data/lib/studio_api/generic_request.rb +26 -7
- data/lib/studio_api/rpm.rb +9 -4
- data/rubygem-studio_api.changes +15 -0
- data/test/file_test.rb +25 -8
- data/test/rpm_test.rb +12 -0
- metadata +5 -5
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.
|
|
1
|
+
3.2.0
|
data/lib/studio_api/file.rb
CHANGED
|
@@ -2,18 +2,18 @@ require "studio_api/studio_resource"
|
|
|
2
2
|
require "cgi"
|
|
3
3
|
module StudioApi
|
|
4
4
|
# Represents overlay files which can be loaded to appliance.
|
|
5
|
-
#
|
|
5
|
+
#
|
|
6
6
|
# Supports finding files for appliance, updating metadata, deleting, uploading and downloading.
|
|
7
|
-
#
|
|
7
|
+
#
|
|
8
8
|
# @example Find files for appliance
|
|
9
9
|
# StudioApi::File.find :all, :params => { :appliance_id => 1234 }
|
|
10
10
|
#
|
|
11
11
|
# @example Upload file Xorg.conf
|
|
12
|
-
# File.open ("/tmp/xorg.conf)
|
|
13
|
-
# StudioApi::File.upload file, 1234, :path => "/etc/X11",
|
|
12
|
+
# File.open ("/tmp/xorg.conf") do |file|
|
|
13
|
+
# StudioApi::File.upload file, 1234, :path => "/etc/X11",
|
|
14
14
|
# :filename => "Xorg.conf", :permissions => "0755",
|
|
15
15
|
# :owner => "root"
|
|
16
|
-
#
|
|
16
|
+
# end
|
|
17
17
|
#
|
|
18
18
|
# @example Update metadata
|
|
19
19
|
# file = StudioApi::File.find 1234
|
|
@@ -27,10 +27,15 @@ module StudioApi
|
|
|
27
27
|
self.element_name = "file"
|
|
28
28
|
|
|
29
29
|
# Downloads file to output. Allow downloading to stream or to path.
|
|
30
|
-
# @return [String] content of file
|
|
31
|
-
|
|
30
|
+
# @return [String] content of file if no block
|
|
31
|
+
# @return [nil] if block given
|
|
32
|
+
# @yield [socket response segment] Read the Net::HTTPResponse segments
|
|
33
|
+
# @yieldparam[body segment] buffered chunk of body
|
|
34
|
+
# @yieldreturn [nil]
|
|
35
|
+
def content &block
|
|
32
36
|
rq = GenericRequest.new self.class.studio_connection
|
|
33
|
-
|
|
37
|
+
path = "/files/#{id.to_i}/data"
|
|
38
|
+
block_given? ? rq.get_file(path, &block) : rq.get(path)
|
|
34
39
|
end
|
|
35
40
|
|
|
36
41
|
# Overwritte file content and keep metadata ( of course without such things like size )
|
|
@@ -45,7 +50,7 @@ module StudioApi
|
|
|
45
50
|
end
|
|
46
51
|
|
|
47
52
|
# Uploads file to appliance
|
|
48
|
-
# @param (String,File) content as String or as opened File
|
|
53
|
+
# @param (String,File) content as String or as opened File
|
|
49
54
|
# ( in this case its name is used as default for uploaded file name)
|
|
50
55
|
# @param (#to_i) appliance_id id of appliance where to upload
|
|
51
56
|
# @param (Hash<#to_s,#to_s>) options optional parameters, see API documentation
|
|
@@ -64,7 +69,7 @@ module StudioApi
|
|
|
64
69
|
end
|
|
65
70
|
end
|
|
66
71
|
|
|
67
|
-
private
|
|
72
|
+
private
|
|
68
73
|
# file uses for update parameter put
|
|
69
74
|
# @private
|
|
70
75
|
def new?
|
|
@@ -66,6 +66,15 @@ module StudioApi
|
|
|
66
66
|
do_request(Net::HTTP::Get.new(Util.join_relative_url(@connection.uri.request_uri,path)))
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
+
# sends get request to suse studio
|
|
70
|
+
# @return (nil) as response
|
|
71
|
+
# @raise [ActiveResource::ConnectionError] when problem occur during connection
|
|
72
|
+
def get_file(path, &block)
|
|
73
|
+
do_file_request(Net::HTTP::Get.new(
|
|
74
|
+
Util.join_relative_url(@connection.uri.request_uri,path)),
|
|
75
|
+
&block)
|
|
76
|
+
end
|
|
77
|
+
|
|
69
78
|
# sends delete request
|
|
70
79
|
# @param (String) path relative path from api root
|
|
71
80
|
# @return (String) response body from studio
|
|
@@ -102,18 +111,28 @@ module StudioApi
|
|
|
102
111
|
request.basic_auth @connection.user, @connection.password
|
|
103
112
|
@http.start() do
|
|
104
113
|
response = @http.request request
|
|
105
|
-
|
|
106
|
-
msg = error_message response
|
|
107
|
-
create_active_resource_exception response,msg
|
|
108
|
-
end
|
|
114
|
+
handle_active_resource_exception response
|
|
109
115
|
response.body
|
|
110
116
|
end
|
|
111
117
|
end
|
|
112
118
|
|
|
119
|
+
def do_file_request request, &block
|
|
120
|
+
request.basic_auth @connection.user, @connection.password
|
|
121
|
+
@http.start do |http|
|
|
122
|
+
http.request request do |response|
|
|
123
|
+
handle_active_resource_exception response
|
|
124
|
+
response.read_body {|body| yield body }
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
113
129
|
#XXX not so nice to use internal method, but better to be DRY and proper test if it works with supported rails
|
|
114
|
-
def
|
|
115
|
-
response.
|
|
116
|
-
|
|
130
|
+
def handle_active_resource_exception response
|
|
131
|
+
unless response.kind_of? Net::HTTPSuccess
|
|
132
|
+
msg = error_message response
|
|
133
|
+
response.instance_variable_set "@message",msg
|
|
134
|
+
ActiveResource::Connection.new('').send :handle_response, response
|
|
135
|
+
end
|
|
117
136
|
end
|
|
118
137
|
|
|
119
138
|
def error_message response
|
data/lib/studio_api/rpm.rb
CHANGED
|
@@ -3,9 +3,9 @@ require 'cgi'
|
|
|
3
3
|
|
|
4
4
|
module StudioApi
|
|
5
5
|
# Represents Additional rpms which can user upload to studio.
|
|
6
|
-
#
|
|
6
|
+
#
|
|
7
7
|
# Allows uploading, downloading, listing (via find) and deleting
|
|
8
|
-
#
|
|
8
|
+
#
|
|
9
9
|
# @example Delete own rpm
|
|
10
10
|
# rpms = StudioApi::Rpm.find :all, :params => { :base_system => "SLE11" }
|
|
11
11
|
# my_pac = rpms.find {|r| r.filename =~ /my_pac/ }
|
|
@@ -30,8 +30,13 @@ module StudioApi
|
|
|
30
30
|
|
|
31
31
|
# Downloads file to specified path.
|
|
32
32
|
# @return [String] content of rpm
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
# @yield [tempfile] Access the tempfile from the block parameter
|
|
34
|
+
# @yieldparam[tempfile Tempfile] Tempfile instance
|
|
35
|
+
# @yieldreturn [nil] Tempfile gets closed when the block returns
|
|
36
|
+
def content &block
|
|
37
|
+
request = GenericRequest.new self.class.studio_connection
|
|
38
|
+
path = "/rpms/#{id.to_i}/data"
|
|
39
|
+
block_given? ? request.get_file(path, &block) : request.get(path)
|
|
35
40
|
end
|
|
36
41
|
end
|
|
37
42
|
end
|
data/rubygem-studio_api.changes
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
-------------------------------------------------------------------
|
|
2
|
+
Tue Feb 21 16:48:12 UTC 2012 - jreidinger@suse.com
|
|
3
|
+
|
|
4
|
+
- add feature for chunk processing of downloaded overlay files
|
|
5
|
+
and rpms ( thanks to vmoravec )
|
|
6
|
+
- 3.2.0
|
|
7
|
+
|
|
8
|
+
-------------------------------------------------------------------
|
|
9
|
+
Mon Nov 28 15:13:50 UTC 2011 - jreidinger@suse.com
|
|
10
|
+
|
|
11
|
+
- rails 3.1 fixes
|
|
12
|
+
-- fix persistency when model created by new
|
|
13
|
+
- improve documentation of configuration of appliance
|
|
14
|
+
- 3.1.4
|
|
15
|
+
|
|
1
16
|
-------------------------------------------------------------------
|
|
2
17
|
Wed Aug 17 12:59:00 UTC 2011 - jreidinger@novell.com
|
|
3
18
|
|
data/test/file_test.rb
CHANGED
|
@@ -36,14 +36,31 @@ class File1Test < Test::Unit::TestCase
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
def test_update
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
register_fake_response_from_file :get, "/api/files/#{@file_id}",
|
|
40
|
+
'file.xml'
|
|
41
|
+
register_fake_response_from_file :put, "/api/files/#{@file_id}",
|
|
42
|
+
'file.xml'
|
|
43
|
+
|
|
44
|
+
f = StudioApi::File.find(@file_id)
|
|
45
|
+
f.path = "/tmp"
|
|
46
|
+
assert f.save
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_content
|
|
50
|
+
file_name = 'file.xml'
|
|
51
|
+
file_path = File.join File.dirname(__FILE__), 'responses'
|
|
52
|
+
register_fake_response_from_file :get, "/api/files/#{@file_id}/data", file_name
|
|
53
|
+
register_fake_response_from_file :get, "/api/files/#{@file_id}", file_name
|
|
54
|
+
studio_file = StudioApi::File.find(@file_id)
|
|
55
|
+
response = StringIO.new
|
|
56
|
+
File.open(File.join(file_path, file_name), 'r') do |file|
|
|
57
|
+
assert_equal studio_file.content, file.read
|
|
58
|
+
studio_file.content do |body|
|
|
59
|
+
response << body
|
|
60
|
+
end
|
|
61
|
+
file.rewind
|
|
62
|
+
assert_equal file.read, response.string
|
|
63
|
+
end
|
|
47
64
|
end
|
|
48
65
|
end
|
|
49
66
|
|
data/test/rpm_test.rb
CHANGED
|
@@ -50,4 +50,16 @@ class RpmTest < Test::Unit::TestCase
|
|
|
50
50
|
assert StudioApi::Rpm.upload(@rpm_data, "SLE11")
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
def test_download_with_block
|
|
54
|
+
register_fake_response :get, "/api/rpms/#{@rpm_id}/data", @rpm_data
|
|
55
|
+
file_content = nil
|
|
56
|
+
rpm = StudioApi::Rpm.new(:id=> @rpm_id)
|
|
57
|
+
response = StringIO.new
|
|
58
|
+
rpm.content do |body|
|
|
59
|
+
response << body
|
|
60
|
+
end
|
|
61
|
+
assert_equal @rpm_data, response.string
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
|
|
53
65
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: studio_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 15
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 3
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
version: 3.
|
|
8
|
+
- 2
|
|
9
|
+
- 0
|
|
10
|
+
version: 3.2.0
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Josef Reidinger
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date:
|
|
18
|
+
date: 2012-02-21 00:00:00 +00:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|