ansible_tower_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 +4 -4
- data/lib/ansible_tower_client.rb +1 -3
- data/lib/ansible_tower_client/base_model.rb +4 -0
- data/lib/ansible_tower_client/collection.rb +0 -1
- data/lib/ansible_tower_client/connection.rb +3 -0
- data/lib/ansible_tower_client/job_template.rb +9 -1
- data/lib/ansible_tower_client/middleware/raise_tower_error.rb +23 -0
- data/lib/ansible_tower_client/version.rb +1 -1
- metadata +3 -5
- data/lib/ansible_tower_client/error.rb +0 -39
- data/lib/ansible_tower_client/json_values.rb +0 -15
- data/lib/ansible_tower_client/valid_json.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d07c93de33e2d4030e213e4fbddb7c8f302a7e6
|
4
|
+
data.tar.gz: 48b627c92d4ce8fc4aa06e3bdfd95ca6786d7962
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d168c39fefdd4640ce3f17fb868280676a855a3704bcaf83e460c1bee27f44570c1c5ccc87c285d7ab5cebaa80e3b615caac12275e3118b25412d094ff530b46
|
7
|
+
data.tar.gz: a070d079a997df26b3bacfb0668cb43497e77d1243d584669edc1cdcd31f9cc46068a5425ac966c68bb460ef46f7e67dcf61b187a0f3788f37764f03cba4b35b
|
data/lib/ansible_tower_client.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
require "ansible_tower_client/error"
|
2
1
|
require "json"
|
2
|
+
require "yaml"
|
3
3
|
require "ansible_tower_client/logging"
|
4
4
|
require "ansible_tower_client/null_logger"
|
5
|
-
require "ansible_tower_client/valid_json"
|
6
5
|
require "ansible_tower_client/version"
|
7
6
|
|
8
7
|
require "ansible_tower_client/connection"
|
@@ -17,7 +16,6 @@ require "ansible_tower_client/host"
|
|
17
16
|
require "ansible_tower_client/inventory"
|
18
17
|
require "ansible_tower_client/job"
|
19
18
|
require "ansible_tower_client/job_template"
|
20
|
-
require "ansible_tower_client/json_values"
|
21
19
|
require "more_core_extensions/all"
|
22
20
|
require "active_support/inflector"
|
23
21
|
|
@@ -10,9 +10,12 @@ module AnsibleTowerClient
|
|
10
10
|
|
11
11
|
require 'faraday'
|
12
12
|
require 'faraday_middleware'
|
13
|
+
require 'ansible_tower_client/middleware/raise_tower_error'
|
14
|
+
Faraday::Response.register_middleware :raise_tower_error => -> { Middleware::RaiseTowerError }
|
13
15
|
@connection = Faraday.new(options[:base_url], :ssl => {:verify => verify_ssl}) do |f|
|
14
16
|
f.use FaradayMiddleware::FollowRedirects, :limit => 3, :standards_compliant => true
|
15
17
|
f.request(:url_encoded)
|
18
|
+
f.response(:raise_tower_error)
|
16
19
|
f.adapter(Faraday.default_adapter)
|
17
20
|
f.basic_auth(options[:username], options[:password])
|
18
21
|
end
|
@@ -3,7 +3,7 @@ module AnsibleTowerClient
|
|
3
3
|
def launch(options = {})
|
4
4
|
launch_url = "#{url}launch/"
|
5
5
|
options = options.dup
|
6
|
-
new_limit = options.delete('limit')
|
6
|
+
new_limit = options.delete(:limit) || options.delete('limit')
|
7
7
|
response = with_temporary_changes(new_limit) do
|
8
8
|
api.post(launch_url, options).body
|
9
9
|
end
|
@@ -18,6 +18,14 @@ module AnsibleTowerClient
|
|
18
18
|
api.get(spec_url).body
|
19
19
|
end
|
20
20
|
|
21
|
+
def survey_spec_hash
|
22
|
+
survey_spec.nil? ? {} : hashify(:survey_spec)
|
23
|
+
end
|
24
|
+
|
25
|
+
def extra_vars_hash
|
26
|
+
extra_vars.empty? ? {} : hashify(:extra_vars)
|
27
|
+
end
|
28
|
+
|
21
29
|
def self.endpoint
|
22
30
|
"job_templates".freeze
|
23
31
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module AnsibleTowerClient
|
2
|
+
module Middleware
|
3
|
+
class RaiseTowerError < Faraday::Response::Middleware
|
4
|
+
CLIENT_ERROR_STATUSES = 400...600
|
5
|
+
|
6
|
+
def on_complete(env)
|
7
|
+
case env[:status]
|
8
|
+
when 404
|
9
|
+
raise Faraday::Error::ResourceNotFound, response_values(env)
|
10
|
+
when 407
|
11
|
+
# mimic the behavior that we get with proxy requests with HTTPS
|
12
|
+
raise Faraday::Error::ConnectionFailed, %(407 "Proxy Authentication Required ")
|
13
|
+
when CLIENT_ERROR_STATUSES
|
14
|
+
raise Faraday::Error::ClientError, env.body
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def response_values(env)
|
19
|
+
{:status => env.status, :headers => env.response_headers, :body => env.body}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
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.2.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: 2016-
|
12
|
+
date: 2016-04-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -161,17 +161,15 @@ files:
|
|
161
161
|
- lib/ansible_tower_client/base_model.rb
|
162
162
|
- lib/ansible_tower_client/collection.rb
|
163
163
|
- lib/ansible_tower_client/connection.rb
|
164
|
-
- lib/ansible_tower_client/error.rb
|
165
164
|
- lib/ansible_tower_client/group.rb
|
166
165
|
- lib/ansible_tower_client/hash_model.rb
|
167
166
|
- lib/ansible_tower_client/host.rb
|
168
167
|
- lib/ansible_tower_client/inventory.rb
|
169
168
|
- lib/ansible_tower_client/job.rb
|
170
169
|
- lib/ansible_tower_client/job_template.rb
|
171
|
-
- lib/ansible_tower_client/json_values.rb
|
172
170
|
- lib/ansible_tower_client/logging.rb
|
171
|
+
- lib/ansible_tower_client/middleware/raise_tower_error.rb
|
173
172
|
- lib/ansible_tower_client/null_logger.rb
|
174
|
-
- lib/ansible_tower_client/valid_json.rb
|
175
173
|
- lib/ansible_tower_client/version.rb
|
176
174
|
homepage: https://github.com/ManageIQ/ansible_tower_client
|
177
175
|
licenses:
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
|
3
|
-
module AnsibleTowerClient
|
4
|
-
class ResourceNotFound < Faraday::ResourceNotFound
|
5
|
-
def initialize(klass, attrs = {})
|
6
|
-
@klass = klass
|
7
|
-
@attrs = attrs
|
8
|
-
@key = attrs.keys.first
|
9
|
-
@value = attrs[@key]
|
10
|
-
super(issue_error)
|
11
|
-
end
|
12
|
-
|
13
|
-
def issue_error
|
14
|
-
method = @key.nil? ? 'general' : @key
|
15
|
-
send("#{method}_msg")
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def id_msg
|
21
|
-
"Couldn't find #{@klass} with '#{@key}'=#{@value}"
|
22
|
-
end
|
23
|
-
|
24
|
-
def general_msg
|
25
|
-
"Couldn't find #{@klass}"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class Error < StandardError
|
30
|
-
attr_reader :message
|
31
|
-
def initialize(klass)
|
32
|
-
@message = "Error on #{klass.class.name}: #{klass.inspect}"
|
33
|
-
super(message)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class InvalidHash < Error; end
|
38
|
-
class InvalidJson < Error; end
|
39
|
-
end
|