mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-18 05:19:34 +00:00
Remove unnecessary singletons (#11713)
This commit is contained in:
parent
6509a3670a
commit
ac8498ab80
@ -18,7 +18,6 @@ import lombok.Getter;
|
|||||||
import org.openmetadata.schema.security.SecurityConfiguration;
|
import org.openmetadata.schema.security.SecurityConfiguration;
|
||||||
|
|
||||||
public class EntityMaskerFactory {
|
public class EntityMaskerFactory {
|
||||||
|
|
||||||
@Getter private static EntityMasker entityMasker;
|
@Getter private static EntityMasker entityMasker;
|
||||||
|
|
||||||
private EntityMaskerFactory() {}
|
private EntityMaskerFactory() {}
|
||||||
@ -28,11 +27,8 @@ public class EntityMaskerFactory {
|
|||||||
if (entityMasker != null) {
|
if (entityMasker != null) {
|
||||||
return entityMasker;
|
return entityMasker;
|
||||||
}
|
}
|
||||||
if (Boolean.TRUE.equals(config.getMaskPasswordsAPI())) {
|
entityMasker =
|
||||||
entityMasker = PasswordEntityMasker.getInstance();
|
Boolean.TRUE.equals(config.getMaskPasswordsAPI()) ? new PasswordEntityMasker() : new NoopEntityMasker();
|
||||||
} else {
|
|
||||||
entityMasker = NoopEntityMasker.getInstance();
|
|
||||||
}
|
|
||||||
return entityMasker;
|
return entityMasker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,17 +19,7 @@ import org.openmetadata.schema.entity.services.ingestionPipelines.IngestionPipel
|
|||||||
import org.openmetadata.schema.entity.teams.AuthenticationMechanism;
|
import org.openmetadata.schema.entity.teams.AuthenticationMechanism;
|
||||||
|
|
||||||
public class NoopEntityMasker extends EntityMasker {
|
public class NoopEntityMasker extends EntityMasker {
|
||||||
|
protected NoopEntityMasker() {}
|
||||||
private static NoopEntityMasker INSTANCE;
|
|
||||||
|
|
||||||
private NoopEntityMasker() {}
|
|
||||||
|
|
||||||
public static NoopEntityMasker getInstance() {
|
|
||||||
if (INSTANCE == null) {
|
|
||||||
INSTANCE = new NoopEntityMasker();
|
|
||||||
}
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object maskServiceConnectionConfig(Object connectionConfig, String connectionType, ServiceType serviceType) {
|
public Object maskServiceConnectionConfig(Object connectionConfig, String connectionType, ServiceType serviceType) {
|
||||||
|
@ -31,21 +31,10 @@ import org.openmetadata.service.util.IngestionPipelineBuilder;
|
|||||||
import org.openmetadata.service.util.ReflectionUtil;
|
import org.openmetadata.service.util.ReflectionUtil;
|
||||||
|
|
||||||
public class PasswordEntityMasker extends EntityMasker {
|
public class PasswordEntityMasker extends EntityMasker {
|
||||||
|
|
||||||
private static PasswordEntityMasker INSTANCE;
|
|
||||||
|
|
||||||
protected static final String PASSWORD_MASK = "*********";
|
protected static final String PASSWORD_MASK = "*********";
|
||||||
|
|
||||||
private static final String NEW_KEY = "";
|
private static final String NEW_KEY = "";
|
||||||
|
|
||||||
private PasswordEntityMasker() {}
|
protected PasswordEntityMasker() {}
|
||||||
|
|
||||||
public static PasswordEntityMasker getInstance() {
|
|
||||||
if (INSTANCE == null) {
|
|
||||||
INSTANCE = new PasswordEntityMasker();
|
|
||||||
}
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object maskServiceConnectionConfig(Object connectionConfig, String connectionType, ServiceType serviceType) {
|
public Object maskServiceConnectionConfig(Object connectionConfig, String connectionType, ServiceType serviceType) {
|
||||||
if (connectionConfig != null) {
|
if (connectionConfig != null) {
|
||||||
@ -252,9 +241,6 @@ public class PasswordEntityMasker extends EntityMasker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String createKey(String previousKey, String key) {
|
private String createKey(String previousKey, String key) {
|
||||||
if (NEW_KEY.equals(previousKey)) {
|
return NEW_KEY.equals(previousKey) ? key : previousKey + "." + key;
|
||||||
return key;
|
|
||||||
}
|
|
||||||
return previousKey + "." + key;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,10 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.openmetadata.schema.security.SecurityConfiguration;
|
import org.openmetadata.schema.security.SecurityConfiguration;
|
||||||
|
|
||||||
public class EntityMaskerFactoryTest {
|
public class EntityMaskerFactoryTest {
|
||||||
|
private static final SecurityConfiguration CONFIG = new SecurityConfiguration();
|
||||||
SecurityConfiguration config;
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
config = new SecurityConfiguration();
|
|
||||||
EntityMaskerFactory.setEntityMasker(null);
|
EntityMaskerFactory.setEntityMasker(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,12 +22,13 @@ public class EntityMaskerFactoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testInitWithNoopEntityMasker() {
|
void testInitWithNoopEntityMasker() {
|
||||||
assertTrue(EntityMaskerFactory.createEntityMasker(config) instanceof NoopEntityMasker);
|
CONFIG.setMaskPasswordsAPI(false);
|
||||||
|
assertTrue(EntityMaskerFactory.createEntityMasker(CONFIG) instanceof NoopEntityMasker);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testInitWithPasswordEntityMasker() {
|
void testInitWithPasswordEntityMasker() {
|
||||||
config.setMaskPasswordsAPI(true);
|
CONFIG.setMaskPasswordsAPI(true);
|
||||||
assertTrue(EntityMaskerFactory.createEntityMasker(config) instanceof PasswordEntityMasker);
|
assertTrue(EntityMaskerFactory.createEntityMasker(CONFIG) instanceof PasswordEntityMasker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user