Serverless CN
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: feature author: Oliver.W, Tim --- # Verfication Feature [![hackmd-github-sync-badge](https://hackmd.io/4q5NJy6pRse5xfM9E0Tkrw/badge)](https://hackmd.io/4q5NJy6pRse5xfM9E0Tkrw) ## Requirements 目前用户遇到的问题多为配置和账户相关问题,在这些问题上,serverless framework目前并没有有效的方式校验并提示用户。腾讯的错误信息也不够友好,不足以让用户知道如何使配置serverless以解决问题,同时还存在以下问题: * 组件的多个版本需要维护非常多的校验文件。 * 无法为校验添加多个规则 * 无法添加警告校验信息 * 无法进行组件之外的校验,比如组件间引用的校验。 * 校验文件无法在不更新组件的情况下单独更新。 ### Key Results * 添加在Serverless Platform的服务端校验。 * 每个校验支持多条校验规则,同时可以对规则进行分组和添加优先级(error/warning) ![](https://i.imgur.com/NGP3nbf.png) * 可以动态更新,加载校验规则文件(不需要重新部署platform) * 一次校验可以返回所有错误。 ![](https://i.imgur.com/As6JERa.png) * 校验文件统一存储在git repo中,可以进行修改 https://github.com/serverlessinc/tencent-component-types * 组件的校验自动向前匹配最近的版本进行校验。 * 可以提供警告信息,单纯的警告不会终止部署 ![](https://i.imgur.com/oiuhFbn.png) * 向前兼容(`components@v<=3.15.0`) ![](https://i.imgur.com/1dCS6jn.png) ![](https://i.imgur.com/rEUdQfv.png) ### 问题 * SCF-name 名称长度的校验。 * 环境变量注入 * 多个组件的基础信息。 * inputs的配置进行校验。 * 上传文件之后。 ### 例子 1. 必填字段缺失 > component: 不存在 2. 字段校验,多条件, > app: 应用名称超长 3. 组件间关联字段丢失 > vpc-name: 未定义 预期返回结果:(暂定) ``` scf 组件校验结果 : 错误2 警告2 规则版本v0.0.3 ----------------------------------------- * app - 组件component是必填字段,需要指定要是用的组件名称。(错误-红) * stage - 名称不能包含非英文及数字的特殊字符。(错误-红色) - 名称长度过长,建议控制长度为10个字符。(警告-黄色) * inputs.field - 当前vpc名称不存在。(警告-黄色) ``` ``` scf 组件校验结果 : 错误2 警告1 规则版本v0.0.3 ----------------------------------------- 当前组件版本已不再更新,建议升级到 1.00 版本之上(警告-黄色) * app - 此字段类型不正确,请使用 String 类型。(警告-红色) * inputs.field3 - 此字段为必填字段。(警告-红色) ----------------------------------------- 可以使用 sls deploy --force 跳过校验进行部署。 ``` 1. YAML config 2. Create Instance Obj 1. get component <!-- 3. Validation (component non-refer fields) --> 4. Save Instance (complete reference fields) 5. Validation (component fields) ## User Experience ### Developer Scenario: Developer publish a new verison of components When developer upload a new validation to the repo Then the validation rules will sync to Serverless Platform And during components deploy will use the rules to verify the config file. ### User Scenario: Deploy a component app with Serverless CLI Given a complete config a serverless app When user deploy the app to cloud Then the Serverless Platform will check the configs by components And list the error & warning messages in console ## Architecture Design ### 校验规则的更新和使用过程: 1. 在 https://github.com/serverlessinc/tencent-component-types 存入scf@0.0.0.yml, scf@1.0.0.yml 等文件存放 types.(只有在校验规则有 breaking change 的时候才引入新版本的校验规则) 2. 当文件更改时, GitHub Action 同步配置到 Redis 3. 用户部署时从 redis 拿到对应 Component 规则,并对用户的 yml 做校验 ### 具体设计要点: - 匹配规则: 如果用户 component 版本是 1.0.1,我们在数据库中找到 0.0.0 和 3.0.0 两个匹配规则,使用 0.0.0 版本匹配规则。如果用户 component 没有配置版本(大多数情况),使用最高版本配置规则 - 校验规则:沿用目前 types 的格式 关键词:type, required, allow, regex, min, max(for number type)... - 校验使用的库:https://github.com/sideway/joi 兼容原有的 types 系统,并增加两个新特性: - 允许对同一个字段进行多个校验 - 加入 waring 和 error 字段标记错误程度 例子 ``` message(可选): "当前组件版本已不再更新,建议升级到 1.00 版本之上/建议使用http组件替换更新,详情查看:xxxx" messageLevel: warning inputs: region: type: string required: false allow: - ap-guangzhou - ap-shanghai message: 'region 无法识别' level: error name: type: string required: false rules: - regex: '^[A-Za-z][\w-_]{0,28}[A-Za-z0-9]$' message: '名称不能包含非英文及数字的特殊字符' level: error - regex: '^[A-Za-z][\w-_]{0,10}[A-Za-z0-9]$' message: '名称长度过长,建议控制长度为10个字符' level: warning // 对outpus校验 未来添加暂不实现。 outputs: ``` ### 配置说明列表 filename example: `scf@0.8.2.yml` | field | 必填 | 示例 | 备注 | | ----------- | ---- | ----------------------------------------------- | --------------------------- | | message | 否 | string/number/boolean/object/array/datetime/url | | | messageLevel | 否 | | 默认 warning | | inputs | 否 | | 默认 error, error会终止进程 | | outpus | 否 | | | inputs 中字段支持的条件 | type | 必填 | 规则 | 示例 | 备注 | | -------- | ---- | ---- | ----------------------------------------------- | ----------- | | type | 是 | 是 | string/number/boolean/object/array/datetime/url | | | required | 否 | 是 | | 默认 false | | rules | 否 | 否 | | | | items | 否 | 否 | | 数组类型 | | keys | 否 | 否 | | Object 类型 | > 只有一个规则,可以将规则直接写在inputs字段条件中,不需要嵌套在 rules rules 配置(多个规则放在rules 下,单个规则放在字段下) | type | 必填 | 支持type | 示例 | 备注 | | ------- | ---- | ------------------- | ---- | ---------- | | regex | 是 | string | | | | min | 否 | string,number,array | | | | max | 否 | string,number,array | | | | allow | 否 | string,number | | | | message | 否 | / | | | | level | 否 | / | | 默认 error | <!-- | string | | min, max, regex, allow | | | number | | min, max, allow | | | boolean | | / | | | object | | / | | | array | | min, max | | | datetime | | / | | | url | | / | | --> ### 返回校验结果 <!-- ``` { typeVersion: '0.0.1' errors: [{ path: ['name'], message: '错误信息' }], warnings: [] } ``` --> ```yml // 组件为单位的错误信息 component: version: messages: [{ path: 'message' level: 'warning/error' message: 'hello' }, { path: 'inputs.name' level: 'warning/error' message: 'hello' }] ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully