Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
18 changed files
with
3,108 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
ADD_EXECUTABLE(s3 s3.cpp) | ||
ADD_EXECUTABLE(check check.cpp) | ||
|
||
SET(S3_LIBS ${requiredlibs}) | ||
TARGET_LINK_LIBRARIES(s3 miniocpp ${S3_LIBS}) | ||
TARGET_LINK_LIBRARIES(check miniocpp ${S3_LIBS}) | ||
|
||
INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/s3 DESTINATION bin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,238 @@ | ||
#include <s3_signature_v2.h> | ||
|
||
#include <curlpp/cURLpp.hpp> | ||
#include <curlpp/Easy.hpp> | ||
#include <curlpp/Options.hpp> | ||
#include <curlpp/Exception.hpp> | ||
#include <curlpp/Infos.hpp> | ||
#include "pugixml.hpp" | ||
|
||
#include <utils.h> | ||
#include <creds.h> | ||
#include <http.h> | ||
#include <signer.h> | ||
#include <xml.h> | ||
#include <client.h> | ||
|
||
size_t DataCallback(minio::http::DataCallbackArgs args) { | ||
std::cout << "writeCallBack(): [" << std::string(args.buffer, args.length) << "]" << std::endl; | ||
return args.size * args.length; | ||
} | ||
|
||
size_t WriteCallback(char* ptr, size_t size, size_t nmemb, void *f) | ||
{ | ||
FILE *file = (FILE *)f; | ||
return fwrite(ptr, size, nmemb, file); | ||
}; | ||
|
||
|
||
void CheckHeadRequest() { | ||
curlpp::Cleanup cleaner; | ||
curlpp::Easy request; | ||
|
||
std::stringstream ss; | ||
|
||
// Request settings. | ||
request.setOpt(new curlpp::options::CustomRequest{"HEAD"}); | ||
request.setOpt(new curlpp::Options::Url("https://httpbin.org/anything")); | ||
request.setOpt(new curlpp::Options::Verbose(true)); | ||
|
||
// Response settings. | ||
// request.setOpt(new curlpp::options::Header(true)); | ||
request.setOpt(new curlpp::options::NoBody(true)); | ||
// request.setOpt(new curlpp::options::WriteStream(&ss)); | ||
// curlpp::types::WriteFunctionFunctor functor(WriteMemoryCallback); | ||
// curlpp::options::WriteFunction *test = functor); | ||
request.setOpt(new curlpp::options::WriteFunction([](char* ptr, size_t size, size_t nmemb)->size_t { | ||
std::cout << "DEBUG:: " << std::string(ptr, nmemb) << std::endl; | ||
return size * nmemb; | ||
})); | ||
|
||
// Execute. | ||
request.perform(); | ||
|
||
std::cout << "Error: " << ss.str() << std::endl; | ||
// std::cout << "StatusCode: " << response.StatusCode() << std::endl; | ||
// std::cout << "Headers: " << response.Headers().ToHttpHeaders() << std::endl; | ||
// std::cout << "Data: " << response.Data() << std::endl; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
// CheckHeadRequest(); | ||
int x = 4; | ||
auto l = [&r = x, x = x+1]()->int { | ||
r += 2; | ||
return x+2; | ||
}; // Updates ::x to 6, and initializes y to 7. | ||
std::cout << "x = " << x << std::endl; | ||
auto y = l(); | ||
std::cout << "x = " << x << std::endl; | ||
std::cout << "y = " << y << std::endl; | ||
|
||
minio::http::BaseUrl base_url1("localhost:9000"); | ||
base_url1.SetHttps(false); | ||
minio::creds::StaticProvider provider("minio", "minio123"); | ||
|
||
minio::Client client(base_url1, &provider); | ||
|
||
std::cout << "StatObject()" << std::endl; | ||
minio::StatObjectResponse sor = client.StatObject("my123", "zero1"); | ||
std::cout << "IsSuccess: " << minio::utils::BoolToString(sor.IsSuccess()) << std::endl; | ||
std::cout << "Error: " << sor.err_ << std::endl; | ||
std::cout << "StatusCode: " << sor.status_code_ << std::endl; | ||
std::cout << "Headers: " << sor.headers_.ToHttpHeaders() << std::endl; | ||
std::cout << "Code: " << sor.code_ << std::endl; | ||
std::cout << "Message: " << sor.message_ << std::endl; | ||
|
||
// std::cout << "DownloadObject()" << std::endl; | ||
// minio::DownloadObjectResponse dor = client.DownloadObject("my123", "zero", "/tmp/a"); | ||
// std::cout << "IsSuccess: " << minio::utils::BoolToString(dor.IsSuccess()) << std::endl; | ||
// std::cout << "Error: " << dor.err_ << std::endl; | ||
// std::cout << "StatusCode: " << dor.status_code_ << std::endl; | ||
// std::cout << "Headers: " << dor.headers_.ToHttpHeaders() << std::endl; | ||
// std::cout << "Code: " << dor.code_ << std::endl; | ||
// std::cout << "Message: " << dor.message_ << std::endl; | ||
|
||
std::cout << "MakeBucket()" << std::endl; | ||
minio::MakeBucketResponse mbr = client.MakeBucket("my123"); | ||
std::cout << "IsSuccess: " << minio::utils::BoolToString(mbr.IsSuccess()) << std::endl; | ||
std::cout << "Error: " << mbr.err_ << std::endl; | ||
std::cout << "StatusCode: " << mbr.status_code_ << std::endl; | ||
std::cout << "Headers: " << mbr.headers_.ToHttpHeaders() << std::endl; | ||
std::cout << "Code: " << mbr.code_ << std::endl; | ||
std::cout << "Message: " << mbr.message_ << std::endl; | ||
|
||
std::cout << "GetRegion()" << std::endl; | ||
minio::GetRegionResponse grr = client.GetRegion("my123", ""); | ||
std::cout << "IsSuccess: " << minio::utils::BoolToString(grr.IsSuccess()) << std::endl; | ||
std::cout << "Region: " << grr.region_ << std::endl; | ||
std::cout << "Error: " << grr.err_ << std::endl; | ||
std::cout << "StatusCode: " << grr.status_code_ << std::endl; | ||
std::cout << "Headers: " << grr.headers_.ToHttpHeaders() << std::endl; | ||
std::cout << "Code: " << grr.code_ << std::endl; | ||
std::cout << "Message: " << grr.message_ << std::endl; | ||
|
||
std::cout << "ListBuckets()" << std::endl; | ||
minio::ListBucketsResponse blr = client.ListBuckets(); | ||
std::cout << "IsSuccess: " << minio::utils::BoolToString(blr.IsSuccess()) << std::endl; | ||
std::cout << "Buckets: "; | ||
for (auto b: blr.buckets_) { | ||
std::cout << "(" << b.Name() << ", " << b.CreationDate().ToHttpHeaderValue() << ") "; | ||
} | ||
std::cout << std::endl; | ||
std::cout << "Error: " << blr.err_ << std::endl; | ||
std::cout << "StatusCode: " << blr.status_code_ << std::endl; | ||
std::cout << "Headers: " << blr.headers_.ToHttpHeaders() << std::endl; | ||
std::cout << "Code: " << blr.code_ << std::endl; | ||
std::cout << "Message: " << blr.message_ << std::endl; | ||
|
||
std::cout << "BucketExists()" << std::endl; | ||
minio::BucketExistsResponse ber = client.BucketExists("my123"); | ||
std::cout << "IsSuccess: " << minio::utils::BoolToString(ber.IsSuccess()) << std::endl; | ||
std::cout << "Exist: " << minio::utils::BoolToString(ber.exist_) << std::endl; | ||
std::cout << "Error: " << ber.err_ << std::endl; | ||
std::cout << "StatusCode: " << ber.status_code_ << std::endl; | ||
std::cout << "Headers: " << ber.headers_.ToHttpHeaders() << std::endl; | ||
std::cout << "Code: " << ber.code_ << std::endl; | ||
std::cout << "Message: " << ber.message_ << std::endl; | ||
|
||
std::cout << "RemoveBucket()" << std::endl; | ||
minio::RemoveBucketResponse rbr = client.RemoveBucket("my123"); | ||
std::cout << "IsSuccess: " << minio::utils::BoolToString(rbr.IsSuccess()) << std::endl; | ||
std::cout << "Error: " << rbr.err_ << std::endl; | ||
std::cout << "StatusCode: " << rbr.status_code_ << std::endl; | ||
std::cout << "Headers: " << rbr.headers_.ToHttpHeaders() << std::endl; | ||
std::cout << "Code: " << rbr.code_ << std::endl; | ||
std::cout << "Message: " << rbr.message_ << std::endl; | ||
|
||
return 0; | ||
|
||
minio::http::Method method = minio::http::Method::kPut; | ||
std::string body = "<VersioningConfiguration><Status>Enabled</Status></VersioningConfiguration>"; | ||
minio::utils::Multimap query_params; | ||
query_params.Add("versioning", ""); | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
minio::RequestBuilder rb(method, "us-east-1", base_url1); | ||
rb.SetQueryParams(query_params); | ||
rb.SetBucketName("put"); | ||
rb.SetBody(body); | ||
|
||
minio::http::Request req = rb.Build(&provider); | ||
minio::http::Response response = req.Execute(); | ||
std::cout << "Error: " << response.Error() << std::endl; | ||
std::cout << "StatusCode: " << response.StatusCode() << std::endl; | ||
std::cout << "Headers: " << response.Headers().ToHttpHeaders() << std::endl; | ||
std::cout << "Data: " << response.Data() << std::endl; | ||
|
||
/////////////////////////////////////////////////////////////////////////// | ||
// minio::http::BaseUrl base_url("httpbin.org"); | ||
// RequestBuilder request_builder(method, "us-east-1", base_url); | ||
// | ||
// // request_builder.SetUserAgent(std::string_view user_agent); | ||
// // request_builder.SetHeaders(minio::utils::Multimap headers); | ||
// request_builder.SetQueryParams(query_params); | ||
// request_builder.SetBucketName("put"); | ||
// // request_builder.SetObjectName("path/to/myobject"); | ||
// request_builder.SetBody(body); | ||
// // request_builder.SetNoBodyTrace(bool no_body_trace); | ||
// | ||
// minio::http::Request r = request_builder.Build(&provider); | ||
// minio::http::Response resp = r.Execute(); | ||
// // minio::http::Response resp = r.Execute(DataCallback); | ||
// std::cout << "Error: " << resp.Error() << std::endl; | ||
// std::cout << "StatusCode: " << resp.StatusCode() << std::endl; | ||
// std::cout << "Headers: " << resp.Headers().ToHttpHeaders() << std::endl; | ||
// std::cout << "Data: " << resp.Data() << std::endl; | ||
|
||
///////////////////////////////////////////////////////////////// | ||
// std::string url = "http://httpbin.org/put"; | ||
// minio::utils::Multimap headerMap; | ||
// headerMap.Add("Content-Length", std::to_string(body.size())); | ||
// | ||
// minio::http::Request req(method, url); | ||
// req.SetHeaders(headerMap); | ||
// req.SetBody(body); | ||
// minio::http::Response res = req.Execute(); | ||
// std::cout << "Error: " << res.Error() << std::endl; | ||
// std::cout << "StatusCode: " << res.StatusCode() << std::endl; | ||
// std::cout << "Headers: " << res.Headers().ToHttpHeaders() << std::endl; | ||
// std::cout << "Data: " << res.Data() << std::endl; | ||
|
||
////////////////////////////////////////////////////////////////////// | ||
// curlpp::Cleanup cleaner; | ||
// curlpp::Easy request; | ||
// | ||
// // Request settings. | ||
// request.setOpt(new curlpp::options::CustomRequest{minio::http::MethodToString(method)}); | ||
// request.setOpt(new curlpp::Options::Url(url)); | ||
// // request.setOpt(new curlpp::Options::Verbose(true)); | ||
// | ||
// std::list<std::string> headers = headerMap.ToHttpHeaders(); | ||
// headers.push_back("Expect:"); // disable 100 continue from server. | ||
// request.setOpt(new curlpp::Options::HttpHeader(headers)); | ||
// | ||
// std::stringstream body_stream(body); | ||
// request.setOpt(new curlpp::Options::ReadStream(&body_stream)); | ||
// request.setOpt(new curlpp::Options::InfileSize(body.size())); | ||
// request.setOpt(new curlpp::Options::Upload(true)); | ||
// | ||
// // Response settings. | ||
// request.setOpt(new curlpp::options::Header(true)); | ||
// | ||
// minio::http::Response response; | ||
// // response.SetDataCallback(DataCallback); | ||
// | ||
// using namespace std::placeholders; | ||
// request.setOpt(new curlpp::options::WriteFunction(std::bind(&minio::http::Response::ResponseCallback, &response, &request, _1, _2, _3))); | ||
// | ||
// // Execute. | ||
// request.perform(); | ||
// | ||
// std::cout << "Error: " << response.Error() << std::endl; | ||
// std::cout << "StatusCode: " << response.StatusCode() << std::endl; | ||
// std::cout << "Headers: " << response.Headers().ToHttpHeaders() << std::endl; | ||
// std::cout << "Data: " << response.Data() << std::endl; | ||
return EXIT_SUCCESS; | ||
} |
Oops, something went wrong.