Added terminal function for admin

main
lasseedfast 5 months ago
parent 8501e9da08
commit bae27c758b
  1. 35
      README.md
  2. 59
      arango.py

@ -59,6 +59,41 @@ Features:
- Create and delete users - Create and delete users
- Set user permissions for databases and collections - Set user permissions for databases and collections
## Interactive Admin Terminal Guide
You can use the built-in terminal guide to perform common admin tasks interactively:
- **Create a database**
- **Create a user and set permissions**
To start the guide, you have two options:
**Option 1: Run from Python code**
```python
from _arango import admin
admin()
```
**Option 2: Run directly from the terminal**
```bash
python -m _arango.arango admin
```
Or, if your Python path is set up, you can also run:
```bash
python -m _arango.arango
```
This will start the guide if you add logic to handle command-line arguments (see below).
Permission options are explained in the guide:
- `rw` – read and write access
- `ro` – read-only access
- `none` – no access
For more details on permissions, see: [ArangoDB User Permissions](https://docs.python-arango.com/en/main/specs.html#user-permissions)
## Using as a Base for Your Own Project ## Using as a Base for Your Own Project
If you want to use this package as a starting point for your own ArangoDB utilities, you can clone the repository: If you want to use this package as a starting point for your own ArangoDB utilities, you can clone the repository:

@ -230,8 +230,63 @@ class AdminArango:
+ (f", collection '{collection}'" if collection else "") + (f", collection '{collection}'" if collection else "")
) )
def admin():
"""
Interactive terminal guide for ArangoDB admin tasks:
1) Create a database
2) Create a user and set permissions
"""
GREY = "\033[90m"
RESET = "\033[0m"
admin = AdminArango()
print("\nArangoDB Admin Guide")
print("1) Create a database")
print("2) Create user and set permissions")
choice = input("Choose an option (1/2): ").strip()
if choice == "1":
db_name = input("Enter new database name: ").strip()
add_user = input("Add a user to this database? (y/n): ").strip().lower()
users = []
if add_user == "y":
username = input("Enter username: ").strip()
password = input("Enter password: ").strip()
users.append({"username": username, "password": password})
admin.create_database(db_name, users=users if users else None)
elif choice == "2":
username = input("Enter new username: ").strip()
password = input("Enter password: ").strip()
active = input("Should the user be active? (y/n): ").strip().lower() == "y"
admin.create_user(username, password=password, active=active)
db_name = input("Set permissions for which database?: ").strip()
print(
f"{GREY}Permission options:\n"
" rw - read and write access\n"
" ro - read-only access\n"
" none - no access\n"
"See: https://docs.python-arango.com/en/main/specs.html#user-permissions"
f"{RESET}"
)
permission = input("Permission (rw/ro/none): ").strip()
print(
f"{GREY}Leave collection blank to set permissions for the whole database.{RESET}"
)
collection = input("Collection (leave blank for database-level): ").strip()
collection = collection if collection else None
admin.set_user_permission(username, permission, db_name, collection)
else:
print("Invalid choice.")
# You can call admin_terminal_guide() from __main__ or elsewhere as needed.
arango = Arango() arango = Arango()
if __name__ == "__main__": if __name__ == "__main__":
arango = Arango() import sys
print("Connected to ArangoDB") if len(sys.argv) > 1 and sys.argv[1] == "admin":
admin()
else:
arango = Arango()
print("Connected to ArangoDB")

Loading…
Cancel
Save