Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c599134
Allow chunked encoding, incremental sending of body on HTTP REST call…
jeremybarnes Jun 14, 2014
ec0daf8
Merge branch 'master' of github.com:datacratic/soa
jeremybarnes Jun 18, 2014
d154f71
Add ability to turn off log categories by default (PLAT-564)
jeremybarnes Jun 18, 2014
4c88e4f
Merge branch 'master' of github.com:datacratic/soa into datacratic-in…
jeremybarnes Jun 18, 2014
dcf0bef
More flexibility in handling signal errors in Runner (TRIVIAL)
jeremybarnes Jun 29, 2014
ede3305
Make HttpNamedEndpoint keep shared pointer to connection
jeremybarnes Jul 1, 2014
f39f83d
Merge branch 'master' of github.com:datacratic/soa into datacratic-in…
jeremybarnes Jul 3, 2014
2bfa70c
Merge branch 'datacratic-internal-branch-5' of github.com:datacratic/…
jeremybarnes Nov 1, 2014
183fb68
Added missing header to zmq_named_pub_sub.h (TRIVIAL)
jeremybarnes Nov 3, 2014
6cdcde2
Further fixes for file:// URIs to accept relative path (TRIVIAL)
jeremybarnes Nov 3, 2014
b5b9162
Started adding in credentials handling infrastructure
jeremybarnes Nov 5, 2014
4dc6386
Merge branch 'master' of github.com:datacratic/soa into datacratic-in…
jeremybarnes Nov 5, 2014
032620d
Refactored S3 credentials to use credential provider
jeremybarnes Nov 6, 2014
1796331
Cleaned up dead code from S3 refactor
jeremybarnes Nov 6, 2014
e65f5ab
Merge branch 'master' of github.com:datacratic/soa into pluggable_cre…
jeremybarnes Nov 6, 2014
19f9ef3
Allow cloud credentials to be ignored programatically
jeremybarnes Nov 13, 2014
12b2aa5
Added ability to get credentials from a remote provider
jeremybarnes Nov 13, 2014
69ce3ad
Fixed incorrect use of lexical_cast in RestParamDefault (TRIVIAL)
jeremybarnes Nov 13, 2014
3d97b46
Added TRACE_REST_REQUESTS environment variable (TRIVIAL)
jeremybarnes Nov 13, 2014
584c7c7
Don't require service discovery to use NamedEndpoint (TRIVIAL)
jeremybarnes Nov 13, 2014
bb708e9
Improvements to value descriptions for objects without
jeremybarnes Nov 13, 2014
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
117 changes: 117 additions & 0 deletions credentials/credential_provider.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/* credential_provider.cc
Jeremy Barnes, 5 November 2014
Copyright (c) 2014 Datacratic Inc. All rights reserved.

Basic functionality to get credentials.
*/

#include "credential_provider.h"
#include <mutex>

using namespace std;

namespace Datacratic {

/*****************************************************************************/
/* CREDENTIAL PROVIDER */
/*****************************************************************************/

CredentialProvider::
~CredentialProvider()
{
}

namespace {

std::mutex providersLock;
std::multimap<std::string, std::shared_ptr<CredentialProvider> > providers;

} // file scope

void
CredentialProvider::
registerProvider(const std::string & name,
std::shared_ptr<CredentialProvider> provider)
{
std::unique_lock<std::mutex> guard(providersLock);

auto prefixes = provider->getResourceTypePrefixes();

for (string prefix: prefixes)
providers.insert({ prefix, provider });
}

std::vector<Credential>
getCredentials(const std::string & resourceType,
const std::string & resource,
const CredentialContext & context,
Json::Value extraData)
{
std::unique_lock<std::mutex> guard(providersLock);

std::vector<Credential> result;

for (auto it = providers.lower_bound(resourceType); it != providers.end();
++it) {
if (resourceType.find(it->first) != 0)
break; // not a prefix
auto creds = it->second->getSync(resourceType, resource, context,
extraData);
result.insert(result.end(), creds.begin(), creds.end());
}

return result;
}

Credential
getCredential(const std::string & resourceType,
const std::string & resource,
const CredentialContext & context,
Json::Value extraData,
TimePeriod validTime)
{
std::unique_lock<std::mutex> guard(providersLock);

cerr << "getCredential" << endl;

for (auto it = providers.begin(), end = providers.end();
it != end; ++it) {
cerr << "testing " << it->first << " against " << resourceType
<< " " << resource << endl;
if (resourceType.find(it->first) != 0)
break; // not a prefix
cerr << "FOUND" << endl;

auto creds = it->second->getSync(resourceType, resource, context,
extraData);
if (!creds.empty()) {
cerr << "credentials for " << resourceType << " " << resource
<< " are " << endl << jsonEncode(creds[0]) << endl;
return creds[0];
}
}

for (auto it = providers.lower_bound(resourceType); it != providers.end();
++it) {
cerr << "testing " << it->first << " against " << resourceType
<< endl;
if (resourceType.find(it->first) != 0)
break; // not a prefix
cerr << "FOUND" << endl;

auto creds = it->second->getSync(resourceType, resource, context,
extraData);
if (!creds.empty()) {
cerr << "credentials for " << resourceType << " " << resource
<< " are " << endl << jsonEncode(creds[0]) << endl;
return creds[0];
}
}

throw ML::Exception("No credentials found for " + resourceType + " "
+ resource);
}


} // namespace Datacratic

41 changes: 41 additions & 0 deletions credentials/credential_provider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* credential_provider.h -*- C++ -*-
Jeremy Barnes, 5 November 2014
Copyright (c) 2014 Datacratic Inc. All rights reserved.

