ansible_tower_client 0.15.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -1
- data/lib/ansible_tower_client.rb +3 -0
- data/lib/ansible_tower_client/api.rb +37 -5
- data/lib/ansible_tower_client/base_models/workflow_job.rb +8 -0
- data/lib/ansible_tower_client/base_models/workflow_job_node.rb +11 -0
- data/lib/ansible_tower_client/connection.rb +49 -8
- data/lib/ansible_tower_client/exception.rb +1 -0
- data/lib/ansible_tower_client/hash_model.rb +2 -1
- data/lib/ansible_tower_client/v2/credential_type_v2.rb +9 -0
- data/lib/ansible_tower_client/v2/credential_v2.rb +13 -0
- data/lib/ansible_tower_client/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1b0a1ac463760d8b5494152a6e9646ed367655dfbf857f1899a322cbf89b98f
|
4
|
+
data.tar.gz: 643abb688c74f01c1e7caaed8fb7cb3e1e65eab2a658c1825a5dd1e7176cc398
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f7a7d8a683736eddec813fd3e85aab35675e6bbe1cddc3da13f780e6ebe8d0672ea76bccfe0352f5cdd2255ad2500abf875b193973740e530db2e8704ed200f
|
7
|
+
data.tar.gz: 7d3388d96c17847d266597a5a47d31b02cd6777d819dcad8c448df4e44bf1787399f0d282c39d2ae45453db8f62efa4376a93f99acd04c641d91a1715f54eb18
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,17 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
5
5
|
|
6
6
|
## [Unreleased]
|
7
7
|
|
8
|
+
## [0.16.0] - 2018-07-06
|
9
|
+
### Added
|
10
|
+
- Added support for API v2 and v2 Credentials [(#107)](https://github.com/ansible/ansible_tower_client_ruby/pull/107)
|
11
|
+
- Added AnsibleTowerClient::WorkflowJobNode [(#109)](https://github.com/ansible/ansible_tower_client_ruby/pull/109)
|
12
|
+
- Set the Faraday logger when creating a connection [(#110)](https://github.com/ansible/ansible_tower_client_ruby/pull/110)
|
13
|
+
- Added AnsibleTowerClient::CredentialTypev2 [(#108)](https://github.com/ansible/ansible_tower_client_ruby/pull/108)
|
14
|
+
- Added AnsibleTowerClient::WorkflowJob#extra_vars_hash [(#111)](https://github.com/ansible/ansible_tower_client_ruby/pull/111)
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
- Substitute invalid characters for dynamically defined class names [(#105)](https://github.com/ansible/ansible_tower_client_ruby/pull/105)
|
18
|
+
|
8
19
|
## [0.15.0] - 2018-06-05
|
9
20
|
### Added
|
10
21
|
- Added AnsibleTowerClient::WorkflowJob [(#104)](https://github.com/ansible/ansible_tower_client_ruby/pull/104)
|
@@ -80,7 +91,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
80
91
|
### Fixed
|
81
92
|
- Adjusted project_spec to test on a Project [(#63)](https://github.com/ansible/ansible_tower_client_ruby/pull/63)
|
82
93
|
|
83
|
-
[Unreleased]: https://github.com/ansible/ansible_tower_client_ruby/compare/v0.
|
94
|
+
[Unreleased]: https://github.com/ansible/ansible_tower_client_ruby/compare/v0.16.0...master
|
95
|
+
[0.16.0]: https://github.com/ansible/ansible_tower_client_ruby/compare/v0.15.0...v0.16.0
|
84
96
|
[0.15.0]: https://github.com/ansible/ansible_tower_client_ruby/compare/v0.14.0...v0.15.0
|
85
97
|
[0.14.0]: https://github.com/ansible/ansible_tower_client_ruby/compare/v0.13.0...v0.14.0
|
86
98
|
[0.13.0]: https://github.com/ansible/ansible_tower_client_ruby/compare/v0.12.2...v0.13.0
|
data/lib/ansible_tower_client.rb
CHANGED
@@ -28,11 +28,14 @@ require "ansible_tower_client/base_models/project_update"
|
|
28
28
|
require "ansible_tower_client/base_models/schedule"
|
29
29
|
require "ansible_tower_client/base_models/system_job"
|
30
30
|
require "ansible_tower_client/base_models/system_job_template"
|
31
|
+
require "ansible_tower_client/base_models/workflow_job_node"
|
31
32
|
require "ansible_tower_client/base_models/workflow_job"
|
32
33
|
require "ansible_tower_client/base_models/workflow_job_template"
|
33
34
|
require "ansible_tower_client/base_models/workflow_job_template_node"
|
34
35
|
|
35
36
|
require "ansible_tower_client/v2/job_template_v2"
|
37
|
+
require "ansible_tower_client/v2/credential_v2"
|
38
|
+
require "ansible_tower_client/v2/credential_type_v2"
|
36
39
|
|
37
40
|
require "more_core_extensions/all"
|
38
41
|
require "active_support/inflector"
|
@@ -6,9 +6,10 @@ module AnsibleTowerClient
|
|
6
6
|
|
7
7
|
DEFAULT_ERROR_MSG = "An unknown error was returned from the provider".freeze
|
8
8
|
|
9
|
-
attr_reader :instance
|
10
|
-
def initialize(connection)
|
11
|
-
@instance
|
9
|
+
attr_reader :instance, :api_version
|
10
|
+
def initialize(connection, api_version)
|
11
|
+
@instance = connection
|
12
|
+
@api_version = api_version
|
12
13
|
end
|
13
14
|
|
14
15
|
def config
|
@@ -35,6 +36,11 @@ module AnsibleTowerClient
|
|
35
36
|
Collection.new(self, credential_class)
|
36
37
|
end
|
37
38
|
|
39
|
+
def credential_types
|
40
|
+
raise AnsibleTowerClient::UnsupportedApiError, 'requires API v2 or higher' if api_version?(1)
|
41
|
+
Collection.new(self, credential_type_class)
|
42
|
+
end
|
43
|
+
|
38
44
|
def groups
|
39
45
|
Collection.new(self, group_class)
|
40
46
|
end
|
@@ -95,6 +101,10 @@ module AnsibleTowerClient
|
|
95
101
|
Collection.new(self, system_job_template_class)
|
96
102
|
end
|
97
103
|
|
104
|
+
def workflow_job_nodes
|
105
|
+
Collection.new(self, workflow_job_node_class)
|
106
|
+
end
|
107
|
+
|
98
108
|
def workflow_jobs
|
99
109
|
Collection.new(self, workflow_job_class)
|
100
110
|
end
|
@@ -142,7 +152,17 @@ module AnsibleTowerClient
|
|
142
152
|
end
|
143
153
|
|
144
154
|
def credential_class
|
145
|
-
@credential_class ||=
|
155
|
+
@credential_class ||= begin
|
156
|
+
if api_version?(2)
|
157
|
+
AnsibleTowerClient::CredentialV2
|
158
|
+
else
|
159
|
+
AnsibleTowerClient::Credential
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def credential_type_class
|
165
|
+
@credential_type_class ||= AnsibleTowerClient::CredentialTypeV2
|
146
166
|
end
|
147
167
|
|
148
168
|
def group_class
|
@@ -179,7 +199,7 @@ module AnsibleTowerClient
|
|
179
199
|
|
180
200
|
def job_template_class
|
181
201
|
@job_template_class ||= begin
|
182
|
-
if
|
202
|
+
if awx_version_between?(2, 3)
|
183
203
|
AnsibleTowerClient::JobTemplateV2
|
184
204
|
else
|
185
205
|
AnsibleTowerClient::JobTemplate
|
@@ -215,6 +235,10 @@ module AnsibleTowerClient
|
|
215
235
|
@workflow_job_class ||= AnsibleTowerClient::WorkflowJob
|
216
236
|
end
|
217
237
|
|
238
|
+
def workflow_job_node_class
|
239
|
+
@workflow_job_node_class ||= AnsibleTowerClient::WorkflowJobNode
|
240
|
+
end
|
241
|
+
|
218
242
|
def workflow_job_template_class
|
219
243
|
@workflow_job_template_class ||= AnsibleTowerClient::WorkflowJobTemplate
|
220
244
|
end
|
@@ -230,5 +254,13 @@ module AnsibleTowerClient
|
|
230
254
|
return original if instance.url_prefix.path == "/"
|
231
255
|
File.join(instance.url_prefix.path, Regexp.last_match[1])
|
232
256
|
end
|
257
|
+
|
258
|
+
def awx_version_between?(min, max)
|
259
|
+
Gem::Version.new(version).between?(Gem::Version.new(min), Gem::Version.new(max))
|
260
|
+
end
|
261
|
+
|
262
|
+
def api_version?(desired)
|
263
|
+
Gem::Version.new(api_version).eql?(Gem::Version.new(desired))
|
264
|
+
end
|
233
265
|
end
|
234
266
|
end
|
@@ -1,4 +1,12 @@
|
|
1
1
|
module AnsibleTowerClient
|
2
2
|
class WorkflowJob < BaseModel
|
3
|
+
def workflow_job_nodes
|
4
|
+
# this is where Ansible API deviates from other part by using `workflow_nodes`
|
5
|
+
Collection.new(api).find_all_by_url(related['workflow_nodes'])
|
6
|
+
end
|
7
|
+
|
8
|
+
def extra_vars_hash
|
9
|
+
extra_vars.empty? ? {} : hashify(:extra_vars)
|
10
|
+
end
|
3
11
|
end
|
4
12
|
end
|
@@ -1,29 +1,70 @@
|
|
1
1
|
module AnsibleTowerClient
|
2
2
|
class Connection
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :options
|
4
4
|
|
5
|
-
|
5
|
+
# Options:
|
6
|
+
# - base_url: you have two options here:
|
7
|
+
# a) pass in only scheme and hostname e.g. 'https://localhost:54321' to allow client to connect to both api v1
|
8
|
+
# and v2 versions like this: `client.api(:version => 1)` and `client.api(:version => 2)`. This requires ansible
|
9
|
+
# tower API being accessible directly at `https://localhost:54321/api/v1` and `https://localhost:54321/api/v2`.
|
10
|
+
# b) pass in a complete api address e.g. 'https://localhost:54321/tower'. Client will then connect to the path
|
11
|
+
# directly and it's your responsibility to know what version of API is there.
|
12
|
+
# - username
|
13
|
+
# - password
|
14
|
+
# - verify_ssl
|
15
|
+
def initialize(options = {})
|
6
16
|
raise "Credentials are required" unless options[:username] && options[:password]
|
7
17
|
raise ":base_url is required" unless options[:base_url]
|
8
|
-
|
9
|
-
verify_ssl = verify_ssl == OpenSSL::SSL::VERIFY_NONE ? false : true
|
18
|
+
logger = options[:logger] || AnsibleTowerClient.logger
|
10
19
|
|
11
20
|
require 'faraday'
|
12
21
|
require 'faraday_middleware'
|
13
22
|
require 'ansible_tower_client/middleware/raise_tower_error'
|
14
23
|
Faraday::Response.register_middleware :raise_tower_error => -> { Middleware::RaiseTowerError }
|
15
|
-
|
24
|
+
|
25
|
+
@options = {
|
26
|
+
:url => options[:base_url],
|
27
|
+
:verify_ssl => (options[:verify_ssl] || OpenSSL::SSL::VERIFY_PEER) != OpenSSL::SSL::VERIFY_NONE,
|
28
|
+
:username => options[:username],
|
29
|
+
:password => options[:password],
|
30
|
+
:logger => logger,
|
31
|
+
}
|
32
|
+
|
33
|
+
reset
|
34
|
+
end
|
35
|
+
|
36
|
+
def connection(url:, username:, password:, verify_ssl: false, logger: nil)
|
37
|
+
Faraday.new(url, :ssl => {:verify => verify_ssl}) do |f|
|
16
38
|
f.use(FaradayMiddleware::EncodeJson)
|
17
39
|
f.use(FaradayMiddleware::FollowRedirects, :limit => 3, :standards_compliant => true)
|
18
40
|
f.request(:url_encoded)
|
19
41
|
f.response(:raise_tower_error)
|
42
|
+
f.response(:logger, logger)
|
20
43
|
f.adapter(Faraday.default_adapter)
|
21
|
-
f.basic_auth(
|
44
|
+
f.basic_auth(username, password)
|
22
45
|
end
|
23
46
|
end
|
24
47
|
|
25
|
-
def api
|
26
|
-
@api ||=
|
48
|
+
def api(version: 2)
|
49
|
+
@api[version] ||= begin
|
50
|
+
# Build uri path.
|
51
|
+
options = @options.clone.tap do |opts|
|
52
|
+
opts[:url] = URI(opts[:url]).tap { |url| url.path = url_path_for_version(url.path, version) }
|
53
|
+
end
|
54
|
+
|
55
|
+
Api.new(connection(**options), version)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def reset
|
60
|
+
@api = {}
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def url_path_for_version(orig_path, api_version)
|
66
|
+
return orig_path unless orig_path.sub(/\/$/, "").empty?
|
67
|
+
"/api/v#{api_version}"
|
27
68
|
end
|
28
69
|
end
|
29
70
|
end
|
@@ -46,7 +46,8 @@ module AnsibleTowerClient
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def convert_value(key, value, parent)
|
49
|
-
method = key_to_attribute(key)
|
49
|
+
method = key_to_attribute(key).gsub(/\W/, '_') # replace all unqualified characters for method and class names
|
50
|
+
|
50
51
|
new_val =
|
51
52
|
if attr_excluded?(method)
|
52
53
|
value
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ansible_tower_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Dunne
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-06
|
12
|
+
date: 2018-07-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -165,6 +165,7 @@ files:
|
|
165
165
|
- lib/ansible_tower_client/base_models/system_job.rb
|
166
166
|
- lib/ansible_tower_client/base_models/system_job_template.rb
|
167
167
|
- lib/ansible_tower_client/base_models/workflow_job.rb
|
168
|
+
- lib/ansible_tower_client/base_models/workflow_job_node.rb
|
168
169
|
- lib/ansible_tower_client/base_models/workflow_job_template.rb
|
169
170
|
- lib/ansible_tower_client/base_models/workflow_job_template_node.rb
|
170
171
|
- lib/ansible_tower_client/collection.rb
|
@@ -174,6 +175,8 @@ files:
|
|
174
175
|
- lib/ansible_tower_client/logging.rb
|
175
176
|
- lib/ansible_tower_client/middleware/raise_tower_error.rb
|
176
177
|
- lib/ansible_tower_client/null_logger.rb
|
178
|
+
- lib/ansible_tower_client/v2/credential_type_v2.rb
|
179
|
+
- lib/ansible_tower_client/v2/credential_v2.rb
|
177
180
|
- lib/ansible_tower_client/v2/job_template_v2.rb
|
178
181
|
- lib/ansible_tower_client/version.rb
|
179
182
|
homepage: https://github.com/Ansible/ansible_tower_client_ruby
|