ARC SDK
UserConfig.h
1 // -*- indent-tabs-mode: nil -*-
2 
3 #ifndef __ARC_USERCONFIG_H__
4 #define __ARC_USERCONFIG_H__
5 
6 #include <list>
7 #include <vector>
8 #include <string>
9 
10 #include <arc/ArcConfig.h>
11 #include <arc/DateTime.h>
12 #include <arc/URL.h>
13 #include <arc/User.h>
14 
15 namespace Arc {
16 
19  class Logger;
20  class XMLNode;
21 
23  enum ServiceType {
26  };
27 
29 
37  public:
39  enum Type {
42  ANY
43  };
44 
46 
52  ConfigEndpoint(const std::string& URLString = "", const std::string& InterfaceName = "", ConfigEndpoint::Type type = ConfigEndpoint::ANY)
54 
57 
59  std::string URLString;
60 
62  std::string InterfaceName;
63 
65 
71 
73  operator bool() const {
74  return (!URLString.empty());
75  }
76 
78  bool operator!() const {
79  return (URLString.empty());
80  }
81 
83  bool operator==(ConfigEndpoint c) const {
85  }
86  };
87 
89  std::string tostring(const ServiceType st);
90 
92 
99  public:
101  typedef enum {
109  } initializeType;
115  bool operator==(initializeType v) { return (val == v); };
117  bool operator!=(initializeType v) { return (val != v); };
119  operator initializeType(void) { return val; };
120  private:
121  initializeType val;
122  };
123 
125 
196  class UserConfig {
197  public:
199 
215 
244  UserConfig(const std::string& conffile,
245  initializeCredentialsType initializeCredentials = initializeCredentialsType(),
246  bool loadSysConfig = true);
248 
273  UserConfig(const std::string& conffile,
274  const std::string& jfile,
275  initializeCredentialsType initializeCredentials = initializeCredentialsType(),
276  bool loadSysConfig = true);
278 
285  UserConfig(const long int& ptraddr);
286  ~UserConfig() {}
287 
289 
375  bool InitializeCredentials(initializeCredentialsType initializeCredentials);
377 
388  bool CredentialsFound() const {
389  return !((proxyPath.empty() && (certificatePath.empty() || keyPath.empty())) || caCertificatesDirectory.empty());
390  }
391 
393 
413  bool LoadConfigurationFile(const std::string& conffile, bool ignoreJobListFile = true);
414 
416 
426  bool SaveToFile(const std::string& filename) const;
427 
429 
440  void ApplyToConfig(BaseConfig& ccfg) const;
441 
443 
449  operator bool() const { return ok; }
451 
455  bool operator!() const { return !ok; }
456 
458 
476  bool JobListFile(const std::string& path);
478 
486  const std::string& JobListFile() const { return joblistfile; }
487 
489 
508  bool Timeout(int newTimeout);
510 
517  int Timeout() const { return timeout; }
518 
520 
533  bool Verbosity(const std::string& newVerbosity);
535 
544  const std::string& Verbosity() const { return verbosity; }
545 
547 
565  bool Broker(const std::string& name);
567 
583  bool Broker(const std::string& name, const std::string& argument) { broker = std::make_pair<std::string, std::string>(name, argument); return true;}
585 
593  const std::pair<std::string, std::string>& Broker() const { return broker; }
594 
596 
606  bool Bartender(const std::vector<URL>& urls) { bartenders = urls; return true; }
608 
616  void AddBartender(const URL& url) { bartenders.push_back(url); }
618 
625  const std::vector<URL>& Bartender() const { return bartenders; }
626 
628 
640  bool VOMSESPath(const std::string& path) { vomsesPath = path; return true; }
642 
649  const std::string& VOMSESPath();
650 
652 
662  bool UserName(const std::string& name) { username = name; return true; }
664 
671  const std::string& UserName() const { return username; }
672 
674 
684  bool Password(const std::string& newPassword) { password = newPassword; return true; }
686 
693  const std::string& Password() const { return password; }
694 
696 
709  bool ProxyPath(const std::string& newProxyPath) { proxyPath = newProxyPath; return true;}
711 
717  const std::string& ProxyPath() const { return proxyPath; }
718 
720 
737  bool CertificatePath(const std::string& newCertificatePath) { certificatePath = newCertificatePath; return true; }
739 
747  const std::string& CertificatePath() const { return certificatePath; }
748 
750 
768  bool KeyPath(const std::string& newKeyPath) { keyPath = newKeyPath; return true; }
770 
781  const std::string& KeyPath() const { return keyPath; }
782 
784 
797  bool KeyPassword(const std::string& newKeyPassword) { keyPassword = newKeyPassword; return true; }
799 
808  const std::string& KeyPassword() const { return keyPassword; }
809 
811 
823  bool KeySize(int newKeySize) { keySize = newKeySize; return true;}
825 
834  int KeySize() const { return keySize; }
835 
837 
850  bool CACertificatePath(const std::string& newCACertificatePath) { caCertificatePath = newCACertificatePath; return true; }
852 
859  const std::string& CACertificatePath() const { return caCertificatePath; }
860 
862 
878  bool CACertificatesDirectory(const std::string& newCACertificatesDirectory) { caCertificatesDirectory = newCACertificatesDirectory; return true; }
880 
888  const std::string& CACertificatesDirectory() const { return caCertificatesDirectory; }
889 
891 
903  bool CertificateLifeTime(const Period& newCertificateLifeTime) { certificateLifeTime = newCertificateLifeTime; return true; }
905 
912  const Period& CertificateLifeTime() const { return certificateLifeTime; }
913 
915 
923  bool SLCS(const URL& newSLCS) { slcs = newSLCS; return true; }
925 
930  const URL& SLCS() const { return slcs; }
931 
933 
943  bool StoreDirectory(const std::string& newStoreDirectory) { storeDirectory = newStoreDirectory; return true; }
945 
952  const std::string& StoreDirectory() const { return storeDirectory; }
953 
955 
965  bool JobDownloadDirectory(const std::string& newDownloadDirectory) { downloadDirectory = newDownloadDirectory; return true; }
966 
968 
977  const std::string& JobDownloadDirectory() const { return downloadDirectory; }
978 
980 
989  bool IdPName(const std::string& name) { idPName = name; return true; }
991 
997  const std::string& IdPName() const { return idPName; }
998 
1000 
1014  bool OverlayFile(const std::string& path) { overlayfile = path; return true; }
1016 
1020  const std::string& OverlayFile() const { return overlayfile; }
1021 
1023 
1032  bool UtilsDirPath(const std::string& dir);
1034 
1038  const std::string& UtilsDirPath() const { return utilsdir; };
1039 
1041 
1048  void SetUser(const User& u) { user = u; };
1049 
1051 
1055  const User& GetUser() const { return user; };
1056 
1058 
1068  bool InfoInterface(const std::string& infointerface_) {
1069  infointerface = infointerface_;
1070  return true;
1071  }
1073 
1077  const std::string& InfoInterface() const { return infointerface; };
1078 
1080 
1091  bool SubmissionInterface(const std::string& submissioninterface_) {
1092  submissioninterface = submissioninterface_;
1093  return true;
1094  }
1096 
1100  const std::string& SubmissionInterface() const { return submissioninterface; };
1101 
1103 
1108  const std::list<std::string>& RejectDiscoveryURLs() const { return rejectDiscoveryURLs; };
1110 
1117  void AddRejectDiscoveryURLs(const std::list<std::string>& urls) { rejectDiscoveryURLs.insert(rejectDiscoveryURLs.end(), urls.begin(), urls.end()); }
1119 
1123  void ClearRejectDiscoveryURLs() { rejectDiscoveryURLs.clear(); }
1124 
1126 
1131  const std::list<std::string>& RejectManagementURLs() const { return rejectManagementURLs; };
1132 
1133 
1135 
1142  ConfigEndpoint GetService(const std::string& alias);
1143 
1145 
1152  std::list<ConfigEndpoint> GetServicesInGroup(const std::string& group, ConfigEndpoint::Type type = ConfigEndpoint::ANY);
1153 
1155 
1162  std::list<ConfigEndpoint> GetDefaultServices(ConfigEndpoint::Type type = ConfigEndpoint::ANY);
1163 
1165 
1176  std::list<ConfigEndpoint> GetServices(const std::string& groupOrAlias, ConfigEndpoint::Type type = ConfigEndpoint::ANY);
1177 
1179  std::map<std::string, ConfigEndpoint> GetAllConfiguredServices() { return allServices; }
1180 
1181 
1183 
1189  static const std::string ARCUSERDIRECTORY;
1191 
1196  static const std::string SYSCONFIG;
1198 
1202  static const std::string SYSCONFIGARCLOC;
1204 
1210  static const std::string DEFAULTCONFIG;
1212 
1216  static const std::string EXAMPLECONFIG;
1217 
1219 
1226  static const int DEFAULT_TIMEOUT = 20;
1227 
1229 
1237  static const std::string DEFAULT_BROKER;
1238 
1239  private:
1240 
1241  static ConfigEndpoint ServiceFromLegacyString(std::string);
1242 
1243  void setDefaults();
1244  static bool makeDir(const std::string& path);
1245  static bool copyFile(const std::string& source,
1246  const std::string& destination);
1247  bool CreateDefaultConfigurationFile() const;
1248 
1249  std::list<ConfigEndpoint> FilterServices(const std::list<ConfigEndpoint>&, ConfigEndpoint::Type);
1250 
1251 
1252  std::string joblistfile;
1253 
1254  int timeout;
1255 
1256  std::string verbosity;
1257 
1258  // Broker name and arguments.
1259  std::pair<std::string, std::string> broker;
1260 
1261  std::list<ConfigEndpoint> defaultServices;
1262  std::map<std::string, ConfigEndpoint> allServices;
1263  std::map<std::string, std::list<ConfigEndpoint> > groupMap;
1264  std::list<std::string> rejectDiscoveryURLs;
1265  std::list<std::string> rejectManagementURLs;
1266 
1267  // Vector needed for random access.
1268  std::vector<URL> bartenders;
1269 
1270  std::string proxyPath;
1271  std::string certificatePath;
1272  std::string keyPath;
1273  std::string keyPassword;
1274  int keySize;
1275  std::string caCertificatePath;
1276  std::string caCertificatesDirectory;
1277  Period certificateLifeTime;
1278 
1279  URL slcs;
1280 
1281  std::string vomsesPath;
1282 
1283  std::string storeDirectory;
1284  std::string downloadDirectory;
1285  std::string idPName;
1286 
1287  std::string username;
1288  std::string password;
1289 
1290  std::string overlayfile;
1291  std::string utilsdir;
1292 
1293  std::string submissioninterface;
1294  std::string infointerface;
1295  // User whose identity (uid/gid) should be used to access filesystem
1296  // Normally this is the same as the process owner
1297  User user;
1298  // Private members not refered to outside this class:
1299  bool ok;
1300 
1301  initializeCredentialsType initializeCredentials;
1302 
1303  static Logger logger;
1304  };
1305 
1306 
1308 
1321  public:
1323  CertEnvLocker(const UserConfig& cfg);
1325  ~CertEnvLocker(void);
1326 
1327  protected:
1328  std::string x509_user_key_old;
1329  std::string x509_user_key_new;
1330  bool x509_user_key_set;
1331  std::string x509_user_cert_old;
1332  std::string x509_user_cert_new;
1333  bool x509_user_cert_set;
1334  std::string x509_user_proxy_old;
1335  std::string x509_user_proxy_new;
1336  bool x509_user_proxy_set;
1337  std::string ca_cert_dir_old;
1338  bool ca_cert_dir_set;
1339  };
1340 
1343 } // namespace Arc
1344 
1345 #endif // __ARC_USERCONFIG_H__