-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for Google Application Default Credentials (#8394)
* fixed conflicts Signed-off-by: fahadshamiinsta <[email protected]> * applying spotless Java check Signed-off-by: fahadshamiinsta <[email protected]> * added a comment to test helper method Signed-off-by: fahadshamiinsta <[email protected]> * added a comment to GoogleApplicationDefaultCredentials class with document reference Signed-off-by: fahadshamiinsta <[email protected]> * to rerun gradle checks Signed-off-by: fahadshamiinsta <[email protected]> * increasing coverage by adding another test Signed-off-by: fahadshamiinsta <[email protected]> * test name change Signed-off-by: fahadshamiinsta <[email protected]> * rerun ci Signed-off-by: fahadshamiinsta <[email protected]> * rerun ci Signed-off-by: fahadshamiinsta <[email protected]> * force push to rerun ci Signed-off-by: fahadshamiinsta <[email protected]> * pushing to trigger ci checks Signed-off-by: fahadshamiinsta <[email protected]> --------- Signed-off-by: fahadshamiinsta <[email protected]>
- Loading branch information
1 parent
c132db9
commit 4c283a7
Showing
4 changed files
with
157 additions
and
29 deletions.
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
33 changes: 33 additions & 0 deletions
33
...cs/src/main/java/org/opensearch/repositories/gcs/GoogleApplicationDefaultCredentials.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,33 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.repositories.gcs; | ||
|
||
import com.google.auth.oauth2.GoogleCredentials; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* This class facilitates to fetch Application Default Credentials | ||
* see <a href="https://cloud.google.com/docs/authentication/application-default-credentials">How Application Default Credentials works</a> | ||
*/ | ||
public class GoogleApplicationDefaultCredentials { | ||
private static final Logger logger = LogManager.getLogger(GoogleApplicationDefaultCredentials.class); | ||
|
||
public GoogleCredentials get() { | ||
GoogleCredentials credentials = null; | ||
try { | ||
credentials = SocketAccess.doPrivilegedIOException(GoogleCredentials::getApplicationDefault); | ||
} catch (IOException e) { | ||
logger.error("Failed to retrieve \"Application Default Credentials\"", e); | ||
} | ||
return credentials; | ||
} | ||
} |
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