mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-02 19:48:17 +00:00
Remove UserRepository constructor which could cause NPE (#8047)
This commit is contained in:
parent
b6ff10f781
commit
13b76dfd88
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright 2021 Collate
|
||||
* Licensed 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.openmetadata.service;
|
||||
|
||||
import com.codahale.metrics.health.HealthCheck;
|
||||
import java.io.IOException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jdbi.v3.core.Jdbi;
|
||||
import org.openmetadata.service.jdbi3.CollectionDAO;
|
||||
import org.openmetadata.service.jdbi3.ListFilter;
|
||||
import org.openmetadata.service.jdbi3.UserRepository;
|
||||
import org.openmetadata.service.util.EntityUtil.Fields;
|
||||
|
||||
@Slf4j
|
||||
public class CatalogHealthCheck extends HealthCheck {
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public CatalogHealthCheck(Jdbi jdbi) {
|
||||
super();
|
||||
CollectionDAO repo = jdbi.onDemand(CollectionDAO.class);
|
||||
this.userRepository = new UserRepository(repo);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Result check() {
|
||||
try {
|
||||
ListFilter filter = new ListFilter();
|
||||
userRepository.listAfter(null, Fields.EMPTY_FIELDS, filter, 1, null);
|
||||
return Result.healthy();
|
||||
} catch (IOException e) {
|
||||
LOG.error("Health check error {}", e.getMessage());
|
||||
return Result.unhealthy(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -74,10 +74,6 @@ public class UserRepository extends EntityRepository<User> {
|
||||
return new Fields(allowedFields, fields);
|
||||
}
|
||||
|
||||
public UserRepository(CollectionDAO dao) {
|
||||
this(dao, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityReference getOriginalOwner(User entity) {
|
||||
// For User entity, the entity and the owner are the same
|
||||
|
||||
@ -60,6 +60,7 @@ import org.openmetadata.service.jdbi3.EntityRepository;
|
||||
import org.openmetadata.service.jdbi3.ListFilter;
|
||||
import org.openmetadata.service.jdbi3.UserRepository;
|
||||
import org.openmetadata.service.resources.Collection;
|
||||
import org.openmetadata.service.secrets.SecretsManager;
|
||||
import org.openmetadata.service.security.Authorizer;
|
||||
import org.openmetadata.service.util.ElasticSearchClientUtils;
|
||||
import org.openmetadata.service.util.EntityUtil;
|
||||
@ -83,14 +84,15 @@ public class BuildSearchIndexResource {
|
||||
private final ExecutorService threadScheduler;
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Collection(constructorType = Collection.ConstructorType.DAO_AUTH_CONFIG)
|
||||
public BuildSearchIndexResource(CollectionDAO dao, Authorizer authorizer, OpenMetadataApplicationConfig config) {
|
||||
@Collection(constructorType = Collection.ConstructorType.DAO_AUTH_SM_CONFIG)
|
||||
public BuildSearchIndexResource(
|
||||
CollectionDAO dao, Authorizer authorizer, SecretsManager secretsManager, OpenMetadataApplicationConfig config) {
|
||||
if (config.getElasticSearchConfiguration() != null) {
|
||||
this.client = ElasticSearchClientUtils.createElasticSearchClient(config.getElasticSearchConfiguration());
|
||||
this.elasticSearchIndexDefinition = new ElasticSearchIndexDefinition(client, dao);
|
||||
}
|
||||
this.dao = dao;
|
||||
this.userRepository = new UserRepository(dao);
|
||||
this.userRepository = new UserRepository(dao, secretsManager);
|
||||
this.authorizer = authorizer;
|
||||
this.threadScheduler =
|
||||
new ThreadPoolExecutor(
|
||||
|
||||
@ -56,6 +56,8 @@ import org.openmetadata.service.fernet.Fernet;
|
||||
import org.openmetadata.service.jdbi3.CollectionDAO;
|
||||
import org.openmetadata.service.jdbi3.UserRepository;
|
||||
import org.openmetadata.service.jdbi3.locator.ConnectionAwareAnnotationSqlLocator;
|
||||
import org.openmetadata.service.secrets.SecretsManager;
|
||||
import org.openmetadata.service.secrets.SecretsManagerFactory;
|
||||
import org.openmetadata.service.security.jwt.JWTTokenGenerator;
|
||||
|
||||
public final class TablesInitializer {
|
||||
@ -354,7 +356,7 @@ public final class TablesInitializer {
|
||||
user.setAuthenticationMechanism(authenticationMechanism);
|
||||
}
|
||||
try {
|
||||
addOrUpdateUser(user, jdbi);
|
||||
addOrUpdateUser(user, jdbi, config);
|
||||
if (jwtAuthMechanism != null) {
|
||||
printToConsoleMandatory(JsonUtils.pojoToJson(user));
|
||||
}
|
||||
@ -392,7 +394,9 @@ public final class TablesInitializer {
|
||||
}
|
||||
try {
|
||||
CollectionDAO daoObject = jdbi.onDemand(CollectionDAO.class);
|
||||
UserRepository userRepository = new UserRepository(daoObject);
|
||||
SecretsManager secretsManager =
|
||||
SecretsManagerFactory.createSecretsManager(config.getSecretsManagerConfiguration(), config.getClusterName());
|
||||
UserRepository userRepository = new UserRepository(daoObject, secretsManager);
|
||||
RestUtil.PutResponse<User> addedUser = userRepository.createOrUpdate(null, user);
|
||||
printToConsoleInDebug("Updated user entry: " + addedUser.getEntity());
|
||||
if (jwtAuthMechanism != null) {
|
||||
@ -403,9 +407,11 @@ public final class TablesInitializer {
|
||||
}
|
||||
}
|
||||
|
||||
private static void addOrUpdateUser(User user, Jdbi jdbi) throws Exception {
|
||||
private static void addOrUpdateUser(User user, Jdbi jdbi, OpenMetadataApplicationConfig config) throws Exception {
|
||||
CollectionDAO daoObject = jdbi.onDemand(CollectionDAO.class);
|
||||
UserRepository userRepository = new UserRepository(daoObject);
|
||||
SecretsManager secretsManager =
|
||||
SecretsManagerFactory.createSecretsManager(config.getSecretsManagerConfiguration(), config.getClusterName());
|
||||
UserRepository userRepository = new UserRepository(daoObject, secretsManager);
|
||||
User addedUser = userRepository.create(null, user);
|
||||
printToConsoleInDebug("Added user entry: " + addedUser.getName());
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user