Implement S3 logging

This commit is contained in:
Julian Raufelder 2021-04-30 11:03:12 +02:00
parent ee3787e8bb
commit b6b3cd2d9b
No known key found for this signature in database
GPG Key ID: 17EE71F6634E381D

@ -2,7 +2,10 @@ package org.cryptomator.data.cloud.s3;
import android.content.Context;
import com.amazonaws.Request;
import com.amazonaws.Response;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.handlers.RequestHandler2;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
@ -11,6 +14,8 @@ import com.amazonaws.services.s3.AmazonS3Client;
import org.cryptomator.domain.S3Cloud;
import org.cryptomator.util.crypto.CredentialCryptor;
import timber.log.Timber;
class S3ClientFactory {
private AmazonS3 apiClient;
@ -38,13 +43,41 @@ class S3ClientFactory {
client.setEndpoint(cloud.s3Endpoint());
}
client.addRequestHandler(new LoggingAwareRequestHandler());
return client;
}
private String decrypt(String password, Context context) {
return CredentialCryptor //
.getInstance(context) //
.decrypt(password);
}
private static class LoggingAwareRequestHandler extends RequestHandler2 {
@Override
public void beforeRequest(Request<?> request) {
Timber.tag("S3Client").d("Sending request (%s) %s", request.getAWSRequestMetrics().getTimingInfo().getStartTimeNano(), request.toString());
}
@Override
public void afterResponse(Request<?> request, Response<?> response) {
Timber.tag("S3Client").d( //
"Response received (%s) with status %s (%s)", //
request.getAWSRequestMetrics().getTimingInfo().getStartTimeNano(), //
response.getHttpResponse().getStatusText(), //
response.getHttpResponse().getStatusCode());
}
@Override
public void afterError(Request<?> request, Response<?> response, Exception e) {
Timber.tag("S3Client").e( //
e,
"Error occurred (%s) with status %s (%s)", //
request.getAWSRequestMetrics().getTimingInfo().getStartTimeNano(), //
response.getHttpResponse().getStatusText(), //
response.getHttpResponse().getStatusCode());
}
}
}