Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for cs3 api #72

Merged
merged 4 commits into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion include/davix/params/davix_request_params_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ namespace RequestProtocol{
// Use gcloud API
Gcloud,
// Use Swift API
Swift
Swift,
// Use CS3 API
CS3
};
}

Expand Down Expand Up @@ -121,6 +123,11 @@ typedef std::string AwsRegion;
///
typedef std::string AwsToken;

///
/// \brief string for Reva security token
///
typedef std::string RevaToken;

///
/// \brief string for Azure private key
///
Expand Down
32 changes: 32 additions & 0 deletions include/davix/params/davixrequestparams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <vector>
#include <string>
#include <map>

#include "davix_request_params_types.hpp"
#include "../auth/davixauth.hpp"
Expand All @@ -47,6 +48,12 @@ namespace gcloud {
class Credentials;
}

namespace reva {
class Credentials;
struct Credential;
typedef std::map<std::string, Credential> CredentialMap;
}

struct RequestParamsInternal;


Expand Down Expand Up @@ -160,6 +167,31 @@ class DAVIX_EXPORT RequestParams
///
const AwsToken & getAwsToken() const;

///
/// \brief define the Reva Credentials
/// \param credentials credential map of type reva::Credential
///
void setRevaCredentials(Davix::reva::Credentials & credentials);

///
/// \brief get Reva Token
/// \return reva token of type std::string
///
const RevaToken getRevaToken(std::string uri) const&;

///
/// \brief get Reva Credentials
/// \return credential map of type std::map<std::string, Credential> CredentialMap
/// \n Credential consists of a RevaToken and a write_access flag
///
const Davix::reva::Credentials & getRevaCredentials() const;

///
/// \brief get Reva Credentials
/// \return credentials type reva::Credential
///
void getRevaCredentialMap(Davix::reva::CredentialMap & cmap);

