YAML file parsing method, device, equipment and storage medium

By performing lexical and syntax analysis of yaml files, identifyable statements are generated and stored, the difficulty in back-end server parsing code modification caused by changes in yaml file format in WAF upgrade is solved, and flexible and efficient configuration upgrade is achieved.

CN112069788BInactive Publication Date: 2024-11-22HANGZHOU DBAPPSECURITY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010946759.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-09-10
Publication Date
2024-11-22
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

During the WAF upgrade process, the existing technology needs to modify the parsing code of the backend server to adapt to changes in the yaml file format, resulting in the process being inflexible and error-prone.

Method used

By treating the data in the yaml file as plain text, performing lexical analysis and syntax analysis, generating recognizable statements, and storing them in the format that the backend server can parse, avoiding hard-coded modification of the backend server's parsing code .

Benefits of technology

It realizes flexibility and convenience in the WAF upgrade process, avoids errors caused by hard coding, and improves the flexibility and efficiency of configuration upgrades.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112069788B_ABST
    Figure CN112069788B_ABST
Patent Text Reader

Abstract

The present invention discloses a yaml file parsing method, device, equipment and storage medium, the method comprising: reading a yaml file storing front-end settings in the form of plain text, obtaining a string of the front-end settings stored in the yaml file; performing lexical analysis on the string to obtain recognizable blocks corresponding to characters in the string, and performing grammatical analysis on the obtained recognizable blocks to obtain recognizable statements composed of the recognizable blocks; storing the recognizable statements in a corresponding file in a format that can be parsed by a back-end server, and sending the file to the back-end server. Thus, even if the format of the yaml language needs to be modified during the WAF upgrade process, there is no need to modify the parsing code of the back-end server, but the parsing of the yaml file can be implemented in accordance with the method of the present application, which is more flexible and convenient, and will not cause corresponding errors due to hard coding.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of WAF technology, and more specifically, to a YAML file parsing method, device, equipment and storage medium. Background Art

[0002] In WAF (Web Application Protection System), yaml files are used to save front-end configurations. Yaml files are files that use the yaml format for storage, and the yaml format is a highly readable format used to express data serialization; the back-end server parses the yaml file to generate the data required by the back-end server. However, when the WAF needs to be upgraded, the data structure corresponding to the yaml format needs to be modified, and the parsing code of the back-end server often needs to be modified at the same time to modify the data structure of the back-end server, that is, the parsing code in the back-end server is modified by hard coding to change the relevant data structure. This method is not flexible, convenient, and prone to errors. Summary of the invention

[0003] The object of the present invention is to provide a YAML file parsing method, device, equipment and storage medium, which can be more flexible and convenient, and will not cause corresponding errors due to hard coding.

[0004] In order to achieve the above object, the present invention provides the following technical solutions:

[0005] A YAML file parsing method, comprising:

[0006] Read the yaml file storing the front-end settings in plain text form to obtain the character string of the front-end settings stored in the yaml file;

[0007] Performing lexical analysis on the character string to obtain recognizable word blocks corresponding to the characters in the character string, and performing grammatical analysis on the obtained recognizable word blocks to obtain recognizable sentences composed of the recognizable word blocks;

[0008] The recognizable statements are stored in a corresponding file in a format that can be parsed by a back-end server, and the file is sent to the back-end server.

[0009] Preferably, performing lexical analysis on the string to obtain recognizable word blocks corresponding to characters in the string includes:

[0010] It is determined in sequence that each character in the character string is the current character, and it is determined that in a lexical file pre-set in a format based on the yaml language, a word block having a corresponding relationship with the current character is a recognizable word block corresponding to the current character.

[0011] Preferably, performing grammatical analysis on the obtained recognizable word blocks to obtain recognizable sentences composed of the recognizable word blocks includes:

[0012] A syntax tree constructed based on the format of the yaml language is obtained, and the recognizable word blocks are reorganized based on the syntax tree to obtain corresponding recognizable sentences.

[0013] Preferably, it also includes:

[0014] If the format of the YAML language needs to change, obtain the lexical file and syntax tree based on the format of the YAML language after the change, and use the obtained lexical file and syntax tree to replace the lexical file and syntax tree before the format of the YAML language changes.

[0015] Preferably, the lexical file and the syntax tree are stored in a pluggable storage device.

[0016] A YAML file parsing device, comprising:

[0017] The reading module is used to: read the yaml file storing the front-end settings in plain text form, and obtain the character string of the front-end settings stored in the yaml file;

