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 2022/12/12 08:28:36 UTC

[GitHub] [shardingsphere] zzzwjZhang opened a new pull request, #22825: add YamlMaskConfiguration and Swapper

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

   Ref https://github.com/apache/shardingsphere/issues/22759
   
   Changes proposed in this pull request:
     -  init mask rule configuration and mask rule
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [ ] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [ ] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the pull request.
   - [ ] 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] strongduanmu commented on a diff in pull request #22825: add YamlMaskConfiguration and Swapper

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


##########
features/mask/core/src/main/java/org/apache/shardingsphere/mask/yaml/config/YamlMaskRuleConfiguration.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.mask.yaml.config;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
+import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration;
+import org.apache.shardingsphere.mask.yaml.config.rule.YamlMaskTableRuleConfiguration;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * Mask rule configuration for YAML.
+ */
+@Getter
+@Setter
+public class YamlMaskRuleConfiguration implements YamlRuleConfiguration {

Review Comment:
   Please add final for YamlMaskRuleConfiguration.



##########
features/mask/core/src/main/java/org/apache/shardingsphere/mask/yaml/config/rule/YamlMaskColumnRuleConfiguration.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.mask.yaml.config.rule;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.infra.util.yaml.YamlConfiguration;
+
+/**
+ * Mask column rule configuration for YAML.
+ */
+@Getter
+@Setter
+public class YamlMaskColumnRuleConfiguration implements YamlConfiguration {

Review Comment:
   Please add final for YamlMaskColumnRuleConfiguration.



##########
features/mask/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper:
##########
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-org.apache.shardingsphere.mask.algorithm.hash.MD5MaskAlgorithm
+org.apache.shardingsphere.mask.yaml.swapper.YamlMaskRuleConfigurationSwapper

Review Comment:
   Why remove the MaskAlgorithm spi file?



##########
features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/swapper/rule/YamlMaskTableRuleConfigurationSwapperTest.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.mask.yaml.swapper.rule;
+
+import org.apache.shardingsphere.mask.api.config.rule.MaskColumnRuleConfiguration;
+import org.apache.shardingsphere.mask.api.config.rule.MaskTableRuleConfiguration;
+import org.apache.shardingsphere.mask.yaml.config.rule.YamlMaskColumnRuleConfiguration;
+import org.apache.shardingsphere.mask.yaml.config.rule.YamlMaskTableRuleConfiguration;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public final class YamlMaskTableRuleConfigurationSwapperTest {
+    
+    private final YamlMaskTableRuleConfigurationSwapper swapper = new YamlMaskTableRuleConfigurationSwapper();
+    
+    @Test
+    public void assertSwapToYamlConfiguration() {
+        Collection<MaskColumnRuleConfiguration> encryptColumnRuleConfigs = Arrays.asList(
+                new MaskColumnRuleConfiguration("mask_column_1", "md5_mask"),
+                new MaskColumnRuleConfiguration("mask_column_2", "keep_from_x_to_y"),
+                new MaskColumnRuleConfiguration("mask_column_3", "keep_first_m_last_m"));
+        MaskTableRuleConfiguration encryptTableRuleConfig = new MaskTableRuleConfiguration("test_table", encryptColumnRuleConfigs);
+        YamlMaskTableRuleConfiguration actualYamlMaskTableRuleConfig = swapper.swapToYamlConfiguration(encryptTableRuleConfig);
+        assertThat(actualYamlMaskTableRuleConfig.getName(), is("test_table"));
+        Map<String, YamlMaskColumnRuleConfiguration> actualColumns = actualYamlMaskTableRuleConfig.getColumns();
+        assertThat(actualColumns.size(), is(3));
+        YamlMaskColumnRuleConfiguration actualYamlMaskColumnRuleConfigFirst = actualColumns.get("mask_column_1");
+        assertThat(actualYamlMaskColumnRuleConfigFirst.getMaskAlgorithm(), is("md5_mask"));
+        YamlMaskColumnRuleConfiguration actualYamlMaskColumnRuleConfigSecond = actualColumns.get("mask_column_2");
+        assertThat(actualYamlMaskColumnRuleConfigSecond.getMaskAlgorithm(), is("keep_from_x_to_y"));
+        YamlMaskColumnRuleConfiguration actualYamlMaskColumnRuleConfigThird = actualColumns.get("mask_column_3");
+        assertThat(actualYamlMaskColumnRuleConfigThird.getMaskAlgorithm(), is("keep_first_m_last_m"));
+    }
+    
+    @Test
+    public void assertSwapToObject() {
+        YamlMaskColumnRuleConfiguration encryptColumnRuleConfig = new YamlMaskColumnRuleConfiguration();
+        encryptColumnRuleConfig.setLogicColumn("mask_column");
+        encryptColumnRuleConfig.setMaskAlgorithm("md5_mask");
+        Map<String, YamlMaskColumnRuleConfiguration> columns = new LinkedHashMap<>(1);
+        columns.put("mask_column", encryptColumnRuleConfig);
+        YamlMaskTableRuleConfiguration yamlMaskTableRuleConfig = new YamlMaskTableRuleConfiguration();
+        yamlMaskTableRuleConfig.setName("test_table");
+        yamlMaskTableRuleConfig.setColumns(columns);
+        MaskTableRuleConfiguration actualMaskTableRuleConfig = swapper.swapToObject(yamlMaskTableRuleConfig);
+        assertThat(actualMaskTableRuleConfig.getName(), is("test_table"));
+        Collection<MaskColumnRuleConfiguration> actualColumns = actualMaskTableRuleConfig.getColumns();
+        assertThat(actualColumns.size(), is(1));
+        MaskColumnRuleConfiguration actualMaskColumnRuleConfig = actualColumns.iterator().next();
+        assertThat(actualMaskColumnRuleConfig.getLogicColumn(), is("mask_column"));
+        assertThat(actualMaskColumnRuleConfig.getMaskAlgorithm(), is("md5_mask"));
+        

Review Comment:
   Please remove this useless blank line.



-- 
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 #22825: add YamlMaskConfiguration and Swapper

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

   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/22825?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 [#22825](https://codecov.io/gh/apache/shardingsphere/pull/22825?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (b044306) into [master](https://codecov.io/gh/apache/shardingsphere/commit/c1845a7d1f8f808a4187b6ee1f169acf87ef25c6?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (c1845a7) will **increase** coverage by `0.04%`.
   > The diff coverage is `96.07%`.
   
   > :exclamation: Current head b044306 differs from pull request most recent head c87c34e. Consider uploading reports for the commit c87c34e to get more accurate results
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #22825      +/-   ##
   ============================================
   + Coverage     49.31%   49.35%   +0.04%     
   - Complexity     2448     2449       +1     
   ============================================
     Files          4131     4137       +6     
     Lines         57685    57736      +51     
     Branches       9891     9895       +4     
   ============================================
   + Hits          28448    28497      +49     
   - Misses        26784    26786       +2     
     Partials       2453     2453              
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/22825?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...re/mask/yaml/config/YamlMaskRuleConfiguration.java](https://codecov.io/gh/apache/shardingsphere/pull/22825/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-ZmVhdHVyZXMvbWFzay9jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9tYXNrL3lhbWwvY29uZmlnL1lhbWxNYXNrUnVsZUNvbmZpZ3VyYXRpb24uamF2YQ==) | `75.00% <75.00%> (ø)` | |
   | [...yaml/swapper/YamlMaskRuleConfigurationSwapper.java](https://codecov.io/gh/apache/shardingsphere/pull/22825/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-ZmVhdHVyZXMvbWFzay9jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9tYXNrL3lhbWwvc3dhcHBlci9ZYW1sTWFza1J1bGVDb25maWd1cmF0aW9uU3dhcHBlci5qYXZh) | `95.65% <95.65%> (ø)` | |
   | [...l/config/rule/YamlMaskColumnRuleConfiguration.java](https://codecov.io/gh/apache/shardingsphere/pull/22825/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-ZmVhdHVyZXMvbWFzay9jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9tYXNrL3lhbWwvY29uZmlnL3J1bGUvWWFtbE1hc2tDb2x1bW5SdWxlQ29uZmlndXJhdGlvbi5qYXZh) | `100.00% <100.00%> (ø)` | |
   | [...ml/config/rule/YamlMaskTableRuleConfiguration.java](https://codecov.io/gh/apache/shardingsphere/pull/22825/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-ZmVhdHVyZXMvbWFzay9jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9tYXNrL3lhbWwvY29uZmlnL3J1bGUvWWFtbE1hc2tUYWJsZVJ1bGVDb25maWd1cmF0aW9uLmphdmE=) | `100.00% <100.00%> (ø)` | |
   | [...r/rule/YamlMaskColumnRuleConfigurationSwapper.java](https://codecov.io/gh/apache/shardingsphere/pull/22825/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-ZmVhdHVyZXMvbWFzay9jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9tYXNrL3lhbWwvc3dhcHBlci9ydWxlL1lhbWxNYXNrQ29sdW1uUnVsZUNvbmZpZ3VyYXRpb25Td2FwcGVyLmphdmE=) | `100.00% <100.00%> (ø)` | |
   | [...er/rule/YamlMaskTableRuleConfigurationSwapper.java](https://codecov.io/gh/apache/shardingsphere/pull/22825/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-ZmVhdHVyZXMvbWFzay9jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9tYXNrL3lhbWwvc3dhcHBlci9ydWxlL1lhbWxNYXNrVGFibGVSdWxlQ29uZmlndXJhdGlvblN3YXBwZXIuamF2YQ==) | `100.00% <100.00%> (ø)` | |
   
   :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] strongduanmu merged pull request #22825: add YamlMaskConfiguration and Swapper

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


-- 
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] zzzwjZhang commented on a diff in pull request #22825: add YamlMaskConfiguration and Swapper

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


##########
features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/swapper/rule/YamlMaskTableRuleConfigurationSwapperTest.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.mask.yaml.swapper.rule;
+
+import org.apache.shardingsphere.mask.api.config.rule.MaskColumnRuleConfiguration;
+import org.apache.shardingsphere.mask.api.config.rule.MaskTableRuleConfiguration;
+import org.apache.shardingsphere.mask.yaml.config.rule.YamlMaskColumnRuleConfiguration;
+import org.apache.shardingsphere.mask.yaml.config.rule.YamlMaskTableRuleConfiguration;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public final class YamlMaskTableRuleConfigurationSwapperTest {
+    
+    private final YamlMaskTableRuleConfigurationSwapper swapper = new YamlMaskTableRuleConfigurationSwapper();
+    
+    @Test
+    public void assertSwapToYamlConfiguration() {
+        Collection<MaskColumnRuleConfiguration> encryptColumnRuleConfigs = Arrays.asList(
+                new MaskColumnRuleConfiguration("mask_column_1", "md5_mask"),
+                new MaskColumnRuleConfiguration("mask_column_2", "keep_from_x_to_y"),
+                new MaskColumnRuleConfiguration("mask_column_3", "keep_first_m_last_m"));
+        MaskTableRuleConfiguration encryptTableRuleConfig = new MaskTableRuleConfiguration("test_table", encryptColumnRuleConfigs);
+        YamlMaskTableRuleConfiguration actualYamlMaskTableRuleConfig = swapper.swapToYamlConfiguration(encryptTableRuleConfig);
+        assertThat(actualYamlMaskTableRuleConfig.getName(), is("test_table"));
+        Map<String, YamlMaskColumnRuleConfiguration> actualColumns = actualYamlMaskTableRuleConfig.getColumns();
+        assertThat(actualColumns.size(), is(3));
+        YamlMaskColumnRuleConfiguration actualYamlMaskColumnRuleConfigFirst = actualColumns.get("mask_column_1");
+        assertThat(actualYamlMaskColumnRuleConfigFirst.getMaskAlgorithm(), is("md5_mask"));
+        YamlMaskColumnRuleConfiguration actualYamlMaskColumnRuleConfigSecond = actualColumns.get("mask_column_2");
+        assertThat(actualYamlMaskColumnRuleConfigSecond.getMaskAlgorithm(), is("keep_from_x_to_y"));
+        YamlMaskColumnRuleConfiguration actualYamlMaskColumnRuleConfigThird = actualColumns.get("mask_column_3");
+        assertThat(actualYamlMaskColumnRuleConfigThird.getMaskAlgorithm(), is("keep_first_m_last_m"));
+    }
+    
+    @Test
+    public void assertSwapToObject() {
+        YamlMaskColumnRuleConfiguration encryptColumnRuleConfig = new YamlMaskColumnRuleConfiguration();
+        encryptColumnRuleConfig.setLogicColumn("mask_column");
+        encryptColumnRuleConfig.setMaskAlgorithm("md5_mask");
+        Map<String, YamlMaskColumnRuleConfiguration> columns = new LinkedHashMap<>(1);
+        columns.put("mask_column", encryptColumnRuleConfig);
+        YamlMaskTableRuleConfiguration yamlMaskTableRuleConfig = new YamlMaskTableRuleConfiguration();
+        yamlMaskTableRuleConfig.setName("test_table");
+        yamlMaskTableRuleConfig.setColumns(columns);
+        MaskTableRuleConfiguration actualMaskTableRuleConfig = swapper.swapToObject(yamlMaskTableRuleConfig);
+        assertThat(actualMaskTableRuleConfig.getName(), is("test_table"));
+        Collection<MaskColumnRuleConfiguration> actualColumns = actualMaskTableRuleConfig.getColumns();
+        assertThat(actualColumns.size(), is(1));
+        MaskColumnRuleConfiguration actualMaskColumnRuleConfig = actualColumns.iterator().next();
+        assertThat(actualMaskColumnRuleConfig.getLogicColumn(), is("mask_column"));
+        assertThat(actualMaskColumnRuleConfig.getMaskAlgorithm(), is("md5_mask"));
+        

Review Comment:
   fixed



-- 
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