midpoint-cli 1.4.0__tar.gz → 1.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. midpoint_cli-1.5.0/PKG-INFO +806 -0
  2. midpoint_cli-1.5.0/README.md +773 -0
  3. {midpoint_cli-1.4.0 → midpoint_cli-1.5.0}/pyproject.toml +8 -7
  4. {midpoint_cli-1.4.0 → midpoint_cli-1.5.0}/src/midpoint_cli/__init__.py +32 -19
  5. {midpoint_cli-1.4.0 → midpoint_cli-1.5.0}/src/midpoint_cli/client/__init__.py +120 -2
  6. {midpoint_cli-1.4.0 → midpoint_cli-1.5.0}/src/midpoint_cli/client/objects.py +224 -57
  7. midpoint_cli-1.5.0/src/midpoint_cli/client/progress.py +62 -0
  8. midpoint_cli-1.5.0/src/midpoint_cli/prompt/__init__.py +297 -0
  9. {midpoint_cli-1.4.0 → midpoint_cli-1.5.0}/src/midpoint_cli/prompt/base.py +8 -0
  10. {midpoint_cli-1.4.0 → midpoint_cli-1.5.0}/src/midpoint_cli/prompt/console.py +153 -6
  11. {midpoint_cli-1.4.0 → midpoint_cli-1.5.0}/src/midpoint_cli/prompt/delete.py +13 -2
  12. {midpoint_cli-1.4.0 → midpoint_cli-1.5.0}/src/midpoint_cli/prompt/get.py +5 -1
  13. midpoint_cli-1.5.0/src/midpoint_cli/prompt/info.py +27 -0
  14. midpoint_cli-1.5.0/src/midpoint_cli/prompt/org.py +146 -0
  15. {midpoint_cli-1.4.0 → midpoint_cli-1.5.0}/src/midpoint_cli/prompt/put.py +1 -0
  16. {midpoint_cli-1.4.0 → midpoint_cli-1.5.0}/src/midpoint_cli/prompt/resource.py +9 -1
  17. midpoint_cli-1.5.0/src/midpoint_cli/prompt/role.py +122 -0
  18. {midpoint_cli-1.4.0 → midpoint_cli-1.5.0}/src/midpoint_cli/prompt/script.py +1 -0
  19. {midpoint_cli-1.4.0 → midpoint_cli-1.5.0}/src/midpoint_cli/prompt/task.py +42 -11
  20. midpoint_cli-1.5.0/src/midpoint_cli/prompt/user.py +293 -0
  21. midpoint_cli-1.4.0/PKG-INFO +0 -255
  22. midpoint_cli-1.4.0/README.md +0 -221
  23. midpoint_cli-1.4.0/src/midpoint_cli/client/progress.py +0 -33
  24. midpoint_cli-1.4.0/src/midpoint_cli/prompt/__init__.py +0 -165
  25. midpoint_cli-1.4.0/src/midpoint_cli/prompt/org.py +0 -87
  26. midpoint_cli-1.4.0/src/midpoint_cli/prompt/user.py +0 -120
  27. {midpoint_cli-1.4.0 → midpoint_cli-1.5.0}/LICENSE +0 -0
  28. {midpoint_cli-1.4.0 → midpoint_cli-1.5.0}/src/midpoint_cli/client/observer.py +0 -0
  29. {midpoint_cli-1.4.0 → midpoint_cli-1.5.0}/src/midpoint_cli/client/patch.py +0 -0
  30. {midpoint_cli-1.4.0 → midpoint_cli-1.5.0}/src/midpoint_cli/client/session.py +0 -0
  31. {midpoint_cli-1.4.0 → midpoint_cli-1.5.0}/src/midpoint_cli/prompt/complete.py +0 -0
  32. {midpoint_cli-1.4.0 → midpoint_cli-1.5.0}/src/midpoint_cli/prompt/configuration.py +0 -0
