redfish_client 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ef675df00d6ecec6a42816c288047a68a9cf85f6
4
- data.tar.gz: 0a6d6dc6e5c8af0b70857f7fcf8d49ddfde0c2c8
2
+ SHA256:
3
+ metadata.gz: 7927655fca079fcda9d87e9a2b528e747af59e9385a24ad3c59b92c0e0caa6dc
4
+ data.tar.gz: 7981e1da150898a1b5a084f8277eb7a8cb642182ee1ef109764e3252a3109c42
5
5
  SHA512:
6
- metadata.gz: 6c44c7d4045c017703ce35a137bbb8de69ce9e77bc18459b9fc333829d9b612f294ff05bce990895de7fadf92ab68019000ec62ec8491459b50baef4520f9cfd
7
- data.tar.gz: 780cabd5d73abcb4a146e13ccd0ad548e07716fa0e499ea8014574b61638667fe533ab566f12944ef1b862c97e6c85ad97de6631e8512be42712ea88350843be
6
+ metadata.gz: 6687e1bcc7461fef0bfba86dcd9b1436aed911ede07d917d5e28d8bb87aa19bb77eb6d106eb3f8f4fd2c1b75bbe2b566d496d70d884fd9350f5875c5f68b6e18
7
+ data.tar.gz: 81df752a968d94871a7409bc6a057662c2842848cb8f3f1c2f43fa77bf5e9818f5fe052f6ece86ae3f0a97476dbb16c6c7678d8bda7dcc1106ea8c72abb70a12
data/.codeclimate.yml ADDED
@@ -0,0 +1,3 @@
1
+ plugins:
2
+ rubocop:
3
+ enabled: true
data/.rubocop.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  AllCops:
2
+ TargetRubyVersion: 2.3
2
3
  Exclude:
3
4
  - redfish_client.gemspec
4
5
  - Gemfile
@@ -14,6 +15,9 @@ Style/Documentation:
14
15
  Style/BracesAroundHashParameters:
15
16
  EnforcedStyle: context_dependent
16
17
 
18
+ Metrics/AbcSize:
19
+ Max: 20
20
+
17
21
  Metrics/BlockLength:
18
22
  Exclude:
19
23
  - spec/**/*.rb
data/.travis.yml CHANGED
@@ -1,8 +1,27 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  cache: bundler
4
+
4
5
  rvm:
5
6
  - 2.4.3
7
+
8
+ env:
9
+ global:
10
+ - CC_TEST_REPORTER_ID=5bfd87f6c63155c74a46e37c94800e369d3b791988b2601113d843b1391474af
11
+
12
+ before_script:
13
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
14
+ - chmod +x ./cc-test-reporter
15
+ - ./cc-test-reporter before-build
16
+
17
+ after_script:
18
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
19
+
20
+ branches:
21
+ only:
22
+ - master
23
+ - /^\d+\.\d+(\.\d+)?(-\S*)?$/
24
+
6
25
  deploy:
7
26
  provider: rubygems
8
27
  api_key:
data/README.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Redfish Ruby Client
2
2
 
