Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /xywa23_agentsudo /examples /wildcard_scopes.py
| """ | |
| Wildcard Scopes Example | |
| Demonstrates how to use wildcard patterns for flexible permissions. | |
| """ | |
| from agentsudo import Agent, sudo | |
| def read_users(): | |
| print("๐ Reading users") | |
| def read_orders(): | |
| print("๐ Reading orders") | |
| def write_users(): | |
| print("โ๏ธ Writing users") | |
| def write_orders(): | |
| print("โ๏ธ Writing orders") | |
| def main(): | |
| print("=" * 60) | |
| print("AgentSudo - Wildcard Scopes Example") | |
| print("=" * 60) | |
| # Agent with wildcard read permissions | |
| readonly_agent = Agent( | |
| name="ReadOnlyBot", | |
| scopes=["read:*"] # Matches read:users, read:orders, etc. | |
| ) | |
| print("\n--- ReadOnly Agent (read:*) ---") | |
| with readonly_agent.start_session(): | |
| read_users() # โ Matches read:* | |
| read_orders() # โ Matches read:* | |
| try: | |
| write_users() # โ Doesn't match read:* | |
| except Exception as e: | |
| print(f"โ Blocked: {type(e).__name__}") | |
| # Agent with specific wildcard | |
| orders_agent = Agent( | |
| name="OrdersBot", | |
| scopes=["read:orders*", "write:orders*"] # Matches orders, orders_archive, etc. | |
| ) | |
| print("\n--- Orders Agent (read:orders*, write:orders*) ---") | |
| with orders_agent.start_session(): | |
| read_orders() # โ Matches read:orders* | |
| write_orders() # โ Matches write:orders* | |
| try: | |
| read_users() # โ Doesn't match orders* | |
| except Exception as e: | |
| print(f"โ Blocked: {type(e).__name__}") | |
| # God mode agent | |
| admin_agent = Agent( | |
| name="AdminBot", | |
| scopes=["*"] # Matches everything | |
| ) | |
| print("\n--- Admin Agent (*) ---") | |
| with admin_agent.start_session(): | |
| read_users() # โ Matches * | |
| read_orders() # โ Matches * | |
| write_users() # โ Matches * | |
| write_orders() # โ Matches * | |
| if __name__ == "__main__": | |
| main() | |
Xet Storage Details
- Size:
- 2.04 kB
- Xet hash:
- 4efa5f72e1eebf78bd4540d7d78c45fcc45bc3932beab18f7ed685b9587774ad
ยท
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.