Skip to content

Commit

Permalink
Merge pull request #186 from state-alchemists/1.0.0
Browse files Browse the repository at this point in the history
Add Fastapp Authorization
  • Loading branch information
goFrendiAsgard authored Jan 30, 2025
2 parents dfb6c61 + 15c6dca commit 1dd968f
Show file tree
Hide file tree
Showing 50 changed files with 1,734 additions and 670 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/_zrb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
Run-command:
runs-on: ubuntu-latest
container:
image: stalchmst/zrb:1.0.0b6
image: stalchmst/zrb:1.0.0b9
steps:
- name: Check out repository code
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10-bookworm
FROM python:3.10-slim-bookworm

# Create and set workdir
RUN mkdir -p /project
Expand Down
85 changes: 85 additions & 0 deletions docs/notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Create permission bulk

```json
[
{"name": "book:create", "description": "create book"},
{"name": "book:update", "description": "update book"},
{"name": "book:delete", "description": "delete book"},
{"name": "book:view", "description": "view book"}
]
```

# Create roles bulk

```json
[
{
"name": "librarian",
"description": "Full access to manage books",
"permission_names": [
"book:create",
"book:update",
"book:delete",
"book:view"
]
},
{
"name": "assistant-librarian",
"description": "Can create, update, and view books, but not delete them",
"permission_names": [
"book:create",
"book:update",
"book:view"
]
},
{
"name": "viewer",
"description": "Can only view books",
"permission_names": [
"book:view"
]
}
]
```

# Create user bulk

```json
[
{
"username": "john_doe",
"password": "password123",
"role_names": [
"librarian"
],
"active": true
},
{
"username": "jane_smith",
"password": "securePass!2025",
"role_names": [
"assistant-librarian"
],
"active": true

},
{
"username": "alex_viewer",
"password": "viewOnly@2025",
"role_names": [
"viewer"
],
"active": true

},
{
"username": "emily_helper",
"password": "strongPass$567",
"role_names": [
"assistant-librarian",
"viewer"
],
"active": true
}
]
```
32 changes: 31 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "zrb"
version = "1.0.0b6"
version = "1.0.0b9"
description = "Your Automation Powerhouse"
authors = ["Go Frendi Gunawan <gofrendiasgard@gmail.com>"]
license = "AGPL-3.0-or-later"
Expand Down Expand Up @@ -52,12 +52,13 @@ python-jose = {extras = ["cryptography"], version = "^3.3.0"}
ulid-py = "^1.1.0"
pydantic-ai = "^0.0.19"
fastembed = "^0.5.1"
psutil = "^6.1.1"

[tool.poetry.extras]
# poetry install -E rag
rag = ["chromadb", "pdfplumber"]

[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
alembic = "^1.14.0" # FastApp dependencies
flake8 = "~7.1.1"
pytest = "~8.3.3"
Expand Down
3 changes: 3 additions & 0 deletions src/zrb/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ def serve_cli():
cli.run(sys.argv[1:])
except KeyboardInterrupt:
print(stylize_warning("\nStopped"), file=sys.stderr)
sys.exit(1)
except RuntimeError as e:
if f"{e}".lower() != "event loop is closed":
raise e
sys.exit(1)
except NodeNotFoundError as e:
print(stylize_error(f"{e}"), file=sys.stderr)
sys.exit(1)
30 changes: 15 additions & 15 deletions src/zrb/builtin/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
)
async def get_git_diff(ctx: AnyContext):
ctx.print(stylize_faint("Get directory"))
repo_dir = await get_repo_dir(log_method=ctx.print)
repo_dir = await get_repo_dir(print_method=ctx.print)
diff = await get_diff(
repo_dir, ctx.input.source, ctx.input.current, log_method=ctx.print
repo_dir, ctx.input.source, ctx.input.current, print_method=ctx.print
)
result = []
decorated = []
Expand Down Expand Up @@ -88,17 +88,17 @@ async def get_git_diff(ctx: AnyContext):
)
async def prune_local_branches(ctx: AnyContext):
ctx.print(stylize_faint("Get directory"))
repo_dir = await get_repo_dir(log_method=ctx.print)
repo_dir = await get_repo_dir(print_method=ctx.print)
ctx.print(stylize_faint("Get existing branches"))
branches = await get_branches(repo_dir, log_method=ctx.print)
branches = await get_branches(repo_dir, print_method=ctx.print)
ctx.print(stylize_faint("Get current branch"))
current_branch = await get_current_branch(repo_dir, log_method=ctx.print)
current_branch = await get_current_branch(repo_dir, print_method=ctx.print)
for branch in branches:
if branch == current_branch or branch == "main" or branch == "master":
continue
ctx.print(stylize_faint(f"Removing local branch: {branch}"))
try:
await delete_branch(repo_dir, branch, log_method=ctx.print)
await delete_branch(repo_dir, branch, print_method=ctx.print)
except Exception as e:
ctx.log_error(e)

Expand All @@ -117,11 +117,11 @@ async def prune_local_branches(ctx: AnyContext):
)
async def git_commit(ctx: AnyContext):
ctx.print(stylize_faint("Get directory"))
repo_dir = await get_repo_dir(log_method=ctx.print)
repo_dir = await get_repo_dir(print_method=ctx.print)
ctx.print(stylize_faint("Add changes to staging"))
await add(repo_dir, log_method=ctx.print)
await add(repo_dir, print_method=ctx.print)
ctx.print(stylize_faint("Commit changes"))
await commit(repo_dir, ctx.input.message, log_method=ctx.print)
await commit(repo_dir, ctx.input.message, print_method=ctx.print)


