2013-08-20 09:29:03 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Rackspace
|
|
|
|
class AutoScale
|
|
|
|
class Webhook < Fog::Model
|
|
|
|
|
2013-09-05 08:10:13 -04:00
|
|
|
# @!attribute [r] id
|
|
|
|
# @return [String] The webhook id
|
|
|
|
identity :id
|
2013-08-20 09:29:03 -04:00
|
|
|
|
2013-09-05 08:10:13 -04:00
|
|
|
# @!attribute [r] id
|
|
|
|
# @return [String] The group id (i.e. grand-parent)
|
2013-08-28 07:49:03 -04:00
|
|
|
attribute :group_id
|
2013-09-05 08:10:13 -04:00
|
|
|
|
|
|
|
# @!attribute [r] id
|
|
|
|
# @return [String] The policy id (i.e. parent)
|
2013-08-28 07:49:03 -04:00
|
|
|
attribute :policy_id
|
|
|
|
|
2013-09-05 08:10:13 -04:00
|
|
|
# @!attribute [r] name
|
|
|
|
# @return [String] The webhook name
|
|
|
|
attribute :name
|
|
|
|
|
|
|
|
# @!attribute [r] metadata
|
2013-09-16 05:34:07 -04:00
|
|
|
# @return [Hash] The metadata
|
2013-09-05 08:10:13 -04:00
|
|
|
attribute :metadata
|
|
|
|
|
|
|
|
# @!attribute [r] links
|
|
|
|
# @return [Array] The webhook links
|
|
|
|
attribute :links
|
2013-08-20 09:29:03 -04:00
|
|
|
|
2013-09-05 08:10:13 -04:00
|
|
|
# Creates webhook
|
|
|
|
# * requires attribute: :name
|
|
|
|
#
|
|
|
|
# @return [Boolean] returns true if webhook is being created
|
|
|
|
#
|
|
|
|
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
|
|
|
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
|
|
|
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
|
|
|
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
|
|
|
#
|
|
|
|
# @see Webhooks#create
|
|
|
|
# @see
|
2013-08-28 07:49:03 -04:00
|
|
|
def save
|
|
|
|
requires :name
|
|
|
|
|
|
|
|
options = {}
|
|
|
|
options['name'] = name unless name.nil?
|
|
|
|
options['metadata'] = metadata unless metadata.nil?
|
|
|
|
|
|
|
|
data = service.create_webhook(group_id, policy_id, options)
|
2013-09-05 08:10:13 -04:00
|
|
|
merge_attributes(data.body['webhooks'][0])
|
2013-08-28 07:49:03 -04:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2013-09-05 08:10:13 -04:00
|
|
|
# Updates the webhook
|
|
|
|
#
|
|
|
|
# @return [Boolean] returns true if webhook has started updating
|
|
|
|
#
|
|
|
|
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
|
|
|
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
|
|
|
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
|
|
|
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
|
|
|
#
|
2013-09-16 05:34:07 -04:00
|
|
|
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/PUT_putWebhook_v1.0__tenantId__groups__groupId__policies__policyId__webhooks__webhookId__Webhooks.html
|
2013-09-05 08:10:13 -04:00
|
|
|
def update
|
2013-08-28 07:49:03 -04:00
|
|
|
requires :identity
|
2013-08-20 09:29:03 -04:00
|
|
|
|
|
|
|
options = {
|
|
|
|
'name' => name,
|
|
|
|
'metadata' => metadata
|
|
|
|
}
|
|
|
|
|
2013-08-28 07:49:03 -04:00
|
|
|
data = service.update_webhook(group_id, policy_id, identity, options)
|
|
|
|
merge_attributes(data.body)
|
2013-08-20 09:29:03 -04:00
|
|
|
end
|
|
|
|
|
2013-09-05 08:10:13 -04:00
|
|
|
# Destroy the webhook
|
|
|
|
#
|
|
|
|
# @return [Boolean] returns true if webhook has started deleting
|
|
|
|
#
|
|
|
|
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
|
|
|
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
|
|
|
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
|
|
|
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
|
|
|
#
|
2013-09-16 05:34:07 -04:00
|
|
|
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/DELETE_deleteWebhook_v1.0__tenantId__groups__groupId__policies__policyId__webhooks__webhookId__Webhooks.html
|
2013-09-05 08:10:13 -04:00
|
|
|
def destroy
|
2013-08-28 07:49:03 -04:00
|
|
|
requires :identity
|
|
|
|
service.delete_webhook(group_id, policy_id, identity)
|
|
|
|
true
|
2013-08-20 09:29:03 -04:00
|
|
|
end
|
|
|
|
|
2013-09-05 08:10:13 -04:00
|
|
|
# Retrieves the URL for anonymously executing the policy webhook
|
|
|
|
# @return [String] the URL
|
2013-08-28 07:49:03 -04:00
|
|
|
def execution_url
|
|
|
|
requires :links
|
2013-09-16 05:34:07 -04:00
|
|
|
link = links.find { |l| l['rel'] == 'capability' }
|
|
|
|
link['href'] rescue nil
|
2013-08-28 07:49:03 -04:00
|
|
|
end
|
|
|
|
|
2013-08-20 09:29:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|