@@ -0,0 +1,806 @@
1
+ Metadata-Version: 2.4
2
+ Name: midpoint-cli
3
+ Version: 1.5.0
4
+ Summary: A command line client to Midpoint Identity Management system.
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Author: Yannick Kirschhoffer
8
+ Author-email: alcibiade@alcibiade.org
9
+ Maintainer: Yannick Kirschhoffer
10
+ Maintainer-email: alcibiade@alcibiade.org
11
+ Requires-Python: >=3.9.0,<4.0.0
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: System Administrators
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: System :: Systems Administration
24
+ Requires-Dist: prompt-toolkit (>=3.0,<4.0)
25
+ Requires-Dist: pygments (>=2.18,<3.0)
26
+ Requires-Dist: requests (>=2.32,<3.0)
27
+ Requires-Dist: rich (>=13.0,<15.0)
28
+ Requires-Dist: unidecode (>=1.3,<2.0)
29
+ Requires-Dist: urllib3 (>=2.3,<3.0)
30
+ Project-URL: Repository, https://gitlab.com/alcibiade/midpoint-cli
31
+ Description-Content-Type: text/markdown
32
+
33
+ # Midpoint CLI
34
+
35
+ [![PyPI version](https://badge.fury.io/py/midpoint-cli.svg)](https://badge.fury.io/py/midpoint-cli)
36
+ [![Python Support](https://img.shields.io/pypi/pyversions/midpoint-cli.svg)](https://pypi.org/project/midpoint-cli/)
37
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
38
+ [![GitLab CI/CD](https://gitlab.com/alcibiade/midpoint-cli/badges/master/pipeline.svg)](https://gitlab.com/alcibiade/midpoint-cli/-/pipelines)
39
+ [![Coverage](https://gitlab.com/alcibiade/midpoint-cli/badges/master/coverage.svg)](https://gitlab.com/alcibiade/midpoint-cli/-/commits/master)
40
+ [![Code style: ruff](https://img.shields.io/badge/code%20style-ruff-000000.svg)](https://github.com/astral-sh/ruff)
41
+
42
+ This project is a command line client interface used to drive an Evolveum Midpoint identity management server.
43
+
44
+ ## Table of Contents
45
+
46
+ - [Quick Start](#quick-start)
47
+ - [Features](#features)
48
+ - [Installation](#installation)
49
+ - [Through PyPI](#through-pypi)
50
+ - [Development build](#development-build)
51
+ - [Usage](#usage)
52
+ - [General syntax](#general-syntax)
53
+ - [Configuration files](#external-configuration-files-since-v12)
54
+ - [Environment variables](#environment-variables-since-v12)
55
+ - [Usage Examples](#usage-examples)
56
+ - [Interactive Mode](#interactive-mode)
57
+ - [User Management](#user-management)
58
+ - [Organization Management](#organization-management)
59
+ - [Task Management](#task-management)
60
+ - [Resource Management](#resource-management)
61
+ - [Scripting and Automation](#scripting-and-automation)
62
+ - [Working with XML Definitions](#working-with-xml-definitions)
63
+ - [Using Configuration Files](#using-configuration-files)
64
+ - [Setting up a sandbox environment](#setting-up-a-sandbox-environment)
65
+ - [Requirements](#requirements)
66
+
67
+ ## Features
68
+
69
+ The objectives of this tool are to enable:
70
+
71
+ * **Administrator access** to run tasks and review data
72
+ * **Scripting** for remote controlled automation
73
+ * **Test scenarios** implementation
74
+
75
+ ### Core Capabilities
76
+
77
+ The client currently supports:
78
+
79
+ * **User Management:** List, search, create, update, and delete users
80
+ * **Organizational Units:** Display and manage organizational structures
81
+ * **Task Operations:** List tasks with status and duration, run tasks synchronously with progress monitoring
82
+ * **Resource Management:** List resources, test connectivity, retrieve configurations
83
+ * **Object Operations:** Retrieve, create, update, and delete any Midpoint object type via XML
84
+ * **XML Patch Support:** Apply modifications to existing objects using XML patches
85
+
86
+ ### Task Duration Display
87
+
88
+ * **Running tasks** show real-time elapsed time since start
89
+ * **Completed tasks** display total execution time
90
+ * Human-readable format (e.g., "2h 35m 20s", "5m 30s", "45s")
91
+ * Automatic calculation from Midpoint timestamp fields
92
+
93
+ ### Interactive Mode Features
94
+
95
+ The strong points of this project are:
96
+
97
+ * **Dual Execution Modes:** Run commands directly from shell or use an interactive prompt session
98
+ * **Colorized Output:** Color-coded output when running in a terminal for improved readability
99
+ * **Command History:** Bash-compatible command line history with persistent storage across sessions
100
+ * **Tab Completion:** Auto-completion for task names and OIDs
101
+ * **Interactive Help:** Full built-in help system with command-specific documentation
102
+ * **Standard CLI Syntax:** Classical `midpoint-cli [command] [options]` syntax
103
+
104
+ ### Configuration Flexibility
105
+
106
+ * **Multiple Auth Methods:** Command-line arguments, environment variables, or configuration files
107
+ * **Configuration Priority:** Command-line > Environment variables > Config files > Defaults
108
+ * **Secure Credential Storage:** Use config files or environment variables to avoid exposing passwords
109
+
110
+ ## Quick Start
111
+
112
+ ```bash
113
+ # Install via pip
114
+ pip3 install midpoint-cli
115
+
116
+ # Check version
117
+ midpoint-cli --version
118
+
119
+ # Start interactive session with credentials via command line
120
+ midpoint-cli -u administrator -p password -U https://localhost:8080/midpoint/
121
+
122
+ # Or run a direct command
123
+ midpoint-cli -u administrator -p password -U https://localhost:8080/midpoint/ users
124
+
125
+ # Use environment variables for authentication (recommended)
126
+ export MIDPOINT_URL="https://localhost:8080/midpoint/"
127
+ export MIDPOINT_USERNAME="administrator"
128
+ export MIDPOINT_PASSWORD="password"
129
+
130
+ # Now you can run commands without specifying credentials
131
+ midpoint-cli
132
+ midpoint-cli users
133
+ midpoint-cli tasks
134
+ ```
135
+
136
+ ## Usage
137
+
138
+ ### General syntax
139
+
140
+ ```bash
141
+ usage: midpoint-cli [-h] [-v] [-u USERNAME] [-p PASSWORD] [-U URL]
142
+ [command] [arg [arg ...]]
143
+
144
+ An interactive Midpoint command line client.
145
+
146
+ positional arguments:
147
+ command Optional command to be executed immediately.
148
+ arg Optional command arguments.
149
+
150
+ optional arguments:
151
+ -h, --help show this help message and exit
152
+ -v, --version Show version information
153
+ -u USERNAME, --username USERNAME
154
+ Set the username to authenticate this session.
155
+ -p PASSWORD, --password PASSWORD
156
+ Set the password to authenticate this session.
157
+ -U URL, --url URL Midpoint base URL (e.g., https://localhost:8080/midpoint/)
158
+
159
+ Available commands:
160
+ get Get an XML definition from the server from an existing OID reference.
161
+ Usage: get <object-type> <oid>
162
+ Example: get user 12345678-abcd-1234-abcd-123456789012
163
+
164
+ put Create/Update a server object based on an XML structure.
165
+ Usage: put <xml-file>
166
+ Example: put user-definition.xml
167
+
168
+ delete Delete a server object based on its type and OID.
169
+ Usage: delete <object-type> <oid>
170
+ Example: delete user 12345678-abcd-1234-abcd-123456789012
171
+
172
+ task Manage server tasks.
173
+ Subcommands:
174
+ - tasks: List all tasks with status and duration
175
+ - task run <name-or-oid>: Execute a task and wait for completion
176
+ Example: task run "Recompute All Users"
177
+
178
+ resource Manage resources on the server.
179
+ Subcommands:
180
+ - resources: List all configured resources
181
+ - resource test <name-or-oid>: Test resource connectivity
182
+ Example: resource test "Active Directory"
183
+
184
+ org Manage organizations.
185
+ Usage: org [search-term]
186
+ Example: org Engineering
187
+
188
+ user Manage users.
189
+ Subcommands:
190
+ - users: List all users
191
+ - user search <term> [term ...]: Search for users (OR). Prefix term with + to make it mandatory (AND).
192
+ Example: user search john
193
+ Example: user search +Engineering Doe Smith
194
+ ```
195
+
196
+ ### External configuration files (since v1.2)
197
+
198
+ Settings can be provided from an external configuration file. It can be either:
199
+
200
+ * .midpoint-cli.cfg in the home directory of the current user
201
+ * midpoint-cli.cfg in the current working directory
202
+
203
+ The syntax is as follows:
204
+
205
+ ```
206
+ [Midpoint]
207
+ url = https://localhost:8080/midpoint/
208
+ username = administrator
209
+ password = ...
210
+ ```
211
+
212
+ ### Environment variables (since v1.2)
213
+
214
+ The script will scan environment variables to read input parameters. This is
215
+ particularly useful for injection of password or in-container execution.
216
+
217
+ The variables are:
218
+
219
+ * MIDPOINT_URL
220
+ * MIDPOINT_USERNAME
221
+ * MIDPOINT_PASSWORD
222
+
223
+ ## Usage Examples
224
+
225
+ ### Interactive Mode
226
+
227
+ The interactive mode is one of the strongest features of midpoint-cli. It provides a persistent session with command history, tab completion, colorized output, and a built-in help system. This is ideal for exploring your Midpoint server, troubleshooting, and performing multiple operations without re-authenticating.
228
+
229
+ #### Starting an Interactive Session
230
+
231
+ ```bash
232
+ # Start interactive session with authentication
233
+ midpoint-cli -u administrator -p mypassword -U https://midpoint.example.com/midpoint/
234
+
235
+ # Or use environment variables (recommended)
236
+ export MIDPOINT_URL="https://midpoint.example.com/midpoint/"
237
+ export MIDPOINT_USERNAME="administrator"
238
+ export MIDPOINT_PASSWORD="mypassword"
239
+ midpoint-cli
240
+
241
+ # Or use a configuration file
242
+ # Create ~/.midpoint-cli.cfg with your credentials
243
+ midpoint-cli
244
+ ```
245
+
246
+ #### Interactive Features
247
+
248
+ **Command History Navigation:**
249
+ - Use arrow keys (↑/↓) to navigate through command history
250
+ - History is persistent across sessions (bash-compatible)
251
+ - Search history with Ctrl+R
252
+
253
+ **Tab Completion:**
254
+ - Tab completion available for task names and OIDs
255
+ - Complete commands by pressing Tab
256
+
257
+ **Colorized Output:**
258
+ - Automatic color-coded output when running in a terminal
259
+ - Improved readability for status indicators and tables
260
+
261
+ **Built-in Help System:**
262
+ ```bash
263
+ midpoint> help
264
+ # Shows all available commands
265
+
266
+ midpoint> help users
267
+ # Shows detailed help for the users command
268
+
269
+ midpoint> help task
270
+ # Shows task-related subcommands and usage
271
+ ```
272
+
273
+ #### Common Interactive Workflows
274
+
275
+ **Exploring Users and Organizations:**
276
+ ```bash
277
+ midpoint> users
278
+ # Lists all users with their details
279
+
280
+ midpoint> user search john
281
+ # Search for users matching "john" (OR across all fields)
282
+
283
+ midpoint> user search +Engineering Doe Smith
284
+ # Users in Engineering who match Doe or Smith (mandatory + optional OR)
285
+
286
+ midpoint> org
287
+ # List all organizational units
288
+
289
+ midpoint> get user 12345678-abcd-1234-abcd-123456789012
290
+ # Get detailed XML definition of a specific user
291
+ ```
292
+
293
+ **Task Management Workflow:**
294
+ ```bash
295
+ midpoint> tasks
296
+ # View all tasks with status and duration
297
+
298
+ midpoint> task run "Recompute All Users"
299
+ # Execute a task and monitor progress
300
+ # For running tasks, duration shows elapsed time
301
+ # For completed tasks, duration shows total execution time
302
+
303
+ midpoint> tasks
304
+ # Check updated status after task completion
305
+ ```
306
+
307
+ **Resource Testing and Monitoring:**
308
+ ```bash
309
+ midpoint> resources
310
+ # List all configured resources
311
+
312
+ midpoint> resource test "Active Directory"
313
+ # Test connectivity to a specific resource
314
+
315
+ midpoint> tasks
316
+ # View any reconciliation tasks that may have been triggered
317
+ ```
318
+
319
+ **Quick Object Inspection:**
320
+ ```bash
321
+ midpoint> get user 00000000-0000-0000-0000-000000000002
322
+ # Get administrator user definition
323
+
324
+ midpoint> get task 12345678-task-1234-abcd-123456789012
325
+ # Get task details and configuration
326
+
327
+ midpoint> get resource 12345678-res1-1234-abcd-123456789012
328
+ # Get resource configuration
329
+ ```
330
+
331
+ #### Interactive vs. Direct Execution
332
+
333
+ **Interactive mode advantages:**
334
+ - No need to re-authenticate for each command
335
+ - Command history for repeated operations
336
+ - Tab completion for faster input
337
+ - Persistent session for exploration
338
+ - Better for troubleshooting and manual operations
339
+
340
+ **Direct execution advantages:**
341
+ - Better for scripting and automation
342
+ - Can be used in CI/CD pipelines
343
+ - Single command operations
344
+ - Output can be easily piped to other commands
345
+
346
+ **Example comparison:**
347
+ ```bash
348
+ # Direct execution - requires full authentication each time
349
+ midpoint-cli -u admin -p pass -U https://localhost:8080/midpoint/ users
350
+ midpoint-cli -u admin -p pass -U https://localhost:8080/midpoint/ tasks
351
+ midpoint-cli -u admin -p pass -U https://localhost:8080/midpoint/ resources
352
+
353
+ # Interactive mode - authenticate once, run multiple commands
354
+ midpoint-cli -u admin -p pass -U https://localhost:8080/midpoint/
355
+ midpoint> users
356
+ midpoint> tasks
357
+ midpoint> resources
358
+ midpoint> task run "Recompute All Users"
359
+ midpoint> tasks
360
+ midpoint> exit
361
+ ```
362
+
363
+ ### User Management
364
+
365
+ #### List all users
366
+
367
+ ```bash
368
+ # Direct command execution
369
+ midpoint-cli -u admin -p pass -U https://localhost:8080/midpoint/ users
370
+
371
+ # Output example:
372
+ # OID Name Title FullName Status EmpNo Email OU
373
+ # ------------------------------------ ------------- -------------- --------------- -------- ------- ----------------------- ----
374
+ # 00000000-0000-0000-0000-000000000002 administrator Administrator enabled admin@example.com
375
+ # 12345678-abcd-1234-abcd-123456789012 jdoe IT Manager John Doe enabled E12345 jdoe@example.com IT
376
+ ```
377
+
378
+ #### Search for a specific user
379
+
380
+ ```bash
381
+ # Search by any field (OR: matches users containing "john" OR "jane")
382
+ midpoint-cli user search john jane
383
+
384
+ # Mandatory terms with + prefix (AND: must contain both "john" AND "doe")
385
+ midpoint-cli user search +john +doe
386
+
387
+ # Mixed: must be in Engineering AND match Doe or Smith
388
+ midpoint-cli user search +Engineering Doe Smith
389
+ ```
390
+
391
+ Search terms are case-insensitive and matched as substrings against all user fields (name, full name, email, OU, etc.). Unicode characters are normalised before matching (e.g. `François` matches `francois`).
392
+
393
+ #### Get user details (XML definition)
394
+
395
+ ```bash
396
+ # Retrieve full XML definition of a user by OID
397
+ midpoint-cli get user 12345678-abcd-1234-abcd-123456789012
398
+
399
+ # Save user definition to a file
400
+ midpoint-cli get user 12345678-abcd-1234-abcd-123456789012 > user-backup.xml
401
+ ```
402
+
403
+ #### Create or update a user
404
+
405
+ ```bash
406
+ # Upload a user definition from an XML file
407
+ midpoint-cli put user-definition.xml
408
+
409
+ # Update user with a patch file
410
+ midpoint-cli put user-patch.xml
411
+ ```
412
+
413
+ #### Delete a user
414
+
415
+ ```bash
416
+ # Delete a user by OID
417
+ midpoint-cli delete user 12345678-abcd-1234-abcd-123456789012
418
+ ```
419
+
420
+ ### Organization Management
421
+
422
+ #### List organizational units
423
+
424
+ ```bash
425
+ # List all organizational units
426
+ midpoint-cli org
427
+
428
+ # Interactive mode
429
+ midpoint> org
430
+ # OID Name Parent Description
431
+ # ------------------------------------ -------------- -------- ---------------------
432
+ # 12345678-org1-1234-abcd-123456789012 Engineering Root Engineering Department
433
+ # 12345678-org2-1234-abcd-123456789012 IT Operations Root IT Operations Team
434
+ ```
435
+
436
+ #### Get organization details
437
+
438
+ ```bash
439
+ # Get full XML definition of an org unit
440
+ midpoint-cli get org 12345678-org1-1234-abcd-123456789012
441
+ ```
442
+
443
+ ### Task Management
444
+
445
+ #### List all tasks
446
+
447
+ ```bash
448
+ # List all tasks with status and duration
449
+ midpoint-cli tasks
450
+
451
+ # Output shows running tasks with elapsed time and completed tasks with total execution time
452
+ # Task Name Status Duration Last Run
453
+ # --------------------------- --------- ---------- --------------------
454
+ # Import from HR System RUNNING 1h 25m 30s 2025-10-14 10:30:00
455
+ # Recompute All Users CLOSED 5m 42s 2025-10-14 09:15:00
456
+ # Reconciliation Task WAITING - Not yet started
457
+ ```
458
+
459
+ #### Execute a task synchronously
460
+
461
+ ```bash
462
+ # Run a task and wait for completion
463
+ midpoint-cli task run "Recompute All Users"
464
+
465
+ # Run task by OID
466
+ midpoint-cli task run 12345678-task-1234-abcd-123456789012
467
+ ```
468
+
469
+ #### Get task details
470
+
471
+ ```bash
472
+ # Get task status and XML definition
473
+ midpoint-cli get task 12345678-task-1234-abcd-123456789012
474
+ ```
475
+
476
+ #### Monitor long-running tasks
477
+
478
+ ```bash
479
+ # In interactive mode, you can repeatedly check task status
480
+ midpoint> task run "Import from HR System"
481
+ # Task started: 12345678-task-1234-abcd-123456789012
482
+ # Status: RUNNING (Duration: 5m 30s)
483
+
484
+ midpoint> tasks
485
+ # Check all running tasks with real-time duration updates
486
+ ```
487
+
488
+ ### Resource Management
489
+
490
+ #### List all resources
491
+
492
+ ```bash
493
+ # List configured resources
494
+ midpoint-cli resources
495
+
496
+ # Example output:
497
+ # OID Name Type Status
498
+ # ------------------------------------ ---------------- ------------ --------
499
+ # 12345678-res1-1234-abcd-123456789012 Active Directory LDAP UP
500
+ # 12345678-res2-1234-abcd-123456789012 HR Database Database UP
501
+ ```
502
+
503
+ #### Test a resource connection
504
+
505
+ ```bash
506
+ # Test resource connectivity
507
+ midpoint-cli resource test 12345678-res1-1234-abcd-123456789012
508
+
509
+ # Test by resource name
510
+ midpoint-cli resource test "Active Directory"
511
+ ```
512
+
513
+ #### Get resource configuration
514
+
515
+ ```bash
516
+ # Retrieve full resource definition
517
+ midpoint-cli get resource 12345678-res1-1234-abcd-123456789012 > ad-resource.xml
518
+ ```
519
+
520
+ ### Scripting and Automation
521
+
522
+ #### Batch operations with scripts
523
+
524
+ ```bash
525
+ #!/bin/bash
526
+ # Script to backup all users
527
+
528
+ MIDPOINT_URL="https://midpoint.example.com/midpoint/"
529
+ MIDPOINT_USERNAME="administrator"
530
+ MIDPOINT_PASSWORD="mypassword"
531
+
532
+ export MIDPOINT_URL MIDPOINT_USERNAME MIDPOINT_PASSWORD
533
+
534
+ # Create backup directory
535
+ mkdir -p user-backups
536
+
537
+ # Get list of all users and backup each one
538
+ midpoint-cli users | tail -n +3 | while read -r line; do
539
+ OID=$(echo "$line" | awk '{print $1}')
540
+ NAME=$(echo "$line" | awk '{print $2}')
541
+
542
+ if [ -n "$OID" ] && [ "$OID" != "----" ]; then
543
+ echo "Backing up user: $NAME ($OID)"
544
+ midpoint-cli get user "$OID" > "user-backups/${NAME}.xml"
545
+ fi
546
+ done
547
+
548
+ echo "Backup completed!"
549
+ ```
550
+
551
+ #### Automated user provisioning
552
+
553
+ ```bash
554
+ #!/bin/bash
555
+ # Create users from a list
556
+
557
+ MIDPOINT_CLI="midpoint-cli -u admin -p pass -U https://localhost:8080/midpoint/"
558
+
559
+ # Read user list and create each user
560
+ while IFS=',' read -r username fullname email; do
561
+ cat > /tmp/new-user.xml <<EOF
562
+ <?xml version="1.0" encoding="UTF-8"?>
563
+ <user xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3">
564
+ <name>$username</name>
565
+ <fullName>$fullname</fullName>
566
+ <emailAddress>$email</emailAddress>
567
+ <credentials>
568
+ <password>
569
+ <value>ChangeMe123</value>
570
+ </password>
571
+ </credentials>
572
+ </user>
573
+ EOF
574
+
575
+ echo "Creating user: $username"
576
+ $MIDPOINT_CLI put /tmp/new-user.xml
577
+ done < users.csv
578
+ ```
579
+
580
+ #### Task automation with environment variables
581
+
582
+ ```bash
583
+ # Use environment variables for credentials (more secure)
584
+ export MIDPOINT_URL="https://midpoint.example.com/midpoint/"
585
+ export MIDPOINT_USERNAME="administrator"
586
+ export MIDPOINT_PASSWORD="$(cat /secure/location/password.txt)"
587
+
588
+ # Run tasks without exposing credentials in command line
589
+ midpoint-cli task run "Daily User Reconciliation"
590
+ midpoint-cli task run "Nightly Cleanup Task"
591
+
592
+ # Check task status
593
+ midpoint-cli tasks | grep -E "RUNNING|RUNNABLE"
594
+ ```
595
+
596
+ #### Continuous monitoring script
597
+
598
+ ```bash
599
+ #!/bin/bash
600
+ # Monitor running tasks and send alerts
601
+
602
+ while true; do
603
+ RUNNING_TASKS=$(midpoint-cli tasks | grep "RUNNING" | wc -l)
604
+
605
+ if [ "$RUNNING_TASKS" -gt 5 ]; then
606
+ echo "WARNING: More than 5 tasks running simultaneously!"
607
+ # Send alert (e.g., via email or Slack)
608
+ fi
609
+
610
+ # Check for failed tasks
611
+ FAILED_TASKS=$(midpoint-cli tasks | grep "SUSPENDED")
612
+ if [ -n "$FAILED_TASKS" ]; then
613
+ echo "ALERT: Failed tasks detected:"
614
+ echo "$FAILED_TASKS"
615
+ fi
616
+
617
+ sleep 60 # Check every minute
618
+ done
619
+ ```
620
+
621
+ ### Working with XML Definitions
622
+
623
+ #### Export configuration for version control
624
+
625
+ ```bash
626
+ # Export all critical configurations
627
+ mkdir -p midpoint-config
628
+
629
+ # Export resources
630
+ midpoint-cli resources | tail -n +3 | while read -r line; do
631
+ OID=$(echo "$line" | awk '{print $1}')
632
+ NAME=$(echo "$line" | awk '{print $2}')
633
+ if [ -n "$OID" ] && [ "$OID" != "----" ]; then
634
+ midpoint-cli get resource "$OID" > "midpoint-config/resource-${NAME}.xml"
635
+ fi
636
+ done
637
+
638
+ # Export roles
639
+ midpoint-cli get role 00000000-0000-0000-0000-000000000004 > midpoint-config/superuser-role.xml
640
+
641
+ # Commit to version control
642
+ git add midpoint-config/
643
+ git commit -m "Backup Midpoint configuration"
644
+ ```
645
+
646
+ #### Apply patches to objects
647
+
648
+ ```bash
649
+ # Create a patch file to modify a user
650
+ cat > user-patch.xml <<EOF
651
+ <?xml version="1.0"?>
652
+ <objectModification xmlns="http://midpoint.evolveum.com/xml/ns/public/common/api-types-3">
653
+ <oid>12345678-abcd-1234-abcd-123456789012</oid>
654
+ <modificationType>modify</modificationType>
655
+ <itemDelta>
656
+ <modificationType>replace</modificationType>
657
+ <path>emailAddress</path>
658
+ <value>newemail@example.com</value>
659
+ </itemDelta>
660
+ </objectModification>
661
+ EOF
662
+
663
+ # Apply the patch
664
+ midpoint-cli put user-patch.xml
665
+ ```
666
+
667
+ ### Using Configuration Files
668
+
669
+ Create a configuration file for different environments:
670
+
671
+ **~/.midpoint-cli.cfg** (Production):
672
+ ```ini
673
+ [Midpoint]
674
+ url = https://midpoint.production.example.com/midpoint/
675
+ username = automation-user
676
+ password = secure-production-password
677
+ ```
678
+
679
+ **./midpoint-cli.cfg** (Development - overrides home directory config):
680
+ ```ini
681
+ [Midpoint]
682
+ url = https://localhost:8080/midpoint/
683
+ username = administrator
684
+ password = 5ecr3t
685
+ ```
686
+
687
+ Then simply run commands without authentication parameters:
688
+
689
+ ```bash
690
+ # Uses configuration from file
691
+ midpoint-cli users
692
+ midpoint-cli tasks
693
+ midpoint-cli resource test "AD Resource"
694
+ ```
695
+
696
+ ## Requirements
697
+
698
+ This program is compatible with Python version 3.8 or above.
699
+
700
+ ## Installation
701
+
702
+ ### Through PyPI
703
+
704
+ The most common way to install midpoint-cli on your own computer is to use the PyPI repository:
705
+
706
+ ```bash
707
+ pip3 install midpoint-cli
708
+ ```
709
+
710
+ The installation will automatically install all required dependencies including:
711
+ - `requests` for HTTP communication
712
+ - `tabulate` for formatted table output
713
+ - `args` for argument parsing
714
+
715
+ ### Development build
716
+
717
+ Dependency management, build and test is managed using Python Poetry.
718
+
719
+ To install Poetry, please refer to [the official Python Poetry website](https://python-poetry.org/).
720
+
721
+ To install the current development version from GIT:
722
+
723
+ ```bash
724
+ yk@lunar:~/dev$ git clone https://gitlab.com/alcibiade/midpoint-cli.git
725
+ Cloning into 'midpoint-cli'...
726
+ remote: Enumerating objects: 374, done.
727
+ remote: Counting objects: 100% (374/374), done.
728
+ remote: Compressing objects: 100% (176/176), done.
729
+ remote: Total 374 (delta 229), reused 299 (delta 175)
730
+ Receiving objects: 100% (374/374), 62.84 KiB | 0 bytes/s, done.
731
+ Resolving deltas: 100% (229/229), done.
732
+
733
+ yk@lunar:~/dev$ poetry install
734
+ Creating virtualenv midpoint-cli-54EjqR0S-py3.12 in /home/yk/.cache/pypoetry/virtualenvs
735
+ Updating dependencies
736
+ Resolving dependencies... (5.1s)
737
+
738
+ Package operations: 13 installs, 0 updates, 0 removals
739
+
740
+ - Installing args (0.1.0)
741
+ - Installing certifi (2024.8.30)
742
+ - Installing charset-normalizer (3.3.2)
743
+ - Installing idna (3.10)
744
+ - Installing iniconfig (2.0.0)
745
+ - Installing packaging (24.1)
746
+ - Installing pluggy (1.5.0)
747
+ - Installing urllib3 (2.2.3)
748
+ - Installing pytest (8.3.3)
749
+ - Installing requests (2.32.3)
750
+ - Installing tabulate (0.9.0)
751
+ - Installing unidecode (1.3.8)
752
+
753
+ Writing lock file
754
+
755
+ Installing the current project: midpoint-cli (1.4.0.dev2)
756
+
757
+ yk@lunar:~/dev$ poetry run midpoint-cli --version
758
+ Midpoint CLI Version 1.4.0.dev2
759
+
760
+ ```
761
+
762
+ ### Anaconda
763
+
764
+ Anaconda packages are not available yet.
765
+
766
+ ## Setting up a sandbox environment
767
+
768
+ If you wish to test this project locally and don’t have a midpoint server available, you can use the
769
+ following instructions.
770
+
771
+ ### Using the Evolveum managed Docker image
772
+
773
+ Pull the image locally:
774
+
775
+ ```bash
776
+ yk@lunar:~$ docker pull evolveum/midpoint
777
+ Using default tag: latest
778
+ latest: Pulling from evolveum/midpoint
779
+
780
+ [...]
781
+
782
+ Digest: sha256:1e29b7e891d17bf7b1cf1853c84609e414c3a71d5c420aa38927200b2bdecc8e
783
+ Status: Downloaded newer image for evolveum/midpoint:latest
784
+ docker.io/evolveum/midpoint:latest
785
+
786
+
787
+ ```
788
+
789
+ Then run the server and bind the port 8080:
790
+
791
+ ```bash
792
+ yk@lunar:~$ docker run -d --name midpoint-1 -p8080:8080 evolveum/midpoint
793
+ c048d519395ca48c8e94e361a2239b1c35c5e5305a29600895056e030d6a576f
794
+
795
+ yk@lunar:~$ midpoint-cli
796
+ Welcome to Midpoint client ! Type ? for a list of commands
797
+ midpoint> users
798
+ OID Name Title FullName Status EmpNo Email OU
799
+ ------------------------------------ ------------- ------- ---------------------- -------- ------- ------- ----
800
+ 00000000-0000-0000-0000-000000000002 administrator midPoint Administrator enabled
801
+ midpoint>
802
+
803
+ yk@lunar:~$ docker stop midpoint-1
804
+ midpoint-1
805
+ ```
806
+