Mailinglist Archive: yast-commit (1914 mails)

< Previous Next >
[yast-commit] <rest-service> basesystem : new rest service for administrator's setting
  • From: Jiri Suchomel <jsuchome@xxxxxxx>
  • Date: Wed, 9 Sep 2009 15:33:30 +0200
  • Message-id: <E1Mlf04-0004Gq-3j@xxxxxxxxxxxxxxxx>
ref: refs/heads/basesystem
commit d68739dac50cd29ca597bd620af5dfab25e965f1
Author: Jiri Suchomel <jsuchome@xxxxxxx>
Date: Wed Sep 9 15:33:30 2009 +0200

new rest service for administrator's setting
---
plugins/administrator/.gitignore | 3 +
plugins/administrator/MIT-LICENSE | 20 +++++
plugins/administrator/README | 10 +++
plugins/administrator/Rakefile | 11 +++
.../app/controllers/administrator_controller.rb | 32 +++++++
plugins/administrator/app/models/administrator.rb | 26 ++++++
plugins/administrator/config/rails_parent.rb | 15 ++++
plugins/administrator/config/resources/system.yml | 3 +
.../administrator/doc/administrator_proposal.txt | 49 +++++++++++
plugins/administrator/init.rb | 1 +
plugins/administrator/install.rb | 1 +
...se.yast.modules.yapi.users.administrator.policy | 29 +++++++
.../package/yast2-webservice-administrator.changes | 5 +
.../package/yast2-webservice-administrator.spec | 86 ++++++++++++++++++++
.../functional/administrator_controller_test.rb | 29 +++++++
plugins/administrator/test/test_helper.rb | 52 ++++++++++++
.../administrator/test/unit/administrator_test.rb | 23 +++++
plugins/administrator/uninstall.rb | 1 +
18 files changed, 396 insertions(+), 0 deletions(-)