[0018] A parsing module, used to: perform lexical analysis on the character string to obtain recognizable word blocks corresponding to the characters in the character string, and perform grammatical analysis on the obtained recognizable word blocks to obtain recognizable sentences composed of the recognizable word blocks;

[0019] The sending module is used to store the recognizable sentence in a corresponding file in a format that can be parsed by the back-end server, and send the file to the back-end server.

[0020] Preferably, the parsing module includes:

[0021] The lexical analysis unit is used to: determine in turn that each character in the string is the current character, and determine that in a lexical file pre-set in a format based on the yaml language, a word block having a corresponding relationship with the current character is a recognizable word block corresponding to the current character.

[0022] Preferably, the parsing module includes:

[0023] The syntax analysis unit is used to obtain a syntax tree constructed based on the format of the YAML language, and reorganize the recognizable word blocks based on the syntax tree to obtain corresponding recognizable sentences.

[0024] A YAML file parsing device, comprising:

[0025] Memory for storing computer programs;

[0026] A processor is used to implement the steps of the YAML file parsing method as described in any of the above items when executing the computer program.

[0027] A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the YAML file parsing method as described in any one of the above items.

[0028] The present invention provides a yaml file parsing method, device, equipment and storage medium, the method comprising: reading a yaml file in which front-end settings are stored in the form of plain text, obtaining a string of the front-end settings stored in the yaml file; performing lexical analysis on the string to obtain a recognizable word block corresponding to the characters in the string, and performing grammatical analysis on the obtained recognizable word block to obtain a recognizable statement composed of the recognizable word block; storing the recognizable statement in a corresponding file in a format that can be parsed by a back-end server, and sending the file to the back-end server. It can be seen that in this application, the data in the yaml file is regarded as plain text, and the string in the yaml file is read in plain text. By performing lexical analysis and grammatical analysis on the string, a recognizable statement that can be normally recognized is obtained, and finally stored in the format required by the back-end server, so that even if the format of the yaml language needs to be modified during the WAF upgrade process, there is no need to modify the parsing code of the back-end server, but the parsing of the yaml file can be implemented in accordance with the method of this application, which is more flexible and convenient, and will not cause corresponding errors due to hard coding. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0030] Figure 1 A flowchart of a YAML file parsing method provided by an embodiment of the present invention;

[0031] Figure 2 A schematic diagram of the structure of a YAML file parsing device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0032] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0033] See also Figure 1 , which shows a flowchart of a YAML file parsing method provided by an embodiment of the present invention, which may include:

[0034] S11: Read the YAML file storing the front-end settings in plain text format to obtain a character string of the front-end settings stored in the YAML file.

[0035] The executor of a YAML file parsing method provided in an embodiment of the present invention can be a corresponding YAML file parsing device; since the YAML file parsing device cannot normally recognize the characters contained in the YAML file after obtaining the file, the YAML file storing the front-end configuration is read in the form of plain text to obtain the character string in the YAML file; since the YAML file is read in the form of plain text, the read character string is a plain text that the YAML file parsing device cannot normally recognize, and then the data in a format that the YAML file parsing device can normally recognize is obtained by parsing the read character string.

[0036] S12: Performing lexical analysis on the character string to obtain recognizable word blocks corresponding to the characters in the character string, and performing grammatical analysis on the obtained recognizable word blocks to obtain a recognizable sentence composed of the recognizable word blocks.

[0037] By performing lexical analysis on the string, recognizable blocks that can be recognized by the yaml file parsing device corresponding to the characters therein can be obtained, and then these recognizable blocks are subjected to grammatical analysis to obtain recognizable sentences composed of recognizable blocks, and the yaml file parsing device can recognize the recognizable sentences and then process them accordingly; these recognizable blocks can be called tokens in this application, so this application divides the string read from the yaml file into tokens; obtains the association relationship between these tokens, and combines these tokens into corresponding sentences with corresponding specific meanings based on this association relationship. Therefore, in this application, the yaml file is first read in the form of plain text, and the read string is a string that the yaml file parsing device cannot effectively recognize, and then by performing lexical analysis and grammatical analysis on it, these strings are converted into sentences that can be effectively recognized by the yaml file parsing device, and finally the sentences are stored in a format that can be effectively recognized by the back-end server, so that the back-end server can directly recognize and subsequently process the stored data. Among them, the format that the back-end server can effectively recognize can be xml format, txt format or doc format, etc.

[0038] S13: storing the recognizable statements in a corresponding file in a format that can be parsed by the back-end server, and sending the file to the back-end server.

