17 #ifndef __CREDENTIALS_HPP__ 18 #define __CREDENTIALS_HPP__ 33 namespace credentials {
37 LOG(INFO) <<
"Loading credentials for authentication from '" << path <<
"'";
41 return Error(
"Failed to read credentials file '" + path.
string() +
42 "': " + read.
error());
43 }
else if (read->empty()) {
49 LOG(WARNING) <<
"Failed to stat credentials file '" << path
50 <<
"': " << permissions.
error();
52 LOG(WARNING) <<
"Permissions on credentials file '" << path
53 <<
"' are too open; it is recommended that your" 54 <<
" credentials file is NOT accessible by others";
63 return credentials.
get();
67 Credentials credentials;
70 if (pairs.size() != 2) {
71 return Error(
"Invalid credential format at line " +
72 stringify(credentials.credentials().size() + 1));
76 Credential* credential = credentials.add_credentials();
77 credential->set_principal(pairs[0]);
78 credential->set_secret(pairs[1]);
86 LOG(INFO) <<
"Loading credential for authentication from '" << path <<
"'";
90 return Error(
"Failed to read credential file '" + path.
string() +
91 "': " + read.
error());
92 }
else if (read->empty()) {
98 LOG(WARNING) <<
"Failed to stat credential file '" << path
99 <<
"': " << permissions.
error();
101 LOG(WARNING) <<
"Permissions on credential file '" << path
102 <<
"' are too open; it is recommended that your" 103 <<
" credential file is NOT accessible by others";
110 return credential.
get();
116 Credential credential;
118 if (line.size() != 1) {
119 return Error(
"Expecting only one credential");
122 if (pairs.size() != 2) {
123 return Error(
"Invalid credential format");
126 credential.set_principal(pairs[0]);
127 credential.set_secret(pairs[1]);
135 #endif // __CREDENTIALS_HPP__
Definition: errorbase.hpp:35
T & get()&
Definition: try.hpp:73
Try< Permissions > permissions(const std::string &path)
Definition: permissions.hpp:61
bool rwx
Definition: permissions.hpp:52
std::map< std::string, std::vector< std::string > > pairs(const std::string &s, const std::string &delims1, const std::string &delims2)
Definition: strings.hpp:222
std::vector< std::string > tokenize(const std::string &s, const std::string &delims, const Option< size_t > &maxTokens=None())
Definition: strings.hpp:138
Represents a POSIX or Windows file system path and offers common path manipulations.
Definition: path.hpp:145
void json(JSON::ObjectWriter *writer, const Task &task)
struct os::Permissions::@21 others
static Try error(const E &e)
Definition: try.hpp:42
Result< std::string > read(int_fd fd, size_t size)
Definition: read.hpp:50
Result< Credential > readCredential(const Path &path)
Definition: credentials.hpp:84
Definition: attributes.hpp:24
bool isError() const
Definition: try.hpp:71
Result< Credentials > read(const Path &path)
Definition: credentials.hpp:35
std::string stringify(int flags)
const std::string & string() const
Definition: path.hpp:317