-
Notifications
You must be signed in to change notification settings - Fork 383
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
[#5842] feat(core): supports credential REST endpoint in Gravitino server #5841
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
core/src/main/java/org/apache/gravitino/catalog/CredentialManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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.catalog; | ||
|
||
import java.util.List; | ||
import org.apache.commons.lang3.NotImplementedException; | ||
import org.apache.gravitino.EntityStore; | ||
import org.apache.gravitino.NameIdentifier; | ||
import org.apache.gravitino.connector.BaseCatalog; | ||
import org.apache.gravitino.credential.Credential; | ||
import org.apache.gravitino.exceptions.NoSuchCatalogException; | ||
import org.apache.gravitino.storage.IdGenerator; | ||
import org.apache.gravitino.utils.NameIdentifierUtil; | ||
|
||
/** Get credentials with the specific catalog classloader. */ | ||
public class CredentialManager extends OperationDispatcher { | ||
|
||
public CredentialManager( | ||
CatalogManager catalogManager, EntityStore store, IdGenerator idGenerator) { | ||
super(catalogManager, store, idGenerator); | ||
} | ||
|
||
public List<Credential> getCredentials(NameIdentifier identifier) { | ||
return doWithCatalog( | ||
NameIdentifierUtil.getCatalogIdentifier(identifier), | ||
c -> getCredentials(c.catalog(), identifier), | ||
NoSuchCatalogException.class); | ||
} | ||
|
||
private List<Credential> getCredentials(BaseCatalog catalog, NameIdentifier identifier) { | ||
throw new NotImplementedException( | ||
String.format( | ||
"Load credentials is not implemented for catalog: %s, identifier: %s", | ||
catalog.name(), identifier)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...rc/main/java/org/apache/gravitino/server/web/rest/MetadataObjectCredentialOperations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* 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.server.web.rest; | ||
|
||
import com.codahale.metrics.annotation.ResponseMetered; | ||
import com.codahale.metrics.annotation.Timed; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import javax.inject.Inject; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.Response; | ||
import org.apache.gravitino.MetadataObject; | ||
import org.apache.gravitino.MetadataObjects; | ||
import org.apache.gravitino.NameIdentifier; | ||
import org.apache.gravitino.catalog.CredentialManager; | ||
import org.apache.gravitino.credential.Credential; | ||
import org.apache.gravitino.dto.credential.CredentialDTO; | ||
import org.apache.gravitino.dto.responses.CredentialResponse; | ||
import org.apache.gravitino.dto.util.DTOConverters; | ||
import org.apache.gravitino.metrics.MetricNames; | ||
import org.apache.gravitino.server.web.Utils; | ||
import org.apache.gravitino.utils.MetadataObjectUtil; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@Path("/metalakes/{metalake}/objects/{type}/{fullName}/credentials") | ||
public class MetadataObjectCredentialOperations { | ||
|
||
private static final Logger LOG = | ||
LoggerFactory.getLogger(MetadataObjectCredentialOperations.class); | ||
|
||
private CredentialManager credentialManager; | ||
|
||
@SuppressWarnings("unused") | ||
@Context | ||
private HttpServletRequest httpRequest; | ||
|
||
@Inject | ||
public MetadataObjectCredentialOperations(CredentialManager dispatcher) { | ||
this.credentialManager = dispatcher; | ||
} | ||
|
||
@GET | ||
@Produces("application/vnd.gravitino.v1+json") | ||
@Timed(name = "get-credentials." + MetricNames.HTTP_PROCESS_DURATION, absolute = true) | ||
@ResponseMetered(name = "get-credentials", absolute = true) | ||
public Response getCredentials( | ||
@PathParam("metalake") String metalake, | ||
@PathParam("type") String type, | ||
@PathParam("fullName") String fullName) { | ||
LOG.info( | ||
"Received get credentials request for object type: {}, full name: {} under metalake: {}", | ||
type, | ||
fullName, | ||
metalake); | ||
|
||
try { | ||
return Utils.doAs( | ||
httpRequest, | ||
() -> { | ||
MetadataObject object = | ||
MetadataObjects.parse( | ||
fullName, MetadataObject.Type.valueOf(type.toUpperCase(Locale.ROOT))); | ||
|
||
NameIdentifier identifier = MetadataObjectUtil.toEntityIdent(metalake, object); | ||
List<Credential> credentials = credentialManager.getCredentials(identifier); | ||
if (credentials == null) { | ||
return Utils.ok(new CredentialResponse(new CredentialDTO[0])); | ||
} | ||
return Utils.ok( | ||
new CredentialResponse( | ||
DTOConverters.toDTO(credentials.toArray(new Credential[credentials.size()])))); | ||
}); | ||
} catch (Exception e) { | ||
return ExceptionHandlers.handleCredentialException(OperationType.GET, fullName, e); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure that this exception will not contain any sensitive information?
The control flow shows that some of these information are logged and printed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, the sensitive credential information is not logged.