[0039] Among them, the format that can be parsed by the back-end server is also the data structure in which the back-end server saves the configuration. Therefore, this application stores the recognizable statements obtained by parsing according to this data structure, which enables the back-end server to directly and effectively identify them and obtain the corresponding front-end configuration, thereby realizing operations that need to be implemented based on the front-end configuration.

[0040] In this application, the data in the yaml file is regarded as plain text, and the string in the yaml file is read in plain text. By performing lexical analysis and grammatical analysis on the string, a recognizable sentence that can be normally recognized is obtained, and finally it is stored in the format required by the back-end server. Therefore, even if the format of the yaml language needs to be modified during the WAF upgrade process, there is no need to modify the parsing code of the back-end server. Instead, the parsing of the yaml file can be implemented in the manner of this application, which is more flexible and convenient, and will not cause corresponding errors due to hard coding.

[0041] A YAML file parsing method provided by an embodiment of the present invention performs lexical analysis on a string to obtain recognizable word blocks corresponding to characters in the string, which may include:

[0042] It is determined in sequence that each character in the string is the current character, and it is determined that in a lexical file pre-set in a format based on the yaml language, a word block having a corresponding relationship with the current character is a recognizable word block corresponding to the current character.

[0043] The present application can be pre-set with a lexical file, and can construct corresponding word segmentation rules based on the format of the yaml language to obtain a lexical file containing the word segmentation rules, and then perform lexical analysis on the string based on the lexical file to implement the word segmentation operation of the string. Specifically, the corresponding relationship between each character in the yaml language format and each word block that can be effectively recognized by the yaml file parsing device can be set in the word segmentation rule, that is, for any character in the yaml language format, the word block with a corresponding relationship with the any character can be queried from the word segmentation rule, and the word block is a recognizable word block corresponding to the any character (effectively recognized by the yaml file parsing device), so that in this way, the string in the yaml file can be simply and effectively segmented to obtain word blocks that can be effectively recognized by the yaml file parsing device.

[0044] Correspondingly, the present application may also include the step of presetting a lexical file. In a specific implementation, the word segmentation rules constructed based on the YAML language format may be as follows:

[0045]

[0046]

[0047] A YAML file parsing method provided by an embodiment of the present invention performs grammatical analysis on the obtained recognizable word blocks to obtain recognizable sentences composed of the recognizable word blocks, which may include:

[0048] A syntax tree constructed based on the format of the YAML language is obtained, and reorganized into recognizable word blocks based on the syntax tree to obtain corresponding recognizable sentences.

[0049] The present application may be pre-set with a grammar file (specifically, it may be implemented in the form of a grammar tree), and a corresponding grammar tree may be constructed based on the format of the yaml language, and then the recognizable word blocks may be combined based on the grammar tree to obtain corresponding sentences with corresponding specific meanings, that is, recognizable sentences. Specifically, the grammar tree constructed based on the format of the yaml language may contain the positions of each word block in the sentence when the corresponding sentence is composed according to the format of the yaml language; therefore, after obtaining each recognizable word block, the present application may determine the position of each recognizable word block in the sentence composed according to the format of the yaml language through the grammar tree, and then place these recognizable word blocks at the positions they should be, so that sufficient sentences can be obtained, that is, recognizable sentences. Thus, in this way, the recognizable word blocks can be simply and effectively combined to obtain sentences with corresponding specific meanings that can be effectively recognized by the yaml file parsing device.

[0050] Correspondingly, the present application may also include a step of presetting a syntax tree (or syntax file). In a specific implementation, a syntax tree constructed based on the yaml language format may be as follows:

[0051] Input:

[0052] YAML_START_TOKEN

[0053] YAML_MAP_KEY YAML_MAP_VALUE_START YAML_MAP_VALUE

[0054] YAML_SEQUENCE_KEY YAML_MAP_VALUE_START

[0055] yaml_sequence_entry

[0056] YAML_END_TOKEN

[0057] yaml_sequence_entry:

[0058] yaml_sequence_entry

[0059] YAML_SEQUENCE_SEP YAML_SEQUENCE_VALUE

[0060] It should be noted that data in the yaml language format may include maps and arrays, and the present application can obtain corresponding maps and arrays by performing lexical analysis and sentence analysis on the strings in the yaml file, that is, recognizable sentences that can be effectively recognized by the yaml file parsing device; for example, the plain text string read from the yaml file is as follows:

[0061] sequence:

[0062] aaa

