Skip to content

Commit

Permalink
Merge pull request #8 from mgcam/send_request2public
Browse files Browse the repository at this point in the history
Renamed _send_request to send_request
  • Loading branch information
nerdstrike authored Jun 28, 2024
2 parents 53c2dfd + 7a58128 commit 6e1d71b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ line_length = 88
max-line-length = 88
extend-select = ["B950"]
extend-ignore = ["E501"]
exclude = [
# No need to traverse our git directory
".git",
# There's no value in checking cache directories
"__pycache__"
]
per-file-ignores = """
# Disable 'imported but unused'
__init__.py: F401
"""

[tool.pytest.ini_options]
addopts = [
Expand Down
1 change: 1 addition & 0 deletions src/npg_porch_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .api import send_request
17 changes: 8 additions & 9 deletions src/npg_porch_cli/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class ServerErrorException(Exception):

@dataclass(kw_only=True)
class Pipeline:

name: str
uri: str
version: str
Expand All @@ -59,7 +58,6 @@ def __post_init__(self):

@dataclass(kw_only=True)
class PorchAction:

porch_url: str
action: str
validate_ca_cert: bool = field(default=True)
Expand Down Expand Up @@ -164,7 +162,7 @@ def send(action: PorchAction, pipeline: Pipeline = None) -> dict | list:
def list_pipelines(action: PorchAction) -> list:
"Returns a listing of all pipelines registered with the porch server."

return _send_request(
return send_request(
validate_ca_cert=action.validate_ca_cert,
url=urljoin(action.porch_url, "pipelines"),
method="GET",
Expand All @@ -178,7 +176,7 @@ def list_tasks(action: PorchAction, pipeline: Pipeline = None) -> list:
only tasks belonging to this pipeline are listed.
"""

response_obj = _send_request(
response_obj = send_request(
validate_ca_cert=action.validate_ca_cert,
url=urljoin(action.porch_url, "tasks"),
method="GET",
Expand All @@ -192,7 +190,7 @@ def list_tasks(action: PorchAction, pipeline: Pipeline = None) -> list:
def add_pipeline(action: PorchAction, pipeline: Pipeline):
"Registers a new pipeline with the porch server."

return _send_request(
return send_request(
validate_ca_cert=action.validate_ca_cert,
method="POST",
url=urljoin(action.porch_url, "pipelines"),
Expand All @@ -205,7 +203,7 @@ def add_task(action: PorchAction, pipeline: Pipeline):

if action.task_input is None:
raise TypeError(f"task_input cannot be None for action '{action.action}'")
return _send_request(
return send_request(
validate_ca_cert=action.validate_ca_cert,
url=urljoin(action.porch_url, "tasks"),
method="POST",
Expand All @@ -216,7 +214,7 @@ def add_task(action: PorchAction, pipeline: Pipeline):
def claim_task(action: PorchAction, pipeline: Pipeline):
"Claims a task that belongs to the previously registered pipeline."

return _send_request(
return send_request(
validate_ca_cert=action.validate_ca_cert,
url=urljoin(action.porch_url, "tasks/claim"),
method="POST",
Expand All @@ -231,7 +229,7 @@ def update_task(action: PorchAction, pipeline: Pipeline):
raise TypeError(f"task_input cannot be None for action '{action.action}'")
if action.task_status is None:
raise TypeError(f"task_status cannot be None for action '{action.action}'")
return _send_request(
return send_request(
validate_ca_cert=action.validate_ca_cert,
url=urljoin(action.porch_url, "tasks"),
method="PUT",
Expand All @@ -253,7 +251,8 @@ def update_task(action: PorchAction, pipeline: Pipeline):
}


def _send_request(validate_ca_cert: bool, url: str, method: str, data: dict = None):
def send_request(validate_ca_cert: bool, url: str, method: str, data: dict = None):
"""Sends an HTTPS request."""

headers = {
"Authorization": "Bearer " + get_token(),
Expand Down

0 comments on commit 6e1d71b

Please sign in to comment.