roryqi commented on code in PR #12332: URL: https://github.com/apache/gravitino/pull/12332#discussion_r3703777141
########## core/src/main/java/org/apache/gravitino/authorization/UserGroupIdManager.java: ########## @@ -0,0 +1,156 @@ +/* + * 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.gravitino.authorization; + +import java.io.IOException; +import org.apache.gravitino.Entity; +import org.apache.gravitino.EntityStore; +import org.apache.gravitino.exceptions.NoSuchEntityException; +import org.apache.gravitino.exceptions.NoSuchUserException; +import org.apache.gravitino.meta.UserEntity; +import org.apache.gravitino.storage.IdGenerator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** Manages user and group operations keyed by Gravitino-assigned id within a metalake. */ +class UserGroupIdManager extends UserGroupManager { + + private static final Logger LOG = LoggerFactory.getLogger(UserGroupIdManager.class); + + /** + * Creates a {@link UserGroupIdManager} instance. + * + * @param store the entity store + * @param idGenerator the id generator + */ + UserGroupIdManager(EntityStore store, IdGenerator idGenerator) { + super(store, idGenerator); + } + + boolean removeUserById(String metalake, long userId) { + try { + return store + .idOperations() + .deleteById(AuthorizationUtils.ofUserId(metalake, userId), Entity.EntityType.USER); + } catch (IOException ioe) { + LOG.error( + "Removing user with id {} in the metalake {} failed due to storage issues", + userId, + metalake, + ioe); + throw new RuntimeException(ioe); + } + } + + User getUserById(String metalake, long userId) throws NoSuchUserException { + try { + return store + .idOperations() + .getById( + AuthorizationUtils.ofUserId(metalake, userId), + Entity.EntityType.USER, + UserEntity.class); + } catch (NoSuchEntityException e) { + LOG.warn("User with id {} does not exist in the metalake {}", userId, metalake, e); + throw new NoSuchUserException( + AuthorizationUtils.USER_WITH_ID_DOES_NOT_EXIST_MSG, userId, metalake); + } catch (IOException ioe) { + LOG.error("Getting user with id {} failed due to storage issues", userId, ioe); + throw new RuntimeException(ioe); + } + } + + User enableUserById(String metalake, long userId) throws NoSuchUserException { + return updateEnabledById(metalake, userId, true); + } + + User disableUserById(String metalake, long userId) throws NoSuchUserException { + return updateEnabledById(metalake, userId, false); + } + + User updateUserExternalIdById(String metalake, long userId, String newExternalId) Review Comment: Do we need this api? External id should be immutable in my view. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
