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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86a18d8f7863faba1111ec0be11334fdaee96f1e
4
- data.tar.gz: a0fb3db7bfb6cd83a6726cab8c76836105c1a2f3
3
+ metadata.gz: 0d07c93de33e2d4030e213e4fbddb7c8f302a7e6
4
+ data.tar.gz: 48b627c92d4ce8fc4aa06e3bdfd95ca6786d7962
5
5
  SHA512:
6
- metadata.gz: 2f02ac1ff450afa55d3ea6f99209ed699f8037f19cec9eeb57832ef609c1905d0c97d2b8c78880b494a1e6249d5523902fe681b3ee6dfecb43a392ac8e13c68d
7
- data.tar.gz: a32e851b0b97792c3905528584aa27696ee1b8f0f7c5469935e807694705dc069721481bbb57a687658e1743bae21e16f8b6e565c089502ef1e6d27e2388c613
6
+ metadata.gz: d168c39fefdd4640ce3f17fb868280676a855a3704bcaf83e460c1bee27f44570c1c5ccc87c285d7ab5cebaa80e3b615caac12275e3118b25412d094ff530b46
7
+ data.tar.gz: a070d079a997df26b3bacfb0668cb43497e77d1243d584669edc1cdcd31f9cc46068a5425ac966c68bb460ef46f7e67dcf61b187a0f3788f37764f03cba4b35b
@@ -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
 
@@ -33,6 +33,10 @@ module AnsibleTowerClient
33
33
  super(raw_hash)
34
34
  end
35
35
 
36
+ def hashify(attribute)
37
+ YAML.safe_load(send(attribute))
38
+ end
39
+
36
40
  private
37
41
 
38
42
  # convert a hash to an instance of nested model class
@@ -24,7 +24,6 @@ module AnsibleTowerClient
24
24
 
25
25
  def find(id)
26
26
  raw_body = JSON.parse(api.get("#{klass.endpoint}/#{id}/").body)
27
- raise ResourceNotFound.new(self, :id => id) if raw_body['id'].nil?
28
27
  klass.new(api, raw_body)
29
28
  end
30
29
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module AnsibleTowerClient
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  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.1.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-03-18 00:00:00.000000000 Z
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
@@ -1,15 +0,0 @@
1
- module AnsibleTowerClient
2
- class JSONValues
3
- include ValidJSON
4
-
5
- def initialize(vars)
6
- raise InvalidHash.new(vars) unless vars.kind_of?(Hash)
7
- @vars = vars
8
- end
9
-
10
- def extra_vars
11
- validate(@vars['extra_vars'])
12
- end
13
-
14
- end
15
- end
@@ -1,12 +0,0 @@
1
- module AnsibleTowerClient
2
- module ValidJSON
3
- def validate(text)
4
- begin
5
- JSON.parse(text)
6
- rescue JSON::ParserError => e
7
- raise InvalidJson.new(e)
8
- end
9
- end
10
- end
11
- end
12
-