-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.h
90 lines (83 loc) · 3.11 KB
/
config.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
Copyright (C) 2012 Massimo Maggi
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#pragma once
#include <string>
#include <tclap/CmdLine.h>
#include <boost/property_tree/ptree.hpp>
#include <boost/exception/all.hpp>
using namespace std;
class ConfigException : public boost::exception {};
class Config
{
public:
void addArgs(TCLAP::CmdLine& cmd);
void loadConfig();
string getVault() {return vault;}
string getRegion() {return aws_region;}
string getAWSAccessKey() {return aws_access;}
string getAWSSecretKey() {return aws_secret;}
boost::property_tree::ptree& getRunningConfig();
void putRunningConfig(boost::property_tree::ptree cfg);
string getSDBDomain() {return sdbdomain;}
int getChunkSize() {return transmission_chunk_size;}
int getMaxArchiveSize() {return archive_max_size;}
Config():
tc_config("c", "config", "Path to configuration file", false, string(getenv("HOME")).append("/.glaciersdbtool_rc"), "path"),
tc_vault("v", "vault", "Glacier's vault name", false, "", "string"),
tc_sdbdomain("d", "sdbdomain", "SimpleDB domain", false, "", "string"),
tc_aws_access("a", "awsaccesskey", "AWS Access key", false, "", "string"),
tc_aws_secret("s", "awssecretkey", "AWS Secret key", false, "", "string"),
tc_aws_region("r", "awsregion", "AWS region", false, "", "string"),
tc_transmission_chunk("p", "partsize", "Maximum part size in MB (Amazon multi-part upload)", false, 0, "MB"),
tc_archive_max("m", "maxsize", "Maximum Glacier archive size in MB (max 4096, default 2048)", false, 0, "MB") {
configdata=NULL;
configfile="";
vault="";
aws_region="";
aws_access="";
aws_secret="";
sdbdomain="";
transmission_chunk_size=0;
archive_max_size=0;
}
~Config() {
if(configdata!=NULL) {
delete configdata;
}
}
protected:
string configfile;
string vault;
string aws_access;
string aws_secret;
string aws_region;
string sdbdomain;
int transmission_chunk_size;
int archive_max_size;
boost::property_tree::ptree* configdata;
template <typename T>
T getFromConfigFile(string key,T defaultvalue);
template <typename T>
T evaluateArg(TCLAP::ValueArg<T>& cmdarg,string configkey,T fakevalue, std::function<bool(T&)> validate, string errmsg);
private:
void loadConfigFile();
TCLAP::ValueArg<string> tc_config;
TCLAP::ValueArg<string> tc_vault;
TCLAP::ValueArg<string> tc_sdbdomain;
TCLAP::ValueArg<string> tc_aws_access;
TCLAP::ValueArg<string> tc_aws_secret;
TCLAP::ValueArg<string> tc_aws_region;
TCLAP::ValueArg<int> tc_transmission_chunk;
TCLAP::ValueArg<int> tc_archive_max;
};