ref: refs/heads/master
commit 74c95aa98b5b072c3c6fd66c52039a7fc9497e0d
Author: J. Daniel Schmidt
Date: Thu Oct 15 22:28:41 2009 +0200
registration: cleanup views, render registration result in xml (currently static output)
add context data and user arguments to registration process
---
.../app/controllers/configuration_controller.rb | 56 +++++++-------
.../app/controllers/registration_controller.rb | 42 +++++++++-
plugins/registration/app/models/registration.rb | 83 ++++++++++++++++----
.../app/views/registration/create.html.erb | 12 +---
.../app/views/registration/create.json.erb | 1 +
.../app/views/registration/create.xml.erb | 12 +---
6 files changed, 136 insertions(+), 70 deletions(-)
diff --git a/plugins/registration/app/controllers/configuration_controller.rb b/plugins/registration/app/controllers/configuration_controller.rb
index c692581..5f4f50d 100644
--- a/plugins/registration/app/controllers/configuration_controller.rb
+++ b/plugins/registration/app/controllers/configuration_controller.rb
@@ -6,36 +6,34 @@ class ConfigurationController < ApplicationController
before_filter :login_required
def update
-# FIXME remove static certificate file after testing!!
-newca="-----BEGIN CERTIFICATE-----
-MIID5TCCAs2gAwIBAgIEOeSXnjANBgkqhkiG9w0BAQUFADCBgjELMAkGA1UEBhMC
-VVMxFDASBgNVBAoTC1dlbGxzIEZhcmdvMSwwKgYDVQQLEyNXZWxscyBGYXJnbyBD
-ZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTEvMC0GA1UEAxMmV2VsbHMgRmFyZ28gUm9v
-dCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMDAxMDExMTY0MTI4WhcNMjEwMTE0
-MTY0MTI4WjCBgjELMAkGA1UEBhMCVVMxFDASBgNVBAoTC1dlbGxzIEZhcmdvMSww
-KgYDVQQLEyNXZWxscyBGYXJnbyBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTEvMC0G
-A1UEAxMmV2VsbHMgRmFyZ28gUm9vdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwggEi
-MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDVqDM7Jvk0/82bfuUER84A4n13
-5zHCLielTWi5MbqNQ1mXx3Oqfz1cQJ4F5aHiidlMuD+b+Qy0yGIZLEWukR5zcUHE
-SxP9cMIlrCL1dQu3U+SlK93OvRw6esP3E48mVJwWa2uv+9iWsWCaSOAlIiR5NM4O
-JgALTqv9i86C1y8IcGjBqAr5dE8Hq6T54oN+J3N0Prj5OEL8pahbSCOz6+MlsoCu
-ltQKnMJ4msZoGK43YjdeUXWoWGPAUe5AeH6orxqg4bB4nVCMe+ez/I4jsNtlAHCE
-AQgAFG5Uhpq6zPk3EPbg3oQtnaSFN9OH4xXQwReQfhkhahKpdv0SAulPIV4XAgMB
-AAGjYTBfMA8GA1UdEwEB/wQFMAMBAf8wTAYDVR0gBEUwQzBBBgtghkgBhvt7hwcB
-CzAyMDAGCCsGAQUFBwIBFiRodHRwOi8vd3d3LndlbGxzZmFyZ28uY29tL2NlcnRw
-b2xpY3kwDQYJKoZIhvcNAQEFBQADggEBANIn3ZwKdyu7IvICtUpKkfnRLb7kuxpo
-7w6kAOnu5+/u9vnldKTC2FJYxHT7zmu1Oyl5GFrvm+0fazbuSCUlFLZWohDo7qd/
-0D+j0MNdJu4HzMPBJCGHHt8qElNvQRbn7a6U+oxy+hNH8Dx+rn0ROhPs7fpvcmR7
-nX1/Jv16+yWt6j4pf0zjAFcysLPp7VMX2YuyFA4w6OXVE8Zkr8QA1dhYJPz1j+zx
-x32l2w8n0cbyQIjmH/ZhqPRCyLk306m+LFZ4wnKbWV01QIroTmMatukgalHizqSQ
-33ZwmVxwQ023tqcZZE6St8WRPH9IFmV7Fv3L/PvZ1dZPIWU7Sn9Ho/s=
------END CERTIFICATE-----
-"
-
- # PUT
- puts params.inspect
+ #request.env.each do |k,v | puts "==#{k}== => ==#{v.inspect}==" end
+
+ if request.env["rack.input"].size>0
+ req = Hash.from_xml request.env["rack.input"].read
+ else
+ req = Hash.new
+ end
+
+ newurl = ''
+ newca = ''
+
+ # read registration server url
+ if req['registrationconfig'] &&
+ req['registrationconfig']['server'] &&
+ req['registrationconfig']['server']['url']
+ newurl = req['registrationconfig']['server']['url'].strip
+ end
+
+ # read ca certificate file
+ if req['registrationconfig'] &&
+ req['registrationconfig']['certificate'] &&
+ req['registrationconfig']['certificate']['data']
+ newca = req['registrationconfig']['certificate']['data'].strip + "\n"
+
+ end
+
@registration = Registration.new( { } )
- @registration.set_config 'https://static.test.server/test/path', newca
+ @registration.set_config newurl, newca
render :show
end
diff --git a/plugins/registration/app/controllers/registration_controller.rb b/plugins/registration/app/controllers/registration_controller.rb
index 7ce1c05..78ea36a 100644
--- a/plugins/registration/app/controllers/registration_controller.rb
+++ b/plugins/registration/app/controllers/registration_controller.rb
@@ -9,14 +9,50 @@ class RegistrationController < ApplicationController
# POST to registration => run registration
@registration = Registration.new({})
- # TODO overwrite context data if defined
- #@registration.set_context( { } )
+ begin
+ if request.env["rack.input"].size>0
+ req = Hash.from_xml request.env["rack.input"].read
+ else
+ req = Hash.new
+ end
+ rescue
+ req = Hash.new
+ end
+
+
+
+ valid_context_keys = %w[forcereg nooptional nohwdata yastcall norefresh logfile]
+ context = Hash.new
+
+ #puts req.inspect
+
+ if req['registration'] &&
+ req['registration']['options'] &&
+ req['registration']['options'].is_a?(Hash)
+ req['registration']['options'].each do |k, v|
+ case k
+ when 'debug'
+ context['debugMode'] = v
+ when 'restorerepos'
+ context['restoreRepos'] = v
+ else
+ context[k] = v if valid_context_keys.include? k
+ end
+ end
+ end
+
+ puts context.inspect
+
+ # overwrite context data
+ @registration.set_context( context )
# TODO: parse post data and set the arguments
# @registration.set_arguments( { } )
ret = @registration.register
- headers["Status"] = "400 Bad Request" if ret == 3
+ #if (ret != 0)
+ # headers["Status"] = "400 Bad Request"
+ #end
end
def show
diff --git a/plugins/registration/app/models/registration.rb b/plugins/registration/app/models/registration.rb
index a0d41fe..0516163 100644
--- a/plugins/registration/app/models/registration.rb
+++ b/plugins/registration/app/models/registration.rb
@@ -14,7 +14,12 @@ class Registration
def initialize(hash)
# cleanup arguments
- @arguments = { 'test' => [ 'a{ss}', { 'value' => 'mytestvalue' } ] }
+ @arguments = { }
+ # initialize context
+ init_context hash
+ end
+
+ def init_context(hash)
# set context defaults
@context = { 'yastcall' => [ 'i', 1 ],
'norefresh' => [ 'i', 1 ],
@@ -30,11 +35,10 @@ class Registration
# merge custom context data
raise "Invalid or missing registration initialization context data." unless hash.is_a?(Hash)
-
+
hash.each do |k, v|
- @context.merge!( { k => ['s', v.to_s] } )
+ @context.merge!( { k.to_s => ['s', v.to_s] } )
end
-
end
def find
@@ -48,11 +52,11 @@ class Registration
end
def set_context(hash)
- self.initialize hash
+ self.init_context hash
end
def add_argument(key, value)
- @arguments.merge!( { key => [ 'a{ss}',{ 'value' => "#{value.to_s}" } ] } )
+ @arguments.merge!( { key.to_s => [ 'a{ss}',{ 'value' => value.to_s } ] } )
end
def add_arguments(hash)
@@ -113,23 +117,70 @@ class Registration
def to_xml( options = {} )
- # TODO FIXME ... create the registration xml structure
+ # TODO FIXME ... create the output based on parsed data
+ # return static response during development
+
xml = options[:builder] ||= Builder::XmlMarkup.new(options)
xml.instruct! unless options[:skip_instruct]
xml.registration do
- xml.tag!(:info, "infotest")
- xml.tag!(:foobar, "foobartest" )
- xml.arguments({:type => "array"}) do
- { "eins" => 1, "zwei" => 2, "drei" => 3 }.each do |k,v|
+ if @reg then
+ xml.tag!(:status, 'missinginfo')
+ xml.tag!(:exitcode, 55)
+ xml.tag!(:guid, "abcdefg1234567")
+
+
+ xml.missingarguments do
xml.argument do
- xml.tag!( :name, k)
- xml.tag!( :value, v)
+ xml.tag!(:name, 'regcode-SLES-13-SP5')
+ xml.tag!(:type, 'string')
+ end
+ xml.argument do
+ xml.tag!(:name, 'email')
+ xml.tag!(:type, 'string')
+ end
+ xml.argument do
+ xml.tag!(:name, 'moniker')
+ xml.tag!(:type, 'string')
end
end
- end
- end
- end
+
+ xml.changedrepos do
+ xml.repo do
+ xml.tag!(:name, 'foobar11n')
+ xml.tag!(:alias, 'foobar11a')
+ xml.tag!(:status, 'added')
+ end
+ xml.repo do
+ xml.tag!(:name, 'foobar22n')
+ xml.tag!(:alias, 'foobar22a')
+ xml.tag!(:status, 'deleted')
+ end
+ end
+
+ xml.changedservices do
+ xml.service do
+ xml.tag!(:name, 'foobar33n')
+ xml.tag!(:alias, 'foobar33a')
+ xml.tag!(:status, 'deleted')
+ xml.catalogs do
+ xml.catalog do
+ xml.tag!(:name, 'foobar44n')
+ xml.tag!(:alias, 'foobar44a')
+ xml.tag!(:status, 'enabled')
+ end
+ xml.catalog do
+ xml.tag!(:name, 'foobar55n')
+ xml.tag!(:alias, 'foobar55a')
+ xml.tag!(:status, 'disabled')
+ end # cat
+ end # cats
+ end # service
+ end # changedservices
+
+ end # if reg
+ end # xml-root
+ end # func
def status_to_json( options = {} )
hash = Hash.from_xml(status_to_xml())
diff --git a/plugins/registration/app/views/registration/create.html.erb b/plugins/registration/app/views/registration/create.html.erb
index 6ed6334..b02fb3c 100644
--- a/plugins/registration/app/views/registration/create.html.erb
+++ b/plugins/registration/app/views/registration/create.html.erb
@@ -1,11 +1 @@
-<%= # @registration == nil ? "@registration is nil - FIXME" : @registration.to_xml
- -%>
-<%= case @registration.class.to_s
- when 'NilClass'
- "@registration is nil"
- when 'String'
- @registration.to_s
- when 'Registration'
- @registration.to_xml
- end
- -%>
+<%= @registration.to_xml if @registration -%>
\ No newline at end of file
diff --git a/plugins/registration/app/views/registration/create.json.erb b/plugins/registration/app/views/registration/create.json.erb
new file mode 100644
index 0000000..09982a7
--- /dev/null
+++ b/plugins/registration/app/views/registration/create.json.erb
@@ -0,0 +1 @@
+<%= @registration.to_json if @registration -%>
\ No newline at end of file
diff --git a/plugins/registration/app/views/registration/create.xml.erb b/plugins/registration/app/views/registration/create.xml.erb
index 6ed6334..b02fb3c 100644
--- a/plugins/registration/app/views/registration/create.xml.erb
+++ b/plugins/registration/app/views/registration/create.xml.erb
@@ -1,11 +1 @@
-<%= # @registration == nil ? "@registration is nil - FIXME" : @registration.to_xml
- -%>
-<%= case @registration.class.to_s
- when 'NilClass'
- "@registration is nil"
- when 'String'
- @registration.to_s
- when 'Registration'
- @registration.to_xml
- end
- -%>
+<%= @registration.to_xml if @registration -%>
\ No newline at end of file
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org