Line |
Branch |
Exec |
Source |
1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System. |
3 |
|
|
*/ |
4 |
|
|
|
5 |
|
|
#include "swissknife_notify.h" |
6 |
|
|
|
7 |
|
|
#include "notify/cmd_pub.h" |
8 |
|
|
#include "notify/cmd_sub.h" |
9 |
|
|
|
10 |
|
|
namespace { |
11 |
|
|
|
12 |
|
✗ |
bool ValidateArgs(const swissknife::ArgumentList& args) { |
13 |
|
✗ |
const bool publish = args.count('p') > 0; |
14 |
|
✗ |
const bool subscribe = args.count('s') > 0; |
15 |
|
|
|
16 |
|
✗ |
if (publish == subscribe) { |
17 |
|
✗ |
LogCvmfs(kLogCvmfs, kLogStdout, |
18 |
|
|
"Either the \"publish\" (-p) or the \"subscribe\" (-s) option " |
19 |
|
|
"must be provided"); |
20 |
|
✗ |
return false; |
21 |
|
|
} |
22 |
|
|
|
23 |
|
✗ |
if (publish && (args.count('r') == 0)) { |
24 |
|
✗ |
LogCvmfs(kLogCvmfs, kLogStdout, |
25 |
|
|
"A repository URL (-r) needs to be provided when using the " |
26 |
|
|
"publish command"); |
27 |
|
✗ |
return false; |
28 |
|
|
} |
29 |
|
|
|
30 |
|
✗ |
if (subscribe && (args.count('t') == 0)) { |
31 |
|
✗ |
LogCvmfs(kLogCvmfs, kLogStdout, |
32 |
|
|
"A subscription topic (-t) needs to be provided when using the " |
33 |
|
|
"subscribe command"); |
34 |
|
✗ |
return false; |
35 |
|
|
} |
36 |
|
|
|
37 |
|
✗ |
return true; |
38 |
|
|
} |
39 |
|
|
|
40 |
|
✗ |
uint64_t GetMinRevision(const swissknife::ArgumentList& args) { |
41 |
|
✗ |
if (args.count('m') > 0) { |
42 |
|
✗ |
return std::atoi(args.find('m')->second->c_str()); |
43 |
|
|
} else { |
44 |
|
✗ |
return 0; |
45 |
|
|
} |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
} // namespace |
49 |
|
|
|
50 |
|
|
namespace swissknife { |
51 |
|
|
|
52 |
|
✗ |
CommandNotify::~CommandNotify() {} |
53 |
|
|
|
54 |
|
✗ |
ParameterList CommandNotify::GetParams() const { |
55 |
|
✗ |
ParameterList l; |
56 |
|
✗ |
l.push_back(Parameter::Switch('p', "publish")); |
57 |
|
✗ |
l.push_back(Parameter::Switch('s', "subscribe")); |
58 |
|
✗ |
l.push_back(Parameter::Mandatory('u', "notification server URL")); |
59 |
|
✗ |
l.push_back( |
60 |
|
✗ |
Parameter::Optional('r', "URL of repository with manifest to publish")); |
61 |
|
✗ |
l.push_back(Parameter::Optional('t', "subscription topic")); |
62 |
|
✗ |
l.push_back(Parameter::Optional('m', "minimum revision number of interest")); |
63 |
|
✗ |
l.push_back(Parameter::Switch( |
64 |
|
|
'c', "run continuously (don't exit after first notification)")); |
65 |
|
✗ |
l.push_back(Parameter::Switch('v', "verbose output")); |
66 |
|
✗ |
return l; |
67 |
|
|
} |
68 |
|
|
|
69 |
|
✗ |
int CommandNotify::Main(const ArgumentList& args) { |
70 |
|
✗ |
if (!ValidateArgs(args)) { |
71 |
|
✗ |
return 1; |
72 |
|
|
} |
73 |
|
|
|
74 |
|
✗ |
int ret = 0; |
75 |
|
✗ |
bool verbose = args.count('v') > 0; |
76 |
|
✗ |
std::string server_url = *args.find('u')->second; |
77 |
|
✗ |
bool publish = args.count('p') > 0; |
78 |
|
✗ |
if (publish) { |
79 |
|
✗ |
std::string repository_url = *args.find('r')->second; |
80 |
|
✗ |
ret = notify::DoPublish(server_url, repository_url, verbose); |
81 |
|
✗ |
} else { // subscribe |
82 |
|
✗ |
std::string topic = *args.find('t')->second; |
83 |
|
✗ |
bool continuous = args.count('c') > 0; |
84 |
|
✗ |
const uint64_t revision = GetMinRevision(args); |
85 |
|
✗ |
ret = notify::DoSubscribe(server_url, topic, revision, continuous, verbose); |
86 |
|
|
} |
87 |
|
|
|
88 |
|
✗ |
return ret; |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
} // namespace swissknife |
92 |
|
|
|