From: Greg Blomquist <gblomqui(a)redhat.com>
Allows an authenticated client to delete the configurations for an entire
deployable.
---
configserver/Rakefile | 3 +-
configserver/aeolus-configserver.spec.in | 4 ++-
configserver/src/configserver.rb | 47 ++++++++++++++++++-----------
configserver/src/lib/config_handler.rb | 6 +++-
configserver/src/lib/model/deployable.rb | 19 +++++++++---
configserver/src/lib/model/instance.rb | 25 ++++++----------
6 files changed, 61 insertions(+), 43 deletions(-)
diff --git a/configserver/Rakefile b/configserver/Rakefile
index add7f8f..e04a5db 100644
--- a/configserver/Rakefile
+++ b/configserver/Rakefile
@@ -24,7 +24,7 @@ require 'rake/clean'
require 'rubygems'
require 'rubygems/package_task'
-version = '0.4.1'
+version = '0.4.2'
man_section = '8'
pkg_name = 'aeolus-configserver'
@@ -159,4 +159,3 @@ end
# Default Build all
desc "Build (S)RPMs for #{pkg_name}"
task :default => [ :rpm ]
-
diff --git a/configserver/aeolus-configserver.spec.in
b/configserver/aeolus-configserver.spec.in
index ee4f76a..df9f52a 100644
--- a/configserver/aeolus-configserver.spec.in
+++ b/configserver/aeolus-configserver.spec.in
@@ -17,7 +17,7 @@
Name: aeolus-configserver
Version: @VERSION@
-Release: 4%{?dist}
+Release: 2%{?dist}
Summary: The Aeolus Config Server
Group: Applications/System
@@ -169,6 +169,8 @@ fi
%doc COPYING
%changelog
+* Tue Nov 29 2011 Greg Blomquist <gblomqui(a)redhat.com> 0.4.2-2
+- Allow deletion of deployment configs
* Tue Nov 29 2011 Joe VLcek <jvlcek(a)redhat.com> 0.4.1-4
- Use install -m in place of cp in spec file
* Mon Nov 28 2011 Joe VLcek <jvlcek(a)redhat.com> 0.4.1-3
diff --git a/configserver/src/configserver.rb b/configserver/src/configserver.rb
index 668cae9..4afa872 100644
--- a/configserver/src/configserver.rb
+++ b/configserver/src/configserver.rb
@@ -38,7 +38,25 @@ error 400 do
"Could not parse the given XML document.\n"
end
+## GET /version
+# Retrieve the Application and API version for this config server
+get '/version', :provides => ['text', 'xml'] do
+ logger.debug("Getting the version as text or XML")
+ "<config-server>\n" +
+ " <application-version>#{app_version}</application-version>\n"
+
+ " <api-version>#{api_version}</api-version>\n" +
+ "</config-server>"
+end
+
+get '/version' do
+ logger.debug("Getting the version as HTML")
+ "<html><body>\n" +
+ "<li>Application Version: #{app_version}</li>\n" +
+ "<li>API Version: #{api_version}<li/>\n" +
+ "</body></html>"
+end
+# OAuth protected URLs
before '/configs/*' do
authenticate!
end
@@ -52,29 +70,15 @@ before '/auth*' do
authenticate!
end
+# Test OAuth
get '/auth' do
logger.debug("Client is testing auth credentials")
"Authentication test successful"
end
-## GET /version
-# Retrieve the Application and API version for this config server
-get '/version', :provides => ['text', 'xml'] do
- logger.debug("Getting the version as text or XML")
- "<config-server>\n" +
- " <application-version>#{app_version}</application-version>\n"
+
- " <api-version>#{api_version}</api-version>\n" +
- "</config-server>"
-end
-
-get '/version' do
- logger.debug("Getting the version as HTML")
- "<html><body>\n" +
- "<li>Application Version: #{app_version}</li>\n" +
- "<li>API Version: #{api_version}<li/>\n" +
- "</body></html>"
-end
-
+#
+# API Methods
+#
## GET /ip/
# Retrieve the IP address for an instance that has reported its IP
@@ -143,6 +147,13 @@ delete '/configs/:version/:uuid' do
configs.delete(params[:uuid])
end
+## DELETE /deployment/
+# Permanently delete the configuration data for an entire deployment
+# - delete all instance configurations under that deployment
+delete '/deployment/:version/:uuid' do
+ configs.delete_deployment(params[:uuid])
+end
+
## GET /files/
# Retrieve the configuration files for an instance
get '/files/:version/:uuid' do
diff --git a/configserver/src/lib/config_handler.rb
b/configserver/src/lib/config_handler.rb
index fa249d7..c1c5c09 100644
--- a/configserver/src/lib/config_handler.rb
+++ b/configserver/src/lib/config_handler.rb
@@ -116,7 +116,7 @@ module ConfigServer
else
""
end
- return configs, instance.required_parameters_remaining?
+ return configs, instance.required_parameters_remaining?
end
end
@@ -137,6 +137,10 @@ module ConfigServer
Model::Instance.find(uuid).delete! if exists?(uuid)
end
+ def delete_deployment(uuid)
+ Model::Deployable.find(uuid).delete!
+ end
+
def create(uuid, data)
xml = Model::Instance.validate(uuid, data)
instance = Model::Instance.new(uuid, xml)
diff --git a/configserver/src/lib/model/deployable.rb
b/configserver/src/lib/model/deployable.rb
index dadc669..7a92f26 100644
--- a/configserver/src/lib/model/deployable.rb
+++ b/configserver/src/lib/model/deployable.rb
@@ -27,12 +27,13 @@ module ConfigServer
Deployable.new(uuid) if exists?(uuid)
end
- def self.storage_path
- super "deployables"
+ def self.storage_path(uuid=nil)
+ path = uuid ? File.join("deployables", uuid) : "deployables"
+ super path
end
def self.exists?(uuid)
- File.exists?(File.join(storage_path, uuid))
+ File.exists?(storage_path uuid)
end
@uuid = nil
@@ -50,7 +51,7 @@ module ConfigServer
def add_instance(uuid)
# never actually hold the state of the list of instances
# always pick up the list from the filesystem
- instance_dir = File.join(Instance.storage_path, uuid)
+ instance_dir = Instance.storage_path uuid
if File.directory?(instance_dir)
FileUtils.ln_s(instance_dir, File.join((a)deployable_dir.path, uuid))
end
@@ -63,6 +64,14 @@ module ConfigServer
instance_uuids
end
+ def delete!
+ instance_uuids.each do |instance_uuid|
+ Instance.delete! instance_uuid
+ remove_instance instance_uuid
+ end
+ FileUtils.rm_rf((a)deployable_dir.path)
+ end
+
def instance_uuids
@deployable_dir.entries - EXCLUDED_DIRS
end
@@ -83,7 +92,7 @@ module ConfigServer
private
def ensure_deployable_dir
- path = File.join(Deployable.storage_path, @uuid)
+ path = Deployable.storage_path @uuid
FileUtils.mkdir_p(path, :mode => 0700) if not File.directory?(path)
Dir.new(path)
end
diff --git a/configserver/src/lib/model/instance.rb
b/configserver/src/lib/model/instance.rb
index e5591c3..3730e0a 100644
--- a/configserver/src/lib/model/instance.rb
+++ b/configserver/src/lib/model/instance.rb
@@ -95,17 +95,22 @@ module ConfigServer
attr_reader :instance_config, :ip, :secret, :uuid
def self.exists?(uuid)
- File.exist?(File.join(storage_path, uuid))
+ File.exist?(storage_path uuid)
end
- def self.storage_path
- super "instances"
+ def self.storage_path(uuid=nil)
+ path = uuid ? File.join("instances", uuid) : "instances"
+ super path
end
def self.find(uuid)
Instance.new(uuid) if exists?(uuid)
end
+ def self.delete!(uuid)
+ FileUtils.rm_rf(storage_path uuid)
+ end
+
def self.get_validator
validator_schema = ConfigServer::Model.instance_config_schema_location
begin
@@ -152,7 +157,7 @@ module ConfigServer
Instance.ensure_storage_path
@uuid = uuid
- @instance_dir = File.join(Instance.storage_path, uuid)
+ @instance_dir = Instance.storage_path uuid
ensure_instance_dir
if configs.nil?
@@ -163,18 +168,6 @@ module ConfigServer
self
end
- def delete!
- FileUtils.rm_rf(@instance_dir)
- @uuid = nil
- @ip = nil
- @instance_dir = nil
- @instance_config = nil
- @provided_parameters = nil
- @required_parameters = nil
- @deployable = nil
- @assembly_name = nil
- end
-
def deployable
@deployable ||= Deployable.new(deployable_id)
end
--
1.7.4.4