redfish_client 0.5.0 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +21 -0
- data/lib/redfish_client/connector.rb +31 -12
- data/lib/redfish_client/response.rb +10 -1
- data/lib/redfish_client/version.rb +1 -1
- data/redfish_client.gemspec +3 -3
- metadata +12 -13
- data/.travis.yml +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 685c1b4535b5934f7683db9bdb964e5961962c9d85fc3d83ef5c97051568d58b
|
4
|
+
data.tar.gz: f60cc0d54626c4ab2c55f84e2179a507ff95d8732a40d99bb300bde7666f40f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5b8378d17b32e736e1007c51a3e22a5ad746e816acdb5e586cf91552c07ca5153a5140923a70ae8364c7b7435fb84b9010756157269e2d88d053b692dd055b3
|
7
|
+
data.tar.gz: 5711720aa89461803460a09d323d043505ee54b6cef50183abddb336364f5145a030c6e0050723c22d85e706476e0a49c5f55a357a613a800c55b0e05be62e3d
|
@@ -0,0 +1,21 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
test:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
steps:
|
12
|
+
- name: Clone repo
|
13
|
+
uses: actions/checkout@v2
|
14
|
+
- name: Set up Ruby
|
15
|
+
uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: 2.6
|
18
|
+
- name: Install dependencies
|
19
|
+
run: bundle install
|
20
|
+
- name: Run tests
|
21
|
+
run: bundle exec rake
|
@@ -29,6 +29,7 @@ module RedfishClient
|
|
29
29
|
# Basic and token authentication header names
|
30
30
|
BASIC_AUTH_HEADER = "Authorization"
|
31
31
|
TOKEN_AUTH_HEADER = "X-Auth-Token"
|
32
|
+
LOCATION_HEADER = "Location"
|
32
33
|
|
33
34
|
# Create new connector.
|
34
35
|
#
|
@@ -82,13 +83,11 @@ module RedfishClient
|
|
82
83
|
# @param data [Hash] data to be sent over the socket
|
83
84
|
# @return [Response] response object
|
84
85
|
def request(method, path, data = nil)
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
r = @connection.request(params)
|
86
|
+
return @cache[path] if method == :get && @cache[path]
|
87
|
+
|
88
|
+
do_request(method, path, data).tap do |r|
|
89
|
+
@cache[path] = r if method == :get && r.status == 200
|
90
90
|
end
|
91
|
-
Response.new(r.status, downcase_headers(r.data[:headers]), r.data[:body])
|
92
91
|
end
|
93
92
|
|
94
93
|
# Issue GET request to service.
|
@@ -100,9 +99,7 @@ module RedfishClient
|
|
100
99
|
# @param path [String] path to the resource, relative to the base url
|
101
100
|
# @return [Response] response object
|
102
101
|
def get(path)
|
103
|
-
|
104
|
-
|
105
|
-
request(:get, path).tap { |r| @cache[path] = r if r.status == 200 }
|
102
|
+
request(:get, path)
|
106
103
|
end
|
107
104
|
|
108
105
|
# Issue POST requests to the service.
|
@@ -188,6 +185,16 @@ module RedfishClient
|
|
188
185
|
|
189
186
|
private
|
190
187
|
|
188
|
+
def do_request(method, path, data)
|
189
|
+
params = prepare_request_params(method, path, data)
|
190
|
+
r = @connection.request(params)
|
191
|
+
if r.status == 401
|
192
|
+
login
|
193
|
+
r = @connection.request(params)
|
194
|
+
end
|
195
|
+
Response.new(r.status, downcase_headers(r.data[:headers]), r.data[:body])
|
196
|
+
end
|
197
|
+
|
191
198
|
def downcase_headers(headers)
|
192
199
|
headers.each_with_object({}) { |(k, v), obj| obj[k.downcase] = v }
|
193
200
|
end
|
@@ -212,9 +219,21 @@ module RedfishClient
|
|
212
219
|
r = @connection.request(params)
|
213
220
|
raise_invalid_auth_error unless r.status == 201
|
214
221
|
|
215
|
-
|
216
|
-
|
217
|
-
|
222
|
+
body = JSON.parse(r.data[:body])
|
223
|
+
headers = r.data[:headers]
|
224
|
+
|
225
|
+
add_headers(TOKEN_AUTH_HEADER => headers[TOKEN_AUTH_HEADER])
|
226
|
+
save_session_oid!(body, headers)
|
227
|
+
end
|
228
|
+
|
229
|
+
def save_session_oid!(body, headers)
|
230
|
+
@session_oid = body["@odata.id"] if body.key?("@odata.id")
|
231
|
+
return if @session_oid
|
232
|
+
|
233
|
+
return unless headers.key?(LOCATION_HEADER)
|
234
|
+
|
235
|
+
location = URI.parse(headers[LOCATION_HEADER])
|
236
|
+
@session_oid = [location.path, location.query].compact.join("?")
|
218
237
|
end
|
219
238
|
|
220
239
|
def basic_login
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "uri"
|
4
|
+
|
3
5
|
module RedfishClient
|
4
6
|
# Response struct.
|
5
7
|
#
|
@@ -20,13 +22,20 @@ module RedfishClient
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def monitor
|
23
|
-
|
25
|
+
return nil if done?
|
26
|
+
|
27
|
+
uri = URI.parse(headers["location"])
|
28
|
+
[uri.path, uri.query].compact.join("?")
|
24
29
|
end
|
25
30
|
|
26
31
|
def to_h
|
27
32
|
{ "status" => status, "headers" => headers, "body" => body }
|
28
33
|
end
|
29
34
|
|
35
|
+
def to_s
|
36
|
+
"Response[status=#{status}, headers=#{headers}, body='#{body}']"
|
37
|
+
end
|
38
|
+
|
30
39
|
def self.from_hash(data)
|
31
40
|
new(*data.values_at("status", "headers", "body"))
|
32
41
|
end
|
data/redfish_client.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["tadej.borovsak@xlab.si"]
|
11
11
|
|
12
12
|
spec.summary = "Simple Redfish client library"
|
13
|
-
spec.homepage = "https://github.com/xlab-
|
13
|
+
spec.homepage = "https://github.com/xlab-steampunk/redfish-client-ruby"
|
14
14
|
spec.license = "Apache-2.0"
|
15
15
|
|
16
16
|
if spec.respond_to?(:metadata)
|
@@ -27,9 +27,9 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
|
-
spec.required_ruby_version = "
|
30
|
+
spec.required_ruby_version = ">= 2.1"
|
31
31
|
|
32
|
-
spec.add_runtime_dependency "excon", "~> 0.
|
32
|
+
spec.add_runtime_dependency "excon", "~> 0.71"
|
33
33
|
spec.add_runtime_dependency "server_sent_events", "~> 0.1"
|
34
34
|
|
35
35
|
spec.add_development_dependency "rake", ">= 11.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redfish_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tadej Borovšak
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.71'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.71'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: server_sent_events
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,7 +136,7 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
-
description:
|
139
|
+
description:
|
140
140
|
email:
|
141
141
|
- tadej.borovsak@xlab.si
|
142
142
|
executables: []
|
@@ -144,11 +144,11 @@ extensions: []
|
|
144
144
|
extra_rdoc_files: []
|
145
145
|
files:
|
146
146
|
- ".codeclimate.yml"
|
147
|
+
- ".github/workflows/ci.yml"
|
147
148
|
- ".gitignore"
|
148
149
|
- ".rspec"
|
149
150
|
- ".rubocop.yml"
|
150
151
|
- ".simplecov"
|
151
|
-
- ".travis.yml"
|
152
152
|
- ".yardopts"
|
153
153
|
- Gemfile
|
154
154
|
- README.md
|
@@ -164,18 +164,18 @@ files:
|
|
164
164
|
- lib/redfish_client/root.rb
|
165
165
|
- lib/redfish_client/version.rb
|
166
166
|
- redfish_client.gemspec
|
167
|
-
homepage: https://github.com/xlab-
|
167
|
+
homepage: https://github.com/xlab-steampunk/redfish-client-ruby
|
168
168
|
licenses:
|
169
169
|
- Apache-2.0
|
170
170
|
metadata:
|
171
171
|
allowed_push_host: https://rubygems.org
|
172
|
-
post_install_message:
|
172
|
+
post_install_message:
|
173
173
|
rdoc_options: []
|
174
174
|
require_paths:
|
175
175
|
- lib
|
176
176
|
required_ruby_version: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
|
-
- - "
|
178
|
+
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '2.1'
|
181
181
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -184,9 +184,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
184
|
- !ruby/object:Gem::Version
|
185
185
|
version: '0'
|
186
186
|
requirements: []
|
187
|
-
|
188
|
-
|
189
|
-
signing_key:
|
187
|
+
rubygems_version: 3.2.3
|
188
|
+
signing_key:
|
190
189
|
specification_version: 4
|
191
190
|
summary: Simple Redfish client library
|
192
191
|
test_files: []
|
data/.travis.yml
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
cache: bundler
|
3
|
-
|
4
|
-
rvm:
|
5
|
-
- 2.4.3
|
6
|
-
|
7
|
-
env:
|
8
|
-
global:
|
9
|
-
- CC_TEST_REPORTER_ID=64aae57d1a096aebb16347cbc64d418352f3ec38ebbe4d002bc84c2ceda837b3
|
10
|
-
|
11
|
-
before_script:
|
12
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
13
|
-
- chmod +x ./cc-test-reporter
|
14
|
-
- ./cc-test-reporter before-build
|
15
|
-
|
16
|
-
after_script:
|
17
|
-
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
18
|
-
|
19
|
-
branches:
|
20
|
-
only:
|
21
|
-
- master
|
22
|
-
- /^\d+\.\d+(\.\d+)?(-\S*)?$/
|
23
|
-
|
24
|
-
deploy:
|
25
|
-
provider: rubygems
|
26
|
-
api_key:
|
27
|
-
secure: NdOd7EA9XQZNbnkzLFNXeJcOoaTi93uuwzjADS+fxFJ2HYGJs/T+gi98f742Oj4j187lBQjwICkdduGQjVn3BA/8YZD7sOkdywDSELupTjJmugf/hks6MiKJ0fex5GmHwspjZ7P+9iLPXGcaYWbGamWlSDL+Z/79s4bi8b5sBVwJ01YnIJvFn32/I5vPFwbwUzvH0n3HAjYHZ/kpZ122Zp/DhSpGam2azWF0Tynu7RNMsQrGamAH0mC1DzAscSD6VTyMcSMkD6XUr3GX7w7yvVO0qo7e6EcjrsJKMRC8/s2C/SWQ4pRDAldhQpd4C7/QSaHE0mmQcEYi2qsBmrbFb7cAfRmS5BKn8LSv7YPVH0VFl3fwYAycwqA068TZ68t99YPw7uVcJpDOWBODCQWA1wgV1tXHop7CJOcQW4MoXzyaRbbpF+6lyxXEgTz8Me8zEucMsHWzS9dI1E5x/bWl3TgEM9n+/G6BAcBj/mZv/dxC6H7kWp0ubKw0bRsdET/YmG53vxISaFbnLxNhsHzeE2mFeF+JL7a1amlC4aTiSBnxDgRzDdnoo42Hu8SUg/mp0xLjyoTME1w1zaB+GvmWCdrpkLQL2kNDgQUvBfOp+Zqfb37tKgc15zb7v2sru5acixkSG9UVElleDW8K4R1QcqXwLxCYccCi/ExVR1zSvSM=
|
28
|
-
gem: redfish_client
|
29
|
-
on:
|
30
|
-
tags: true
|
31
|
-
repo: xlab-si/redfish-client-ruby
|