mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2025-01-10 16:20:59 +00:00
fixed fallback to sigv2 for bucket create and GCS
This commit is contained in:
parent
4d49ace06b
commit
966d229787
127
src/s3fs.cpp
127
src/s3fs.cpp
@ -804,7 +804,20 @@ static int do_create_bucket(void)
|
|||||||
headers_t meta;
|
headers_t meta;
|
||||||
|
|
||||||
S3fsCurl s3fscurl(true);
|
S3fsCurl s3fscurl(true);
|
||||||
return s3fscurl.PutRequest("/", meta, -1); // fd=-1 means for creating zero byte object.
|
long res = s3fscurl.PutRequest("/", meta, -1);
|
||||||
|
if(res < 0){ // fd=-1 means for creating zero byte object.
|
||||||
|
long responseCode = s3fscurl.GetLastResponseCode();
|
||||||
|
if((responseCode == 400 || responseCode == 403) && S3fsCurl::IsSignatureV4()){
|
||||||
|
LOWSYSLOGPRINT(LOG_ERR, "Could not connect, so retry to connect by signature version 2.");
|
||||||
|
FPRN("Could not connect, so retry to connect by signature version 2.");
|
||||||
|
S3fsCurl::SetSignatureV4(false);
|
||||||
|
|
||||||
|
// retry to check
|
||||||
|
s3fscurl.DestroyCurlHandle();
|
||||||
|
res = s3fscurl.PutRequest("/", meta, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// common function for creation of a plain object
|
// common function for creation of a plain object
|
||||||
@ -3561,84 +3574,74 @@ static int s3fs_check_service(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
S3fsCurl s3fscurl;
|
S3fsCurl s3fscurl;
|
||||||
if(-1 == s3fscurl.CheckBucket()){
|
int res;
|
||||||
fprintf(stderr, "%s: Failed to access bucket.\n", program_name.c_str());
|
if(0 > (res = s3fscurl.CheckBucket())){
|
||||||
return EXIT_FAILURE;
|
// get response code
|
||||||
}
|
long responseCode = s3fscurl.GetLastResponseCode();
|
||||||
long responseCode = s3fscurl.GetLastResponseCode();
|
|
||||||
|
|
||||||
if(responseCode == 400){
|
// check wrong endpoint, and automatically switch endpoint
|
||||||
if(!S3fsCurl::IsSignatureV4()){
|
if(responseCode == 400 && !is_specified_endpoint){
|
||||||
// signature version 2
|
// check region error
|
||||||
fprintf(stderr, "%s: Bad Request\n", program_name.c_str());
|
BodyData* body = s3fscurl.GetBodyData();
|
||||||
return EXIT_FAILURE;
|
string expectregion;
|
||||||
}
|
if(check_region_error(body->str(), expectregion)){
|
||||||
if(is_specified_endpoint){
|
// not specified endpoint, so try to connect to expected region.
|
||||||
// if specifies endpoint, do not retry to connect.
|
LOWSYSLOGPRINT(LOG_ERR, "Could not connect wrong region %s, so retry to connect region %s.", endpoint.c_str(), expectregion.c_str());
|
||||||
fprintf(stderr, "%s: Bad Request\n", program_name.c_str());
|
FPRN("Could not connect wrong region %s, so retry to connect region %s.", endpoint.c_str(), expectregion.c_str());
|
||||||
return EXIT_FAILURE;
|
endpoint = expectregion;
|
||||||
}
|
if(S3fsCurl::IsSignatureV4()){
|
||||||
|
if(host == "http://s3.amazonaws.com"){
|
||||||
|
host = "http://s3-" + endpoint + ".amazonaws.com";
|
||||||
|
}else if(host == "https://s3.amazonaws.com"){
|
||||||
|
host = "https://s3-" + endpoint + ".amazonaws.com";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check region error for signature version 4
|
// retry to check with new endpoint
|
||||||
BodyData* body = s3fscurl.GetBodyData();
|
s3fscurl.DestroyCurlHandle();
|
||||||
string expectregion;
|
res = s3fscurl.CheckBucket();
|
||||||
if(check_region_error(body->str(), expectregion)){
|
responseCode = s3fscurl.GetLastResponseCode();
|
||||||
// not specified endpoint, so try to connect to expected region.
|
|
||||||
LOWSYSLOGPRINT(LOG_ERR, "Could not connect wrong region %s, so retry to connect region %s.", endpoint.c_str(), expectregion.c_str());
|
|
||||||
FPRN("Could not connect wrong region %s, so retry to connect region %s.", endpoint.c_str(), expectregion.c_str());
|
|
||||||
endpoint = expectregion;
|
|
||||||
if (S3fsCurl::IsSignatureV4()) {
|
|
||||||
if (host == "http://s3.amazonaws.com") {
|
|
||||||
host = "http://s3-" + endpoint + ".amazonaws.com";
|
|
||||||
} else if (host == "https://s3.amazonaws.com") {
|
|
||||||
host = "https://s3-" + endpoint + ".amazonaws.com";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// retry to check
|
|
||||||
s3fscurl.DestroyCurlHandle();
|
|
||||||
if(-1 == s3fscurl.CheckBucket()){
|
|
||||||
fprintf(stderr, "%s: Failed to access bucket.\n", program_name.c_str());
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
responseCode = s3fscurl.GetLastResponseCode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(responseCode == 400){
|
// try signature v2
|
||||||
// retry to use sigv2
|
if(0 > res && (responseCode == 400 || responseCode == 403) && S3fsCurl::IsSignatureV4()){
|
||||||
|
// switch sigv2
|
||||||
LOWSYSLOGPRINT(LOG_ERR, "Could not connect, so retry to connect by signature version 2.");
|
LOWSYSLOGPRINT(LOG_ERR, "Could not connect, so retry to connect by signature version 2.");
|
||||||
FPRN("Could not connect, so retry to connect by signature version 2.");
|
FPRN("Could not connect, so retry to connect by signature version 2.");
|
||||||
S3fsCurl::SetSignatureV4(false);
|
S3fsCurl::SetSignatureV4(false);
|
||||||
|
|
||||||
// retry to check
|
// retry to check with sigv2
|
||||||
s3fscurl.DestroyCurlHandle();
|
s3fscurl.DestroyCurlHandle();
|
||||||
if(-1 == s3fscurl.CheckBucket()){
|
res = s3fscurl.CheckBucket();
|
||||||
fprintf(stderr, "%s: Failed to access bucket.\n", program_name.c_str());
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
responseCode = s3fscurl.GetLastResponseCode();
|
responseCode = s3fscurl.GetLastResponseCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check errors(after retrying)
|
||||||
|
if(0 > res && responseCode != 200 && responseCode != 301){
|
||||||
if(responseCode == 400){
|
if(responseCode == 400){
|
||||||
fprintf(stderr, "%s: Bad Request\n", program_name.c_str());
|
fprintf(stderr, "%s: Bad Request\n", program_name.c_str());
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
if(responseCode == 403){
|
||||||
|
fprintf(stderr, "%s: invalid credentials\n", program_name.c_str());
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
if(responseCode == 404){
|
||||||
|
fprintf(stderr, "%s: bucket not found\n", program_name.c_str());
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
// unable to connect
|
||||||
|
if(responseCode == CURLE_OPERATION_TIMEDOUT){
|
||||||
|
fprintf(stderr, "%s: unable to connect bucket and timeout\n", program_name.c_str());
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// another error
|
||||||
|
fprintf(stderr, "%s: unable to connect\n", program_name.c_str());
|
||||||
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(responseCode == 403){
|
|
||||||
fprintf(stderr, "%s: invalid credentials\n", program_name.c_str());
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
if(responseCode == 404){
|
|
||||||
fprintf(stderr, "%s: bucket not found\n", program_name.c_str());
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
// unable to connect
|
|
||||||
if(responseCode == CURLE_OPERATION_TIMEDOUT){
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
if(responseCode != 200 && responseCode != 301){
|
|
||||||
fprintf(stderr, "%s: unable to connect\n", program_name.c_str());
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// make sure remote mountpath exists and is a directory
|
// make sure remote mountpath exists and is a directory
|
||||||
if(mount_prefix.size() > 0){
|
if(mount_prefix.size() > 0){
|
||||||
|
Loading…
Reference in New Issue
Block a user