train-rest 0.2.0 → 0.2.1
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/README.md +8 -2
- data/lib/train-rest/auth_handler/redfish.rb +13 -3
- data/lib/train-rest/connection.rb +13 -2
- data/lib/train-rest/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59770f2304519af69df3caaac4f4ef19f964a0a4700952ff6a3b96834867bf13
|
4
|
+
data.tar.gz: 39546783f42569561a1f740c094d0f2adb1a31c49c710b5c9736f172a961306f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8b2b55eb1723538a552ecbc7ce452a3545bd8ae3e35a82c263f3bbc16d6bfed161d053a6a711b0e34723c4f332e6d7797a40035d6142fc9957618a10ad6dac6
|
7
|
+
data.tar.gz: 967e71707994db3086ea1f71e5d987324c405930ecb4473b9ad886ca59b32d15efb2e4c42f4f4075a607d642a11d78d4fe5e4fe6946468eb348735dd24bde514
|
data/README.md
CHANGED
@@ -119,14 +119,20 @@ conn = train.connection
|
|
119
119
|
conn.close
|
120
120
|
```
|
121
121
|
|
122
|
-
Example for logging into a RedFish based system
|
122
|
+
Example for logging into a RedFish based system. Please note that the RedFish
|
123
|
+
authentication handler will append `redfish/v1` to the endpoint automatically,
|
124
|
+
if it is not present.
|
125
|
+
|
126
|
+
Due to this, you can use RedFish systems either with a base URL like in the
|
127
|
+
example below or with a full one. Your own code needs to match the style
|
128
|
+
you choose.
|
123
129
|
|
124
130
|
```ruby
|
125
131
|
require 'train-rest'
|
126
132
|
|
127
133
|
# This will immediately do a login and add headers
|
128
134
|
train = Train.create('rest', {
|
129
|
-
endpoint: 'https://
|
135
|
+
endpoint: 'https://10.20.30.40',
|
130
136
|
validate_ssl: false,
|
131
137
|
|
132
138
|
auth_type: :redfish,
|
@@ -13,7 +13,7 @@ module TrainPlugins
|
|
13
13
|
|
14
14
|
def login
|
15
15
|
response = connection.post(
|
16
|
-
|
16
|
+
login_url,
|
17
17
|
headers: {
|
18
18
|
"Content-Type" => "application/json",
|
19
19
|
"OData-Version" => "4.0",
|
@@ -24,10 +24,11 @@ module TrainPlugins
|
|
24
24
|
}
|
25
25
|
)
|
26
26
|
|
27
|
-
raise StandardError.new("Authentication with Redfish failed") unless response.code === 201
|
28
|
-
|
29
27
|
@session_token = response.headers["x-auth-token"].first
|
30
28
|
@logout_url = response.headers["location"].first
|
29
|
+
|
30
|
+
rescue ::RestClient::RequestFailed => err
|
31
|
+
raise StandardError.new("Authentication with Redfish failed: " + err.message)
|
31
32
|
end
|
32
33
|
|
33
34
|
def logout
|
@@ -39,6 +40,15 @@ module TrainPlugins
|
|
39
40
|
|
40
41
|
{ "X-Auth-Token": @session_token }
|
41
42
|
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
# Prepend the RedFish base, if not a global setting in the connection URL
|
47
|
+
def login_url
|
48
|
+
return "SessionService/Sessions/" if options[:endpoint].include?("redfish/v1")
|
49
|
+
|
50
|
+
"redfish/v1/SessionService/Sessions/"
|
51
|
+
end
|
42
52
|
end
|
43
53
|
end
|
44
54
|
end
|
@@ -13,6 +13,12 @@ module TrainPlugins
|
|
13
13
|
def initialize(options)
|
14
14
|
super(options)
|
15
15
|
|
16
|
+
# Plugin was called with an URI only
|
17
|
+
options[:endpoint] = options[:target].sub("rest://", "https://") unless options[:endpoint]
|
18
|
+
|
19
|
+
# Accept string (CLI) and boolean (API) options
|
20
|
+
options[:verify_ssl] = options[:verify_ssl].to_s == "false" ? false : true
|
21
|
+
|
16
22
|
connect
|
17
23
|
end
|
18
24
|
|
@@ -25,7 +31,7 @@ module TrainPlugins
|
|
25
31
|
end
|
26
32
|
|
27
33
|
def uri
|
28
|
-
components = URI
|
34
|
+
components = URI(options[:endpoint])
|
29
35
|
components.scheme = "rest"
|
30
36
|
components.to_s
|
31
37
|
end
|
@@ -35,7 +41,7 @@ module TrainPlugins
|
|
35
41
|
OpenStruct.new({
|
36
42
|
name: "rest",
|
37
43
|
release: TrainPlugins::Rest::VERSION,
|
38
|
-
family_hierarchy:
|
44
|
+
family_hierarchy: %w{rest api},
|
39
45
|
family: "api",
|
40
46
|
platform: "rest",
|
41
47
|
platform_version: 0,
|
@@ -54,6 +60,7 @@ module TrainPlugins
|
|
54
60
|
|
55
61
|
%i{get post put patch delete head}.each do |method|
|
56
62
|
define_method(method) do |path, *parameters|
|
63
|
+
# TODO: "warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call"
|
57
64
|
request(path, method, *parameters)
|
58
65
|
end
|
59
66
|
end
|
@@ -139,11 +146,15 @@ module TrainPlugins
|
|
139
146
|
end
|
140
147
|
|
141
148
|
def login
|
149
|
+
logger.info format("REST Login via %s authentication handler", auth_type.to_s) if auth_type != :anonymous
|
150
|
+
|
142
151
|
auth_handler.options = options
|
143
152
|
auth_handler.login
|
144
153
|
end
|
145
154
|
|
146
155
|
def logout
|
156
|
+
logger.info format("REST Logout via %s authentication handler", auth_type.to_s) if auth_type != :anonymous
|
157
|
+
|
147
158
|
auth_handler.logout
|
148
159
|
end
|
149
160
|
end
|
data/lib/train-rest/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: train-rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Heinen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: train
|