Skip to content
GitLab
    • Explore Projects Groups Topics Snippets
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • fusiondirectory-integrator fusiondirectory-integrator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 7
    • Issues 7
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • fusiondirectoryfusiondirectory
  • fusiondirectory-integratorfusiondirectory-integrator
  • Merge requests
  • !40
An error occurred while fetching the assigned milestone of the selected merge_request.

Resolve "[Integrator] - Refactor of current logic and creation of fusiondirectory library."

  • Review changes

  • Download
  • Patches
  • Plain diff
Merged dockx thibault requested to merge 30-integrator-refactor-of-current-logic-and-creation-of-fusiondirectory-library into dev 1 year ago
  • Overview 0
  • Commits 12
  • Pipelines 13
  • Changes 3

Related to #30 (closed)

Viewing commit d192213e
Prev Next
Show latest version
3 files
+ 50
− 177

    Preferences

    File browser
    Compare changes
  • Verified
    d192213e
    dockx thibault
    :sparkles: feat(Integrator) - PHASE 1 refactor passed. · d192213e
    dockx thibault authored 11 months ago
src/FusionDirectory/Cli/FusionDirectory.php
+ 17
− 15
  • View file @ d192213e

  • Edit in single-file editor

  • Open in Web IDE


@@ -70,7 +70,7 @@ class FusionDirectory extends Application
{
return [
'list-vars' => [
'help' => 'List possible vars to give --set-var',
'help' => 'List an example of a possible var to give to --set-var followed by --write-vars',
'command' => 'cmdListVars',
],
'set-var:' => [
@@ -111,8 +111,10 @@ class FusionDirectory extends Application
}
}
/**
* Output variables and their current values
* @return void
* Only print an example of variables that can be changed.
*/
protected function cmdListVars (): void
{
@@ -121,22 +123,26 @@ class FusionDirectory extends Application
}
}
/**
* @param string $var
* @return void
* @throws Exception
* Note : This allows to set var in the variables.php file in FD.
* This method needs rework as multiple variables are not received, only a string.
* (logic of multiple should be defined in parent class)
*/
protected function cmdSetVar (array $vars): void
protected function cmdSetVar (string $var): void
{
$varsToSet = [];
foreach ($vars as $var) {
if (preg_match('/^([^=]+)=(.+)$/', $var, $m)) {
if (isset($this->vars[strtolower($m[1])])) {
$varsToSet[strtolower($m[1])] = $m[2];
} else {
throw new Exception('Var "' . $m[1] . '" does not exists. Use --list-vars to get the list of vars.');
}
if (preg_match('/^([^=]+)=(.+)$/', $var, $m)) {
if (isset($this->vars[strtolower($m[1])])) {
$varsToSet[strtolower($m[1])] = $m[2];
} else {
throw new Exception('Incorrect syntax for --set-var: "' . $var . '". Use var=value');
throw new Exception('Var "' . $m[1] . '" does not exists. Use --list-vars to get the list of vars.');
}
} else {
throw new Exception('Incorrect syntax for --set-var: "' . $var . '". Use var=value');
}
if (isset($varsToSet['fd_home'])) {
@@ -206,10 +212,6 @@ class FusionDirectory extends Application
}
}
if ($secret !== NULL) {
if (!class_exists('SecretBox')) {
/* Temporary hack waiting for core namespace/autoload refactor */
require_once($this->vars['fd_home'] . '/include/SecretBox.inc');
}
$location['bind_pwd'] = SecretBox::decrypt($location['bind_pwd'], $secret);
}
$locations[(string)$loc['name']] = $location;
src/FusionDirectory/Cli/LdapApplication.php
+ 33
− 33
  • View file @ d192213e

  • Edit in single-file editor

  • Open in Web IDE


@@ -39,15 +39,15 @@ class LdapApplication extends FusionDirectory
*/
protected string $base;
// /**
// * @var string path to the FusionDirectory configuration file
// */
// protected string $configFilePath;
// /**
// * @var string path to the FusionDirectory configuration file
// */
// protected string $configFilePath;
// /**
// * @var string path to the FusionDirectory secrets file containing the key to decrypt passwords
// */
// protected string $secretsFilePath;
// /**
// * @var string path to the FusionDirectory secrets file containing the key to decrypt passwords
// */
// protected string $secretsFilePath;
/**
* May not be needed once SecretBox situation clears up
@@ -59,36 +59,36 @@ class LdapApplication extends FusionDirectory
{
parent::__construct();
$this->options = [
'ldapuri:' => [
'help' => 'URI to connect to, defaults to configuration file value',
$this->options = [
'ldapuri:' => [
'help' => 'URI to connect to, defaults to configuration file value',
],
'binddn:' => [
'help' => 'DN to bind with, defaults to configuration file value',
'binddn:' => [
'help' => 'DN to bind with, defaults to configuration file value',
],
'bindpwd:' => [
'help' => 'Password to bind with, defaults to configuration file value',
'bindpwd:' => [
'help' => 'Password to bind with, defaults to configuration file value',
],
'saslmech:' => [
'help' => 'SASL mech, activates SASL if specified',
'saslmech:' => [
'help' => 'SASL mech, activates SASL if specified',
],
'saslrealm:' => [
'help' => 'SASL realm',
'saslrealm:' => [
'help' => 'SASL realm',
],
'saslauthcid:' => [
'help' => 'SASL authcid',
'saslauthcid:' => [
'help' => 'SASL authcid',
],
'saslauthzid:' => [
'help' => 'SASL authzid',
'saslauthzid:' => [
'help' => 'SASL authzid',
],
'yes' => [
'help' => 'Answer yes to all questions',
'yes' => [
'help' => 'Answer yes to all questions',
],
'verbose' => [
'help' => 'Verbose output',
'verbose' => [
'help' => 'Verbose output',
],
'help' => [
'help' => 'Show this help',
'help' => [
'help' => 'Show this help',
],
];
}
@@ -105,11 +105,11 @@ class LdapApplication extends FusionDirectory
return;
}
$locations = $this->loadFusionDirectoryConfigurationFile();
$location = (string)key($locations);
$locations = $this->loadFusionDirectoryConfigurationFile();
$location = (string)key($locations);
if (count($locations) > 1) {
/* Give the choice between locations to user */
$question = 'There are several locations in your config file, which one should be used: ('.implode(',', array_keys($locations)).')';
$question = 'There are several locations in your config file, which one should be used: (' . implode(',', array_keys($locations)) . ')';
do {
$answer = $this->askUserInput($question, $location);
} while (!isset($locations[$answer]));
@@ -118,7 +118,7 @@ class LdapApplication extends FusionDirectory
$config = $locations[$location];
if ($this->verbose()) {
printf('Connecting to LDAP at %s'."\n", $this->getopt['ldapuri'][0] ?? $config['uri']);
printf('Connecting to LDAP at %s' . "\n", $this->getopt['ldapuri'][0] ?? $config['uri']);
}
$this->ldap = new Ldap\Link($this->getopt['ldapuri'][0] ?? $config['uri']);
if (($this->getopt['saslmech'][0] ?? '') === '') {
src/FusionDirectory/Cli/VarHandling.php deleted 100644 → 0
+ 0
− 129
  • View file @ f5b42557

<?php
/*
This code is part of FusionDirectory (https://www.fusiondirectory.org/)
Copyright (C) 2020-2021 FusionDirectory
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.
*/
namespace FusionDirectory\Cli;
/**
* Trait for cli tools using a variable system through their options
*/
trait VarHandling
{
// /**
// * Current values of variables
// * @var array<string,string>
// */
// protected $vars;
// /**
// * Get the options related to variables handling
// * @return array<string,array<string,string>>
// */
// protected function getVarOptions (): array
// {
// return [
// 'list-vars' => [
// 'help' => 'List possible vars to give --set-var',
// 'command' => 'cmdListVars',
// ],
// 'set-var:' => [
// 'help' => 'Set the variable value',
// 'command' => 'cmdSetVar',
// ],
// ];
// }
// abstract protected function verbose (): bool;
// /**
// * Read variables.inc file from FusionDirectory and update variables accordingly
// */
// protected function readFusionDirectoryVariablesFile (): void
// {
// if ($this->verbose()) {
// printf('Reading vars from %s'."\n", $this->vars['fd_home'].'/include/variables.inc');
// }
// require_once($this->vars['fd_home'].'/include/variables.inc');
//
// $fd_cache = LdapApplication::removeFinalSlash(CACHE_DIR);
// $varsToSet = [
// 'fd_config_dir' => LdapApplication::removeFinalSlash(CONFIG_DIR),
// 'config_file' => LdapApplication::removeFinalSlash(CONFIG_FILE),
// 'fd_smarty_path' => LdapApplication::removeFinalSlash(SMARTY),
// 'fd_spool_dir' => LdapApplication::removeFinalSlash(SPOOL_DIR),
// 'fd_cache' => $fd_cache,
// 'locale_cache_dir' => LdapApplication::removeFinalSlash(str_replace($fd_cache.'/', '', LOCALE_DIR)),
// 'tmp_dir' => LdapApplication::removeFinalSlash(str_replace($fd_cache.'/', '', TEMP_DIR)),
// 'template_dir' => LdapApplication::removeFinalSlash(str_replace($fd_cache.'/', '', CONFIG_TEMPLATE_DIR)),
// 'fai_log_dir' => LdapApplication::removeFinalSlash(str_replace($fd_cache.'/', '', FAI_LOG_DIR)),
// 'class_cache' => LdapApplication::removeFinalSlash(CLASS_CACHE),
// ];
// foreach ($varsToSet as $var => $value) {
// if (isset($this->vars[$var])) {
// $this->vars[$var] = $value;
// }
// }
// }
// /**
// * Output variables and their current values
// */
// protected function cmdListVars (): void
// {
// foreach ($this->vars as $key => $value) {
// printf("%-20s [%s]\n", $key, $value);
// }
// }
/**
* Set variables values
* @param array<string> $vars
*/
// protected function cmdSetVar (array $vars): void
// {
// $varsToSet = [];
// foreach ($vars as $var) {
// if (preg_match('/^([^=]+)=(.+)$/', $var, $m)) {
// if (isset($this->vars[strtolower($m[1])])) {
// $varsToSet[strtolower($m[1])] = $m[2];
// } else {
// throw new \Exception('Var "'.$m[1].'" does not exists. Use --list-vars to get the list of vars.');
// }
// } else {
// throw new \Exception('Incorrect syntax for --set-var: "'.$var.'". Use var=value');
// }
// }
//
// if (isset($varsToSet['fd_home'])) {
// if ($this->verbose()) {
// printf('Setting var %s to "%s"'."\n", 'fd_home', LdapApplication::removeFinalSlash($varsToSet['fd_home']));
// }
// $this->vars['fd_home'] = LdapApplication::removeFinalSlash($varsToSet['fd_home']);
// }
// $this->readFusionDirectoryVariablesFile();
// unset($varsToSet['fd_home']);
// foreach ($varsToSet as $var => $value) {
// if ($this->verbose()) {
// printf('Setting var %s to "%s"'."\n", $var, $value);
// }
// $this->vars[$var] = $value;
// }
// }
}
Assignee
dockx thibault's avatar
dockx thibault
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 Participants
Reference:
Source branch: 30-integrator-refactor-of-current-logic-and-creation-of-fusiondirectory-library

Menu

Explore Projects Groups Topics Snippets