如何构建 perl Web 服务基础架构 [英] How to build a perl web-service infrastructure

查看:47
本文介绍了如何构建 perl Web 服务基础架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多脚本可用于管理多服务器基础架构.其中一些脚本需要 root 访问权限,一些需要访问数据库,其中大多数是基于 perl 的.我想将所有这些脚本转换为可以从不同应用程序执行的非常简单的 Web 服务.这些 Web 服务将接受常规请求输入,并作为执行结果输出 json.我想我应该设置一个简单的 perl 调度程序,将其命名为 action,它可以进行日志记录、检查凭据和执行这些简单的脚本.类似的东西:

I have many scripts that I use to manage a multi server infrastructure. Some of these scripts require root access, some require access to a databases, and most of them are perl based. I would like to convert all these scripts into very simple web services that can be executed from different applications. These web services would take regular request inputs and would output json as a result of being executed. I'm thinking that I should setup a simple perl dispatcher, call it action, that would do logging, checking credentials, and executing these simple scripts. Something like:

http://host/action/update-dns?server=www.google.com&ip=192.168.1.1

这将调用 action perl 驱动程序,后者将调用带有适当参数(可能以某种方式清除)的 update-dns 脚本并返回适当的 json回复.我希望此基础架构具有以下属性:

This would invoke the action perl driver which in turn would call the update-dns script with the appropriate parameters (perhaps cleaned in some way) and return an appropriate json response. I would like for this infrastructure to have the following attributes:

  • 所有脚本都驻留在一个地方.如果将新脚本放在那里,它会自动变为可调用的.
  • 所有脚本都需要有某种形式的清单来描述、谁可以调用它(属于某个 ldap 组)、它需要什么参数、响应是什么等等.这样就可以自我解释了.
  • 所有脚本都记录在谁做了什么以及响应是什么方面.
  • 如果有命令行方式来执行类似# action update-dns --server=www.google.com --up=192.168.1.1

我是否必须从头开始做这件事,还是已经有一些东西可以让我捎带回去?

Do I have to get this going from scratch or is there something already on top of which I can piggy back on?

推荐答案

你可能想看看我的框架 子::规范.文档仍然很少,但我已经将它用于几个项目,包括我在 CPAN 中的其他模块.

You might want to check out my framework Sub::Spec. The documentation is still sparse, but I'm already using it for several projects, including for my other modules in CPAN.

这个想法是你在函数中编写代码,为这些函数装饰/添加足够的元数据(包括一些摘要、参数规范等),并且会有工具链来处理你需要的东西,例如在命令行中运行您的函数(使用 Sub::Spec::CmdLine,以及通过 HTTP(使用 Sub::Spec::HTTP::ServerSub::Spec::HTTP::Client).

The idea is you write your code in functions, decorate/add enough metadata to these functions (including some summary, specification of arguments, etc.) and there will be toolchains to take care of what you need, e.g. running your functions in the command-line (using Sub::Spec::CmdLine, and over HTTP (using Sub::Spec::HTTP::Server and Sub::Spec::HTTP::Client).

有一个处于起步阶段的示例项目.另请查看 http://gudangapi.com/.例如,函数 GudangAPI::API::finance::currency::id::bca::get_bca_exchange_rate() 将作为 API 函数通过 HTTP API 访问.

There is a sample project in its infancy. Also take a look at http://gudangapi.com/. For example, the function GudangAPI::API::finance::currency::id::bca::get_bca_exchange_rate() will be accessible as an API function via HTTP API.

联系我如果你有兴趣部署这样的东西.

Contact me if you are interested in deploying something like this.

这篇关于如何构建 perl Web 服务基础架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