【问题标题】:Certbot pluging development - How to get command line argumentsCertbot 插件开发 - 如何获取命令行参数
【发布时间】:2019-07-02 18:09:10
【问题描述】:

我正在为 Certbot 开发一个插件,我需要在用户运行插件时从用户那里获取一些参数。我在文档中搜索并找不到获取插件代码参数的方法。我的插件只包含一个 Authenticator。插件代码如下,

@zope.interface.implementer(interfaces.IAuthenticator)
@zope.interface.provider(interfaces.IPluginFactory)
class Authenticator(common.Plugin):

    def prepare(self):
      pass

    def get_chall_pref(self, domain):
      return [challenges.HTTP01]

   def perform(self, achalls):
     param = #need to get param here

   def cleanup(self, achalls):
     self.reverter.recovery_routine()

【问题讨论】:

    标签: lets-encrypt certbot


    【解决方案1】:
    class Authenticator(common.Plugin):
    
        @classmethod
        def add_parser_arguments(cls, add):
          add('server-url', help='url or ip of the server')
    
        def perform(self, achalls):
          param = self.conf('server-url')
    

    在上面的代码中,add_parser_arguments 方法来自IPlugin 接口。在该方法中,我们可以定义我们的插件需要哪些参数,并可以对其进行描述。 然后可以作为perform函数使用它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-03
      • 2018-06-14
      • 1970-01-01
      • 2019-06-09
      相关资源
      最近更新 更多