@make_task(
Expand All @@ -139,12 +139,12 @@ async def git_commit(ctx: AnyContext):
)
async def git_pull(ctx: AnyContext):
ctx.print(stylize_faint("Get directory"))
repo_dir = await get_repo_dir(log_method=ctx.print)
repo_dir = await get_repo_dir(print_method=ctx.print)
ctx.print(stylize_faint("Get current branch"))
current_branch = await get_current_branch(repo_dir, log_method=ctx.print)
current_branch = await get_current_branch(repo_dir, print_method=ctx.print)
remote = ctx.input.remote
ctx.print(stylize_faint(f"Pulling from {remote}/{current_branch}"))
await pull(repo_dir, remote, current_branch, log_method=ctx.print)
await pull(repo_dir, remote, current_branch, print_method=ctx.print)


@make_task(
Expand All @@ -161,9 +161,9 @@ async def git_pull(ctx: AnyContext):
alias="push",
)
async def git_push(ctx: AnyContext):
repo_dir = await get_repo_dir(log_method=ctx.print)
repo_dir = await get_repo_dir(print_method=ctx.print)
ctx.print(stylize_faint("Get current branch"))
current_branch = await get_current_branch(repo_dir, log_method=ctx.print)
current_branch = await get_current_branch(repo_dir, print_method=ctx.print)
remote = ctx.input.remote
ctx.print(stylize_faint(f"Pushing to {remote}/{current_branch}"))
await push(repo_dir, remote, current_branch, log_method=ctx.print)
await push(repo_dir, remote, current_branch, print_method=ctx.print)
12 changes: 6 additions & 6 deletions src/zrb/builtin/git_subtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
)
async def git_add_subtree(ctx: AnyContext):
ctx.print(stylize_faint("Get directory"))
repo_dir = await get_repo_dir(log_method=ctx.print)
repo_dir = await get_repo_dir(print_method=ctx.print)
ctx.print(stylize_faint("Add subtree"))
await add_subtree(
repo_dir=repo_dir,
name=ctx.input.name,
repo_url=ctx.input["repo-url"],
branch=ctx.input["repo-branch"],
prefix=ctx.input["repo-prefix"],
log_method=ctx.print,
print_method=ctx.print,
)


Expand All @@ -56,7 +56,7 @@ async def git_add_subtree(ctx: AnyContext):
)
async def git_pull_subtree(ctx: AnyContext):
ctx.print(stylize_faint("Get directory"))
repo_dir = await get_repo_dir(log_method=ctx.print)
repo_dir = await get_repo_dir(print_method=ctx.print)
config = load_config(repo_dir)
if not config.data:
raise ValueError("No subtree config found")
Expand All @@ -69,7 +69,7 @@ async def git_pull_subtree(ctx: AnyContext):
prefix=detail.prefix,
repo_url=detail.repo_url,
branch=detail.branch,
log_method=ctx.print,
print_method=ctx.print,
)
except Exception as e:
if first_err is None:
Expand All @@ -88,7 +88,7 @@ async def git_pull_subtree(ctx: AnyContext):
)
async def git_push_subtree(ctx: AnyContext):
ctx.print(stylize_faint("Get directory"))
repo_dir = await get_repo_dir(log_method=ctx.print)
repo_dir = await get_repo_dir(print_method=ctx.print)
config = load_config(repo_dir)
if not config.data:
raise ValueError("No subtree config found")
Expand All @@ -101,7 +101,7 @@ async def git_push_subtree(ctx: AnyContext):
prefix=detail.prefix,
repo_url=detail.repo_url,
branch=detail.branch,
log_method=ctx.print,
print_method=ctx.print,
)
except Exception as e:
if first_err is None:
Expand Down
7 changes: 4 additions & 3 deletions src/zrb/builtin/project/add/fastapp/fastapp_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@


@make_task(
name="validate-create-fastapp",
name="validate-add-fastapp",
input=[project_dir_input, app_name_input],
retries=0,
)
async def validate_create_fastapp(ctx: AnyContext):
async def validate_add_fastapp(ctx: AnyContext):
project_dir = ctx.input.project_dir
if not os.path.isdir(project_dir):
raise ValueError(f"Project directory not exists: {project_dir}")
Expand All @@ -39,7 +39,7 @@ async def validate_create_fastapp(ctx: AnyContext):
project_dir_input,
app_name_input,
],
upstream=validate_create_fastapp,
upstream=validate_add_fastapp,
source_path=os.path.join(os.path.dirname(__file__), "fastapp_template"),
render_source_path=False,
destination_path="{ctx.input.project_dir}",
Expand All @@ -57,6 +57,7 @@ async def validate_create_fastapp(ctx: AnyContext):
"my_app_name": "{to_snake_case(ctx.input.app)}",
"MY_APP_NAME": "{to_snake_case(ctx.input.app).upper()}",
"my-secure-password": lambda _: get_random_name(),
"my-secret-key": lambda _: get_random_name(),
},
),
# Register fastapp's tasks to project's zrb_init (project_dir/zrb_init.py)
Expand Down
Loading

0 comments on commit 1dd968f

Please sign in to comment.