Introduce IcingaApplication#environment

Precedence as follows:

- DEnvironment=...
- const Environment = ...
- object IcingaApplication "app" { environment = "..." }

The wrapped script constant handling is required
since we cannot directly link from libremote (SNI handling)
to libicinga where the object resides. Instead we'll
use the Application class helpers for hiding the ScriptGlobal
calls.
This commit is contained in:
Michael Friedrich 2018-08-10 10:15:41 +02:00
parent caefa58cf6
commit 97513965e6
8 changed files with 60 additions and 7 deletions

View File

@ -27,7 +27,7 @@ mkclass_target(sysloglogger.ti sysloglogger-ti.cpp sysloglogger-ti.hpp)
set(base_SOURCES
i2-base.hpp
application.cpp application.hpp application-ti.hpp application-version.cpp
application.cpp application.hpp application-ti.hpp application-version.cpp application-environment.cpp
array.cpp array.hpp array-script.cpp
base64.cpp base64.hpp
boolean.cpp boolean.hpp boolean-script.cpp

View File

@ -0,0 +1,34 @@
/******************************************************************************
* Icinga 2 *
* Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
* *
* 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 2 *
* 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, write to the Free Software Foundation *
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
#include "base/application.hpp"
#include "base/scriptglobal.hpp"
using namespace icinga;
String Application::GetAppEnvironment()
{
Value defaultValue = Empty;
return ScriptGlobal::Get("Environment", &defaultValue);
}
void Application::SetAppEnvironment(const String& name)
{
ScriptGlobal::Set("Environment", name);
}

View File

@ -107,6 +107,9 @@ public:
static String GetAppVersion();
static String GetAppSpecVersion();
static String GetAppEnvironment();
static void SetAppEnvironment(const String& name);
static double GetStartTime();
static void SetStartTime(double ts);

View File

@ -293,6 +293,16 @@ String IcingaApplication::GetNodeName() const
return ScriptGlobal::Get("NodeName");
}
String IcingaApplication::GetEnvironment() const
{
return Application::GetAppEnvironment();
}
void IcingaApplication::SetEnvironment(const String& value, bool suppress_events, const Value& cookie)
{
Application::SetAppEnvironment(value);
}
void IcingaApplication::ValidateVars(const Lazy<Dictionary::Ptr>& lvalue, const ValidationUtils& utils)
{
MacroProcessor::ValidateCustomVars(this, lvalue());

View File

@ -50,6 +50,9 @@ public:
String GetNodeName() const;
String GetEnvironment() const override;
void SetEnvironment(const String& value, bool suppress_events = false, const Value& cookie = Empty) override;
void ValidateVars(const Lazy<Dictionary::Ptr>& lvalue, const ValidationUtils& utils) override;
private:

View File

@ -26,6 +26,12 @@ namespace icinga
class IcingaApplication : Application
{
[config, no_storage, virtual] String environment {
get;
set;
default {{{ return Application::GetAppEnvironment(); }}}
};
[config] bool enable_notifications {
default {{{ return true; }}}
};

View File

@ -441,10 +441,11 @@ void ApiListener::NewClientHandlerInternal(const Socket::Ptr& client, const Stri
TlsStream::Ptr tlsStream;
String environmentName = GetEnvironment();
String environmentName = Application::GetAppEnvironment();
String serverName = hostname;
if (!environmentName.IsEmpty() && environmentName != "")
if (!environmentName.IsEmpty())
serverName += ":" + environmentName;
{

View File

@ -48,10 +48,6 @@ class ApiListener : ConfigObject
default {{{ return Application::GetConst("ApiBindPort", "5665"); }}}
};
[config] String environment {
default {{{ return Application::GetConst("Environment"); }}}
};
[config] bool accept_config;
[config] bool accept_commands;