-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implements EncryptionRule DistSQL Parser Visitor with AST (#301)
* feat: implements encrypt rule distsql visitor interface with ast Signed-off-by: wangbo <wangbo@sphere-ex.com> * feat: add TODO Signed-off-by: wangbo <wangbo@sphere-ex.com> * chore: fix import package error Signed-off-by: wangbo <wangbo@sphere-ex.com> * chore: fix ci error Signed-off-by: wangbo <wangbo@sphere-ex.com> * chore: fix lint Signed-off-by: wangbo <wangbo@sphere-ex.com> * feat: add encrypt distsql ast Signed-off-by: wangbo <wangbo@sphere-ex.com> --------- Signed-off-by: wangbo <wangbo@sphere-ex.com> Co-authored-by: wangbo <wangbo@sphere-ex.com>
- Loading branch information
Showing
15 changed files
with
6,695 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
shardingsphere-operator/pkg/distsql/antlr4/encrypt/Alphabet.g4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
lexer grammar Alphabet; | ||
|
||
FOR_GENERATOR: 'DO NOT MATCH ANY THING, JUST FOR GENERATOR'; | ||
|
||
fragment A: [Aa]; | ||
fragment B: [Bb]; | ||
fragment C: [Cc]; | ||
fragment D: [Dd]; | ||
fragment E: [Ee]; | ||
fragment F: [Ff]; | ||
fragment G: [Gg]; | ||
fragment H: [Hh]; | ||
fragment I: [Ii]; | ||
fragment J: [Jj]; | ||
fragment K: [Kk]; | ||
fragment L: [Ll]; | ||
fragment M: [Mm]; | ||
fragment N: [Nn]; | ||
fragment O: [Oo]; | ||
fragment P: [Pp]; | ||
fragment Q: [Qq]; | ||
fragment R: [Rr]; | ||
fragment S: [Ss]; | ||
fragment T: [Tt]; | ||
fragment U: [Uu]; | ||
fragment V: [Vv]; | ||
fragment W: [Ww]; | ||
fragment X: [Xx]; | ||
fragment Y: [Yy]; | ||
fragment Z: [Zz]; | ||
fragment UL_: '_'; |
57 changes: 57 additions & 0 deletions
57
shardingsphere-operator/pkg/distsql/antlr4/encrypt/BaseRule.g4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
grammar BaseRule; | ||
|
||
import Symbol, Keyword, Literals; | ||
|
||
literal | ||
: STRING_ | (MINUS_)? INT_ | TRUE | FALSE | ||
; | ||
|
||
algorithmDefinition | ||
: TYPE LP_ NAME EQ_ algorithmTypeName (COMMA_ propertiesDefinition)? RP_ | ||
; | ||
|
||
algorithmTypeName | ||
: buildinAlgorithmTypeName | STRING_ | ||
; | ||
|
||
buildinAlgorithmTypeName | ||
: MD5 | ||
| AES | ||
| RC4 | ||
| SM3 | ||
| SM4 | ||
| CHAR_DIGEST_LIKE | ||
; | ||
|
||
propertiesDefinition | ||
: PROPERTIES LP_ properties? RP_ | ||
; | ||
|
||
properties | ||
: property (COMMA_ property)* | ||
; | ||
|
||
property | ||
: key=STRING_ EQ_ value=literal | ||
; | ||
|
||
tableName | ||
: IDENTIFIER_ | ||
; |
184 changes: 184 additions & 0 deletions
184
shardingsphere-operator/pkg/distsql/antlr4/encrypt/Keyword.g4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
lexer grammar Keyword; | ||
|
||
import Alphabet; | ||
|
||
WS | ||
: [ \t\r\n] + ->skip | ||
; | ||
|
||
CREATE | ||
: C R E A T E | ||
; | ||
|
||
ALTER | ||
: A L T E R | ||
; | ||
|
||
DROP | ||
: D R O P | ||
; | ||
|
||
SHOW | ||
: S H O W | ||
; | ||
|
||
RESOURCE | ||
: R E S O U R C E | ||
; | ||
|
||
RULE | ||
: R U L E | ||
; | ||
|
||
FROM | ||
: F R O M | ||
; | ||
|
||
ENCRYPT | ||
: E N C R Y P T | ||
; | ||
|
||
TYPE | ||
: T Y P E | ||
; | ||
|
||
ENCRYPT_ALGORITHM | ||
: E N C R Y P T UL_ A L G O R I T H M | ||
; | ||
|
||
ASSISTED_QUERY_ALGORITHM | ||
: A S S I S T E D UL_ Q U E R Y UL_ A L G O R I T H M | ||
; | ||
|
||
LIKE_QUERY_ALGORITHM | ||
: L I K E UL_ Q U E R Y UL_ A L G O R I T H M | ||
; | ||
|
||
NAME | ||
: N A M E | ||
; | ||
|
||
PROPERTIES | ||
: P R O P E R T I E S | ||
; | ||
|
||
COLUMN | ||
: C O L U M N | ||
; | ||
|
||
RULES | ||
: R U L E S | ||
; | ||
|
||
TABLE | ||
: T A B L E | ||
; | ||
|
||
COLUMNS | ||
: C O L U M N S | ||
; | ||
|
||
CIPHER | ||
: C I P H E R | ||
; | ||
|
||
PLAIN | ||
: P L A I N | ||
; | ||
|
||
ASSISTED_QUERY_COLUMN | ||
: A S S I S T E D UL_ Q U E R Y UL_ C O L U M N | ||
; | ||
|
||
LIKE_QUERY_COLUMN | ||
: L I K E UL_ Q U E R Y UL_ C O L U M N | ||
; | ||
|
||
QUERY_WITH_CIPHER_COLUMN | ||
: Q U E R Y UL_ W I T H UL_ C I P H E R UL_ C O L U M N | ||
; | ||
|
||
TRUE | ||
: T R U E | ||
; | ||
|
||
FALSE | ||
: F A L S E | ||
; | ||
|
||
DATA_TYPE | ||
: D A T A UL_ T Y P E | ||
; | ||
|
||
PLAIN_DATA_TYPE | ||
: P L A I N UL_ D A T A UL_ T Y P E | ||
; | ||
|
||
CIPHER_DATA_TYPE | ||
: C I P H E R UL_ D A T A UL_ T Y P E | ||
; | ||
|
||
ASSISTED_QUERY_DATA_TYPE | ||
: A S S I S T E D UL_ Q U E R Y UL_ D A T A UL_ T Y P E | ||
; | ||
|
||
LIKE_QUERY_DATA_TYPE | ||
: L I K E UL_ Q U E R Y UL_ D A T A UL_ T Y P E | ||
; | ||
|
||
IF | ||
: I F | ||
; | ||
|
||
EXISTS | ||
: E X I S T S | ||
; | ||
|
||
COUNT | ||
: C O U N T | ||
; | ||
|
||
MD5 | ||
: M D [5] | ||
; | ||
|
||
AES | ||
: A E S | ||
; | ||
|
||
RC4 | ||
: R C [4] | ||
; | ||
|
||
SM3 | ||
: S M [3] | ||
; | ||
|
||
SM4 | ||
: S M [4] | ||
; | ||
|
||
CHAR_DIGEST_LIKE | ||
: C H A R UL_ D I G E S T UL_ L I K E | ||
; | ||
|
||
NOT | ||
: N O T | ||
; |
50 changes: 50 additions & 0 deletions
50
shardingsphere-operator/pkg/distsql/antlr4/encrypt/Literals.g4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
lexer grammar Literals; | ||
|
||
import Alphabet, Symbol; | ||
|
||
IDENTIFIER_ | ||
: [A-Za-z_$0-9]*?[A-Za-z_$]+?[A-Za-z_$0-9]* | ||
| BQ_ ~'`'+ BQ_ | ||
; | ||
|
||
STRING_ | ||
: (DQ_ ('\\'. | '""' | ~('"' | '\\'))* DQ_) | ||
| (SQ_ ('\\'. | '\'\'' | ~('\'' | '\\'))* SQ_) | ||
; | ||
|
||
INT_ | ||
: [0-9]+ | ||
; | ||
|
||
HEX_ | ||
: [0-9a-fA-F] | ||
; | ||
|
||
NUMBER_ | ||
: INT_? DOT_? INT_ (E (PLUS_ | MINUS_)? INT_)? | ||
; | ||
|
||
HEXDIGIT_ | ||
: '0x' HEX_+ | 'X' SQ_ HEX_+ SQ_ | ||
; | ||
|
||
BITNUM_ | ||
: '0b' ('0' | '1')+ | B SQ_ ('0' | '1')+ SQ_ | ||
; |
Oops, something went wrong.