[0063] bbb

[0064] map_key:map_value

[0065] …

[0066] This application performs lexical analysis on the above string and obtains multiple corresponding recognizable word blocks, as shown below:

[0067] YAML_START_TOKEN(---)NEWLINE(newline)YAML_SEQUENCE_KEY(sequence)YAML_MAP_VALUE_START(:)NEWLINE(newline)YAML_SEQUENCE_SEP(-)YAML_SEQUENCE_VALUE(aaa)NEWLINE(newline)YAML_SEQUENCE_SEP(-)YAML_SEQUENCE_VALUE(bbb)NEWLINE(newline)YAML_MAP_KEY(map_key)YAML_MAP_VALUE_START(:)YAML_MAP_VALUE(map_value)NEWLINE(newline)YAML_END_TOKEN(…)

[0068] The present application performs grammatical analysis on the above-mentioned multiple recognizable word blocks and obtains corresponding recognizable sentences as follows: the above-mentioned string contains an array and a map, the array sequence contains two elements aaa and bbb, the key of the map is map_key and the value is map_value.

[0069] A YAML file parsing method provided by an embodiment of the present invention may further include:

[0070] If the format of the YAML language needs to change, obtain the lexical file and syntax tree based on the format of the YAML language after the change, and use the obtained lexical file and syntax tree to replace the lexical file and syntax tree before the format of the YAML language changes.

[0071] When the WAF needs to be upgraded and the format corresponding to the yaml language needs to be modified, the present application can obtain the lexical file and syntax tree obtained after the format of the yaml language is changed from the external input, and then use the lexical file and syntax tree to replace the existing lexical file and syntax tree, so as to obtain a file corresponding to the yaml format corresponding to the upgraded WAF through the replacement of the lexical file and syntax tree, so as to achieve adaptation to the WAF upgrade in this simple and convenient way, so that the parsing of the yaml file can be effectively realized after the WAF is upgraded.

[0072] An embodiment of the present invention provides a YAML file parsing method, wherein both a lexical file and a syntax tree can be stored in a pluggable storage device.

[0073] It should be noted that since a YAML file parsing method disclosed in the present application may need to be applied in different devices, the present application can store the lexical file and the syntax tree in a pluggable storage device, so that the YAML file can be parsed on the device only by inserting the storage device into the corresponding device, thereby increasing the applicability of the present solution.

[0074] In a specific application scenario, a YAML file parsing method provided by an embodiment of the present invention may include:

[0075] (1) Write the lexical file according to the format specification of the YAML language;

[0076] (2) Write a grammar file according to the format specification of the YAML language, so as to construct a grammar tree corresponding to the YAML language. The grammar tree specifies the relationship between word blocks;

[0077] (3) Determine the data structure of the backend server to save the configuration (the data structure in this application is the data structure corresponding to the format);

[0078] (4) Read the yaml file that stores the front-end configuration in plain text;

[0079] (5) segmenting the character string read in step (3) according to the lexical file generated in step (1);

[0080] (6) Parse the result of step (5) according to the syntax tree generated in step (2);

[0081] (7) Save the result generated in step (6) to the data structure determined in step (3).

[0082] The present invention provides a flexible and convenient method adapted to WAF configuration upgrade, introduces lexical analysis and grammatical analysis, treats the data in the yaml file as plain text for word segmentation through lexical analysis, then combines the word blocks obtained by word segmentation into corresponding sentences according to the grammar file, and finally generates final data in the format required by the back-end server; thereby, the traditional configuration upgrade solution is improved, the flexibility of configuration upgrade is improved, and the workload of R&D personnel is reduced.

[0083] The embodiment of the present invention also provides a yaml file parsing device, such as Figure 2 As shown, it may include:

[0084] The reading module is used to: read the yaml file containing the front-end settings in plain text form, and obtain the character string of the front-end settings saved in the yaml file;

[0085] The parsing module is used to: perform lexical analysis on the character string to obtain recognizable word blocks corresponding to the characters in the character string, and perform grammatical analysis on the obtained recognizable word blocks to obtain recognizable sentences composed of the recognizable word blocks;

[0086] The sending module is used to store the recognizable sentences in a corresponding file in a format that can be parsed by the back-end server, and send the file to the back-end server.

[0087] An embodiment of the present invention provides a YAML file parsing device, wherein the parsing module may include:

[0088] The lexical analysis unit is used to: determine in turn that each character in the string is the current character, and determine that in a lexical file pre-set in a format based on the yaml language, a word block having a corresponding relationship with the current character is a recognizable word block corresponding to the current character.

