From: Marcin Haba Date: Sat, 11 Aug 2018 06:13:29 +0000 (+0200) Subject: baculum: Add name field to api client parameters X-Git-Tag: Release-9.4.0~95 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a53fc41d4e9d34c99a8fa56e02ecf48fa2efe08a;p=thirdparty%2Fbacula.git baculum: Add name field to api client parameters --- diff --git a/gui/baculum/protected/API/Class/OAuth2/OAuth2Config.php b/gui/baculum/protected/API/Class/OAuth2/OAuth2Config.php index 3e6e6c052d..6088bb5b4a 100644 --- a/gui/baculum/protected/API/Class/OAuth2/OAuth2Config.php +++ b/gui/baculum/protected/API/Class/OAuth2/OAuth2Config.php @@ -45,6 +45,14 @@ class OAuth2Config extends ConfigFileModule { */ private $required_options = array('client_id', 'client_secret', 'redirect_uri', 'scope'); + /** + * New options with default values that has been added later (after creating config). + * They are added to config output. + * + * @see OAuth2Config::setAddedOptions() + */ + private $added_options = array('name' => ''); + /** * Get (read) OAuth2 client config. * @@ -56,7 +64,7 @@ class OAuth2Config extends ConfigFileModule { $config = $this->readConfig(self::CONFIG_FILE_PATH, self::CONFIG_FILE_FORMAT); $is_valid = true; if (!is_null($section)) { - $config = array_key_exists($section, $config) ? $config[$section] : array(); + $config = key_exists($section, $config) ? $config[$section] : array(); $is_valid = $this->validateConfig($config); } else { foreach ($config as $value) { @@ -69,6 +77,8 @@ class OAuth2Config extends ConfigFileModule { if ($is_valid === false) { // no validity, no config $config = array(); + } else { + $this->setAddedOptions($config, $section); } return $config; } @@ -101,7 +111,7 @@ class OAuth2Config extends ConfigFileModule { * case errors and it could cause save to log a private auth params. */ for ($i = 0; $i < count($this->required_options); $i++) { - if (!array_key_exists($this->required_options[$i], $config)) { + if (!key_exists($this->required_options[$i], $config)) { $is_valid = false; $emsg = 'Invalid OAuth2 config. Missing ' . $this->required_options[$i] . ' option.'; $this->getModule('logging')->log( @@ -116,4 +126,27 @@ class OAuth2Config extends ConfigFileModule { } return $is_valid; } + + /** + * Add "on the fly" new options to config. + * Note, this method should be used after config validation. + * + * @param array reference $config config to set added options. + * @param mixed $section determines if passed all config or only section + * @return none + */ + private function setAddedOptions(&$config, $section = null) { + foreach ($this->added_options as $added_opt => $defval) { + if (is_null($section)) { + foreach($config as $key => $value) { + if (!key_exists($added_opt, $value)) { + $config[$key][$added_opt] = $defval; + } + } + } elseif (!key_exists($added_opt, $config)) { + $config[$added_opt] = $defval; + } + } + } } +?> diff --git a/gui/baculum/protected/API/Pages/Panel/APIHome.page b/gui/baculum/protected/API/Pages/Panel/APIHome.page index 412f45df1f..84142f109a 100644 --- a/gui/baculum/protected/API/Pages/Panel/APIHome.page +++ b/gui/baculum/protected/API/Pages/Panel/APIHome.page @@ -16,6 +16,9 @@ <%[ Refresh token ]%> +
+ +