Skip to content

Commit

Permalink
API extension points for plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
stbenjam committed Feb 10, 2015
1 parent c1a73b1 commit ffc9009
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/controllers/api/v2/hostgroups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def show
param :domain_id, :number
param :realm_id, :number
param :puppet_proxy_id, :number
Hostgroup.extended_attributes.each do |attribute|
param attribute[:name], attribute[:type], attribute[:options]
end
param_group :taxonomies, ::Api::V2::BaseController
end
end
Expand Down Expand Up @@ -93,7 +96,6 @@ def action_permission
def allowed_nested_id
%w(puppetclass_id location_id organization_id)
end

end
end
end
3 changes: 3 additions & 0 deletions app/controllers/api/v2/hosts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def show
param :comment, String, :desc => N_("Additional information about this host")
param :capabilities, String
param :compute_profile_id, :number
Host::Managed.extended_attributes.each do |attribute|
param attribute[:name], attribute[:type], attribute[:options]
end
param :compute_attributes, Hash do
end
end
Expand Down
18 changes: 18 additions & 0 deletions app/models/concerns/api_extensions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module ApiExtensions
extend ActiveSupport::Concern

module ClassMethods
def add_attribute(attribute, type, options = {})
@extended_attributes ||= []
@extended_attributes << {:name => attribute, :type => type, :options => options}
end

def extended_attributes
@extended_attributes || []
end

def extended_rabl_attributes
@extended_attributes.map { |attr| attr[:name] }
end
end
end
1 change: 1 addition & 0 deletions app/models/host/managed.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Host::Managed < Host::Base
include ReportCommon
include ApiExtensions
include Hostext::Search
PROVISION_METHODS = %w[build image]

Expand Down
1 change: 1 addition & 0 deletions app/models/hostgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Hostgroup < ActiveRecord::Base
extend FriendlyId
friendly_id :title
include Taxonomix
include ApiExtensions
include HostCommon
include NestedAncestryCommon
include ScopedSearchExtensions
Expand Down
2 changes: 2 additions & 0 deletions app/views/api/v2/hostgroups/main.json.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ attributes :subnet_id, :subnet_name, :operatingsystem_id, :operatingsystem_name,
:environment_id, :environment_name, :compute_profile_id, :compute_profile_name, :ancestry,
:puppet_proxy_id, :puppet_ca_proxy_id, :ptable_id, :ptable_name, :medium_id, :medium_name,
:architecture_id, :architecture_name, :realm_id, :realm_name, :created_at, :updated_at

attributes *Hostgroup.extended_rabl_attributes
2 changes: 2 additions & 0 deletions app/views/api/v2/hosts/main.json.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ attributes :ip, :environment_id, :environment_name, :last_report, :mac, :realm_i
:puppet_proxy_id, :certname, :image_id, :image_name, :created_at, :updated_at,
:last_compile, :last_freshcheck, :serial, :source_file_id, :puppet_status

attributes *Host.extended_rabl_attributes

if SETTINGS[:organizations_enabled]
attributes :organization_id, :organization_name
end
Expand Down

0 comments on commit ffc9009

Please sign in to comment.