Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add grant workflow to cli #420

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion contxt/cli/commands/edge_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import click

from contxt.cli.clients import Clients
from contxt.cli.utils import fields_option, print_table, sort_option
from contxt.cli.utils import fields_option, print_item, print_table, sort_option
from contxt.models.contxt import EdgeNode


Expand All @@ -22,3 +22,15 @@ def get(clients: Clients, org_id: str, project_id: int, fields: List[str], sort:
"""Get edge nodes for a project"""
items = clients.contxt.get_edge_nodes(organization_id=org_id, project_id=project_id)
print_table(items=items, keys=fields, sort_by=sort)


@edge_nodes.command()
@click.argument("edge_node_id")
@click.argument("target")
@click.pass_obj
def add_grant(clients: Clients, edge_node_id: str, target: int) -> None:
"""Add grant to edge node"""
result = clients.contxt.create_edge_node_grant(
edge_node_id=edge_node_id, to_service_instance_id=target
)
print_item(result)
13 changes: 13 additions & 0 deletions contxt/cli/commands/service_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,16 @@ def create(
def delete(clients: Clients, id: str) -> None:
"""Delete service instance"""
clients.contxt_deployments.delete(f"{clients.org_id}/service_instances/{id}")


@service_instances.command()
@click.argument("service_instance_id")
@click.argument("target")
@click.pass_obj
def add_grant(clients: Clients, service_instance_id: str, target: int) -> None:
"""Add grant to service instance"""
json = {"to_service_instance_id": target}
result = clients.contxt_deployments.post(
f"{clients.org_id}/service_instances/{service_instance_id}/grants", json
)
print_item(result)
5 changes: 5 additions & 0 deletions contxt/services/contxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ def get_edge_nodes(self, organization_id: str, project_id: int) -> List[EdgeNode
resp = self.get(f"organizations/{organization_id}/stacks/{project_id}/edgenodes")
return [EdgeNode.from_api(rec) for rec in resp]

def create_edge_node_grant(self, edge_node_id: str, to_service_instance_id: int) -> Dict:
return self.post(
f"edgenodes/{edge_node_id}/grants", data={"to_service_instance_id": to_service_instance_id}
)

def get_service(self, service_id: int) -> Service:
resp = self.get(f"services/{service_id}")
return Service.from_api(resp)
2 changes: 1 addition & 1 deletion poetry.lock

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

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tabulate = "*"
sgqlc = ">=15,<17"
python-slugify = ">=6.1.2,<9.0.0"

[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
black = "^25"
flake8 = "^7.1.2"
isort = "^6"
Expand Down Expand Up @@ -62,4 +62,4 @@ requires = ["poetry-core>=1.0"]
build-backend = "poetry.core.masonry.api"

[mypy]
exclude = "/contxt/generated/"
exclude = "/contxt/generated/"