简体   繁体   English

如何在我的 Jelastic 清单中进行可选的 email 设置并将值返回给用户?

[英]How can I make an optional email settings in my Jelastic manifest and return the value to the user?

Let's say I have a Jelastic manifest where, in the settings section, I ask the user for an email address (to setup some service).假设我有一个 Jelastic 清单,在设置部分中,我要求用户提供 email 地址(以设置一些服务)。 Because the user using Jelastic already is logged on Jelastic with an email, it might make sense to propose to the user that she uses that email.由于使用 Jelastic 的用户已经使用 email 登录 Jelastic,因此建议用户使用 email 可能是有意义的。 It saves her typing during the manifest setup.它可以节省她在清单设置期间的输入。 So, ideally, what I would like to do is this:所以,理想情况下,我想做的是:

settings:
  fields:
    - name: email
      caption: Email
      type: string
      default: ${user.email}

Then, in the manifest success text, I would like to display it, along with other credentials for the deployed services in the installed Jelastic environment:然后,在清单成功文本中,我想显示它以及已安装 Jelastic 环境中已部署服务的其他凭据:

success:
  text: |
    **Email**: ${settings.email}

The email is typically used as a username in a service deployed on the new Jelastic environment and in the success text it would be displayed near the corresponding password. email 通常用作部署在新 Jelastic 环境中的服务中的用户名,并在成功文本中显示在相应密码附近。

This above is all nice, but it doesn't work.上面这一切都很好,但它不起作用。 Indeed, I cannot use the ${user.email} in the default field for the email settings.实际上,我不能在email设置的default字段中使用${user.email}

Currently, the only viable way I've found to make it work is as follows:目前,我发现使其工作的唯一可行方法如下:

settings:
  fields:
    - name: useJelasticEmailAsEmail
      type: toggle
      caption: Use Jelastic Email
      value: true
      hidden: false
      showIf:
        false:
          name: email
          caption: email
          type: string
          required: true

Then, I can use it to install a service like so:然后,我可以使用它来安装这样的服务:

onInstall:
- script: 'return { result: 0, email: ${settings.useJelasticEmailAsEmail} ? "${user.email}" : "${settings.email}" };'
- install:
    jps: my-service-manifest.yml
    settings:
      username: ${response.email}

However, after installation of my-service-manifest.yml , I have no access to the actually used email anymore, therefore I cannot use the ${response.email} in my success text, except maybe if my-service-manifest.yml returned the email somehow (possibly with a return statement?).但是,安装my-service-manifest.yml后,我无法再访问实际使用的 email,因此我无法在成功文本中使用${response.email} ,除非my-service-manifest.yml以某种方式返回了 email(可能带有返回语句?)。

The thing is, I may have many services to install like that, but only one requires the email.问题是,我可能有很多这样的服务要安装,但只有一个需要 email。 Additionally, it might be that for some reason that service requiring the email must be installed first.此外,可能由于某种原因,必须首先安装需要 email 的服务。 In such a case, with the above solution, I'd need to propagate the email through all services in order to get it out to the success text.在这种情况下,使用上述解决方案,我需要通过所有服务传播 email 以便将其发送到成功文本。 The email would be consumed by the first service and somehow returned to the next. email 将被第一个服务消耗并以某种方式返回到下一个服务。 The next service does not need the email, but must propagate it, therefore it should take it as settings argument and return it to the next service, and so on.下一个服务不需要 email,但必须传播它,因此它应该将其作为设置参数并将其返回给下一个服务,依此类推。 This is not very nice to have a manifest taking arguments it doesn't need, therefore that solution is probably not the right one.拥有一个不需要 arguments 的清单并不是很好,因此该解决方案可能不是正确的解决方案。

I find that very complicated for a very simple problem.对于一个非常简单的问题,我发现这非常复杂。 There must be something easier to do, right?一定有一些更容易做的事情,对吧? Can someone give me a hint?有人可以给我一个提示吗?

I'd need a solution for a manifest where I have many of such optional parameters.我需要一个清单的解决方案,其中我有许多这样的可选参数。 Currently, I have an issue with the email and also with secrets.目前,我对 email 和机密有疑问。 In my use-cases, it makes sense that these secrets be provided by me directly in the settings or that they be automatically generated with eg ${fn.password(20)} .在我的用例中,这些秘密由我直接在设置中提供,或者使用例如${fn.password(20)}自动生成是有意义的。 For some installations I need to set them myself, for some other installations I need to let them be automatically generated.对于某些安装我需要自己设置它们,对于其他一些安装我需要让它们自动生成。

So, the working solution I have found goes as follows, assuming I have 2 optional parameters:因此,假设我有 2 个可选参数,我找到的工作解决方案如下:

  1. in the settings section of my jps manifest, I do在我的 jps 清单的settings部分,我做
settings:
  fields:
    - name: useOptionalParam1
      type: toggle
      caption: Use optional param1
      value: true
      hidden: false
      showIf:
        false:
          name: param1
          caption: Param1
          type: string
          required: true
    - name: useOptionalParam2
      type: toggle
      caption: Use optional param2
      value: true
      hidden: false
      showIf:
        false:
          name: param2
          caption: Param2
          type: string
          required: true
  1. define values for those params in the globals section (for the email, this is not necessary, because it is defined as user.email ):globals部分中为这些参数定义值(对于 email,这不是必需的,因为它被定义为user.email ):
globals:
  OPTIONAL_PARAM1: ${fn.password(20)}
  OPTIONAL_PARAM2: ${fn.password(20)}
  1. define an action like this:定义这样的动作:
actions:
  getOptionalParams:
    - script: 'return { result: 0, param1: ${settings.useOptionalParam1} ? "${globals.OPTIONAL_PARAM1}" : "${settings.param1}", param2: ${settings.useOptionalParam2} ? "${globals.OPTIONAL_PARAM2}" : "${settings.param2}" };'
  1. call the action wherever necessary;必要时采取行动; for example, before the success text:例如,在成功文本之前:
# settings, globals, nodes sections
[...]

onInstall:
  - myVariousInstalls
  - getOptionalParams

success:
  text: |
    **PARAM1**: ${response.param1}  
    **PARAM2**: ${response.param2}

Note the last call to getOptionalParams at the very end of the onInstall section.请注意在onInstall部分最后对getOptionalParams的最后一次调用。 It is there to provide the response object to the success section.它在那里向success部分提供response object。 Interestingly, that works fine.有趣的是,这很好用。 The getOptionalParams action can also be called anywhere in the myVariousInstalls action. getOptionalParams操作也可以在myVariousInstalls操作中的任何位置调用。 It must be called before an operation, for example like this:它必须在操作之前调用,例如:

actions:
[...]
  myVariousInstalls:
    - getOptionalParams
    - install:
        jps: path/to/manifest
        settings:
          param1: ${response.param1}

In so doing, I solve my initial problem.这样做,我解决了我最初的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM