irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

irods_environment_properties.cpp
Go to the documentation of this file.
4 #include "irods_exception.hpp"
5 
6 #include "rods.h"
7 #include "irods_log.hpp"
8 
9 #include <string>
10 #include <algorithm>
11 #include <fstream>
12 
13 #include <boost/algorithm/string.hpp>
14 #include <boost/lexical_cast.hpp>
15 #include <boost/filesystem.hpp>
16 
17 
18 namespace irods {
20  std::string& _env_file,
21  std::string& _session_file ) {
22  // capture parent process id for use in creation of 'session'
23  // file which contains the cwd for a given session. this cwd
24  // is only updated by the icd command which writes a new irods
25  // CFG_IRODS_CWD_KW to the session dir which repaves the existing
26  // one in the original irodsEnv file.
27  std::stringstream ppid_str; ppid_str << getppid();
28 
29  // if a json version exists, then attempt to capture
30  // that
31  std::string json_file;
32  try {
33  json_file = get_irods_home_directory().string();
34  } catch (const irods::exception& e) {
35  irods::log(e);
36  return ERROR(-1, "failed to get irods home directory");
37  }
38  std::string json_session_file = json_file;
39  std::string env_var = to_env( CFG_IRODS_ENVIRONMENT_FILE_KW );
40  char* irods_env = getenv(env_var.c_str());
41  if ( irods_env && strlen( irods_env ) > 0 ) {
42  json_file = irods_env;
43  // "cwd" is used in this case instead of the ppid given the
44  // assumption that scripts will set the env file var to allow
45  // for more complex interactions possibly yielding complex pid
46  // hierarchies. this routes all references to the same session
47  // for this given use case
48  json_session_file = json_file + ".cwd";
49 
50  }
51  else {
52  char* home_dir = getenv( "HOME" );
53  // if home env exists, prefer that for run in place
54  // or use of existing irods service accound
55  if ( home_dir ) {
56  json_file = home_dir;
57  }
58 
59  json_file += IRODS_JSON_ENV_FILE;
60  json_session_file = json_file + "." + ppid_str.str();
61 
62  }
63 
64  _env_file = json_file;
65  _session_file = json_session_file;
66 
67  return SUCCESS();
68 
69  } // get_json_environment_file
70 
71 // Access method for singleton
74  return instance;
75  }
76 
78  capture();
79  } // ctor
80 
82  std::string json_file, json_session_file;
83  error ret = get_json_environment_file(json_file, json_session_file);
84  if (!ret.ok()) {
85  irods::log(PASS(ret));
86  return;
87  }
88 
89  if (!boost::filesystem::exists(json_file)) {
90  rodsLog(LOG_ERROR, "environment_properties::capture: missing environment file. should be at [%s]", json_file.c_str());
91  return;
92  }
93 
94  try {
95  capture_json( json_file );
96  config_props_.set< std::string >( CFG_IRODS_ENVIRONMENT_FILE_KW, json_file );
97  try {
98  capture_json( json_session_file );
99  } catch ( const irods::exception& e ) {
100  // debug - irods::log( PASS( ret ) );
101  }
102  config_props_.set< std::string >( CFG_IRODS_SESSION_ENVIRONMENT_FILE_KW, json_session_file );
103  return;
104  } catch ( const irods::exception& e ) {
105  irods::log(e);
106  }
107  }
108 
110  const std::string& _fn ) {
111  error ret = config_props_.load( _fn );
112  if (!ret.ok() ) {
113  THROW(ret.code(), ret.result());
114  }
115 
116  } // capture_json
117 
118  void environment_properties::remove(const std::string& _key ) {
119  config_props_.remove(_key);
120  }
121 
122 } // namespace irods
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
irods::environment_properties::capture
void capture()
Definition: irods_environment_properties.cpp:81
THROW
#define THROW(_code, _msg)
Definition: irods_exception.hpp:68
irods::environment_properties::instance
static environment_properties & instance()
Definition: irods_environment_properties.cpp:72
irods::get_irods_home_directory
boost::filesystem::path get_irods_home_directory()
Definition: irods_default_paths.cpp:36
irods_get_full_path_for_config_file.hpp
irods_environment_properties.hpp
irods::environment_properties
Definition: irods_environment_properties.hpp:17
PASS
#define PASS(prev_error_)
Definition: irods_error.hpp:118
irods::configuration_parser::remove
T remove(const std::string &_key)
Definition: irods_configuration_parser.hpp:119
irods_exception.hpp
irods::environment_properties::remove
T remove(const std::string &_key)
Definition: irods_environment_properties.hpp:58
irods::experimental::administration::client::v1::exists
auto exists(rcComm_t &conn, const user &user) -> bool
Definition: user_administration.cpp:359
irods::to_env
std::string to_env(const std::string &)
Definition: irods_configuration_parser.cpp:172
irods_default_paths.hpp
irods::get_json_environment_file
error get_json_environment_file(std::string &_env_file, std::string &_session_file)
Definition: irods_environment_properties.cpp:19
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
irods::configuration_parser::set
T & set(const std::string &_key, const T &_val)
Definition: irods_configuration_parser.hpp:38
irods::environment_properties::config_props_
configuration_parser config_props_
Definition: irods_environment_properties.hpp:81
SUCCESS
#define SUCCESS()
Definition: irods_error.hpp:121
irods::error::code
long long code() const
Definition: irods_error.cpp:194
irods::IRODS_JSON_ENV_FILE
static const std::string IRODS_JSON_ENV_FILE
Definition: irods_environment_properties.hpp:13
irods
Definition: apiHandler.hpp:35
irods::configuration_parser::load
error load(const std::string &)
Definition: irods_configuration_parser.cpp:72
terminate_irods_processes.e
e
Definition: terminate_irods_processes.py:19
irods::log
void log(const error &)
Definition: irods_log.cpp:13
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
irods::error
Definition: irods_error.hpp:23
irods::environment_properties::environment_properties
environment_properties()
Definition: irods_environment_properties.cpp:77
irods::CFG_IRODS_SESSION_ENVIRONMENT_FILE_KW
const std::string CFG_IRODS_SESSION_ENVIRONMENT_FILE_KW("irods_session_environment_file")
irods::CFG_IRODS_ENVIRONMENT_FILE_KW
const std::string CFG_IRODS_ENVIRONMENT_FILE_KW("irods_environment_file")
irods::environment_properties::capture_json
void capture_json(const std::string &)
Definition: irods_environment_properties.cpp:109
irods::exception
Definition: irods_exception.hpp:15
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
irods::error::result
std::string result() const
Definition: irods_error.cpp:201
rods.h
irods_log.hpp