Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: Cleanups and upgrades. #23

Merged
merged 5 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# eJMask Contribution Guidelines

Thank you so much for wanting to contribute to eJMask! Here are a few important things you should know about contributing:

1. API changes require discussion, use cases, etc. Code comes later.
2. Pull requests are great for small fixes for bugs, documentation, etc.
3. Code contributions require updating relevant documentation.

This project takes all contributions through [pull requests](https://help.github.com/articles/using-pull-requests). Code should *not* be pushed directly to `master`.

The following guidelines apply to all contributors.

## Types of contributions

All types of contributions, from minor documentation changes to new capabilities, performance improvements, extending tests, etc., are all welcome.

## Making Changes

* Fork the `eJMask` repository.
* Make your changes and push them to a topic branch in your fork.
* See our commit message guidelines further down in this document.
* Submit a pull request to the repository.
* Update the `eJMask` GitHub issue with the generated pull request link.

## General Guidelines

* Only one logical change per commit.
* Do not mix whitespace changes with functional code changes.
* Do not mix unrelated functional changes.
* When writing a commit message:
* Describe *why* a change is being made.
* Do not assume the reviewer understands what the original problem was.
* Do not assume the code is self-evident/self-documenting.
* Describe any limitations of the current code.
* Any significant changes should be accompanied by tests.
* The project already has good test coverage, so look at some of the existing tests if you're unsure how to go about it.
* Please squash all commits for a change into a single commit (this can be done using `git rebase -i`).

## Commit Message Guidelines

* Provide a brief description of the change in the first line.
* Insert a single blank line after the first line.
* Provide a detailed description of the change in the following lines, breaking paragraphs where needed.
* The first line should be limited to 50 characters and should not end in a period.
* Subsequent lines should be wrapped at 72 characters.

## Java Guidelines

- Please make sure:
* Source code is always formatted before commit.
* You remove all unused imports.
* Usage of `@Override`.
- Please avoid:
* Trailing whitespace on all lines.
* All unused imports.
* Empty blocks.
66 changes: 0 additions & 66 deletions CONTRIBUTING.adoc

This file was deleted.

5 changes: 3 additions & 2 deletions ejmask-api/pom.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" ?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<?xml version="1.0" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ebay.ejmask</groupId>
<artifactId>ejmask-parent</artifactId>
<version>1.1.0</version>
<version>1.2.0-SNAPSHOT</version>
</parent>
prasanthkv marked this conversation as resolved.
Show resolved Hide resolved

<artifactId>ejmask-api</artifactId>
Expand Down
28 changes: 15 additions & 13 deletions ejmask-api/src/main/java/com/ebay/ejmask/api/IPatternBuilder.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.ebay.ejmask.api;

import java.util.Arrays;
import java.util.List;
import java.util.Collection;
import java.util.Collections;

/**
* Copyright (c) 2023 eBay Inc.
Expand All @@ -21,6 +21,15 @@

public interface IPatternBuilder {

/**
* Set true if the build can be groupable.
*
* @return true if groupable
*/
default boolean isGroupable() {
return true;
}

/**
* Build pattern to match
*
Expand All @@ -41,19 +50,12 @@ public interface IPatternBuilder {

/**
* Build pattern to match
*
* @param visibleCharacters as no of characters to be visible.
* @param fieldNames as list of field names
* @param fieldNames as list of field names
* @return list of pattern entities
*/
default List<PatternEntity> buildPatternEntities(int visibleCharacters, String... fieldNames) {
return Arrays.asList(new PatternEntity(buildPattern(visibleCharacters, fieldNames), buildReplacement(visibleCharacters, fieldNames)));
}
/**
* Set true if the build can be groupable.
*
* @return true if groupable
*/
default boolean isGroupable() {
return true;
default Collection<PatternEntity> buildPatternEntities(int visibleCharacters, String... fieldNames) {
return Collections.singletonList(new PatternEntity(this.buildPattern(visibleCharacters, fieldNames), this.buildReplacement(visibleCharacters, fieldNames)));
}
}
64 changes: 32 additions & 32 deletions ejmask-api/src/main/java/com/ebay/ejmask/api/MaskingPattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@ public MaskingPattern(int order, String regex, String replacement) {
this.replacement = replacement;
}

/**
* Get the value of order
*
* @return the value of order
*/
public int getOrder() { return order; }

/**
* Get the value of pattern
*
* @return the value of pattern
*/
public Pattern getPattern() { return pattern; }

/**
* Get the value of replacement
*
* @return the value of replacement
*/
public String getReplacement() { return replacement; }

/**
* Replace sensitive data with mask
*
Expand Down Expand Up @@ -71,6 +92,17 @@ public int compareTo(MaskingPattern that) {
return that.order > this.order ? -1 : 1;
}

/**
* Returns the hash code of the given instance
*
* @return the hash code of this object.
* @see Object#hashCode
*/
@Override
public int hashCode() {
return Objects.hashCode(this);
}

/**
* Indicates whether some other object is "equal to" this one.
*
Expand All @@ -89,17 +121,6 @@ public boolean equals(Object obj) {
&& Objects.equals(this.pattern, that.pattern);
}

/**
* Returns the hash code of the given instance
*
* @return the hash code of this object.
* @see Object#hashCode
*/
@Override
public int hashCode() {
return Objects.hashCode(this);
}

/**
* Returns the string representation of this pattern.
*
Expand All @@ -109,25 +130,4 @@ public int hashCode() {
public String toString() {
return "order=" + this.order + ";pattern=" + this.pattern.pattern() + ";replacement=" + this.replacement;
}

/**
* Get the value of order
*
* @return the value of order
*/
public int getOrder() { return order; }

/**
* Get the value of pattern
*
* @return the value of pattern
*/
public Pattern getPattern() { return pattern; }

/**
* Get the value of replacement
*
* @return the value of replacement
*/
public String getReplacement() { return replacement; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
public class PatternEntity {

private final String patternTemplate;

private final String replacementTemplate;

/**
Expand Down
5 changes: 3 additions & 2 deletions ejmask-bom/pom.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" ?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<?xml version="1.0" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ebay.ejmask</groupId>
<artifactId>ejmask-parent</artifactId>
<version>1.1.0</version>
<version>1.2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
5 changes: 3 additions & 2 deletions ejmask-core/pom.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" ?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<?xml version="1.0" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ebay.ejmask</groupId>
<artifactId>ejmask-parent</artifactId>
<version>1.1.0</version>
<version>1.2.0-SNAPSHOT</version>
</parent>

<artifactId>ejmask-core</artifactId>
Expand Down
15 changes: 11 additions & 4 deletions ejmask-core/src/main/java/com/ebay/ejmask/core/EJMask.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static void addFilter(int order, String regex, String substitute) {
* @param content as sting which need to be masked
* @return cleaned up string
*/
public static String mask(final String content) {
public static String mask(String content) {
return mask(content, true, true);
}

Expand Down Expand Up @@ -130,7 +130,7 @@ public static String mask(String content, boolean preProcessingRequired, boolean
* @param content as sting which need to be masked
* @return cleaned up string
*/
public static String maskWithOutProcessor(final String content) {
public static String maskWithOutProcessor(String content) {
return mask(content, false, false);
}

Expand All @@ -142,7 +142,7 @@ public static String maskWithOutProcessor(final String content) {
* @param postProcessingRequired as boolean whether post-processing step required
* @return cleaned up string
*/
public static String mask(final String content, boolean preProcessingRequired, boolean postProcessingRequired) {
public static String mask(String content, boolean preProcessingRequired, boolean postProcessingRequired) {
try {
//filterPattern on original content
if (CommonUtils.isBlank(content)) {
Expand Down Expand Up @@ -171,7 +171,7 @@ public static String mask(final String content, boolean preProcessingRequired, b
*/
private static String process(String content, Operation operation) {
for (IContentProcessor processor : PROCESSORS) {
final ProcessorResult result = operation.process(processor, content);
ProcessorResult result = operation.process(processor, content);
if (result != null) {
if (CommonUtils.isNotBlank(result.getContent())) {
content = result.getContent();
Expand Down Expand Up @@ -203,6 +203,13 @@ private static String maskSensitiveContent(String content) {
*/
@FunctionalInterface
interface Operation {
/**
* Process the given content.
*
* @param processor the processor
* @param content the content
* @return the result
*/
ProcessorResult process(IContentProcessor processor, String content);
}
}
Expand Down
Loading
Loading