1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System. |
3 |
|
|
*/ |
4 |
|
|
|
5 |
|
|
#include "gateway_util.h" |
6 |
|
|
|
7 |
|
|
#include <vector> |
8 |
|
|
|
9 |
|
|
#include "logging.h" |
10 |
|
|
#include "util/string.h" |
11 |
|
|
|
12 |
|
|
namespace gateway { |
13 |
|
|
|
14 |
|
|
int APIVersion() { return 2; } |
15 |
|
|
|
16 |
|
|
bool ReadKeys(const std::string& key_file_name, std::string* key_id, |
17 |
|
|
std::string* secret) { |
18 |
|
|
if (!(key_id && secret)) { |
19 |
|
|
return false; |
20 |
|
|
} |
21 |
|
|
|
22 |
|
|
FILE* key_file_fd = std::fopen(key_file_name.c_str(), "r"); |
23 |
|
|
if (!key_file_fd) { |
24 |
|
|
return false; |
25 |
|
|
} |
26 |
|
|
|
27 |
|
|
std::string line; |
28 |
|
|
if (!GetLineFile(key_file_fd, &line)) { |
29 |
|
|
fclose(key_file_fd); |
30 |
|
|
return false; |
31 |
|
|
} |
32 |
|
|
|
33 |
|
|
fclose(key_file_fd); |
34 |
|
|
|
35 |
|
|
std::vector<std::string> tokens = SplitString(line, ' '); |
36 |
|
|
if (tokens.size() < 2) { |
37 |
|
|
return false; |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
if (tokens[0] == "plain_text") { |
41 |
|
|
*key_id = tokens[1]; |
42 |
|
|
*secret = tokens[2]; |
43 |
|
|
} else { |
44 |
|
|
return false; |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
return true; |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
} // namespace gateway |