2013-08-20 09:29:03 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Rackspace
|
|
|
|
class AutoScale
|
|
|
|
class Webhook < Fog::Model
|
|
|
|
|
2013-09-30 17:14:32 -04:00
|
|
|
# @!attribute [r] id
|
2013-09-05 08:10:13 -04:00
|
|
|
# @return [String] The webhook id
|
|
|
|
identity :id
|
2013-08-20 09:29:03 -04:00
|
|
|
|
2013-10-02 09:57:02 -04:00
|
|
|
# @!attribute [r] group
|
|
|
|
# @return [String] The associated group
|
|
|
|
attribute :group
|
2013-09-05 08:10:13 -04:00
|
|
|
|
2013-10-02 09:57:02 -04:00
|
|
|
# @!attribute [r] policy
|
|
|
|
# @return [String] The associated policy
|
|
|
|
attribute :policy
|
2013-08-28 07:49:03 -04:00
|
|
|
|
2013-09-30 17:14:32 -04:00
|
|
|
# @!attribute [r] name
|
2013-09-05 08:10:13 -04:00
|
|
|
# @return [String] The webhook name
|
|
|
|
attribute :name
|
2013-09-30 17:14:32 -04:00
|
|
|
|
2013-09-05 08:10:13 -04:00
|
|
|
# @!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
|
2013-09-30 17:14:32 -04:00
|
|
|
|
2013-09-05 08:10:13 -04:00
|
|
|
# @!attribute [r] links
|
|
|
|
# @return [Array] The webhook links
|
|
|
|
attribute :links
|
2013-08-20 09:29:03 -04:00
|
|
|
|
2013-09-30 17:14:32 -04:00
|
|
|
# Create webhook
|
2013-09-05 08:10:13 -04:00
|
|
|
# * 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-09-30 17:14:32 -04:00
|
|
|
def create
|
2013-08-28 07:49:03 -04:00
|
|
|
requires :name
|
|
|
|
|
|
|
|
options = {}
|
2013-09-26 09:54:43 -04:00
|
|
|
options['name'] = name if name
|
|
|
|
options['metadata'] = metadata if metadata
|
2013-08-28 07:49:03 -04:00
|
|
|
|
2013-10-02 09:57:02 -04:00
|
|
|
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-30 17:14:32 -04:00
|
|
|
# Updates the webhook
|
2013-09-05 08:10:13 -04:00
|
|
|
#
|
|
|
|
# @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-09-30 17:14:32 -04:00
|
|
|
requires :identity
|
|
|
|
|
|
|
|
options = {
|
|
|
|
'name' => name,
|
|
|
|
'metadata' => metadata
|
|
|
|
}
|
2013-08-20 09:29:03 -04:00
|
|
|
|
2013-10-02 09:57:02 -04:00
|
|
|
data = service.update_webhook(group.id, policy.id, identity, options)
|
2013-09-30 17:14:32 -04:00
|
|
|
merge_attributes(data.body)
|
2013-10-02 09:57:02 -04:00
|
|
|
true
|
2013-09-30 17:14:32 -04:00
|
|
|
end
|
2013-08-20 09:29:03 -04:00
|
|
|
|
2013-09-30 17:14:32 -04:00
|
|
|
# Saves the webhook
|
|
|
|
# Creates hook if it is new, otherwise it will update it
|
|
|
|
# @return [Boolean] true if policy has saved
|
|
|
|
def save
|
|
|
|
if persisted?
|
|
|
|
update
|
|
|
|
else
|
|
|
|
create
|
|
|
|
end
|
|
|
|
true
|
|
|
|
end
|
2013-08-20 09:29:03 -04:00
|
|
|
|
2013-09-30 17:14:32 -04:00
|
|
|
# Destroy the webhook
|
2013-09-05 08:10:13 -04:00
|
|
|
#
|
|
|
|
# @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-09-30 17:14:32 -04:00
|
|
|
requires :identity
|
2013-10-02 09:57:02 -04:00
|
|
|
service.delete_webhook(group.id, policy.id, identity)
|
2013-08-28 07:49:03 -04:00
|
|
|
true
|
2013-09-30 17:14:32 -04:00
|
|
|
end
|
2013-08-20 09:29:03 -04:00
|
|
|
|
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
|
2013-09-30 17:14:32 -04:00
|
|
|
end
|
2013-08-20 09:29:03 -04:00
|
|
|
end
|
|
|
|
end
|