|
|
|
|
@ -230,8 +230,63 @@ class AdminArango: |
|
|
|
|
+ (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() |
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|
import sys |
|
|
|
|
if len(sys.argv) > 1 and sys.argv[1] == "admin": |
|
|
|
|
admin() |
|
|
|
|
else: |
|
|
|
|
arango = Arango() |
|
|
|
|
print("Connected to ArangoDB") |
|
|
|
|
|