///
/// \brief set whether we're using an S3 path-based url
/// \param alternate whether using an S3 path-based url
Expand Down
3 changes: 3 additions & 0 deletions include/davix/status/davixstatusrequest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ enum Code {
/// Insufficient storage
InsufficientStorage = 0x27,

/// Environment Variable Missing
EnvVarNotSet = 0x28,

/// Undefined error
UnknowError = 0x100

Expand Down
59 changes: 59 additions & 0 deletions include/davix/utils/davix_cs3_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef DAVIX_CS3_UTILS_HPP
#define DAVIX_CS3_UTILS_HPP

#include <params/davixrequestparams.hpp>
#include <map>

namespace Davix {
namespace reva {

struct Credential {
RevaToken token;
bool token_write_access;
};

typedef std::map<std::string, Credential> CredentialMap;

//creates a deep copy of CredentialMap

///
/// @class Credentials
/// @brief Reva credentials
///
/// Reva credentials
class DAVIX_EXPORT Credentials {
public:
Credentials();

bool isEmpty() const;
RevaToken getToken(std::string uri) const&;
void getCredentialMap(CredentialMap &cmap) const;
void addCredentials(std::string uri, std::string token, bool token_write_access);

Credentials(const Credentials&); // Copy constructor
Credentials(Credentials&&); // Move constructor
Credentials& operator=(const Credentials&); // Copy assignment operator
Credentials& operator=(Credentials&&); // Move assignment operator
virtual ~Credentials(); // Destructor

private:
CredentialMap *credMap;
};


///
/// @class CredentialProvider
/// @brief Reva credential provider
///
/// Reva credential provider
class DAVIX_EXPORT CredentialProvider{
public:
CredentialProvider(){};
void updateCredentials(Credentials &creds, std::string uri, bool token_write_access);
};


}//Reva
}//Davix

#endif //DAVIX_CS3_UTILS_HPP
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ set(DAVIX_SOURCES
utils/davix_gcloud_utils.cpp
utils/davix_logger_internal.hpp utils/davix_logger.cpp
utils/davix_misc_utils.cpp
utils/davix_cs3_utils.cpp
utils/davix_utils_internal.hpp utils/davix_s3_utils.cpp
utils/davix_swift_utils.cpp
utils/simple_get_pass.h utils/simple_get_pass.cpp
Expand Down
53 changes: 53 additions & 0 deletions src/backend/BackendRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "BackendRequest.hpp"
#include <core/ContentProvider.hpp>
#include <utils/davix_s3_utils.hpp>
#include <utils/davix_cs3_utils.hpp>
#include <utils/davix_azure_utils.hpp>
#include <utils/davix_gcloud_utils.hpp>
#include <utils/davix_swift_utils.hpp>
Expand Down Expand Up @@ -134,6 +135,58 @@ void BackendRequest::configureSwiftParams() {
_current.reset(new Uri(signed_url));
}

//------------------------------------------------------------------------------
// Configure request for Reva.
//------------------------------------------------------------------------------
void BackendRequest::configureRevaParams()
{
std::string uri = getOriginalUri()->getString();

if (_request_type != "COPY") {
std::string token = _params.getRevaToken(uri);
if (token != ""){
_headers_field.emplace_back("X-Access-Token", token);
}
}
else {
reva::CredentialMap cmap;
_params.getRevaCredentialMap(cmap);

//In pull mode : Dst = Active Endpoint and Src = Passive Endpoint
//In push mode : Dst = Passive Endpoint and Src = Active Endpoint
std::string active_token, passive_token;

//In pull mode original uri = destination uri
if(_params.getCopyMode() == Davix::CopyMode::Pull){
for (reva::CredentialMap::iterator itr = cmap.begin(); itr != cmap.end(); ++itr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an iteration over the whole map?
Wouldn't that mean the active_token and passive_token values depend only on the last element in the map?

Shouldn't there be a filtering by uri?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This credMap is supposed to live only in the context of that transfer. So we only have two token at any time.
If this is not destroyed when that transfer job completes then we would have to find an alternative.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. If the map is guaranteed to only have 2 elements in it, it's ok.

Making sure I have to have the correct rationale:

  • active_token / passive_token naming is influenced primarily by 3rd push/pull role (E.g.: destination is active for 3rd pull / source is active for 3rd push)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is correct. The names are borrowed from a draft RFC on HTTP-TPC.

if(itr->second.token_write_access){
active_token = itr->second.token;
}
else{
passive_token = itr->second.token;
}
}
}

//In push mode original uri = src uri
else if(_params.getCopyMode() == Davix::CopyMode::Push){
for (reva::CredentialMap::iterator itr = cmap.begin(); itr != cmap.end(); ++itr) {
if(itr->second.token_write_access){
passive_token = itr->second.token;
}
else{
active_token = itr->second.token;
}
}
}

_headers_field.emplace_back("X-Access-Token", active_token);
_headers_field.emplace_back("TransferHeaderX-Access-Token", passive_token);

}
}


//------------------------------------------------------------------------------
// Set-up deadline, but only if uninitialized
//------------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions src/backend/BackendRequest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ class BackendRequest {
//----------------------------------------------------------------------------
void configureSwiftParams();

//----------------------------------------------------------------------------
// Configure request for Reva.
//----------------------------------------------------------------------------
void configureRevaParams();

//----------------------------------------------------------------------------
// Set-up deadline, but only if uninitialized
//----------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/backend/SessionFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ std::string SessionFactory::httpizeProtocol(const std::string &protocol) {
proto.compare(0,2, "s3") == 0 ||
proto.compare(0,3, "dav") == 0 ||
proto.compare(0, 6, "gcloud") == 0 ||
proto.compare(0, 5, "swift") == 0){
proto.compare(0, 5, "swift") == 0 ||
proto.compare(0, 3, "cs3") == 0){

proto.assign("http");

Expand Down
4 changes: 4 additions & 0 deletions src/modules/copy/copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ void DavixCopyInternal::copy(const Uri &src, const Uri &dst,
destination.replace(0, 3, "http");
}

if(destination.compare(0, 3, "cs3") == 0){
destination.replace(0, 3, "http");
}

// Perform COPY hopping through redirections
HttpRequest* request = NULL;
do {
Expand Down
5 changes: 5 additions & 0 deletions src/neon/neonrequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ void configureRequestParamsProto(const Uri &uri, RequestParams &params){
params.setProtocol(RequestProtocol::Webdav);
}else if ( proto.compare(0, 6, "gcloud") ==0) {
params.setProtocol(RequestProtocol::Gcloud);
}else if (proto.compare(0, 3, "cs3")==0){
params.setProtocol(RequestProtocol::CS3);
}
}
}
Expand Down Expand Up @@ -151,6 +153,9 @@ void NeonRequest::prepareUriParams() {
// configure swift params if needed
if(_params.getProtocol() == RequestProtocol::Swift)
configureSwiftParams();

if(_params.getProtocol() == RequestProtocol::CS3)
configureRevaParams();
}

//------------------------------------------------------------------------------
Expand Down
19 changes: 19 additions & 0 deletions src/params/davixrequestparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <params/davixrequestparams.hpp>
#include <libs/time_utils.h>
#include <utils/davix_gcloud_utils.hpp>
#include <utils/davix_cs3_utils.hpp>



Expand Down Expand Up @@ -99,6 +100,7 @@ struct RequestParamsInternal{
_aws_cred(),
_aws_region(),
_aws_token(),
_reva_creds(),
_aws_alternate(false),
_azure_key(),
_gcloud_creds(),
Expand Down Expand Up @@ -151,6 +153,7 @@ struct RequestParamsInternal{
_aws_cred(param_private._aws_cred),
_aws_region(param_private._aws_region),
_aws_token(param_private._aws_token),
_reva_creds(param_private._reva_creds),
_aws_alternate(param_private._aws_alternate),
_azure_key(param_private._azure_key),
_gcloud_creds(param_private._gcloud_creds),
Expand Down Expand Up @@ -202,6 +205,7 @@ struct RequestParamsInternal{
std::pair<AwsSecretKey, AwsAccessKey> _aws_cred;
AwsRegion _aws_region;
AwsToken _aws_token;
reva::Credentials _reva_creds;
bool _aws_alternate;
AzureSecretKey _azure_key;
gcloud::Credentials _gcloud_creds;
Expand Down Expand Up @@ -393,6 +397,21 @@ const AwsToken & RequestParams::getAwsToken() const {
return d_ptr->_aws_token;
}

void RequestParams::setRevaCredentials(reva::Credentials &credentials) {
d_ptr->_reva_creds = credentials;
}
void RequestParams::getRevaCredentialMap(reva::CredentialMap & cmap) {
d_ptr->_reva_creds.getCredentialMap(cmap);
}

const RevaToken RequestParams::getRevaToken(std::string uri) const& {
return d_ptr->_reva_creds.getToken(uri);
}

const reva::Credentials & RequestParams::getRevaCredentials() const {
return d_ptr->_reva_creds;
}

void RequestParams::setAwsAlternate(const bool &alternate) {
d_ptr->_aws_alternate = alternate;
}
Expand Down
Loading