Exemplo n.º 1
0
int __s3fs_test_bucket(const char *bucketName)
{
    S3_init();

    S3ResponseHandler responseHandler =
    {
        &responsePropertiesCallback, &responseCompleteCallback
    };

    char locationConstraint[64];
    do {
        S3_test_bucket(protocolG, uriStyleG, accessKeyIdG, secretAccessKeyG,
                       0, bucketName, sizeof(locationConstraint),
                       locationConstraint, 0, &responseHandler, 0);
    } while (S3_status_is_retryable(statusG) && should_retry());

    const char *reason = "Unknown";
    int result = statusG == S3StatusOK ? 1 : 0;

    switch (statusG) {
    case S3StatusOK:
        // bucket exists
        reason = locationConstraint[0] ? locationConstraint : "USA";
        break;
    case S3StatusErrorNoSuchBucket:
        reason = "Does Not Exist";
        break;
    case S3StatusErrorAccessDenied:
        reason = "Access Denied";
        break;
    default:
        break;
    }

    fprintf(stderr, "S3 test_bucket: %s\n", reason);

    S3_deinitialize();

    return result;
}
Exemplo n.º 2
0
Arquivo: wcd.c Projeto: flsafe/Webdir
static int bucket_exists(char *bname){

    s3_init();

    if (! load_settings()){
			printf("Configure your ~/.webdir-settings file!\n");
			exit(1);
		}

    char skey[STR];
    get_secret_key(skey);
    char akey[STR];
    get_access_key(akey);
		char hostname[STR];
		get_host(hostname);

    S3ResponseHandler res_handler = {
        &res_properties, &res_complete/* Can properties be null?*/
    };

    char loc_constraint[STR];
    do {
        S3_test_bucket(S3ProtocolHTTPS, 
                       S3UriStylePath, 
                       akey, 
                       skey,
                       hostname, 
                       bname, 
                       sizeof(loc_constraint),
                       loc_constraint, 
                       0, 
                       &res_handler, 
                       0);
    } while (S3_status_is_retryable(RequestStatus) && should_retry());


    S3_deinitialize();

		return RequestStatus == S3StatusOK; // Bucket exists
}