dmlite  0.6
DomeTalker.h
Go to the documentation of this file.
1 /*
2  * Copyright 2016 CERN
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 
19 /// @file DomeTalker.h
20 /// @brief Utility class, used to send requests to Dome
21 /// @author Georgios Bitzes <georgios.bitzes@cern.ch>
22 /// @date Mar 2016
23 
24 #ifndef UTILS_DOMETALKER_H
25 #define UTILS_DOMETALKER_H
26 
27 #include <davix/davix.hpp>
28 #include "DavixPool.h"
29 #include "cpp/authn.h"
30 
31 #include <boost/property_tree/ptree.hpp>
32 
33 namespace dmlite {
34 
36  std::string clientName;
37  std::string remoteAddress;
38  std::vector<std::string> groups;
39 
40  DomeCredentials(std::string cn, std::string ra, std::vector<std::string> gr) :
41  clientName(cn), remoteAddress(ra), groups(gr) {}
42 
45  if(ctx) {
46  clientName = ctx->credentials.clientName;
47  if (!clientName.size())
48  clientName = ctx->user.name;
49 
50  remoteAddress = ctx->credentials.remoteAddress;
51 
52  for(size_t i = 0; i < ctx->groups.size(); i++) {
53  groups.push_back(ctx->groups[i].name);
54  }
55  }
56  }
57 };
58 
60  DOME_HTTP_OK = 200,
61 
67 
70 };
71 
72 int http_status(const dmlite::DmException &e);
73 
74 class DomeTalker {
75 public:
76  DomeTalker(DavixCtxPool &pool, const DomeCredentials &creds, std::string uri, std::string verb, std::string cmd);
77  ~DomeTalker();
78 
79  bool execute();
80  bool execute(const boost::property_tree::ptree &params);
81  bool execute(const std::string &str);
82  bool execute(const std::ostringstream &ss);
83 
84  // only send a single json param
85  bool execute(const std::string &key, const std::string &value);
86 
87  // only send two
88  bool execute(const std::string &key1, const std::string &value1,
89  const std::string &key2, const std::string &value2);
90 
91  // get error message, if it exists
92  std::string err();
93 
94  // get response status
95  int status();
96 
97  // produce the appropriate code for a dmlite exception
98  int dmlite_code();
99 
100  const boost::property_tree::ptree& jresp();
101  const std::string& response();
102 private:
105  std::string uri_;
106  std::string verb_;
107  std::string cmd_;
108 
109  std::string target_;
110 
113 
114  Davix::DavixError *err_;
115  std::string response_;
116  boost::property_tree::ptree json_;
118  int status_;
119 };
120 
121 }
122 #endif
Definition: DomeTalker.h:64
std::string remoteAddress
Definition: authn.h:25
Definition: DomeTalker.h:74
int http_status(const dmlite::DmException &e)
Definition: DomeTalker.h:62
Definition: DomeTalker.h:65
std::string clientName
Definition: DomeTalker.h:36
std::string name
Definition: authn.h:43
Security context. To be created by the Authn.
Definition: authn.h:64
std::string target_
Definition: DomeTalker.h:109
Definition: DavixPool.h:48
Base exception class.
Definition: exceptions.h:17
std::string response_
Definition: DomeTalker.h:115
Definition: DomeTalker.h:35
Definition: DomeTalker.h:69
int status_
Definition: DomeTalker.h:118
Authentication API. Any sort of security check is plugin-specific.
Definition: DavixPool.h:87
Definition: DomeTalker.h:60
Definition: DavixPool.h:94
DomeCredentials(std::string cn, std::string ra, std::vector< std::string > gr)
Definition: DomeTalker.h:40
std::vector< GroupInfo > groups
Definition: authn.h:75
UserInfo user
Definition: authn.h:74
DomeHttpCode
Definition: DomeTalker.h:59
DavixCtxPool & pool_
Definition: DomeTalker.h:103
Davix::DavixError * err_
Definition: DomeTalker.h:114
std::string remoteAddress
Definition: DomeTalker.h:37
Definition: DomeTalker.h:63
SecurityCredentials credentials
Definition: authn.h:72
std::string clientName
Definition: authn.h:24
std::string uri_
Definition: DomeTalker.h:105
bool parsedJson_
Definition: DomeTalker.h:117
std::string cmd_
Definition: DomeTalker.h:107
std::string verb_
Definition: DomeTalker.h:106
DavixStuff * ds_
Definition: DomeTalker.h:112
Definition: DomeTalker.h:66
DavixGrabber grabber_
Definition: DomeTalker.h:111
DomeCredentials()
Definition: DomeTalker.h:43
Definition: DomeTalker.h:68
boost::property_tree::ptree json_
Definition: DomeTalker.h:116
Namespace for the dmlite C++ API.
Definition: authn.h:15
DomeCredentials creds_
Definition: DomeTalker.h:104
std::vector< std::string > groups
Definition: DomeTalker.h:38
DomeCredentials(const SecurityContext *ctx)
Definition: DomeTalker.h:44