diff --git a/plugins/administrator/.gitignore b/plugins/administrator/.gitignore
new file mode 100644
index 0000000..945bd79
--- /dev/null
+++ b/plugins/administrator/.gitignore
@@ -0,0 +1,3 @@
+package/www/
+package/www.tar.bz2
+coverage
diff --git a/plugins/administrator/MIT-LICENSE
b/plugins/administrator/MIT-LICENSE
new file mode 100644
index 0000000..658dd59
--- /dev/null
+++ b/plugins/administrator/MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 Novell, Inc.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/plugins/administrator/README b/plugins/administrator/README
new file mode 100644
index 0000000..2c90b86
--- /dev/null
+++ b/plugins/administrator/README
@@ -0,0 +1,10 @@
+System
+======
+
+REST interface for configuration of system administrator's attributes:
+
+- password
+- mail aliases
+
+
+Copyright (c) 2009 Novell, released under the MIT license
diff --git a/plugins/administrator/Rakefile b/plugins/administrator/Rakefile
new file mode 100644
index 0000000..2c69676
--- /dev/null
+++ b/plugins/administrator/Rakefile
@@ -0,0 +1,11 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+require 'rake/packagetask'
+require File.join(File.dirname(__FILE__), 'config', 'rails_parent')
+require File.join(RailsParent.parent, 'config', 'boot')
+require 'tasks/rails'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
diff --git a/plugins/administrator/app/controllers/administrator_controller.rb
b/plugins/administrator/app/controllers/administrator_controller.rb
new file mode 100644
index 0000000..1152dfa
--- /dev/null
+++ b/plugins/administrator/app/controllers/administrator_controller.rb
@@ -0,0 +1,32 @@
+class AdministratorController < ApplicationController
+
+ before_filter :login_required
+
+ # GET action
+ def show
+ @aliases = Administrator.instance.aliases
+
+ respond_to do |format|
+ format.html { render :xml => @aliases.to_xml(:root => 'aliases'),
:location => "none" } #return xml only
+ format.xml { render :xml => @aliases.to_xml(:root => 'aliases'),
:location => "none" }
+ format.json { render :json => @aliases.to_json, :location => "none" }
+ end
+ end
+
+ # PUT action
+ def update
+
+ @admin = Administrator.instance
+
+ if params.has_key?(:password) && !params[:password].empty?
+ @admin.save_password(params[:password])
+ end
+
+ if params.has_key?(:aliases)
+ @admin.save_aliases(params[:aliases])
+ end
+
+ show
+ end
+
+end
diff --git a/plugins/administrator/app/models/administrator.rb
b/plugins/administrator/app/models/administrator.rb
new file mode 100644
index 0000000..f5bb343
--- /dev/null
+++ b/plugins/administrator/app/models/administrator.rb
@@ -0,0 +1,26 @@
+require 'singleton'
+require 'yast_service'
+
+class Administrator
+
+ attr_reader :aliases
+
+ include Singleton
+
+ def initialize
+ @aliases = []
+ Rails.logger.debug "===================== reading aliases now ? =========="
+ end
+
+ def save_password(pw)
+ Rails.logger.debug "--------------------- saving password #{pw}--------"
+ end
+
+ def save_aliases(new_aliases)
+ # TODO compare new_aliases with aliases
+ Rails.logger.debug "--------------------- current aliases
#{aliases.inspect}"
+ Rails.logger.debug "--------------------- saving aliases
#{new_aliases.inspect}"
+ @aliases = new_aliases
+ end
+
+end
diff --git a/plugins/administrator/config/rails_parent.rb
b/plugins/administrator/config/rails_parent.rb
new file mode 100644
index 0000000..b869908
--- /dev/null
+++ b/plugins/administrator/config/rails_parent.rb
@@ -0,0 +1,15 @@
+class RailsParent
+
+ def RailsParent.parent
+ parent = ENV["RAILS_PARENT"]
+ unless parent
+ parent = File.expand_path(File.join('..','..','..', 'webservice'),
File.dirname(__FILE__))
+ unless File.directory?( parent || "" )
+ $stderr.puts "Nope: #{parent}\nPlease set RAILS_PARENT environment"
+ exit 1
+ end
+ end
+ parent
+ end
+
+end
diff --git a/plugins/administrator/config/resources/system.yml
b/plugins/administrator/config/resources/system.yml
new file mode 100644
index 0000000..0dccdee
--- /dev/null
+++ b/plugins/administrator/config/resources/system.yml
@@ -0,0 +1,3 @@
+interface: org.opensuse.yast.modules.yapi.users.administrator
+controller: administrator
+singular: true
diff --git a/plugins/administrator/doc/administrator_proposal.txt
b/plugins/administrator/doc/administrator_proposal.txt
new file mode 100644
index 0000000..7b41c25
--- /dev/null
+++ b/plugins/administrator/doc/administrator_proposal.txt
@@ -0,0 +1,49 @@
+Admin password module proposal (fate #307141)
+---------------------------------------------
+
+Tasks:
+ - change administrator (root's) password
+ - configure notification e-mail addresses
+ (mail aliases for root)
+
+
+Model
+
+ singleton class Administrator
+
+ attributes
+ string password
+ list<string> forward_mail_to
+
+ methods
+ (accessing the system, probably using YaPI::USERS)
+
+ save_password
+ save_aliases
+
+Policies
+
+ org.opensuse.yast.modules.yapi.users.administrator.read
+ org.opensuse.yast.modules.yapi.users.administrator.write
+
+API
+
+ URL: /administrator
+
+ REST service pseudo-code:
+
+ # GET method
+ def show
+
+ read and return current mail aliases
+
+ # PUT method
+ def update (params)
+
+ if password changed
+
+ save the new password
+
+ if aliases changed
+
+ save new list of aliases
diff --git a/plugins/administrator/init.rb b/plugins/administrator/init.rb
new file mode 100644
index 0000000..3c19a74
--- /dev/null
+++ b/plugins/administrator/init.rb
@@ -0,0 +1 @@
+# Include hook code here
diff --git a/plugins/administrator/install.rb b/plugins/administrator/install.rb
new file mode 100644
index 0000000..f7732d3
--- /dev/null
+++ b/plugins/administrator/install.rb
@@ -0,0 +1 @@
+# Install hook code here
diff --git
a/plugins/administrator/package/org.opensuse.yast.modules.yapi.users.administrator.policy

b/plugins/administrator/package/org.opensuse.yast.modules.yapi.users.administrator.policy
new file mode 100644
index 0000000..1ea1fbd
--- /dev/null
+++
b/plugins/administrator/package/org.opensuse.yast.modules.yapi.users.administrator.policy
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD PolicyKit Policy
Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd";>
+
+<policyconfig>
+ <vendor>Novell, Inc.</vendor>
+ <vendor_url>http://www.novell.com</vendor_url>
+
+ <action id="org.opensuse.yast.modules.yapi.users.administrator.read">
+ <description>Read system administrator's settings</description>
+ <message>Authentication is required to read administrator's
settings</message>
+ <defaults>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>no</allow_active>
+ <allow_active>auth_admin_keep_session</allow_active>
+ </defaults>
+ </action>
+
+ <action id="org.opensuse.yast.modules.yapi.users.administrator.write">
+ <description>Update system administrator's settings</description>
+ <message>Authentication is required to update administrator's
settings</message>
+ <defaults>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>no</allow_active>
+ <allow_active>auth_admin_keep_session</allow_active>
+ </defaults>
+ </action>
+</policyconfig>
+
diff --git
a/plugins/administrator/package/yast2-webservice-administrator.changes
b/plugins/administrator/package/yast2-webservice-administrator.changes
new file mode 100644
index 0000000..f60b2c5
--- /dev/null
+++ b/plugins/administrator/package/yast2-webservice-administrator.changes
@@ -0,0 +1,5 @@
+-------------------------------------------------------------------
+Tue Sep 8 15:19:19 CEST 2009 - jsuchome@xxxxxxx
+
+- initial version (fate#307141)
+
diff --git a/plugins/administrator/package/yast2-webservice-administrator.spec
b/plugins/administrator/package/yast2-webservice-administrator.spec
new file mode 100644
index 0000000..0563464
--- /dev/null
+++ b/plugins/administrator/package/yast2-webservice-administrator.spec
@@ -0,0 +1,86 @@
+#
+# spec file for package yast2-webservice-administrator
+#
+# Copyright (c) 2008 SUSE LINUX Products GmbH, Nuernberg, Germany.
+# This file and all modifications and additions to the pristine
+# package are under the same license as the package itself.
+#
+# Please submit bugfixes or comments via http://bugs.opensuse.org/
+#
+
+
+Name: yast2-webservice-administrator
+PreReq: yast2-webservice
+# requires YaPI::USERS
+Requires: ysat2-users
+Provides:
yast2-webservice:/srv/www/yastws/app/controllers/administrator_controller.rb
+License: MIT
+Group: Productivity/Networking/Web/Utilities
+Autoreqprov: on
+Version: 0.0.1
+Release: 0
+Summary: YaST2 - Webservice - Administrator
+Source: www.tar.bz2
+Source1: org.opensuse.yast.modules.yapi.users.administrator.policy
+BuildRoot: %{_tmppath}/%{name}-%{version}-build
+BuildArch: noarch
+
+#
+%define pkg_user yastws
+%define plugin_name administrator
+#
+
+
+%description
+YaST2 - Webservice - REST based interface for administrator's attributes
+
+Authors:
+--------
+ Jiri Suchomel <jsuchome@xxxxxxxxxx>
+
+%prep
+%setup -q -n www
+
+%build
+
+%install
+
+#
+# Install all web and frontend parts.
+#
+mkdir -p $RPM_BUILD_ROOT/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}
+cp -a * $RPM_BUILD_ROOT/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}
+
+# Policies
+mkdir -p $RPM_BUILD_ROOT/usr/share/PolicyKit/policy
+install -m 0644 %SOURCE1 $RPM_BUILD_ROOT/usr/share/PolicyKit/policy/
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%post
+# granting all permissions for the web user
+/etc/yastws/tools/policyKit-rights.rb --user yastws --action grant >&
/dev/null || :
+
+%postun
+
+%files
+%defattr(-,root,root)
+%dir /srv/www/%{pkg_user}
+%dir /srv/www/%{pkg_user}/vendor
+%dir /srv/www/%{pkg_user}/vendor/plugins
+%dir /srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/MIT-LICENSE
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/README
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/Rakefile
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/init.rb
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/install.rb
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/uninstall.rb
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/app
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/config
+%dir /usr/share/PolicyKit
+%dir /usr/share/PolicyKit/policy
+%attr(644,root,root) %config
/usr/share/PolicyKit/policy/org.opensuse.yast.modules.yapi.users.%{plugin_name}.policy
+
+
+%changelog
diff --git
a/plugins/administrator/test/functional/administrator_controller_test.rb
b/plugins/administrator/test/functional/administrator_controller_test.rb
new file mode 100644
index 0000000..872d97e
--- /dev/null
+++ b/plugins/administrator/test/functional/administrator_controller_test.rb
@@ -0,0 +1,29 @@
+require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
+require 'test/unit'
+
+
+class AdministratorControllerTest < ActionController::TestCase
+ fixtures :accounts
+
+ def setup
+ @controller = AdministratorController.new
+ @request = ActionController::TestRequest.new
+ # http://railsforum.com/viewtopic.php?id=1719
+ @request.session[:account_id] = 1 # defined in fixtures
+
+ @model = Administrator.instance
+ end
+
+ test "check 'show' result" do
+ ret = get :show
+ # success (200 OK)
+ assert_response :success
+
+ # is returned a valid XML?
+ ret_hash = Hash.from_xml(ret.body)
+ assert ret_hash
+ assert ret_hash.has_key?("aliases")
+ assert ret_hash["aliases"].is_a? Array
+ end
+
+end
diff --git a/plugins/administrator/test/test_helper.rb
b/plugins/administrator/test/test_helper.rb
new file mode 100644
index 0000000..7d67910
--- /dev/null
+++ b/plugins/administrator/test/test_helper.rb
@@ -0,0 +1,52 @@
+# find the rails parent
+require File.join(File.dirname(__FILE__), '..', 'config', 'rails_parent')
+# first config rails
+require File.expand_path( File.join("config","environment"),
RailsParent.parent )
+# then enable testing, this will get the routing right
+ENV["RAILS_ENV"] = "test"
+require 'test_help'
+
+class ActiveSupport::TestCase
+ # Transactional fixtures accelerate your tests by wrapping each test method
+ # in a transaction that's rolled back on completion. This ensures that the
+ # test database remains unchanged so your fixtures don't have to be reloaded
+ # between every test method. Fewer database queries means faster tests.
+ #
+ # Read Mike Clark's excellent walkthrough at
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
+ #
+ # Every Active Record database supports transactions except MyISAM tables
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
+ # is recommended.
+ #
+ # The only drawback to using transactional fixtures is when you actually
+ # need to test transactions. Since your test is bracketed by a transaction,
+ # any transactions started in your code will be automatically rolled back.
+ self.use_transactional_fixtures = true
+
+ # Instantiated fixtures are slow, but give you @david where otherwise you
+ # would need people(:david). If you don't want to migrate your existing
+ # test cases which use the @david style and don't mind the speed hit (each
+ # instantiated fixtures translates to a database query per test method),
+ # then set this back to true.
+ self.use_instantiated_fixtures = false
+
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in
alphabetical order.
+ #
+ # Note: You'll currently still have to declare fixtures explicitly in
integration tests
+ # -- they do not yet inherit this setting
+ fixtures :all
+
+ # Add more helper methods to be used by all tests here...
+
+ # See http://pennysmalls.com/2009/03/04/rails-23-breakage-and-fixage/
+ def clean_backtrace(&block)
+ yield
+ rescue ActiveSupport::TestCase::Assertion => error
+ framework_path =
Regexp.new(File.expand_path("#{File.dirname(__FILE__)}/assertions"))
+ error.backtrace.reject! { |line| File.expand_path(line) =~ framework_path }
+ raise
+ end
+
+end
diff --git a/plugins/administrator/test/unit/administrator_test.rb
b/plugins/administrator/test/unit/administrator_test.rb
new file mode 100644
index 0000000..1c4a062
--- /dev/null
+++ b/plugins/administrator/test/unit/administrator_test.rb
@@ -0,0 +1,23 @@
+require 'test_helper'
+
+require 'administrator'
+
+class AdministratorTest < ActiveSupport::TestCase
+
+ def setup
+ @model = Administrator.instance
+ end
+
+ def test_save_password
+ ret = @model.save_password("new password")
+ assert ret
+ end
+
+ def test_save_aliases
+ assert @model.aliases.size == 0
+ ret = @model.save_aliases([ "test@xxxxxxxxxx", "a@b" ])
+ assert ret
+ assert @model.aliases.size == 2
+ end
+
+end
diff --git a/plugins/administrator/uninstall.rb
b/plugins/administrator/uninstall.rb
new file mode 100644
index 0000000..9738333
--- /dev/null
+++ b/plugins/administrator/uninstall.rb
@@ -0,0 +1 @@
+# Uninstall hook code here
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages