int main(int argc, char **argv)
{
    int rc;

    strlcpy(cmd_name, basename(argv[0]), sizeof(cmd_name));
    rc = ct_parseopts(argc, argv);
    if (rc < 0) {
        CT_WARN("try '%s --help' for more information", cmd_name);
        return -rc;
    }

    rc = ct_setup();
    if (rc < 0)
        goto error_cleanup;

    rc = S3_initialize(NULL, S3_INIT_ALL, host);
    if(rc != 0){
        CT_ERROR(rc, "Error in S3 init");
        goto error_cleanup;
    }

    rc = ct_run();

error_cleanup:
    ct_s3_cleanup();

    return -rc;
}
Esempio n. 2
0
void bluesky_store_init_s3(void)
{
    char *s3Host;
    /*
     * pick up S3_HOSTNAME in case there is another S3 host to use
     */
    
    s3Host = getenv("S3_HOSTNAME");
    S3_initialize(NULL, S3_INIT_ALL, s3Host);
    bluesky_store_register(&store_impl, "s3");
}
Esempio n. 3
0
int main(int argc, char** argv)
{
    if (2 > argc){
       usage();
       return 1;
    }

    char *slash = argv[1];

    while (*slash && (*slash != '/')) {
        slash++;
    }
    *slash++ = 0;

    const char *bucketName = argv[1];
    const char *key = slash;


    S3Protocol protocolG = S3ProtocolHTTP;
    const char* accessKeyIdG = getenv("S3_ACCESS_KEY_ID");
    const char* secretAccessKeyG = getenv("S3_SECRET_ACCESS_KEY");

    S3Status status;
    const char* hostname = getenv("S3_HOSTNAME");    
    if ((status = S3_initialize("s3", S3_INIT_ALL, hostname)) != S3StatusOK)
    {
        fprintf(stdout, "Failed to initialize libs3: %s\n", S3_get_status_name(status));
        exit(-1);
    }

    S3BucketContext bucketContext =
    {
        0,
        bucketName,
        protocolG,
        S3UriStylePath,
        accessKeyIdG,
        secretAccessKeyG,
        0
    };

    S3ResponseHandler responseHandler =
    { 
        0,
        &responseCompleteCallback
    };


    //----------------------create bucket-----------------//
    S3_delete_object(&bucketContext, key, 0, &responseHandler, 0);
    S3_deinitialize();

    return 0;
}
static void S3_init()
{
    S3Status status;
    const char *hostname = getenv("S3_HOSTNAME");
    
    if ((status = S3_initialize("s3", S3_INIT_ALL, hostname))
        != S3StatusOK) {
        fprintf(stderr, "Failed to initialize libs3: %s\n", 
                S3_get_status_name(status));
        exit(-1);
    }
}
Esempio n. 5
0
File: wcd.c Progetto: flsafe/Webdir
static void s3_init(){
    S3Status status;
		char host[STR] = "";

		get_host(host);
    
    if ((status = S3_initialize("s3", S3_INIT_ALL, host))
        != S3StatusOK) {
        fprintf(stderr, "Failed to initialize libs3: %s\n", 
                S3_get_status_name(status));
        exit(-1);
    }
}
int main(int argc, char** args)
{
    if (3 > argc){
       usage();
       return 1;
    }

    const char* bucketName = args[1];
    const char* key = args[2];

    S3Protocol protocolG = S3ProtocolHTTP;
    const char* accessKeyIdG = getenv("S3_ACCESS_KEY_ID");
    const char* secretAccessKeyG = getenv("S3_SECRET_ACCESS_KEY");

    S3Status status;
    const char* hostname = getenv("S3_HOSTNAME");    
    if ((status = S3_initialize("s3", S3_INIT_ALL, hostname)) != S3StatusOK)
    {
        fprintf(stdout, "Failed to initialize libs3: %s\n", S3_get_status_name(status));
        exit(-1);
    }

    S3BucketContext bucketContext = 
    {
        0,
        bucketName,
        protocolG,
        S3UriStylePath,
        accessKeyIdG,
        secretAccessKeyG,
        0
    };

    S3ResponseHandler responseHandler = { &responsePropertiesCallback,
                                          &responseCompleteCallback
                                        };

    //----------------------check whether object is exist-----------------//
    S3_head_object(&bucketContext, key, 0, &responseHandler, 0);

    S3_deinitialize();

    return 0;
}
Esempio n. 7
0
int main(int argc, char *argv[])
{
    S3_initialize(NULL, S3_INIT_ALL, NULL);

    bucket.bucketName = "mvrable-benchmark";
    bucket.protocol = S3ProtocolHTTP;
    bucket.uriStyle = S3UriStyleVirtualHost;
    bucket.accessKeyId = getenv("AWS_ACCESS_KEY_ID");
    bucket.secretAccessKey = getenv("AWS_SECRET_ACCESS_KEY");

    if (argc != 3) {
        fprintf(stderr, "Usage: %s <file> <delay>\n", argv[0]);
        return 1;
    }

    key = argv[1];
    double inter_request_delay = atof(argv[2]);
    run_test(inter_request_delay * 1e9);

    return 0;
}
Esempio n. 8
0
int
myS3Init (void)
{
    int status = -1;
    char *tmpPtr;

    if (S3Initialized) return 0;

    S3Initialized = 1;

#ifdef libs3_3_1_4
    if ((status = S3_initialize ("s3", S3_INIT_ALL)) != S3StatusOK) {
#else
    if ((status = S3_initialize ("s3", S3_INIT_ALL, NULL)) != S3StatusOK) {
#endif
        status = myS3Error (status, S3_INIT_ERROR);
    }

    bzero (&S3Auth, sizeof (S3Auth));

    if ((tmpPtr = getenv("S3_ACCESS_KEY_ID")) != NULL) {
	rstrcpy (S3Auth.accessKeyId, tmpPtr, MAX_NAME_LEN);
        if ((tmpPtr = getenv("S3_SECRET_ACCESS_KEY")) != NULL) {
	    rstrcpy (S3Auth.secretAccessKey, tmpPtr, MAX_NAME_LEN);
	    return 0;
	}
    }

    if ((status = readS3AuthInfo ()) < 0) {
        rodsLog (LOG_ERROR,
          "initHpssAuth: readHpssAuthInfo error. status = %d", status);
        return status;
    }

    return status;
}

int
readS3AuthInfo (void)
{
    FILE *fptr;
    char s3AuthFile[MAX_NAME_LEN];
    char inbuf[MAX_NAME_LEN];
    int lineLen, bytesCopied;
    int linecnt = 0;

    snprintf (s3AuthFile, MAX_NAME_LEN, "%-s/%-s",
      getConfigDir(), S3_AUTH_FILE);

    fptr = fopen (s3AuthFile, "r");

    if (fptr == NULL) {
        rodsLog (LOG_ERROR,
          "readS3AuthInfo: open S3_AUTH_FILE file %s err. ernro = %d",
          s3AuthFile, errno);
        return (SYS_CONFIG_FILE_ERR);
    }
    while ((lineLen = getLine (fptr, inbuf, MAX_NAME_LEN)) > 0) {
        char *inPtr = inbuf;
        if (linecnt == 0) {
            while ((bytesCopied = getStrInBuf (&inPtr, 
	      S3Auth.accessKeyId, &lineLen, LONG_NAME_LEN)) > 0) {
                linecnt ++;
                break;
            }
        } else if (linecnt == 1) {
            while ((bytesCopied = getStrInBuf (&inPtr, 
	      S3Auth.secretAccessKey, &lineLen, LONG_NAME_LEN)) > 0) {
                linecnt ++;
                break;
            }
        }
    }
    if (linecnt != 2)  {
        rodsLog (LOG_ERROR,
          "readS3AuthInfo: read %d lines in S3_AUTH_FILE file",
          linecnt);
        return (SYS_CONFIG_FILE_ERR);
    }
    return 0;
}
Esempio n. 9
0
int putFileIntoS3(char *fileName, char *s3ObjName)
{

  S3Status status;
  char *key;
  struct stat statBuf;
  uint64_t fileSize;
  FILE *fd;
  char *accessKeyId;
  char *secretAccessKey;
  put_object_callback_data data;


  accessKeyId = getenv("S3_ACCESS_KEY_ID");
  if (accessKeyId == NULL) {
    printf("S3_ACCESS_KEY_ID environment variable is undefined");
    return(-1);
  }

  secretAccessKey = getenv("S3_SECRET_ACCESS_KEY");
  if (secretAccessKey == NULL) {
    printf("S3_SECRET_ACCESS_KEY environment variable is undefined");
    return(-1);
  }

  key = (char *) strchr(s3ObjName, '/');
  if (key == NULL) {
    printf("S3 Key for the Object Not defined\n");
    return(-1);
  }
  *key = '\0';
  key++;
  if (stat(fileName, &statBuf) == -1) {
    printf("Unknown input file");
    return(-1);
  }
  fileSize = statBuf.st_size;

  fd = fopen(fileName, "r" );
  if (fd == NULL) {
    printf("Unable to open input file");
    return(-1);
  }
  data.infile = fd;


  S3BucketContext bucketContext =
    {s3ObjName,  1, 0, accessKeyId, secretAccessKey};
  S3PutObjectHandler putObjectHandler =
    {
      { &responsePropertiesCallback, &responseCompleteCallback },
      &putObjectDataCallback
    };


  if ((status = S3_initialize("s3", S3_INIT_ALL))
      != S3StatusOK) {
    printf("Failed to initialize libs3: %s\n",S3_get_status_name(status));
    return(-1);
  }

  S3_put_object(&bucketContext, key, fileSize, NULL, 0,
		&putObjectHandler, &data);
  if (statusG != S3StatusOK) {
    printf("Put failed: %i\n", statusG);
    S3_deinitialize();
    return(-1);
  }
  S3_deinitialize();

  fclose(fd);
  return(0);
}
S3Status cloud_init(const char* hostname) {
  return S3_initialize("s3", S3_INIT_ALL, hostname);
}
Esempio n. 11
0
int main(int argc, char** argv)
{
    if (3 > argc){
       usage();
       return 1;
    }

    char *slash = argv[1];
    while (*slash && (*slash != '/')) {
        slash++;
    }
    if (!*slash || !*(slash + 1)) {
        fprintf(stderr, "\nERROR: Invalid bucket/key name: %s\n",
                argv[1]);
       usage();
       exit(-1);
    }
    *slash++ = 0;

    const char* bucketName = argv[1];
    const char *key = slash;
    const char *uploadId = 0;
    const char *filename = argv[2];
    uint64_t contentLength = 0;
    const char *cacheControl = 0, *contentType = 0, *md5 = 0;
    const char *contentDispositionFilename = 0, *contentEncoding = 0;
    int64_t expires = -1;
    S3CannedAcl cannedAcl = S3CannedAclPrivate;
    int metaPropertiesCount = 0;
    S3NameValue metaProperties[S3_MAX_METADATA_COUNT];
    char useServerSideEncryption = 0;
    int noStatus = 0;

    put_object_callback_data data;

    data.infile = 0;
    data.gb = 0;
    data.noStatus = noStatus;

    if (filename) {
        if (!contentLength) {
            struct stat statbuf;
            // Stat the file to get its length
            if (stat(filename, &statbuf) == -1) {
                fprintf(stderr, "\nERROR: Failed to stat file %s: ",
                        filename);
                perror(0);
                exit(-1);
            }
            contentLength = statbuf.st_size;
        }
        // Open the file
        if (!(data.infile = fopen(filename, "r" FOPEN_EXTRA_FLAGS))) {
            fprintf(stderr, "\nERROR: Failed to open input file %s: ",
                    filename);
            perror(0);
            exit(-1);
        }
    }
    else{
        usage();
    }
    data.contentLength = data.originalContentLength = contentLength;

    S3Protocol protocolG = S3ProtocolHTTP;
    const char* accessKeyIdG = getenv("S3_ACCESS_KEY_ID");
    const char* secretAccessKeyG = getenv("S3_SECRET_ACCESS_KEY");

    S3Status status;
    const char* hostname = getenv("S3_HOSTNAME");    
    if ((status = S3_initialize("s3", S3_INIT_ALL, hostname)) != S3StatusOK)
    {
        fprintf(stdout, "Failed to initialize libs3: %s\n", S3_get_status_name(status));
        exit(-1);
    }

    S3BucketContext bucketContext =
    {
        0,
        bucketName,
        protocolG,
        S3UriStylePath,
        accessKeyIdG,
        secretAccessKeyG,
        0
    };

    S3PutProperties putProperties =
    {
        contentType,
        md5,
        cacheControl,
        contentDispositionFilename,
        contentEncoding,
        expires,
        cannedAcl,
        metaPropertiesCount,
        metaProperties,
        useServerSideEncryption
    };

    S3PutObjectHandler putObjectHandler =
    {
        { &responsePropertiesCallback, &responseCompleteCallback },
        &putObjectDataCallback
    };
    //----------------------create bucket-----------------//
    S3_put_object(&bucketContext, key, contentLength, &putProperties, 0,
                          &putObjectHandler, &data);
    S3_deinitialize();

    return 0;
}