Skip to content

Commit

Permalink
SetEnv: JSON parameter passing through command is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
HaseenaSainul committed Sep 25, 2024
1 parent fd7627a commit b5c2081
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Source/Thunder/IRemoteInstantiation.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace PluginHost {
const uint8_t threads,
const int8_t priority,
const string configuration,
const string environments) = 0;
const std::vector<string>& environments) = 0;
};
}
}
16 changes: 10 additions & 6 deletions Source/Thunder/PluginServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1277,22 +1277,26 @@ namespace PluginHost {
string Substitute(const string& input) const override {
return (_administrator.Configuration().Substitute(input, PluginHost::Service::Configuration()));
}
string SubstituteList(const string& envList) const override {
string envs;
std::vector<string> SubstituteList(const string& envs) const override {

std::vector<string> environmentList;;
Plugin::Config::EnvironmentList environments;
environments.FromString(envList);
environments.FromString(envs);
if (environments.IsSet() == true) {
Core::JSON::ArrayType<Plugin::Config::Environment>::Iterator index(environments.Elements());
while (index.Next() == true) {
if ((index.Current().Key.IsSet() == true) && (index.Current().Value.IsSet() == true)) {
index.Current().Value = Substitute(index.Current().Value.Value());
string env = index.Current().Key.Value() + Plugin::Config::EnvFieldSeparator +
index.Current().Value.Value() + Plugin::Config::EnvFieldSeparator +
((index.Current().Override.Value() == true) ? "1" : "0");
environmentList.push_back(env);
} else {
SYSLOG(Logging::Startup, (_T("Failure in Substituting Value of Key:Value:[%s]:[%s]\n"), index.Current().Key.Value().c_str(), index.Current().Value.Value().c_str()));
}
}
environments.ToString(envs);
}
return envs;
return environmentList;
}
Core::hresult Metadata(string& info /* @out */) const override {
Metadata::Service result;
Expand Down Expand Up @@ -2421,7 +2425,7 @@ namespace PluginHost {
const uint8_t threads,
const int8_t priority,
const string configuration,
const string environments) override
const std::vector<string>& environments) override
{
string persistentPath(_comms.PersistentPath());
string dataPath(_comms.DataPath());
Expand Down
41 changes: 24 additions & 17 deletions Source/ThunderPlugin/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ POP_WARNING()
class ConsoleOptions : public Core::Options {
public:
ConsoleOptions(int argumentCount, TCHAR* arguments[])
: Core::Options(argumentCount, arguments, _T("h:l:c:C:r:p:s:d:a:m:i:u:g:t:e:x:V:v:P:S:f:e:"))
: Core::Options(argumentCount, arguments, _T("h:l:c:C:r:p:s:d:a:m:i:u:g:t:x:V:v:P:S:f:e:"))
, Locator(nullptr)
, ClassName(nullptr)
, Callsign(nullptr)
Expand Down Expand Up @@ -202,7 +202,7 @@ POP_WARNING()
string ProxyStubPath;
string PostMortemPath;
string SystemRootPath;
string Environments;
std::vector<string> Environments;
const TCHAR* User;
const TCHAR* Group;
uint8_t Threads;
Expand Down Expand Up @@ -251,8 +251,8 @@ POP_WARNING()
case 'S':
SystemRootPath = Core::Directory::Normalize(Strip(argument));
break;
case 'E':
Environments = Strip(argument);
case 'e':
Environments.push_back(Strip(argument));
break;
case 'v':
VolatilePath = Core::Directory::Normalize(Strip(argument));
Expand Down Expand Up @@ -669,20 +669,27 @@ int main(int argc, char** argv)
Core::ProcessCurrent().User(string(options.User));
}

if (options.Environments.empty() != true) {
Core::JSON::ArrayType<Plugin::Config::Environment> Environments;
Environments.FromString(options.Environments);
if (Environments.IsSet() == true) {
Core::JSON::ArrayType<Plugin::Config::Environment>::Iterator index(Environments.Elements());
while (index.Next() == true) {
if ((index.Current().Key.IsSet() == true) && (index.Current().Value.IsSet() == true)) {
uint32_t status = Core::SystemInfo::SetEnvironment(index.Current().Key.Value(), index.Current().Value.Value(), index.Current().Override.Value());
if (status != true) {
SYSLOG(Logging::Startup, (_T("Failure in setting Key:Value:[%s]:[%s]\n"), index.Current().Key.Value().c_str(), index.Current().Value.Value().c_str()));
}
for (const string& env : options.Environments) {
size_t start = env.find_first_of(Plugin::Config::EnvFieldSeparator);
size_t end = env.find_last_of(start, Plugin::Config::EnvFieldSeparator);
if ((start != string::npos) && (end != string::npos)) {
string key = env.substr(start);
string value = env.substr(start + 1, end);
string overrideStr = env.substr(end + 1);

bool toOverride = ((overrideStr.size() == 1) && (overrideStr == "1")) ? true: false;

if ((key.empty() != true) && (value.empty() != true)) {
uint32_t status = Core::SystemInfo::SetEnvironment(key, value, toOverride);
if (status != true) {
SYSLOG(Logging::Startup, (_T("Failure in setting Key:Value:[%s]:[%s]\n"), key, value));
}
}
}
} else {
SYSLOG(Logging::Startup, (_T("Environment key:value fromat is invalid :[%s]:[%s]\n"), key, value));
}
} else {
SYSLOG(Logging::Startup, (_T("Invalid Enviroment value :[%s]\n"), env));
}
}

process.Startup(options.Threads, remoteNode, callsign);
Expand Down
10 changes: 5 additions & 5 deletions Source/com/Communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ namespace RPC {
const string& systemRootPath,
const string& remoteAddress,
const string& configuration,
const string& environments)
const std::vector<string>& environments)
: _locator(locator)
, _className(className)
, _callsign(callsign)
Expand Down Expand Up @@ -235,7 +235,7 @@ namespace RPC {
{
return (_configuration);
}
inline const string& Environments() const
inline const std::vector<string>& Environments() const
{
return (_environments);
}
Expand All @@ -254,7 +254,7 @@ namespace RPC {
string _systemRootPath;
string _remoteAddress;
string _configuration;
string _environments;
std::vector<string> _environments;
};

class EXTERNAL Config {
Expand Down Expand Up @@ -527,8 +527,8 @@ namespace RPC {
if (instance.Threads() > 1) {
_options.Add(_T("-t")).Add(Core::NumberType<uint8_t>(instance.Threads()).Text());
}
if (instance.Environments().empty() == false) {
_options.Add(_T("-E")).Add('"' + instance.Environments() + '"');
for (auto const& env : instance.Environments()) {
_options.Add(_T("-e")).Add('"' + env + '"');
}
_priority = instance.Priority();
}
Expand Down
1 change: 1 addition & 0 deletions Source/plugins/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ namespace Plugin {
Core::JSON::Boolean Override;
};
using EnvironmentList = Core::JSON::ArrayType<Environment>;
static constexpr const TCHAR EnvFieldSeparator = _T(';');

class EXTERNAL RootConfig : public Core::JSON::Container {
private:
Expand Down
2 changes: 1 addition & 1 deletion Source/plugins/IShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ namespace PluginHost {
virtual string Substitute(const string& input) const = 0;

//! Substituted environments list
virtual string SubstituteList(const string& environments) const = 0;
virtual std::vector<string> SubstituteList(const string& environments) const = 0;

virtual bool Resumed() const = 0;
virtual Core::hresult Resumed(const bool value) = 0;
Expand Down

0 comments on commit b5c2081

Please sign in to comment.