]> granicus.if.org Git - icinga2/commitdiff
Introduce IcingaApplication#environment
authorMichael Friedrich <michael.friedrich@icinga.com>
Fri, 10 Aug 2018 08:15:41 +0000 (10:15 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Fri, 10 Aug 2018 10:49:48 +0000 (12:49 +0200)
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.

lib/base/CMakeLists.txt
lib/base/application-environment.cpp [new file with mode: 0644]
lib/base/application.hpp
lib/icinga/icingaapplication.cpp
lib/icinga/icingaapplication.hpp
lib/icinga/icingaapplication.ti
lib/remote/apilistener.cpp
lib/remote/apilistener.ti

index c16cda028ae05a8e0905af038a27cdd691f569da..e784a3957bf3df856965a37031bfbebea5a53919 100644 (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
diff --git a/lib/base/application-environment.cpp b/lib/base/application-environment.cpp
new file mode 100644 (file)
index 0000000..a70ea88
--- /dev/null
@@ -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);
+}
index dbb14c38d709eba3a3954769875266af148be529..88fc51ab67a95a74428d9df01ffaf6c7c0f037c3 100644 (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);
 
index b792cdfe7297a251e159c2ce11bdbb920484e924..20a800514c86052a3a4748f8f1dd1f82ac377bbb 100644 (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());
index eac7f5903357bea00d01903eccfd74d5f36d03ed..ba8b77cf33d04799a7d5dfe324175aa12063601d 100644 (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:
index 61d4ecd4ce5e855ccd9dda759b89984e5a510a15..b9f0381b31f29cab823e35e5e50a8a24ccfe6c5b 100644 (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; }}}
        };
index 5e0d2a1bf25979fc7c7dc9f97d8d08b9d695e4db..8c0abf570fa254d3fdd235d5ff2395678cc5cd96 100644 (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;
 
        {
index 05a3309907724d4b4dcff8adfe9e005590696a08..04e4832709434a015fbe918f3efa6b1a68d69943 100644 (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;