Credential provider structure and registration.
*/

#include "soa/credentials/credentials.h"

#pragma once

namespace Datacratic {


/*****************************************************************************/
/* CREDENTIAL PROVIDER */
/*****************************************************************************/

/** Base class that can provide credentials to access a given resource.

Credentials are pluggable to allow for flexible scenarios.
*/
struct CredentialProvider {

virtual ~CredentialProvider();

virtual std::vector<std::string>
getResourceTypePrefixes() const = 0;

virtual std::vector<Credential>
getSync(const std::string & resourceType,
const std::string & resource,
const CredentialContext & context,
Json::Value extraData) const = 0;

static void registerProvider(const std::string & name,
std::shared_ptr<CredentialProvider> provider);
};


} // namespace Datacratic
42 changes: 42 additions & 0 deletions credentials/credentials.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/** credentials.cc
Jeremy Barnes, 5 November 2014
Copyright (c) 2014 Datacratic Inc. All rights reserved.

*/

#include "credentials.h"
#include "soa/types/basic_value_descriptions.h"

using namespace std;

namespace Datacratic {

DEFINE_STRUCTURE_DESCRIPTION(Credential);

CredentialDescription::
CredentialDescription()
{
addField("provider", &Credential::provider,
"Provider of credentials");
addField("protocol", &Credential::protocol,
"Protocol to use to access the service");
addField("location", &Credential::location,
"Location of the service");
addField("id", &Credential::id,
"User ID to use to access the service");
addField("secret", &Credential::secret,
"Secret key to use to access the service");
addField("extra", &Credential::extra,
"Extra configuration needed to access the service");
addField("validUntil", &Credential::validUntil,
"Time until which the credential is valid");
}

DEFINE_STRUCTURE_DESCRIPTION(CredentialContext);

CredentialContextDescription::
CredentialContextDescription()
{
}

} // namespace Datacratic
50 changes: 50 additions & 0 deletions credentials/credentials.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* credentials.h -*- C++ -*-
Jeremy Barnes, 5 November 2014

A pluggable mechanism for getting credentials.
*/

#pragma once

#include "soa/types/value_description.h"
#include "soa/types/date.h"
#include "soa/types/periodic_utils.h"

namespace Datacratic {

struct Credential {
std::string provider; ///< Path through which credential was obtained
std::string protocol; ///< Protocol to use to get to service
std::string location; ///< URI to call to get resource
std::string id; ///< User ID
std::string secret; ///< Password / secret / etc

Json::Value extra; ///< Other fields

Date validUntil;
};

DECLARE_STRUCTURE_DESCRIPTION(Credential);

struct CredentialContext {
};

DECLARE_STRUCTURE_DESCRIPTION(CredentialContext);

/** Return credentials for the given resource of the given resource type.

If none are available, then returns an empty list.
*/
std::vector<Credential>
getCredentials(const std::string & resourceType,
const std::string & resource,
const CredentialContext & context,
Json::Value extraData = Json::Value());

Credential getCredential(const std::string & resourceType,
const std::string & resource,
const CredentialContext & context = CredentialContext(),
Json::Value extraData = Json::Value(),
TimePeriod validTime = "99999d");

} // namespace Datacratic
11 changes: 11 additions & 0 deletions credentials/credentials.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# credentials makefile
# Jeremy Barnes, 5 November 2014
# Copyright (c) 2014 Datacratic Inc. All rights reserved.

LIBCREDENTIALS_SOURCES := \
credentials.cc credential_provider.cc

LIBCREDENTIALS_LINK := \
arch utils types value_description

$(eval $(call library,credentials,$(LIBCREDENTIALS_SOURCES),$(LIBCREDENTIALS_LINK)))
37 changes: 0 additions & 37 deletions service/aws.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@
using namespace std;
using namespace ML;


namespace {

std::mutex awsCredentialsLock;
std::map<string, std::string> awsCredentials;

} // file scope


namespace Datacratic {

template<class Hash>
Expand Down Expand Up @@ -595,32 +586,4 @@ performGet(RestParams && params,
resultSelector);
}

void registerAwsCredentials(const string & accessKeyId,
const string & accessKey)
{
unique_lock<mutex> guard(awsCredentialsLock);

string & entry = awsCredentials[accessKeyId];
if (entry.empty()) {
entry = accessKey;
}
else {
if (entry != accessKey) {
throw ML::Exception("access key id '%s' already registered with a"
" different key", accessKeyId.c_str());
}
}
}

string getAwsAccessKey(const string & accessKeyId)
{
auto it = awsCredentials.find(accessKeyId);
if (it == awsCredentials.end()) {
throw ML::Exception("no access key registered for id '%s'",
accessKeyId.c_str());
}

return it->second;
}

} // namespace Datacratic
8 changes: 0 additions & 8 deletions service/aws.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,4 @@ struct AwsBasicApi : public AwsApi {
HttpRestProxy proxy;
};

/** Register an AWS access key for future referencing in urls or association
* with buckets */
void registerAwsCredentials(const std::string & accessKeyId,
const std::string & accessKey);

/** Returns the key associated with the access key id */
std::string getAwsAccessKey(const std::string & accessKeyId);

} // namespace Datacratic
4 changes: 3 additions & 1 deletion service/named_endpoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ NamedEndpoint::
publishAddress(const std::string & address,
const Json::Value & addressConfig)
{
ExcAssert(config);
// If we didn't set up a configuration endpoint or name, then just no-op
if (!config)
return;

//cerr << "publishing " << address << " with " << addressConfig << endl;
config->setUnique(endpointName + "/" + address,
Expand Down
Loading