runcible 0.0.3 → 0.0.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.
- data/lib/runcible/base.rb +24 -11
- data/lib/runcible/resources/user.rb +0 -2
- data/lib/runcible/version.rb +1 -1
- data/test/integration/fixtures/vcr_cassettes/pulp_user.yml +276 -160
- data/test/integration/fixtures/vcr_cassettes/pulp_user_helper.yml +361 -129
- data/test/integration/test_runner.rb +16 -8
- metadata +3 -3
data/lib/runcible/base.rb
CHANGED
@@ -35,10 +35,16 @@ module Runcible
|
|
35
35
|
# :password Password for this user
|
36
36
|
# :oauth Oauth credentials
|
37
37
|
# :headers Additional headers e.g. content-type => "application/json"
|
38
|
+
# :url Scheme and hostname for the pulp server e.g. https://localhost/
|
39
|
+
# :api_path URL path for the api e.g. pulp/api/v2/
|
38
40
|
def self.config=(conf={})
|
39
41
|
@@config = {
|
40
|
-
:
|
41
|
-
|
42
|
+
:api_path => '/pulp/api/v2/',
|
43
|
+
:url => 'https://localhost',
|
44
|
+
:user => '',
|
45
|
+
:http_auth => {:password => {} },
|
46
|
+
:headers => {:content_type => 'application/json',
|
47
|
+
:accept => 'application/json'}
|
42
48
|
}.merge(conf)
|
43
49
|
end
|
44
50
|
|
@@ -47,20 +53,23 @@ module Runcible
|
|
47
53
|
end
|
48
54
|
|
49
55
|
def self.call(method, path, options={})
|
50
|
-
path =
|
56
|
+
path = config[:api_path] + path
|
51
57
|
|
52
|
-
headers =
|
58
|
+
headers = config[:headers]
|
53
59
|
headers[:params] = options[:params] if options[:params]
|
54
|
-
headers = add_oauth_header(method, path, headers) if config[:oauth]
|
55
|
-
headers["pulp-user"] = "admin"#config[:user]
|
56
60
|
|
57
|
-
|
61
|
+
if config[:oauth]
|
62
|
+
headers = add_oauth_header(method, path, headers) if config[:oauth]
|
63
|
+
headers["pulp-user"] = config[:user]
|
64
|
+
client = RestClient::Resource.new(config[:url])
|
65
|
+
else
|
66
|
+
client = RestClient::Resource.new(config[:url], :user => config[:user], :password => config[:http_auth][:password])
|
67
|
+
end
|
58
68
|
|
59
69
|
args = [method]
|
60
|
-
args <<
|
61
|
-
args << headers
|
70
|
+
args << generate_payload(options) if [:post, :put].include?(method)
|
71
|
+
args << headers
|
62
72
|
|
63
|
-
client = RestClient::Resource.new(config[:url], config)
|
64
73
|
process_response(client[path].send(*args))
|
65
74
|
end
|
66
75
|
|
@@ -81,7 +90,7 @@ module Runcible
|
|
81
90
|
payload = {}
|
82
91
|
end
|
83
92
|
|
84
|
-
return payload
|
93
|
+
return payload.to_json
|
85
94
|
end
|
86
95
|
|
87
96
|
def self.process_response(response)
|
@@ -109,6 +118,10 @@ module Runcible
|
|
109
118
|
return local_names
|
110
119
|
end
|
111
120
|
|
121
|
+
def self.add_http_auth_header
|
122
|
+
return {:user => config[:user], :password => config[:http_auth][:password]}
|
123
|
+
end
|
124
|
+
|
112
125
|
def self.add_oauth_header(method, path, headers)
|
113
126
|
default_options = { :site => config[:url],
|
114
127
|
:http_method => method,
|
data/lib/runcible/version.rb
CHANGED