You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2023/01/04 09:14:55 UTC

[GitHub] [shardingsphere] Qianyi951015 opened a new pull request, #23327: Add `EncryptRuleConfigurationImportChecker`

Qianyi951015 opened a new pull request, #23327:
URL: https://github.com/apache/shardingsphere/pull/23327

   
   Changes proposed in this pull request:
     - Add `EncryptRuleConfigurationImportChecker` for `ImportDatabaseConfigurationHandler`
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [x] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [x] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the pull request.
   - [x] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [ ] I have added corresponding unit tests for my changes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] RaigorJiang commented on a diff in pull request #23327: Add `EncryptRuleConfigurationImportChecker`

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on code in PR #23327:
URL: https://github.com/apache/shardingsphere/pull/23327#discussion_r1061287131


##########
proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/EncryptRuleConfigurationImportChecker.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+
+package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.checker;
+
+import org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
+import org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
+import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
+import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * Encrypt rule configuration import checker.
+ */
+public final class EncryptRuleConfigurationImportChecker {
+    
+    /**
+     * Check encrypt rule configuration.
+     *
+     * @param database database
+     * @param currentRuleConfig current rule configuration
+     */
+    public void check(final ShardingSphereDatabase database, final EncryptRuleConfiguration currentRuleConfig) {
+        if (null == database || null == currentRuleConfig) {
+            return;
+        }
+        String databaseName = database.getName();
+        checkTables(currentRuleConfig, databaseName);
+        checkEncryptors(currentRuleConfig);
+    }
+    
+    private void checkTables(final EncryptRuleConfiguration currentRuleConfig, final String databaseName) {
+        Collection<String> tableNames = currentRuleConfig.getTables().stream().map(EncryptTableRuleConfiguration::getName).collect(Collectors.toList());
+        Collection<String> duplicatedTables = tableNames.stream().collect(Collectors.groupingBy(each -> each, Collectors.counting())).entrySet().stream()
+                .filter(each -> each.getValue() > 1).map(Map.Entry::getKey).collect(Collectors.toSet());
+        ShardingSpherePreconditions.checkState(duplicatedTables.isEmpty(), () -> new DuplicateRuleException("ENCRYPT", databaseName, duplicatedTables));
+    }
+    
+    private void checkEncryptors(final EncryptRuleConfiguration currentRuleConfig) {

Review Comment:
   Please add a check: whether the encryptor referenced in the table exists in encryptors.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] codecov-commenter commented on pull request #23327: Add `EncryptRuleConfigurationImportChecker`

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #23327:
URL: https://github.com/apache/shardingsphere/pull/23327#issuecomment-1370726658

   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/23327?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#23327](https://codecov.io/gh/apache/shardingsphere/pull/23327?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (962fa7b) into [master](https://codecov.io/gh/apache/shardingsphere/commit/b270e4d7f1fd767e07534469476e7d02f40193be?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (b270e4d) will **decrease** coverage by `0.01%`.
   > The diff coverage is `11.76%`.
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #23327      +/-   ##
   ============================================
   - Coverage     49.72%   49.70%   -0.02%     
   - Complexity     2456     2457       +1     
   ============================================
     Files          4038     4039       +1     
     Lines         58093    58110      +17     
     Branches       9238     9241       +3     
   ============================================
   - Hits          28887    28886       -1     
   - Misses        26656    26674      +18     
     Partials       2550     2550              
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/23327?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...checker/EncryptRuleConfigurationImportChecker.java](https://codecov.io/gh/apache/shardingsphere/pull/23327/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHJveHkvYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC9oYW5kbGVyL2Rpc3RzcWwvcmFsL2NvbW1vbi9jaGVja2VyL0VuY3J5cHRSdWxlQ29uZmlndXJhdGlvbkltcG9ydENoZWNrZXIuamF2YQ==) | `6.66% <6.66%> (ø)` | |
   | [.../updatable/ImportDatabaseConfigurationHandler.java](https://codecov.io/gh/apache/shardingsphere/pull/23327/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHJveHkvYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC9oYW5kbGVyL2Rpc3RzcWwvcmFsL3VwZGF0YWJsZS9JbXBvcnREYXRhYmFzZUNvbmZpZ3VyYXRpb25IYW5kbGVyLmphdmE=) | `19.23% <50.00%> (+0.80%)` | :arrow_up: |
   | [...handler/distsql/ral/hint/enums/HintSourceType.java](https://codecov.io/gh/apache/shardingsphere/pull/23327/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHJveHkvYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC9oYW5kbGVyL2Rpc3RzcWwvcmFsL2hpbnQvZW51bXMvSGludFNvdXJjZVR5cGUuamF2YQ==) | `0.00% <0.00%> (-42.86%)` | :arrow_down: |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] RaigorJiang merged pull request #23327: Add `EncryptRuleConfigurationImportChecker`

Posted by GitBox <gi...@apache.org>.
RaigorJiang merged PR #23327:
URL: https://github.com/apache/shardingsphere/pull/23327


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org