I want to access my GCP Cloud Storage bucket using the Java AWS S3 API for interoperability, so don't want to use Google APIs in my code. I have seen examples of Basic Authentication using the S3 API when accessing Google Cloud Storage. I want to authenticate via my service account json key ( OAuth 2 ) instead of creating another HMAC key for Cloud Storage. Can anyone point me to a example using Java please. What is the recommended approach - I thought the json oauth 2 authentication is a good one.
Basic authentication goes like this:
// Create a BasicAWSCredentials using Cloud Storage HMAC credentials.
BasicAWSCredentials googleCreds =
new BasicAWSCredentials(googleAccessKeyId, googleAccessKeySecret);
// Create a new client and do the following:
// 1. Change the endpoint URL to use the Google Cloud Storage XML API endpoint.
// 2. Use Cloud Storage HMAC Credentials.
AmazonS3 interopClient =
AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(
new AwsClientBuilder.EndpointConfiguration("https://storage.googleapis.com", "auto"))
.withCredentials(new AWSStaticCredentialsProvider(googleCreds))
.build();
but I want to authenticate with the json key generated for the service account. The service account has access to Cloud Storage Viewer and Cloud Storage Creator.
Thanks
question from:
https://stackoverflow.com/questions/65902663/s3-api-to-access-cloud-storage-using-service-account-with-java 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…