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-orchestrator fusiondirectory-orchestrator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 24
    • Issues 24
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 6
    • Merge requests 6
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • fusiondirectoryfusiondirectory
  • fusiondirectory-orchestratorfusiondirectory-orchestrator
  • Merge requests
  • !79
An error occurred while fetching the assigned milestone of the selected merge_request.

Resolve "[Orchestrator] - Automatic Archiving Based on SupAnn Resource States"

  • Review changes

  • Download
  • Patches
  • Plain diff
Merged dockx thibault requested to merge 74-orchestrator-automatic-archiving-based-on-supann-resource-states into dev 1 month ago
  • Overview 0
  • Commits 6
  • Pipelines 6
  • Changes 1

Related to #74 (closed)

Viewing commit bb879dfc
Prev Next
Show latest version
1 file
+ 69
− 38

    Preferences

    File browser
    Compare changes
  • Verified
    bb879dfc
    dockx thibault
    :sparkles: feat(archive) - refactor archiving logic to streamline user status... · bb879dfc
    dockx thibault authored 1 month ago
    :sparkles: feat(archive) - refactor archiving logic to streamline user status checks and enhance error handling (still error from API)
plugins/tasks/Archive.php
+ 69
− 38
  • View file @ bb879dfc

  • Edit in single-file editor

  • Open in Web IDE


@@ -32,43 +32,45 @@ class Archive implements EndpointInterface
$result = [];
$archiveTasks = $this->gateway->getObjectTypeTask('archive');
foreach ($archiveTasks as $task) {
// Verify the task status and schedule
if ($this->gateway->statusAndScheduleCheck($task)) {
// Retrieve the user's supannAccountStatus
$userStatus = $this->getUserSupannAccountStatus($task['fdtasksgranulardn'][0]);
// Check if the user meets the "toBeArchived" condition
if ($userStatus === 'toBeArchived') {
// Construct the archive URL
$archiveUrl = $_ENV['FUSION_DIRECTORY_API_URL'] . '/archive/user/' . rawurlencode($task['fdtasksgranulardn'][0]);
// Initialize the WebServiceCall object
$webServiceCall = new WebServiceCall($archiveUrl, 'POST');
$webServiceCall->setCurlSettings();
// Execute the request
$response = curl_exec($webServiceCall->ch);
// Handle any cURL errors
$webServiceCall->handleCurlError($webServiceCall->ch);
// Decode and process the response
$responseData = json_decode($response, true);
if ($responseData && isset($responseData['success']) && $responseData['success'] === true) {
$result[$task['dn']]['result'] = "User successfully archived.";
$this->gateway->updateTaskStatus($task['dn'], $task['cn'][0], '2'); // Mark task as completed
} else {
$result[$task['dn']]['result'] = "Error archiving user.";
$this->gateway->updateTaskStatus($task['dn'], $task['cn'][0], '3'); // Mark task as failed
}
// Initialize the WebServiceCall object for login
$webServiceCall = new WebServiceCall($_ENV['FUSION_DIRECTORY_API_URL'] . '/login', 'POST');
$webServiceCall->setCurlSettings(); // Perform login and set the token
// Close the cURL resource
curl_close($webServiceCall->ch);
} else {
$result[$task['dn']]['result'] = "User does not meet the criteria for archiving.";
foreach ($archiveTasks as $task) {
try {
if (!$this->gateway->statusAndScheduleCheck($task)) {
// Skip this task if it does not meet the status and schedule criteria
continue;
}
// Receive null or 'toBeArchived'
$supannState = $this->getUserSupannAccountStatus($task['fdtasksgranulardn'][0]);
if ($supannState !== 'toBeArchived') {
// The task does not meet the criteria for archiving and can therefore be suppressed
$result[$task['dn']]['result'] = "User does not meet the criteria for archiving.";
$this->gateway->removeSubTask($task['dn']);
continue;
}
// Set the archive endpoint and method using the same WebServiceCall object
$archiveUrl = $_ENV['FUSION_DIRECTORY_API_URL'] . '/archive/user/' . rawurlencode($task['fdtasksgranulardn'][0]);
$webServiceCall->setCurlSettings($archiveUrl, [], 'POST'); // Update settings for the archive request
$response = $webServiceCall->execute();
print_r([$response]);
exit;
if (isset($response['success']) && $response['success'] === true) {
$result[$task['dn']]['result'] = "User successfully archived.";
$this->gateway->updateTaskStatus($task['dn'], $task['cn'][0], '2');
} else {
throw new Exception("Invalid API response format");
}
} catch (Exception $e) {
$result[$task['dn']]['result'] = "Error archiving user: " . $e->getMessage();
$this->gateway->updateTaskStatus($task['dn'], $task['cn'][0], $e->getMessage());
}
}
}
return $result;
@@ -101,8 +103,37 @@ class Archive implements EndpointInterface
*/
private function getUserSupannAccountStatus(string $userDn): ?string
{
// Logic to retrieve the supannAccountStatus attribute of the user
$user = $this->gateway->getLdapEntry($userDn, ['supannAccountStatus']);
return $user['supannAccountStatus'][0] ?? NULL;
$supannState = $this->gateway->getLdapTasks(
'(objectClass=supannPerson)',
['supannRessourceEtatDate'],
'',
$userDn
);
if ($this->hasToBeArchived($supannState)) {
return 'toBeArchived';
}
return null;
}
private function hasToBeArchived(array $supannState): bool
{
if (!isset($supannState[0]['supannressourceetatdate']) || !is_array($supannState[0]['supannressourceetatdate'])) {
return false;
}
foreach ($supannState[0]['supannressourceetatdate'] as $key => $value) {
// Skip non-numeric keys (e.g., 'count')
if (!is_numeric($key)) {
continue;
}
if (strpos($value, '{COMPTE}I:toBeArchived') !== false) {
return true;
}
}
return false;
}
}
\ No newline at end of file
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: 74-orchestrator-automatic-archiving-based-on-supann-resource-states

Menu

Explore Projects Groups Topics Snippets