Commit 19cb3ab6 authored by Ciarán Ó Rourke's avatar Ciarán Ó Rourke
Browse files

Command line parsing of relevant variables

parent 0307fae8
......@@ -5,7 +5,7 @@ include_directories(/usr/lib64/glib-2.0/include)
add_executable(
fiphoboserver
server.cc
static_handler.cc
get_request_handler.cc
push_request_handler.cc
)
......@@ -23,4 +23,4 @@ target_compile_features(fiphoboserver PUBLIC cxx_std_14)
target_link_libraries(fiphoboserver PUBLIC proxygen::proxygen)
target_link_libraries(fiphoboserver PUBLIC proxygen::proxygenhttpserver)
target_link_libraries(fiphoboserver PUBLIC fiphobo)
\ No newline at end of file
target_link_libraries(fiphoboserver PUBLIC fiphobo)
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "static_handler.h"
#include <stdlib.h>
#include <cstdio>
#include <folly/FileUtil.h>
#include <folly/executors/GlobalExecutor.h>
#include <folly/io/async/EventBaseManager.h>
#include <proxygen/httpserver/RequestHandler.h>
#include <proxygen/httpserver/ResponseBuilder.h>
#include "../S3_header.h"
#include "../fiphobo/FiPhoExceptions.h"
namespace fiphoboserver {
void StaticHandler::onRequest(std::unique_ptr<proxygen::HTTPMessage> headers) noexcept
{
if (headers->getMethod() != proxygen::HTTPMethod::GET) {
proxygen::ResponseBuilder(downstream_)
.status(400, "Bad method")
.body("Only GET is supported")
.sendWithEOM();
return;
}
#ifdef DEBUG
std::cout << "Got the following GET request: \n";
std::string path = headers->getPath();
std::cout << path << '\n';
headers->getHeaders().forEach([&] (const std::string& header, const std::string& val) {
std::cout << header << ": " << val << '\n';
});
#endif
s3_header.setHeaders(std::move(headers));
try {
#ifdef DEBUG
std::cout << "Bucket: " << s3_header.getBucket() << '\n';
std::cout << "Key: " << s3_header.getKey() << '\n';
std::cout << std::endl;
#endif
phobos.setBucketName(s3_header.getBucket());
#ifdef DEBUG
std::cout << "Send get to phobos layer" << std::endl;
#endif
phobos.startGetOperation(s3_header.getKey());
}
catch (const std::system_error& ex) {
proxygen::ResponseBuilder(downstream_)
.status(404, "Not Found")
.body(folly::to<std::string>(
"Could not find ", headers->getPathAsStringPiece(),
" ex=", folly::exceptionStr(ex)))
.sendWithEOM();
return;
}
catch (const fiphoexceptions::PhobosException& ex) {
proxygen::ResponseBuilder(downstream_)
.status(409, "Conflict")
.body(ex.what())
.sendWithEOM();
return;
}
proxygen::ResponseBuilder(downstream_).status(200, "Ok").send();
}
void StaticHandler::onBody(std::unique_ptr<folly::IOBuf> /*body*/) noexcept
{
// ignore, only support GET
}
void StaticHandler::onEOM() noexcept {}
void StaticHandler::onUpgrade(proxygen::UpgradeProtocol /*protocol*/) noexcept
{
// handler doesn't support upgrades
}
void StaticHandler::requestComplete() noexcept
{
delete this;
}
void StaticHandler::onError(proxygen::ProxygenError /*err*/) noexcept
{
delete this;
}
} // namespace fiphoboserver
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <folly/File.h>
#include <folly/Memory.h>
#include <proxygen/httpserver/RequestHandler.h>
#include "../S3_header.h"
#include "../fiphobo/fiphobo.h"
namespace proxygen {
class ResponseHandler;
}
namespace fiphoboserver {
class StaticHandler : public proxygen::RequestHandler {
public:
void onRequest(
std::unique_ptr<proxygen::HTTPMessage> headers) noexcept override;
void onBody(std::unique_ptr<folly::IOBuf> body) noexcept override;
void onEOM() noexcept override;
void onUpgrade(proxygen::UpgradeProtocol proto) noexcept override;
void requestComplete() noexcept override;
void onError(proxygen::ProxygenError err) noexcept override;
private:
S3_header s3_header;
FiPhobo phobos;
};
} // namespace fiphoboserver
import boto3
import uuid
import sys
import argparse
file_string="EmperorWu.txt"
key_string="ThisIsMyKey3"
if(len(sys.argv) > 1):
key_string = str(sys.argv[1])
if(len(sys.argv) > 2):
file_string = str(sys.argv[2])
parser = argparse.ArgumentParser()
parser.add_argument('-put', action = 'store_true')
parser.add_argument('-get', action = 'store_true')
parser.add_argument('-key', dest = 'key_string', default = 'MyKey')
parser.add_argument('-putfile', dest = 'put_file_string', default = 'EmperorWu.txt')
parser.add_argument('-getfile', dest = 'get_file_string', default = 'get_file.txt')
args = parser.parse_args()
def create_bucket_name(bucket_prefix):
# The generated bucket name must be between 3 and 63 chars long
......@@ -45,21 +48,25 @@ s3_client = session.client(
# print(first_response)
first_bucket_name = "ichec.phobos.7a3d12c6-632b-4291-b87e-07badca60cd0"
first_file_name = "ThisIsMyKey1"
s3_client.upload_file(
Filename=file_string, Bucket=first_bucket_name,
Key=key_string)
if(args.put):
s3_client.upload_file(
Filename=args.put_file_string, Bucket=first_bucket_name,
Key=args.key_string)
# s3_client.download_file(first_bucket_name, first_file_name).download_file(
# "downloadedFile.txt")
#
# response = s3_client.get_object(
# Bucket=first_bucket_name,
# Key=first_file_name
# )
# print("get_object: ")
# print(response)
if(args.get):
s3_client.download_file(
Filename=args.get_file_string, Bucket=first_bucket_name,
Key=args.key_string)
#if(args.get):
# response = s3_client.get_object(
# Bucket=first_bucket_name,
# Key=args.key_string
# )
# print("get_object: ")
# print(response)
# This is another command (HEAD request) that will result in a getmd call to phobos!
# response = s3_client.head_object(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment