manageiq-api-client 0.3.7 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -1
- data/.github/workflows/ci.yaml +4 -4
- data/CHANGELOG.md +11 -1
- data/Gemfile +11 -6
- data/lib/manageiq/api/client/authentication.rb +6 -5
- data/lib/manageiq/api/client/client.rb +2 -1
- data/lib/manageiq/api/client/connection.rb +19 -9
- data/lib/manageiq/api/client/resource.rb +2 -1
- data/lib/manageiq/api/client/version.rb +1 -1
- data/lib/manageiq/api/client.rb +2 -3
- data/manageiq-api-client.gemspec +3 -4
- data/renovate.json +6 -0
- metadata +21 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a7891f16b3eae78cc834f589cdd23b17a272a84cc3073ab9e8565a0c5b7bb5c
|
4
|
+
data.tar.gz: 59448475061016e496a8b957c2bfcf6421be156a098cfa6f1ded20a0897905c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f66d9368405b2e33acbc7d7ac30b3d9197855a9df5b592502741e1c5a2f0efbe6fa81cf6d0884e8a81df90a0dae8f8f4964f16d9d66a70b98a8ac52b96de3b77
|
7
|
+
data.tar.gz: dbb2ad769d72f8075a7749754eb6501814bcecc96336e6a4ded66a549c4f56429475fea90ab6bd1c63a09d5e8cf464f64e7e87ac17d19fb31005a1bac76fc03b
|
data/.codeclimate.yml
CHANGED
data/.github/workflows/ci.yaml
CHANGED
@@ -12,17 +12,17 @@ jobs:
|
|
12
12
|
strategy:
|
13
13
|
matrix:
|
14
14
|
ruby-version:
|
15
|
-
- '2.6'
|
16
|
-
- '2.7'
|
17
15
|
- '3.0'
|
16
|
+
- '3.1'
|
18
17
|
rails-version:
|
19
18
|
- '6.0'
|
20
19
|
- '6.1'
|
20
|
+
- '7.0'
|
21
21
|
env:
|
22
22
|
TEST_RAILS_VERSION: ${{ matrix.rails-version }}
|
23
23
|
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
24
24
|
steps:
|
25
|
-
- uses: actions/checkout@
|
25
|
+
- uses: actions/checkout@v4
|
26
26
|
- name: Set up Ruby
|
27
27
|
uses: ruby/setup-ruby@v1
|
28
28
|
with:
|
@@ -34,4 +34,4 @@ jobs:
|
|
34
34
|
- name: Report code coverage
|
35
35
|
if: ${{ github.ref == 'refs/heads/master' && matrix.ruby-version == '3.0' && matrix.rails-version == '6.1' }}
|
36
36
|
continue-on-error: true
|
37
|
-
uses: paambaati/codeclimate-action@
|
37
|
+
uses: paambaati/codeclimate-action@v6
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.4.1] - 2024-03-06
|
10
|
+
### Added
|
11
|
+
- Drop active_support and more_core_extensions dependency [[#115]](https://github.com/ManageIQ/manageiq-api-client/pull/115)
|
12
|
+
- Add rails 7 support [[#114]](https://github.com/ManageIQ/manageiq-api-client/pull/114)
|
13
|
+
|
14
|
+
## [0.4.0] - 2023-10-16
|
15
|
+
### Added
|
16
|
+
- Add Bearer token support [[#113]](https://github.com/ManageIQ/manageiq-api-client/pull/113)
|
17
|
+
|
9
18
|
## [0.3.7] - 2023-05-19
|
10
19
|
### Changed
|
11
20
|
- Loosen faraday to 1.x. [[#108]](https://github.com/ManageIQ/manageiq-api-client/pull/108)
|
@@ -61,7 +70,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
61
70
|
- Add CHANGELOG.md
|
62
71
|
- Update README with simple instructions reflecting the query interface.
|
63
72
|
|
64
|
-
[Unreleased]: https://github.com/ManageIQ/manageiq-api-client/compare/v0.
|
73
|
+
[Unreleased]: https://github.com/ManageIQ/manageiq-api-client/compare/v0.4.0...HEAD
|
74
|
+
[0.4.0]: https://github.com/ManageIQ/manageiq-api-client/compare/v0.3.7...v0.4.0
|
65
75
|
[0.3.7]: https://github.com/ManageIQ/manageiq-api-client/compare/v0.3.6...v0.3.7
|
66
76
|
[0.3.6]: https://github.com/ManageIQ/manageiq-api-client/compare/v0.3.5...v0.3.6
|
67
77
|
[0.3.5]: https://github.com/ManageIQ/manageiq-api-client/compare/v0.3.4...v0.3.5
|
data/Gemfile
CHANGED
@@ -7,9 +7,14 @@ gemspec
|
|
7
7
|
dev_gemfile = File.expand_path("Gemfile.dev.rb", __dir__)
|
8
8
|
eval_gemfile(dev_gemfile) if File.exist?(dev_gemfile)
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
minimum_version =
|
11
|
+
case ENV['TEST_RAILS_VERSION']
|
12
|
+
when "6.0"
|
13
|
+
"~>6.0.4"
|
14
|
+
when "7.0"
|
15
|
+
"~>7.0.8"
|
16
|
+
else
|
17
|
+
"~>6.1.4"
|
18
|
+
end
|
19
|
+
|
20
|
+
gem "activesupport", minimum_version
|
@@ -6,6 +6,7 @@ module ManageIQ
|
|
6
6
|
attr_reader :password
|
7
7
|
attr_reader :token
|
8
8
|
attr_reader :miqtoken
|
9
|
+
attr_reader :bearer_token
|
9
10
|
attr_reader :group
|
10
11
|
|
11
12
|
DEFAULTS = {
|
@@ -13,26 +14,26 @@ module ManageIQ
|
|
13
14
|
:password => "smartvm"
|
14
15
|
}.freeze
|
15
16
|
|
16
|
-
CUSTOM_INSPECT_EXCLUSIONS = [
|
17
|
+
CUSTOM_INSPECT_EXCLUSIONS = %i[@password @token @miqtoken @bearer_token].freeze
|
17
18
|
include CustomInspectMixin
|
18
19
|
|
19
20
|
def initialize(options = {})
|
20
21
|
@user, @password = fetch_credentials(options)
|
21
|
-
@token, @miqtoken, @group = options.values_at(:token, :miqtoken, :group)
|
22
|
+
@token, @miqtoken, @bearer_token, @group = options.values_at(:token, :miqtoken, :bearer_token, :group)
|
22
23
|
|
23
|
-
unless token || miqtoken
|
24
|
+
unless token || miqtoken || bearer_token
|
24
25
|
raise "Must specify both a user and a password" if user.blank? || password.blank?
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
29
|
def self.auth_options_specified?(options)
|
29
|
-
options.slice(:user, :password, :token, :miqtoken, :group).present?
|
30
|
+
options.slice(:user, :password, :token, :miqtoken, :bearer_token, :group).present?
|
30
31
|
end
|
31
32
|
|
32
33
|
private
|
33
34
|
|
34
35
|
def fetch_credentials(options)
|
35
|
-
if options.slice(:user, :password, :token, :miqtoken).blank?
|
36
|
+
if options.slice(:user, :password, :token, :miqtoken, :bearer_token).blank?
|
36
37
|
[DEFAULTS[:user], DEFAULTS[:password]]
|
37
38
|
else
|
38
39
|
[options[:user], options[:password]]
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module ManageIQ
|
2
2
|
module API
|
3
3
|
class Client
|
4
|
+
extend Forwardable
|
4
5
|
attr_reader :client_options
|
5
6
|
attr_reader :logger
|
6
7
|
attr_reader :url
|
@@ -62,7 +63,7 @@ module ManageIQ
|
|
62
63
|
load_definitions
|
63
64
|
end
|
64
65
|
|
65
|
-
|
66
|
+
def_delegators :connection, :get, :post, :put, :patch, :delete, :options, :error
|
66
67
|
|
67
68
|
private
|
68
69
|
|
@@ -2,6 +2,8 @@ module ManageIQ
|
|
2
2
|
module API
|
3
3
|
class Client
|
4
4
|
class Connection
|
5
|
+
extend Forwardable
|
6
|
+
|
5
7
|
attr_reader :url
|
6
8
|
attr_reader :authentication
|
7
9
|
attr_reader :client
|
@@ -9,7 +11,7 @@ module ManageIQ
|
|
9
11
|
attr_reader :response
|
10
12
|
attr_reader :error
|
11
13
|
|
12
|
-
|
14
|
+
def_delegators :client, :url, :authentication
|
13
15
|
|
14
16
|
API_PREFIX = "/api".freeze
|
15
17
|
CONTENT_TYPE = "application/json".freeze
|
@@ -58,12 +60,12 @@ module ManageIQ
|
|
58
60
|
end
|
59
61
|
|
60
62
|
def api_path(path)
|
61
|
-
if path.to_s.
|
63
|
+
if path.to_s.start_with?(url.to_s)
|
62
64
|
path.to_s
|
63
65
|
elsif path.to_s.blank?
|
64
66
|
URI.join(url, API_PREFIX).to_s
|
65
67
|
else
|
66
|
-
URI.join(url, path.to_s.
|
68
|
+
URI.join(url, path.to_s.start_with?(API_PREFIX) ? path.to_s : "#{API_PREFIX}/#{path}").to_s
|
67
69
|
end
|
68
70
|
end
|
69
71
|
|
@@ -74,10 +76,17 @@ module ManageIQ
|
|
74
76
|
faraday.options.open_timeout = @connection_options[:open_timeout] if @connection_options[:open_timeout]
|
75
77
|
faraday.options.timeout = @connection_options[:timeout] if @connection_options[:timeout]
|
76
78
|
faraday.response(:logger, client.logger)
|
77
|
-
faraday.
|
78
|
-
|
79
|
-
|
80
|
-
|
79
|
+
faraday.response(:follow_redirects, :limit => 3, :standards_compliant => true)
|
80
|
+
# make requests with Net::HTTP
|
81
|
+
faraday.adapter(Faraday.default_adapter)
|
82
|
+
if authentication.token.blank? && authentication.miqtoken.blank? && authentication.bearer_token.blank?
|
83
|
+
if faraday.respond_to?(:basic_auth)
|
84
|
+
# faraday 1.0
|
85
|
+
faraday.basic_auth(authentication.user, authentication.password)
|
86
|
+
else
|
87
|
+
# faraday 2.0
|
88
|
+
faraday.request(:authorization, :basic, authentication.user, authentication.password)
|
89
|
+
end
|
81
90
|
end
|
82
91
|
end
|
83
92
|
end
|
@@ -90,6 +99,7 @@ module ManageIQ
|
|
90
99
|
@response = handle.run_request(method.to_sym, api_path(path), nil, nil) do |request|
|
91
100
|
request.headers[:content_type] = CONTENT_TYPE
|
92
101
|
request.headers[:accept] = CONTENT_TYPE
|
102
|
+
request.headers[:authorization] = "Bearer #{authentication.bearer_token}" unless authentication.bearer_token.blank?
|
93
103
|
request.headers['X-MIQ-Group'] = authentication.group unless authentication.group.blank?
|
94
104
|
request.headers['X-Auth-Token'] = authentication.token unless authentication.token.blank?
|
95
105
|
request.headers['X-MIQ-Token'] = authentication.miqtoken unless authentication.miqtoken.blank?
|
@@ -104,11 +114,11 @@ module ManageIQ
|
|
104
114
|
|
105
115
|
def check_response
|
106
116
|
if response.status == 404
|
107
|
-
message = json_response
|
117
|
+
message = json_response["error"].kind_of?(String) ? json_response["error"] : json_response.dig("error", "message")
|
108
118
|
raise ManageIQ::API::Client::ResourceNotFound, message
|
109
119
|
elsif response.status >= 400
|
110
120
|
@error = ManageIQ::API::Client::Error.new(response.status, json_response)
|
111
|
-
raise @error.message
|
121
|
+
raise ManageIQ::API::Client::Exception, @error.message || "Empty Response"
|
112
122
|
end
|
113
123
|
end
|
114
124
|
end
|
@@ -2,6 +2,7 @@ module ManageIQ
|
|
2
2
|
module API
|
3
3
|
class Client
|
4
4
|
class Resource
|
5
|
+
extend Forwardable
|
5
6
|
include ActionMixin
|
6
7
|
|
7
8
|
CUSTOM_INSPECT_EXCLUSIONS = [:@collection].freeze
|
@@ -21,7 +22,7 @@ module ManageIQ
|
|
21
22
|
attr_reader :collection
|
22
23
|
attr_reader :actions
|
23
24
|
|
24
|
-
|
25
|
+
def_delegators :collection, :client
|
25
26
|
|
26
27
|
def initialize(collection, resource_hash)
|
27
28
|
raise "Cannot instantiate a Resource directly" if instance_of?(Resource)
|
data/lib/manageiq/api/client.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require "active_support"
|
2
2
|
require "active_support/core_ext"
|
3
3
|
require "faraday"
|
4
|
-
require "
|
4
|
+
require "faraday/follow_redirects"
|
5
|
+
require 'forwardable'
|
5
6
|
require "json"
|
6
|
-
require "more_core_extensions/all"
|
7
|
-
require "pp"
|
8
7
|
require "query_relation"
|
9
8
|
|
10
9
|
require "manageiq/api/client/client"
|
data/manageiq-api-client.gemspec
CHANGED
@@ -23,11 +23,10 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
24
|
spec.require_paths = ["lib"]
|
25
25
|
|
26
|
-
spec.add_dependency "activesupport", ">=
|
27
|
-
spec.add_dependency "faraday", "
|
28
|
-
spec.add_dependency "
|
26
|
+
spec.add_dependency "activesupport", ">= 6.0", "<7.1"
|
27
|
+
spec.add_dependency "faraday", ">= 1.0", "< 3.0"
|
28
|
+
spec.add_dependency "faraday-follow_redirects"
|
29
29
|
spec.add_dependency "json", "~> 2.3"
|
30
|
-
spec.add_dependency "more_core_extensions"
|
31
30
|
spec.add_dependency "query_relation"
|
32
31
|
|
33
32
|
spec.add_development_dependency "bundler"
|
data/renovate.json
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: manageiq-api-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alberto Bellotti
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-05-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -17,48 +17,54 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '6.0'
|
21
21
|
- - "<"
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: '7.
|
23
|
+
version: '7.1'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
27
|
requirements:
|
28
28
|
- - ">="
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version: '
|
30
|
+
version: '6.0'
|
31
31
|
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '7.
|
33
|
+
version: '7.1'
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: faraday
|
36
36
|
requirement: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.0'
|
41
|
+
- - "<"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3.0'
|
41
44
|
type: :runtime
|
42
45
|
prerelease: false
|
43
46
|
version_requirements: !ruby/object:Gem::Requirement
|
44
47
|
requirements:
|
45
|
-
- - "
|
48
|
+
- - ">="
|
46
49
|
- !ruby/object:Gem::Version
|
47
50
|
version: '1.0'
|
51
|
+
- - "<"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.0'
|
48
54
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
55
|
+
name: faraday-follow_redirects
|
50
56
|
requirement: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
|
-
- - "
|
58
|
+
- - ">="
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
60
|
+
version: '0'
|
55
61
|
type: :runtime
|
56
62
|
prerelease: false
|
57
63
|
version_requirements: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
|
-
- - "
|
65
|
+
- - ">="
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
67
|
+
version: '0'
|
62
68
|
- !ruby/object:Gem::Dependency
|
63
69
|
name: json
|
64
70
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,20 +79,6 @@ dependencies:
|
|
73
79
|
- - "~>"
|
74
80
|
- !ruby/object:Gem::Version
|
75
81
|
version: '2.3'
|
76
|
-
- !ruby/object:Gem::Dependency
|
77
|
-
name: more_core_extensions
|
78
|
-
requirement: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
type: :runtime
|
84
|
-
prerelease: false
|
85
|
-
version_requirements: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
82
|
- !ruby/object:Gem::Dependency
|
91
83
|
name: query_relation
|
92
84
|
requirement: !ruby/object:Gem::Requirement
|
@@ -233,6 +225,7 @@ files:
|
|
233
225
|
- lib/manageiq/api/client/version.rb
|
234
226
|
- lib/manageiq_api_client.rb
|
235
227
|
- manageiq-api-client.gemspec
|
228
|
+
- renovate.json
|
236
229
|
homepage: http://github.com/ManageIQ/manageiq-api-client
|
237
230
|
licenses:
|
238
231
|
- MIT
|
@@ -252,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
252
245
|
- !ruby/object:Gem::Version
|
253
246
|
version: '0'
|
254
247
|
requirements: []
|
255
|
-
rubygems_version: 3.
|
248
|
+
rubygems_version: 3.3.27
|
256
249
|
signing_key:
|
257
250
|
specification_version: 4
|
258
251
|
summary: ManageIQ API Client
|