From c329c9bdc98e93718558ed48175baeac965b8e11 Mon Sep 17 00:00:00 2001 From: Rustem Galiullin Date: Tue, 21 May 2024 15:57:44 +0400 Subject: [PATCH 1/2] enable skipping ssl certificate --- src/hayhooks/cli/__init__.py | 7 ++++--- src/hayhooks/cli/deploy/__init__.py | 10 ++++++++-- src/hayhooks/cli/status/__init__.py | 7 +++++-- src/hayhooks/cli/undeploy/__init__.py | 6 ++++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/hayhooks/cli/__init__.py b/src/hayhooks/cli/__init__.py index 537dfea..cb518b4 100644 --- a/src/hayhooks/cli/__init__.py +++ b/src/hayhooks/cli/__init__.py @@ -11,10 +11,11 @@ @click.group(context_settings={"help_option_names": ["-h", "--help"]}, invoke_without_command=True) @click.version_option(prog_name="Hayhooks") -@click.option('--server', default="http://localhost:1416") +@click.option('-s', '--server', default="http://localhost:1416", help="Hayhooks server URL") +@click.option('-k', '--disable-ssl', default=False, is_flag=True, help="Disable SSL certificate verification") @click.pass_context -def hayhooks(ctx, server): - ctx.obj = server +def hayhooks(ctx, server, disable_ssl): + ctx.obj = server, disable_ssl hayhooks.add_command(run) diff --git a/src/hayhooks/cli/deploy/__init__.py b/src/hayhooks/cli/deploy/__init__.py index 851f056..c0db55f 100644 --- a/src/hayhooks/cli/deploy/__init__.py +++ b/src/hayhooks/cli/deploy/__init__.py @@ -1,4 +1,5 @@ from pathlib import Path +from urllib.parse import urljoin import click import requests @@ -8,10 +9,15 @@ @click.pass_obj @click.option('-n', '--name') @click.argument('pipeline_file', type=click.File('r')) -def deploy(server, name, pipeline_file): +def deploy(server_conf, name, pipeline_file): + server, disable_ssl = server_conf if name is None: name = Path(pipeline_file.name).stem - resp = requests.post(f"{server}/deploy", json={"name": name, "source_code": str(pipeline_file.read())}) + resp = requests.post( + urljoin(server, "deploy"), + json={"name": name, "source_code": str(pipeline_file.read())}, + verify=not disable_ssl + ) if resp.status_code >= 400: click.echo(f"Error deploying pipeline: {resp.json().get('detail')}") diff --git a/src/hayhooks/cli/status/__init__.py b/src/hayhooks/cli/status/__init__.py index d12f05b..94371df 100644 --- a/src/hayhooks/cli/status/__init__.py +++ b/src/hayhooks/cli/status/__init__.py @@ -1,3 +1,5 @@ +from urllib.parse import urljoin + import click import requests from requests.exceptions import ConnectionError @@ -5,9 +7,10 @@ @click.command() @click.pass_obj -def status(server): +def status(server_conf): + server, disable_ssl = server_conf try: - r = requests.get(f"{server}/status") + r = requests.get(urljoin(server, "status"), verify=not disable_ssl) except ConnectionError: click.echo("Hayhooks server is not responding. To start one, run `hayooks run`") return diff --git a/src/hayhooks/cli/undeploy/__init__.py b/src/hayhooks/cli/undeploy/__init__.py index 9957d7a..fdf0d5c 100644 --- a/src/hayhooks/cli/undeploy/__init__.py +++ b/src/hayhooks/cli/undeploy/__init__.py @@ -1,4 +1,5 @@ from pathlib import Path +from urllib.parse import urljoin import click import requests @@ -8,9 +9,10 @@ @click.command() @click.pass_obj @click.argument('pipeline_name') -def undeploy(server, pipeline_name): +def undeploy(server_conf, pipeline_name): + server, disable_ssl = server_conf try: - resp = requests.post(f"{server}/undeploy/{pipeline_name}") + resp = requests.post(urljoin(server, f"undeploy/{pipeline_name}"), verify=not disable_ssl) if resp.status_code >= 400: click.echo(f"Cannot undeploy pipeline: {resp.json().get('detail')}") From 0c304e45c07646a92ec549648cc7f139b46e4993 Mon Sep 17 00:00:00 2001 From: Rustem Galiullin Date: Tue, 21 May 2024 16:03:19 +0400 Subject: [PATCH 2/2] update docs --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 8f86b2c..b33cc3d 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,20 @@ $ hayhooks undeploy test_pipeline_01 Pipeline successfully undeployed ``` +### Set a hayhooks server + +To connect to a specific server you can pass a `--server` argument to the client: +```bash +$ hayhooks --server http://myserver:1416 status +``` + +#### Disable SSL verification + +For development purposes, you can disable SSL verification with the `--disable-ssl` flag: +```bash +$ hayhooks --disable-ssl status +``` + ## Docker setup > [!TIP]