Project

General

Profile

« Previous | Next » 

Revision 6012d347

Added by Marc Dequènes over 13 years ago

  • ID 6012d3472ddc37bfd6d7350a3e3f44fa7a5553b8

[evol] Clerk work §1

View differences:

bin/clerk
#!/usr/bin/ruby -Ku
#--
# CyborgHood, a distributed system management software.
# Copyright (c) 2009-2011 Marc Dequènes (Duck) <Duck@DuckCorp.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++
# to allow in-place run for test
$: << File.join(File.dirname(__FILE__), "..", "lib")
require 'cyborghood/cyborg'
module CyborgHood
module ClerkLand
include I18nTranslation
bindtextdomain("cyborghood_clerk", {:path => Config::L10N_DIR, :output_charset => "UTF-8"})
class Clerk < Cyborg
# load config before modules are included
Config.load(self.human_name)
include BotNet
def setup
super
define_interface "0.1~"
end
end
end # ClerkLand
end
reg = Needle::Registry.new
reg.define do |b|
b.require 'cyborghood', CyborgHood
b.require 'cyborghood-clerk/land', CyborgHood::ClerkLand
b.bot { CyborgHood::ClerkLand::Clerk.new(b.clerk_land) }
end
bot = reg.bot
trap('INT') do
bot.stop(:quickly)
end
trap('TERM') do
bot.stop(:quickly)
end
bot.run
data/cyborghood/default_config/clerk.yaml
---
data/cyborghood/schema/clerk.yaml
---
type: map
mapping:
"schemacannotbeempty": {type: str}
lib/cyborghood-clerk/interface/0_base.rb
node 'Commands', :dir => '_commands'
node 'Batch' do
# TODO
end
lib/cyborghood-clerk/interface/_commands/0_base.rb
node 'DNS', :dir => '_dns'
lib/cyborghood-clerk/interface/_commands/_dns/get_set.rb
node ['GET', 'SET'], :case_insensitive => true do
action = node_name
node nil do
zone_name = node_name
# on_request do |request|
# task 'dns_manage_zone' do
# end
# end
end
end
lib/cyborghood-clerk/interface/_commands/_dns/info.rb
node 'INFO', :case_insensitive => true do
on_request do |request|
task 'dns_list_managed_zones' do
logger.warn "User: #{request.env.user}"
# do later requests using provided token
set_user request.env.user
# cannot search directly 'person/<user>' until LdapShadows is used,
# then searching the user DN first
ask "Librarian", :user_info, Proc.new{ "/Records/Persons/#{user}" }
on_error do
logger.warn "FUCK"
request.reply.errors << "Internal error"
request.send_reply
end
on_success do
unless results[:user_info]
logger.warn "User not found!"
else
ask "Librarian", :managed_zones, "/Records/DnsDomains/?", :manager => "#{results[:user_info][:dn]}"
on_success do
logger.info "COIN"
# request.reply.results[<key>] fail with: wrong number of arguments (2 for 1)
msg = results[:managed_zones].empty? ?
_("You do not manage any zone.") :
_("You are manager of the following zones: %{zone_list}.",
:zone_list => results[:managed_zones].keys.join(', '))
request.reply.results = msg.translate(request.env.preferred_locales)
logger.info "COIN END"
request.send_reply
end
end
end
end # task dns_list_managed_zones
end
end
lib/cyborghood-clerk/land.rb
#--
# CyborgHood, a distributed system management software.
# Copyright (c) 2009-2011 Marc Dequènes (Duck) <Duck@DuckCorp.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++
module CyborgHood
module ClerkLand
def register_services(container)
container.namespace_define(:clerk_land) do |b|
b.records do
require 'cyborghood-clerk/records'
Records.new
end
end
end
module_function :register_services
end # ClerkLand
end
po/cyborghood_clerk.pot
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: CyborgHood 0.4.0\n"
"POT-Creation-Date: 2011-03-07 02:42+0100\n"
"PO-Revision-Date: 2011-03-07 02:39+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
#: lib/cyborghood-clerk/interface/_commands/_dns/info.rb:30
msgid "You do not manage any zone."
msgstr ""
#: lib/cyborghood-clerk/interface/_commands/_dns/info.rb:31
msgid "You are manager of the following zones: %{zone_list}."
msgstr ""
po/fr/cyborghood_clerk.po
# CyborgHood
# Copyright (C) 2009-2011 DuckCorp
# This file is distributed under the same license as the CyborgHood package.
# Marc Dequènes (Duck) <Duck@DuckCorp.org>, 2009-2010.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: CyborgHood 0.4.0\n"
"POT-Creation-Date: 2011-03-07 02:42+0100\n"
"PO-Revision-Date: 2011-03-07 02:39+0100\n"
"Last-Translator: Marc Dequènes (Duck) <Duck@DuckCorp.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: lib/cyborghood-clerk/interface/_commands/_dns/info.rb:30
msgid "You do not manage any zone."
msgstr "iVous ne gérez aucune zone."
#: lib/cyborghood-clerk/interface/_commands/_dns/info.rb:31
msgid "You are manager of the following zones: %{zone_list}."
msgstr "Vous êtes administrateur des zones suivantes : %{zone_list}."

Also available in: Unified diff