3
+ [![Build Status](https://travis-ci.org/xlab-si/redfish_client.svg?branch=master)](https://travis-ci.org/xlab-si/redfish_client)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/ce990310be22db90c3e2/maintainability)](https://codeclimate.com/github/xlab-si/redfish_client/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/ce990310be22db90c3e2/test_coverage)](https://codeclimate.com/github/xlab-si/redfish_client/test_coverage)
6
+ [![Dependency Status](https://beta.gemnasium.com/badges/github.com/xlab-si/redfish_client.svg)](https://beta.gemnasium.com/projects/github.com/xlab-si/redfish_client)
7
+ [![security](https://hakiri.io/github/xlab-si/redfish_client/master.svg)](https://hakiri.io/github/xlab-si/redfish_client/master)
8
+
9
+
3
10
  This repository contains source code for redfish_client gem that can be used
4
11
  to connect to Redfish services.
5
12
 
@@ -37,16 +44,15 @@ Minimal program that uses this gem would look something like this:
37
44
  ## Development
38
45
 
39
46
  After checking out the repo, run `bin/setup` to install dependencies. Then,
40
- run `rake spec` to run the tests. You can also run `bin/console` for an
41
- interactive prompt that will allow you to experiment.
47
+ run `bundle exec rake spec` to run the tests. You can also run `bin/console`
48
+ for an interactive prompt that will allow you to experiment.
42
49
 
43
- To install this gem onto your local machine, run `bundle exec rake install`.
44
- To release a new version, update the version number in `version.rb`, and then
45
- run `bundle exec rake release`, which will create a git tag for the version,
46
- push git commits and tags, and push the `.gem` file to
47
- [rubygems.org](https://rubygems.org).
50
+ To create new release, increment the version number, commit the change, tag
51
+ the commit and push tag to the GitHub. Travis CI will pick from there on and
52
+ create new release, publishing it on https://rubygems.org.
48
53
 
49
54
 
50
55
  ## Contributing
51
56
 
52
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/redfish_client.
57
+ Bug reports and pull requests are welcome on GitHub at
58
+ https://github.com/xlab-si/redfish_client.
@@ -79,7 +79,6 @@ module RedfishClient
79
79
  @connection.patch(params)
80
80
  end
81
81
 
82
-
83
82
  # Issue DELETE requests to the service.
84
83
  #
85
84
  # @param path [String] path to the resource, relative to the base
@@ -168,7 +168,7 @@ module RedfishClient
168
168
  private
169
169
 
170
170
  def get_path(field, path)
171
- raise NoODataId if path.nil? and !key?(field)
171
+ raise NoODataId if path.nil? && !key?(field)
172
172
  path || @content[field]
173
173
  end
174
174
 
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "base64"
3
4
  require "redfish_client/resource"
4
5
 
5
6
  module RedfishClient
@@ -9,39 +10,36 @@ module RedfishClient
9
10
  # AuthError is raised if the user session cannot be created.
10
11
  class AuthError < StandardError; end
11
12
 
12
- # Token authentication header.
13
- AUTH_HEADER = "X-Auth-Token"
13
+ # Basic and token authentication headers.
14
+ BASIC_AUTH_HEADER = "Authorization"
15
+ TOKEN_AUTH_HEADER = "X-Auth-Token"
14
16
 
15
17
  # Authenticate against the service.
16
18
  #
17
19
  # Calling this method will try to create new session on the service using
18
- # provided credentials. If the session creation fails, {AuthError} will be
19
- # raised.
20
+ # provided credentials. If the session creation fails, basic
21
+ # authentication will be attempted. If basic authentication fails,
22
+ # {AuthError} will be raised.
20
23
  #
21
24
  # @param username [String] username
22
25
  # @param password [String] password
23
26
  # @raise [AuthError] if user session could not be created
24
27
  def login(username, password)
25
- r = self.Links.Sessions.post(
26
- payload: { "UserName" => username, "Password" => password }
27
- )
28
- raise AuthError unless r.status == 201
29
-
30
- logout
31
- rdata = r.data
32
- @connector.add_headers(AUTH_HEADER => rdata[:headers][AUTH_HEADER])
33
- @session = Resource.new(@connector, content: JSON.parse(rdata[:body]))
28
+ # Since session auth is more secure, we try it first and use basic auth
29
+ # only if session auth is not available.
30
+ if session_login_available?
31
+ session_login(username, password)
32
+ else
33
+ basic_login(username, password)
34
+ end
34
35
  end
35
36
 
36
37
  # Sign out of the service.
37
38
  #
38
39
  # If the session could not be deleted, {AuthError} will be raised.
39
40
  def logout
40
- return unless @session
41
- r = @session.delete
42
- raise AuthError unless r.status == 204
43
- @session = nil
44
- @connector.remove_headers([AUTH_HEADER])
41
+ session_logout
42
+ basic_logout
45
43
  end
46
44
 
47
45
  # Find Redfish service object by OData ID field.
@@ -51,5 +49,47 @@ module RedfishClient
51
49
  def find(oid)
52
50
  Resource.new(@connector, oid: oid)
53
51
  end
52
+
53
+ private
54
+
55
+ def session_login_available?
56
+ !@content.dig("Links", "Sessions").nil?
57
+ end
58
+
59
+ def session_login(username, password)
60
+ r = self.Links.Sessions.post(
61
+ payload: { "UserName" => username, "Password" => password }
62
+ )
63
+ raise AuthError, "Invalid credentials" unless r.status == 201
64
+
65
+ session_logout
66
+
67
+ payload = r.data[:headers][TOKEN_AUTH_HEADER]
68
+ @connector.add_headers(TOKEN_AUTH_HEADER => payload)
69
+ @session = Resource.new(@connector, content: JSON.parse(r.data[:body]))
70
+ end
71
+
72
+ def session_logout
73
+ return unless @session
74
+ r = @session.delete
75
+ raise AuthError unless r.status == 204
76
+ @session = nil
77
+ @connector.remove_headers([TOKEN_AUTH_HEADER])
78
+ end
79
+
80
+ def auth_test_path
81
+ @content.values.map { |v| v["@odata.id"] }.compact.first
82
+ end
83
+
84
+ def basic_login(username, password)
85
+ payload = Base64.encode64("#{username}:#{password}").strip
86
+ @connector.add_headers(BASIC_AUTH_HEADER => "Basic #{payload}")
87
+ r = @connector.get(auth_test_path)
88
+ raise AuthError, "Invalid credentials" unless r.status == 200
89
+ end
90
+
91
+ def basic_logout
92
+ @connector.remove_headers([BASIC_AUTH_HEADER])
93
+ end
54
94
  end
55
95
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RedfishClient
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -1,19 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "redfish_client/connector"
4
- require "redfish_client/null_logger"
5
4
  require "redfish_client/root"
6
5
  require "redfish_client/version"
7
6
 
8
7
  module RedfishClient
9
- def self.logger
10
- @logger ||= NullLogger.new
11
- end
12
-
13
- def self.logger=(logger)
14
- @logger = logger
15
- end
16
-
17
8
  def self.new(url, prefix: "/redfish/v1", verify: true)
18
9
  con = Connector.new(url, verify)
19
10
  Root.new(con, oid: prefix)
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tadej Borovšak
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-25 00:00:00.000000000 Z
11
+ date: 2018-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -129,6 +129,7 @@ executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
+ - ".codeclimate.yml"
132
133
  - ".gitignore"
133
134
  - ".rspec"
134
135
  - ".rubocop.yml"
@@ -167,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
168
  version: '0'
168
169
  requirements: []
169
170
  rubyforge_project:
170
- rubygems_version: 2.6.14
171
+ rubygems_version: 2.7.6
171
172
  signing_key:
172
173
  specification_version: 4
173
174
  summary: Simple Redfish client library