Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
v2 api support
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderZagaynov committed Feb 9, 2019
1 parent f61c8cf commit 28c32a3
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/ansible_tower_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require "ansible_tower_client/base_models/activity_stream"
require "ansible_tower_client/base_models/ad_hoc_command"
require "ansible_tower_client/base_models/credential"
require "ansible_tower_client/base_models/credential_type"
require "ansible_tower_client/base_models/group"
require "ansible_tower_client/base_models/host"
require "ansible_tower_client/base_models/inventory"
Expand Down
4 changes: 4 additions & 0 deletions lib/ansible_tower_client/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def credentials
Collection.new(self, credential_class)
end

def credential_types
Collection.new(self, AnsibleTowerClient::CredentialType)
end

def groups
Collection.new(self, group_class)
end
Expand Down
38 changes: 37 additions & 1 deletion lib/ansible_tower_client/base_models/credential.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,43 @@
module AnsibleTowerClient
class Credential < BaseModel
def override_raw_attributes
{ :organization => :organization_id }
{
:organization => :organization_id,
:credential_type => :credential_type_id,
}
end

# https://github.com/ansible/awx/blob/1328fb80a02ef4e37bc021eb07d4be041a41f937/awx/main/models/credential/__init__.py#L76-L90
KIND_CHOICES = {
'ssh' => 'Machine',
'net' => 'Network',
'scm' => 'Source Control',
'aws' => 'Amazon Web Services',
'vmware' => 'VMware vCenter',
'satellite6' => 'Red Hat Satellite 6',
'cloudforms' => 'Red Hat CloudForms',
'gce' => 'Google Compute Engine',
'azure_rm' => 'Microsoft Azure Resource Manager',
'openstack' => 'OpenStack',
'rhv' => 'Red Hat Virtualization',
'insights' => 'Insights',
'tower' => 'Ansible Tower',
}.invert.freeze

# https://github.com/ansible/awx/blob/1328fb80a02ef4e37bc021eb07d4be041a41f937/awx/main/models/credential/__init__.py#L301
def kind
@data['kind'] ||= begin
kind = credential_type.kind
kind == 'cloud' && KIND_CHOICES[credential_type.name] || kind
end.to_s
end

def credential_type
@credential_type ||= api.credential_types.find(credential_type_id)
end

def vault_password
@data['vault_password'] ||= inputs.vault_password.to_s
end
end
end
4 changes: 4 additions & 0 deletions lib/ansible_tower_client/base_models/credential_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module AnsibleTowerClient
class CredentialType < BaseModel
end
end
15 changes: 13 additions & 2 deletions lib/ansible_tower_client/base_models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,19 @@ def update
end

def last_update
return if related['last_update'].blank?
api.project_updates.find(related['last_update'])
return @last_update if defined? @last_update
return @last_update = nil unless related.raw_hash.key?('last_update')
return @last_update = nil if (update_id = related.last_update).blank?

unless update_id.is_a?(Numeric) || update_id =~ /\A\d+\z/
if raw_hash.key?('summary_fields') && summary_fields.raw_hash.key?('last_update')
update_id = summary_fields.last_update.id
else
/\/(?'update_id'\d+)\/?\z/ =~ update_id
end
end

@last_update = update_id.blank? ? nil : api.project_updates.find(update_id)
end
end
end
7 changes: 6 additions & 1 deletion lib/ansible_tower_client/middleware/raise_tower_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ def on_complete(env)
end

def response_values(env)
{:status => env.status, :headers => env.response_headers, :body => env.body}
{
:headers => env.response_headers,
:status => env.status,
:body => env.body,
:url => env.url,
}
end
end
end
Expand Down

0 comments on commit 28c32a3

Please sign in to comment.