ref: refs/heads/eula
commit 9e8e1a7d81cbdd2970a6264e456aed01331cb79d
Author: J. Daniel Schmidt
Date: Wed Oct 14 19:19:38 2009 +0200
add json support, small fixes in controllers, cleanup
---
.../app/controllers/configuration_controller.rb | 42 ++++++++++++++---
.../app/controllers/registration_controller.rb | 15 +++---
plugins/registration/app/models/registration.rb | 46 ++++++++++++++-----
.../app/views/configuration/show.json.erb | 2 +-
4 files changed, 77 insertions(+), 28 deletions(-)
diff --git a/plugins/registration/app/controllers/configuration_controller.rb b/plugins/registration/app/controllers/configuration_controller.rb
index 38e0929..c692581 100644
--- a/plugins/registration/app/controllers/configuration_controller.rb
+++ b/plugins/registration/app/controllers/configuration_controller.rb
@@ -6,22 +6,48 @@ 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
- # setRegistrationServerDetails
- @registration = "PUT to /registration/configuration"
+ puts params.inspect
+ @registration = Registration.new( { } )
+ @registration.set_config 'https://static.test.server/test/path', newca
+ render :show
end
def show
- # do not run registration
- # only get the server url and certificate -> to be done in YSR.pm
-
+ # do not run registration, only get the config
@registration = Registration.new( { } )
- puts @registration.get_config.inspect
-
+ @registration.get_config
end
def index
- @registration = "GET to INDEX /registration/configuration"
+ # same as show
+ show
end
end
diff --git a/plugins/registration/app/controllers/registration_controller.rb b/plugins/registration/app/controllers/registration_controller.rb
index bb80661..7ce1c05 100644
--- a/plugins/registration/app/controllers/registration_controller.rb
+++ b/plugins/registration/app/controllers/registration_controller.rb
@@ -9,20 +9,21 @@ class RegistrationController < ApplicationController
# POST to registration => run registration
@registration = Registration.new({})
- # TODO: parse post data and set context data
+ # TODO overwrite context data if defined
#@registration.set_context( { } )
+
+ # TODO: parse post data and set the arguments
+ # @registration.set_arguments( { } )
+
ret = @registration.register
+ headers["Status"] = "400 Bad Request" if ret == 3
end
def show
- # getRegistrationServerDetails
-
+ # get registration status
@registration = Registration.new( { } )
- puts @registration.get_config.inspect
+ @registration.get_config
render :status
- # do not run registration
- # only get the uuid, server url and certificate -> to be done in YSR.pm
-
end
def index
diff --git a/plugins/registration/app/models/registration.rb b/plugins/registration/app/models/registration.rb
index 8c5e2b0..15ed442 100644
--- a/plugins/registration/app/models/registration.rb
+++ b/plugins/registration/app/models/registration.rb
@@ -13,6 +13,8 @@ class Registration
@reg = ''
def initialize(hash)
+ # cleanup arguments
+ @arguments = { 'test' => [ 'a{ss}', { 'value' => 'mytestvalue' } ] }
# set context defaults
@context = { 'yastcall' => [ 'i', 1 ],
'norefresh' => [ 'i', 1 ],
@@ -27,8 +29,8 @@ class Registration
return if hash.nil?
# merge custom context data
- if hash.class.to_s == 'Hash'
- @context.merge hash
+ if hash.class == Hash
+ hash.each {|k, v| @context.merge!( { k => ['s', "#{v.to_s}"] } ) }
else
raise "Invalid or missing registration initialization context data."
end
@@ -44,19 +46,26 @@ class Registration
self.initialize hash
end
- def set_arguments(hash)
- @arguments = hash
+ def add_argument(key, value)
+ @arguments.merge!( { key => [ 'a{ss}',{ 'value' => "#{value.to_s}" } ] } )
end
def add_arguments(hash)
- @arguments.merge hash
+ hash.each {|k, v| self.add_argument k, v }
+ end
+
+ def set_arguments(hash)
+ @arguments = {}
+ self.add_arguments hash
end
+
def register
- # @reg = YastService.Call("YSR::statelessregister", { 'ctx' => @context, 'arguments' => @arguments } )
# don't know how to pass only one hash, so split it into two. FIXME change later if possible!
- @reg = YastService.Call("YSR::statelessregister", @context, {} )
- # return @reg.inspect
+ # @reg = YastService.Call("YSR::statelessregister", { 'ctx' => @context, 'arguments' => @arguments } )
+
+ @reg = YastService.Call("YSR::statelessregister", @context, @arguments )
+ return @reg['exitcode'] || 99
end
def get_config
@@ -65,8 +74,12 @@ class Registration
end
def set_config(url, ca)
- # TODO: write registration config
- # return @reg.inspect
+ newconfig = { 'regserverurl' => url,
+ 'regserverca' => ca }
+ ret = YastService.Call("YSR::setregistrationconfig", newconfig)
+ puts "YastService.Call retruned: =#{ret}="
+ self.get_config
+ return ret
end
def status_to_xml( options = {} )
@@ -88,7 +101,7 @@ class Registration
end
xml.certificate do
xml.data do
- xml.cdata!(@config['regserverca']) if @config['regserverca'].size > 0
+ xml.cdata!(@config['regserverca']) if @config['regserverca'].size > 0
end
end
end
@@ -96,7 +109,7 @@ class Registration
def to_xml( options = {} )
-
+ # TODO FIXME ... create the registration xml structure
xml = options[:builder] ||= Builder::XmlMarkup.new(options)
xml.instruct! unless options[:skip_instruct]
@@ -114,4 +127,13 @@ class Registration
end
end
+ def config_to_json( options = {} )
+ hash = Hash.from_xml(config_to_xml())
+ return hash.to_json
+ end
+
+ def to_json( options = {} )
+ hash = Hash.from_xml(to_xml())
+ return hash.to_json
+ end
end
diff --git a/plugins/registration/app/views/configuration/show.json.erb b/plugins/registration/app/views/configuration/show.json.erb
index 277ef41..afcec78 100644
--- a/plugins/registration/app/views/configuration/show.json.erb
+++ b/plugins/registration/app/views/configuration/show.json.erb
@@ -1 +1 @@
-<%= @registration == nil ? "@registration is nil - FIXME" : @registration.to_json -%>
+<%= @registration.config_to_json if @registration -%>
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org