SDBConnectionPtr sdbconnect() { AWSConnectionFactory* factory = AWSConnectionFactory::getInstance(); SDBConnectionPtr sdbconn = factory->createSDBConnection (get_access_key(), get_secret_key()); return sdbconn; }
int sdbtest(int argc, char* argv[]) { AWSConnectionFactory* lFactory = AWSConnectionFactory::getInstance(); std::cout << "Testing libaws version " << lFactory->getVersion() << std::endl; char* lAccessKeyId = getenv("AWS_ACCESS_KEY"); char* lSecretAccessKey = getenv("AWS_SECRET_ACCESS_KEY"); if (lAccessKeyId == 0 || lSecretAccessKey == 0) { std::cerr << "Environment variables (i.e. AWS_ACCESS_KEY or AWS_SECRET_ACCESS_KEY) not set" << std::endl; return 1; } SDBConnectionPtr lConSmart = lFactory->createSDBConnection(lAccessKeyId, lSecretAccessKey); SDBConnection* lCon = lConSmart.get(); try { if (createDomain(lCon) != 0) { return 1; } if (listDomains(lCon) != 0) { return 1; } if (putAttributes(lCon) != 0) { return 1; } if (getAttributes(lCon) != 0) { return 1; } if (deleteAttributes(lCon) != 0) { return 1; } if (getAttributes(lCon) != 0) { return 1; } if (query(lCon) != 0) { return 1; } if (queryWithAttributes(lCon) != 0) { return 1; } if (deleteDomain(lCon) != 0) { return 1; } } catch (AWSConnectionException& e) { std::cerr << e.what() << std::endl; return 2; } lFactory->shutdown(); return 0; }
int s3objecttest(int argc, char** argv) { AWSConnectionFactory* lFactory = AWSConnectionFactory::getInstance(); std::cout << "Testing libaws version " << lFactory->getVersion() << std::endl; char* lAccessKeyId = getenv("AWS_ACCESS_KEY"); char* lSecretAccessKey = getenv("AWS_SECRET_ACCESS_KEY"); if (lAccessKeyId == 0 || lSecretAccessKey == 0) { std::cerr << "Environment variables (i.e. AWS_ACCESS_KEY or AWS_SECRET_ACCESS_KEY) not set" << std::endl; return 1; } S3ConnectionPtr lS3Rest = lFactory->createS3Connection(lAccessKeyId, lSecretAccessKey); int lReturnCode; try { lReturnCode = createbucket(lS3Rest.get()); if (lReturnCode != 0) return lReturnCode; lReturnCode = put(lS3Rest.get()); if (lReturnCode != 0) return lReturnCode; lReturnCode = listbucket(lS3Rest.get()); if (lReturnCode != 0) return lReturnCode; lReturnCode = getobject(lS3Rest.get()); if (lReturnCode != 0) return lReturnCode; lReturnCode = deleteobject(lS3Rest.get()); if (lReturnCode != 0) return lReturnCode; lReturnCode = deletebucket(lS3Rest.get()); if (lReturnCode != 0) return lReturnCode; } catch (AWSConnectionException& e) { std::cerr << e.what() << std::endl; return 2; } lFactory->shutdown(); return 0; }
int sqstest(int argc, char** argv) { AWSConnectionFactory* lFactory = AWSConnectionFactory::getInstance(); //logging::LoggerManager::logmanager()->setLoggerConfig("|1|logging.log"); //logging::LoggerManager::logmanager()->setFileName ( "", "logging.log" ); std::cout << "Testing libaws version " << lFactory->getVersion() << std::endl; char* lAccessKeyId = getenv("AWS_ACCESS_KEY"); char* lSecretAccessKey = getenv("AWS_SECRET_ACCESS_KEY"); if (lAccessKeyId == 0 || lSecretAccessKey == 0) { std::cerr << "Environment variables (i.e. AWS_ACCESS_KEY or AWS_SECRET_ACCESS_KEY) not set" << std::endl; return 1; } SQSConnectionPtr lS3Rest; char* lHost = getenv("SQS_HOST"); if (lHost == 0) { lS3Rest = lFactory->createSQSConnection(lAccessKeyId, lSecretAccessKey); } else { // aPort = -1 -> we have specified our own // aIsSecure = false -> we would like http instead of https lS3Rest = lFactory->createSQSConnection(lAccessKeyId, lSecretAccessKey, lHost, -1, false); } int lReturnCode; try { // lReturnCode = testQueues(lS3Rest.get()); // if (lReturnCode != 0) // return lReturnCode; lReturnCode = testMessages(lS3Rest.get()); if (lReturnCode != 0) return lReturnCode; } catch (AWSConnectionException& e) { std::cerr << e.what() << std::endl; return 2; } lFactory->shutdown(); return 0; }
int main ( int argc, char** argv ) { char* lBucketName = 0; char* lPrefix = 0; char* lMarker = 0; char* lDelimiter = 0; int lMaxKeys = 0; char* lAction = 0; char* lAccessKeyId = 0; char* lSecretAccessKey = 0; char* lFileName = 0; char* lKey = 0; int c; opterr = 0; AWSConnectionFactory* lFactory = AWSConnectionFactory::getInstance(); while ((c = getopt (argc, argv, "hi:k:a:n:f:p:mx:d:s:")) != -1) switch (c) { case 'i': lAccessKeyId = optarg; break; case 's': lSecretAccessKey = optarg; break; case 'a': lAction = optarg; break; case 'n': lBucketName = optarg; break; case 'p': lPrefix = optarg; break; case 'm': lMarker = optarg; break; case 'd': lDelimiter = optarg; break; case 'x': lMaxKeys = atoi(optarg); break; case 'f': lFileName = optarg; break; case 'k': lKey = optarg; break; case 'h': { usage(lFactory); exit(1); exit(1); } case '?': if (isprint (optopt)) fprintf (stderr, "Unknown option `-%c'.\n", optopt); else fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); exit(1); default: exit(1); } if (!lAccessKeyId) lAccessKeyId = getenv("AWS_ACCESS_KEY"); if (!lSecretAccessKey) lSecretAccessKey = getenv("AWS_SECRET_ACCESS_KEY"); if (!lAccessKeyId) { std::cerr << "No Access Key given" << std::endl; std::cerr << "Either use -i as a command line argument or set AWS_ACCESS_KEY as an environmental variable" << std::endl; exit(1); } if (!lSecretAccessKey) { std::cerr << "No Secret Access Key given" << std::endl; std::cerr << "Either use -s as a command line argument or set AWS_SECRET_ACCESS_KEY as an environmental variable" << std::endl; exit(1); } S3ConnectionPtr lS3Rest = lFactory->createS3Connection(lAccessKeyId, lSecretAccessKey); if (!lAction) { std::cerr << "No Action parameter specified." << std::endl; std::cerr << "Use -a as a command line argument" << std::endl; exit(1); } std::string lActionString(lAction); if ( lActionString.compare ( "list" ) == 0 ) { listBuckets(lS3Rest); } else if ( lActionString.compare ( "create" ) == 0 ) { if (!lBucketName) { std::cerr << "No bucket name parameter specified." << std::endl; std::cerr << "Use -n as a command line argument" << std::endl; exit(1); } createBucket(lS3Rest, lBucketName); } else if ( lActionString.compare ( "delete" ) == 0) { if (!lBucketName) { std::cerr << "No bucket name parameter specified." << std::endl; std::cerr << "Use -n as a command line argument" << std::endl; exit(1); } deleteBucket(lS3Rest, lBucketName); } else if ( lActionString.compare ( "entries" ) == 0) { if (!lBucketName) { std::cerr << "No bucket name parameter specified." << std::endl; std::cerr << "Use -n as a command line argument" << std::endl; exit(1); } listBucket(lS3Rest, lBucketName, lPrefix==0?"":lPrefix, lMarker==0?"":lMarker, lDelimiter==0?"":lDelimiter, lMaxKeys==0?-1:lMaxKeys); } else if ( lActionString.compare ( "delete-all-entries" ) == 0) { if (!lBucketName) { std::cerr << "No bucket name parameter specified." << std::endl; std::cerr << "Use -n as a command line argument" << std::endl; exit(1); } deleteAllEntries(lS3Rest, lBucketName); } else if ( lActionString.compare ( "logging" ) == 0) { if (!lBucketName) { std::cerr << "No bucket name parameter specified." << std::endl; std::cerr << "Use -n as a command line argument" << std::endl; exit(1); } logging(lS3Rest, lBucketName); } else if ( lActionString.compare ( "put" ) == 0) { if (!lBucketName) { std::cerr << "No bucket name parameter specified." << std::endl; std::cerr << "Use -n as a command line argument" << std::endl; exit(1); } if (!lFileName) { std::cerr << "No file specified." << std::endl; std::cerr << "Use -f as a command line argument" << std::endl; exit(1); } put(lS3Rest, lBucketName, lFileName, lKey==0?"":lKey); } else if ( lActionString.compare ( "putbin" ) == 0) { if (!lBucketName) { std::cerr << "No bucket name parameter specified." << std::endl; std::cerr << "Use -n as a command line argument" << std::endl; exit(1); } if (!lFileName) { std::cerr << "No file specified." << std::endl; std::cerr << "Use -f as a command line argument" << std::endl; exit(1); } putbin(lS3Rest, lBucketName, lFileName, lKey==0?"":lKey); } else if ( lActionString.compare ( "get" ) == 0) { if (!lBucketName) { std::cerr << "No bucket name parameter specified." << std::endl; std::cerr << "Use -n as a command line argument" << std::endl; exit(1); } if (lKey==0) { std::cerr << "No key parameter specified." << std::endl; std::cerr << "Use -k as a command line argument" << std::endl; exit(1); } get(lS3Rest, lBucketName, lKey); } else if ( lActionString.compare ( "del" ) == 0) { if (!lBucketName) { std::cerr << "No bucket name parameter specified." << std::endl; std::cerr << "Use -n as a command line argument." << std::endl; exit(1); } if (!lKey && !lPrefix) { std::cerr << "No key or prefix parameter specified." << std::endl; std::cerr << "Use -k or -p as a command line argument." << std::endl; exit(1); } del(lS3Rest, lBucketName, lKey==0?"":lKey, lPrefix==0?"":lPrefix); } else { std::cerr << "Invalid action: \"" << lActionString << "\"." << std::endl; } }
int main (int argc, char** argv) { char* lAccessKeyId = 0; char* lSecretAccessKey = 0; char* lAction = 0; char* lDomain = 0; int lMaxItems = 0; std::string lNextToken = ""; char lEmpty[] = { '\0' }; char* lNextTokenTmp = lEmpty; char* lAttrName = 0; char* lAttrValue = 0; char* lItem = 0; char* lQuery = 0; bool lReplace = false; int c; opterr = 0; AWSConnectionFactory* lFactory = AWSConnectionFactory::getInstance(); while ( (c = getopt (argc, argv, "hi:s:a:d:x:c:t:k:v:q:r")) != -1) switch (c) { case 'i': lAccessKeyId = optarg; break; case 's': lSecretAccessKey = optarg; break; case 'a': lAction = optarg; break; case 'd': lDomain = optarg; break; case 'x': lMaxItems = atoi (optarg); break; case 'c': lItem = optarg; break; case 't': lNextToken = optarg; break; case 'k': lAttrName = optarg; break; case 'v': lAttrValue = optarg; break; case 'q': lQuery = optarg; break; case 'r': lReplace = true; break; case 'h': { std::cout << "libaws version " << lFactory->getVersion() << std::endl; std::cout << "Usage: sdb <options>" << std::endl; std::cout << " -i: AWS Access Key Id" << std::endl; std::cout << " -s: AWS Secret Access Key" << std::endl; std::cout << " -a action: Action to perform" << std::endl; std::cout << " create-domain" << std::endl; std::cout << " delete-domain" << std::endl; std::cout << " domain-metadata" << std::endl; std::cout << " delete-all-domains" << std::endl; std::cout << " list-domains" << std::endl; std::cout << " put-attribute" << std::endl; std::cout << " delete-attribute" << std::endl; std::cout << " get-attribute" << std::endl; std::cout << " query" << std::endl; std::cout << " list-all" << std::endl; std::cout << " -d domain: A Domain Name" << std::endl; std::cout << " -c item/content: The item" << std::endl; std::cout << " -x #items: Max number of items/domains" << std::endl; std::cout << " -t next token: The next token" << std::endl; std::cout << " -k key/attributes: An attribute" << std::endl; std::cout << " -v value: An attribute value" << std::endl; std::cout << " -q query: Replace Attribue" << std::endl; std::cout << " -r replace: Replace Attribue" << std::endl; std::cout << " -h help: display help" << std::endl; exit (1); } case '?': if (isprint (optopt)) fprintf (stderr, "Unknown option `-%c'.\n", optopt); else fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); exit (1); default: exit (1); } if (!lAccessKeyId) { lAccessKeyId = getenv ("AWS_ACCESS_KEY"); } if (!lSecretAccessKey) { lSecretAccessKey = getenv ("AWS_SECRET_ACCESS_KEY"); } if (!lAccessKeyId) { std::cerr << "No Access Key given" << std::endl; std::cerr << "Either use -i as a command line argument or set AWS_ACCESS_KEY as an environmental variable" << std::endl; exit (1); } if (!lSecretAccessKey) { std::cerr << "No Secret Access Key given" << std::endl; std::cerr << "Either use -s as a command line argument or set AWS_SECRET_ACCESS_KEY as an environmental variable" << std::endl; exit (1); } SDBConnectionPtr lSDBRest; lSDBRest = lFactory->createSDBConnection (lAccessKeyId, lSecretAccessKey); if (!lAction) { std::cerr << "No Action parameter specified." << std::endl; std::cerr << "Use -a as a command line argument" << std::endl; exit (1); } std::string lActionString (lAction); if (lActionString.compare ("list-domains") == 0) { listDomains (lSDBRest, lMaxItems, lNextTokenTmp); exit (0); } if (lActionString.compare ("delete-all-domains") == 0) { deleteAllDomains (lSDBRest, lQuery==0?"":lQuery); exit (0); } if (lActionString.compare ("list-all") == 0) { listAll (lSDBRest); exit (0); } if (!lDomain) { std::cerr << "No domain provided." << std::endl; exit (1); } if (lActionString.compare ("create-domain") == 0) { createDomain (lSDBRest, lDomain); exit (0); } if (lActionString.compare ("delete-domain") == 0) { deleteDomain (lSDBRest, lDomain); exit (0); } if (lActionString.compare ("domain-metadata") == 0) { domainMetadata (lSDBRest, lDomain); exit (0); } if (lActionString.compare ("query") == 0) { query (lSDBRest, lDomain, lQuery==0?"":lQuery, lMaxItems, lNextTokenTmp); exit(0); } if (!lItem) { std::cerr << "No item provided." << std::endl; exit (1); } if (lActionString.compare ("get-attribute") == 0) { if (lAttrName) { getAttribute (lSDBRest, lDomain, lItem, lAttrName); } else { getAttribute (lSDBRest, lDomain, lItem); } } if (!lAttrName) { std::cerr << "No attribute name provided." << std::endl; exit (1); } if (!lAttrValue) { std::cerr << "No attribute value provided." << std::endl; exit (1); } if (lActionString.compare ("put-attribute") == 0) { putAttribute (lSDBRest, lDomain, lItem, lAttrName, lAttrValue, lReplace); } else if (lActionString.compare ("delete-attribute") == 0) { deleteAttribute (lSDBRest, lDomain, lItem, lAttrName, lAttrValue); } else { std::cerr << "Command not recognized." << std::endl; exit (1); } }
int main (int argc, char** argv) { char* lAction = 0; char* lQueueName = 0; char* lPrefix = 0; int lMaxNbMessages = -1; char* lMessage = 0; int lVisibilityTimeOut = -1; char* lAccessKeyId = 0; char* lSecretAccessKey = 0; char* lReceiptHandle = 0; char* lHost = 0; bool lBase64 = true; int c; opterr = 0; AWSConnectionFactory* lFactory = AWSConnectionFactory::getInstance(); while ( (c = getopt (argc, argv, "hbi:s:a:n:p:x:m:r:")) != -1) switch (c) { case 'i': lAccessKeyId = optarg; break; case 's': lSecretAccessKey = optarg; break; case 'a': lAction = optarg; break; case 'o': lHost = optarg; break; case 'n': lQueueName = optarg; break; case 'p': lPrefix = optarg; break; case 'x': lMaxNbMessages = atoi (optarg); break; case 'm': lMessage = optarg; break; case 'v': lVisibilityTimeOut = atoi (optarg); break; case 'r': lReceiptHandle = optarg; break; case 'h': { std::cout << "libaws version " << lFactory->getVersion() << std::endl; std::cout << "Usage: sqs <options>" << std::endl; std::cout << " -i: AWS Access Key Id" << std::endl; std::cout << " -s: AWS Secret Access Key" << std::endl; std::cout << " -a action: Action to perform" << std::endl; std::cout << " list-queues: List all queues" << std::endl; std::cout << " create-queue: Create a queue" << std::endl; std::cout << " delete-queue: Delete a queue" << std::endl; std::cout << " delete-all-queues: Delete all queues" << std::endl; std::cout << " send-message: Send a message" << std::endl; std::cout << " list-message: Receive messages" << std::endl; std::cout << " delete-message: Delete messages" << std::endl; std::cout << " delete-all-messages: Delete all messages retrieved" << std::endl; std::cout << " -o host name" << std::endl; std::cout << " -n name: A Queue Name/URL" << std::endl; std::cout << " -p prefix: Prefix for listing queues" << std::endl; std::cout << " -x #messages: Number of messages to return" << std::endl; std::cout << " -m message: the message to send" << std::endl; std::cout << " -v visibility timeout: the visibility timeout" << std::endl; std::cout << " -r receipt-handle: the receipt-handle" << std::endl; std::cout << " -b base64-handle: do not encode/decode message bodies to/from base64" << std::endl; std::cout << " -h help: display help" << std::endl; exit (1); } case 'b': lBase64 = false; break; case '?': if (isprint (optopt)) fprintf (stderr, "Unknown option `-%c'.\n", optopt); else fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); exit (1); default: exit (1); } if (!lAccessKeyId) { lAccessKeyId = getenv ("AWS_ACCESS_KEY"); } if (!lSecretAccessKey) { lSecretAccessKey = getenv ("AWS_SECRET_ACCESS_KEY"); } if (!lHost) { lHost = getenv ("SQS_HOST"); } if (!lAccessKeyId) { std::cerr << "No Access Key given" << std::endl; std::cerr << "Either use -i as a command line argument or set AWS_ACCESS_KEY as an environmental variable" << std::endl; exit (1); } if (!lSecretAccessKey) { std::cerr << "No Secret Access Key given" << std::endl; std::cerr << "Either use -s as a command line argument or set AWS_SECRET_ACCESS_KEY as an environmental variable" << std::endl; exit (1); } SQSConnectionPtr lSQSRest; if (!lHost) { lSQSRest = lFactory->createSQSConnection (lAccessKeyId, lSecretAccessKey); } else { // aPort = -1 -> we have specified our own // aIsSecure = false -> we would like http instead of https lSQSRest = lFactory->createSQSConnection(lAccessKeyId, lSecretAccessKey, lHost, -1, false); } if (!lAction) { std::cerr << "No Action parameter specified." << std::endl; std::cerr << "Use -a as a command line argument" << std::endl; exit (1); } std::string lActionString (lAction); if (lActionString.compare ("list-queues") == 0) { listQueues (lSQSRest, lPrefix == 0 ? "" : lPrefix); } else if (lActionString.compare ("create-queue") == 0) { if (!lQueueName) { std::cerr << "No queue name parameter specified." << std::endl; std::cerr << "Use -n as a command line argument" << std::endl; exit (1); } createQueue (lSQSRest, lQueueName, lVisibilityTimeOut); } else if (lActionString.compare ("delete-queue") == 0) { if (!lQueueName) { std::cerr << "No queue name parameter specified." << std::endl; std::cerr << "Use -n as a command line argument" << std::endl; exit (1); } deleteQueue (lSQSRest, lQueueName); } else if (lActionString.compare ("delete-all-queues") == 0) { deleteAllQueues (lSQSRest); } else if (lActionString.compare ("send-message") == 0) { if (!lQueueName) { std::cerr << "No queue name parameter specified." << std::endl; std::cerr << "Use -n as a command line argument" << std::endl; exit (1); } if (!lMessage) { std::cerr << "No message parameter specified." << std::endl; std::cerr << "Use -m as a command line argument" << std::endl; exit (1); } sendMessage (lSQSRest, lQueueName, lMessage, lBase64); } else if (lActionString.compare ("list-messages") == 0 || lActionString.compare ("list-message") == 0) { if (!lQueueName) { std::cerr << "No queue name parameter specified." << std::endl; std::cerr << "Use -n as a command line argument" << std::endl; exit (1); } receiveMessage (lSQSRest, lQueueName, lMaxNbMessages, lVisibilityTimeOut, lBase64); } else if (lActionString.compare ("delete-message") == 0) { if (!lQueueName) { std::cerr << "No queue name parameter specified." << std::endl; std::cerr << "Use -n as a command line argument" << std::endl; exit (1); } if (!lReceiptHandle) { std::cerr << "No receipt handle parameter specified." << std::endl; std::cerr << "Use -r as a command line argument" << std::endl; exit (1); } deleteMessage (lSQSRest, lQueueName, lReceiptHandle); } else if (lActionString.compare ("delete-all-messages") == 0) { if (!lQueueName) { std::cerr << "No queue name parameter specified." << std::endl; std::cerr << "Use -n as a command line argument" << std::endl; exit (1); } deleteAllMessages (lSQSRest, lQueueName); } else { std::cerr << "Command not recognized." << std::endl; exit(1); } }