[0089] An embodiment of the present invention provides a YAML file parsing device, wherein the parsing module may include:

[0090] The syntax analysis unit is used to obtain a syntax tree constructed based on the format of the YAML language, and reorganize the recognizable word blocks based on the syntax tree to obtain corresponding recognizable sentences.

[0091] A YAML file parsing device provided by an embodiment of the present invention may further include:

[0092] The update module is used to: if the format of the YAML language needs to be changed, obtain the lexical file and syntax tree based on the format of the YAML language after the change, and use the obtained lexical file and syntax tree to replace the lexical file and syntax tree before the format of the YAML language is changed.

[0093] An embodiment of the present invention provides a YAML file parsing device, in which a lexical file and a syntax tree can be stored in a pluggable storage device.

[0094] The embodiment of the present invention further provides a YAML file parsing device, which may include:

[0095] Memory for storing computer programs;

[0096] A processor is used to implement the steps of the YAML file parsing method as described in any of the above items when executing a computer program.

[0097] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the YAML file parsing method as described in any one of the above items are implemented.

[0098] For the description of the relevant parts of a YAML file parsing device, equipment and storage medium provided by the embodiment of the present invention, please refer to the detailed description of the corresponding parts in the YAML file parsing method provided by the embodiment of the present invention, which will not be repeated here. In addition, the parts of the above technical solutions provided by the embodiment of the present invention that are consistent with the implementation principles of the corresponding technical solutions in the prior art are not described in detail to avoid excessive elaboration.

[0099] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A YAML file parsing method, characterized in that: include: Read the yaml file storing the front-end settings in plain text form to obtain the character string of the front-end settings stored in the yaml file; Performing lexical analysis on the character string to obtain recognizable word blocks corresponding to the characters in the character string, and performing grammatical analysis on the obtained recognizable word blocks to obtain recognizable sentences composed of the recognizable word blocks; Storing the recognizable statements in a corresponding file in a format that can be parsed by a back-end server, and sending the file to the back-end server; Performing lexical analysis on the string to obtain recognizable word blocks corresponding to the characters in the string, including: Determine in sequence that each character in the string is the current character, and determine that a word block having a corresponding relationship with the current character in a lexical file pre-set in a format based on the yaml language is a recognizable word block corresponding to the current character; Performing grammatical analysis on the obtained recognizable word blocks to obtain recognizable sentences composed of the recognizable word blocks, including: Obtaining a syntax tree constructed based on the format of the yaml language, and reorganizing the recognizable word blocks based on the syntax tree to obtain corresponding recognizable sentences; Also includes: If the format of the YAML language needs to change, obtain the lexical file and syntax tree based on the format of the YAML language after the change, and use the obtained lexical file and syntax tree to replace the lexical file and syntax tree before the format of the YAML language changes.

2. The method according to claim 1, characterized in that: The lexical file and the syntax tree are stored in a pluggable storage device.

3. A YAML file parsing device, characterized in that: include: The reading module is used to: read the yaml file storing the front-end settings in plain text form, and obtain the character string of the front-end settings stored in the yaml file; A parsing module, used to: perform lexical analysis on the character string to obtain recognizable word blocks corresponding to the characters in the character string, and perform grammatical analysis on the obtained recognizable word blocks to obtain recognizable sentences composed of the recognizable word blocks; A sending module, used to: store the recognizable sentence in a corresponding file in a format that can be parsed by a back-end server, and send the file to the back-end server; The parsing module comprises: The lexical analysis unit is used to: determine in sequence that each character in the character string is a current character, and determine that a word block having a corresponding relationship with the current character in a lexical file pre-set in a format based on the yaml language is a recognizable word block corresponding to the current character; The parsing module comprises: A syntax analysis unit, used to: obtain a syntax tree constructed based on the format of the YAML language, and reorganize the recognizable word blocks based on the syntax tree to obtain corresponding recognizable sentences; Also includes: The update module is used to obtain the lexical file and syntax tree based on the format of the YAML language after the change if the format of the YAML language needs to be changed, and use the obtained lexical file and syntax tree to replace the lexical file and syntax tree before the format of the YAML language is changed.

4. A YAML file parsing device, characterized in that: include: Memory for storing computer programs; A processor, used to implement the steps of the YAML file parsing method as described in any one of claims 1 to 2 when executing the computer program.

5. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the YAML file parsing method according to any one of claims 1 to 2 are implemented.