Skip to content

Commit

Permalink
Adding user agent (#42)
Browse files Browse the repository at this point in the history
* add user agent to request.request
* switch hcloud.Client to custom HClient
  • Loading branch information
strtgbb authored Dec 19, 2024
1 parent 76f6a77 commit 8ac6398
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions testflows/github/hetzner/runners/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
__author__ = "Vitaliy Zakaznikov"
__version__ = "1.7.__VERSION__"
__name__ = "testflows.github.hetzner.runners"
__license__ = f"""
Copyright 2023 Katteli Inc.
TestFlows.com Open-Source Software Testing Framework (http://testflows.com)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import logging.config
from contextlib import contextmanager
from concurrent.futures import ThreadPoolExecutor, Future

from hcloud import Client
from hcloud.ssh_keys.domain import SSHKey

from github import Github
Expand All @@ -34,6 +33,7 @@ from github.Repository import Repository
from argparse import ArgumentParser, RawTextHelpFormatter, ArgumentTypeError

from testflows.github.hetzner.runners import __version__, __license__
from testflows.github.hetzner.runners.hclient import HClient as Client
from testflows.github.hetzner.runners.actions import Action
from testflows.github.hetzner.runners.scale_up import scale_up
from testflows.github.hetzner.runners.scale_down import scale_down
Expand Down
2 changes: 1 addition & 1 deletion testflows/github/hetzner/runners/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import os
import tempfile

from hcloud import Client
from hcloud.ssh_keys.domain import SSHKey
from hcloud.servers.client import BoundServer

Expand All @@ -35,6 +34,7 @@
from .servers import ssh_client as server_ssh_client
from .servers import ssh_client_command as server_ssh_client_command
from .service import command_options
from .hclient import HClient as Client

current_dir = os.path.dirname(__file__)
deploy_scripts_folder = "/home/ubuntu/.github-hetzner-runners/scripts/"
Expand Down
2 changes: 1 addition & 1 deletion testflows/github/hetzner/runners/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

from dataclasses import dataclass

from hcloud import Client
from hcloud.images.domain import Image
from hcloud.server_types.domain import ServerType
from hcloud.locations.domain import Location
from hcloud.ssh_keys.domain import SSHKey

import testflows.github.hetzner.runners.args as args

from ..hclient import HClient as Client
from ..actions import Action
from ..logger import default_format as logger_format

Expand Down
2 changes: 1 addition & 1 deletion testflows/github/hetzner/runners/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from hcloud import Client
from hcloud.servers.client import BoundServer

from github import Github
from github.Repository import Repository
from github.SelfHostedActionsRunner import SelfHostedActionsRunner

from .hclient import HClient as Client
from .scale_up import server_name_prefix, runner_name_prefix
from .config import Config
from .actions import Action
Expand Down
2 changes: 1 addition & 1 deletion testflows/github/hetzner/runners/estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
from .config import check_prices
from .scale_up import get_runner_server_type_and_location
from .streamingyaml import StreamingYAMLWriter
from .hclient import HClient as Client

from datetime import timedelta
from hcloud import Client
from github import Github
from github.Repository import Repository
from github.WorkflowRun import WorkflowRun
Expand Down
16 changes: 16 additions & 0 deletions testflows/github/hetzner/runners/hclient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from hcloud import Client

from . import __version__ as project_version, __name__ as project_name


class HClient(Client):

def __init__(
self,
token,
api_endpoint="https://api.hetzner.cloud/v1",
poll_interval=1,
):
super().__init__(
token, api_endpoint, project_name, project_version, poll_interval
)
2 changes: 1 addition & 1 deletion testflows/github/hetzner/runners/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from hcloud import Client
from hcloud.servers.client import BoundServer

from .hclient import HClient as Client
from .actions import Action
from .config import Config, check_ssh_key, check_setup_script
from .server import wait_ready, wait_ssh, ssh
Expand Down
4 changes: 4 additions & 0 deletions testflows/github/hetzner/runners/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

from http.client import HTTPResponse
from urllib.request import urlopen, Request, HTTPError
from . import __version__ as project_version, __name__ as project_name

user_agent = f"{project_name}/{project_version}"

def request(
url,
Expand All @@ -32,6 +34,8 @@ def request(
if headers is None:
headers = {}

headers["User-Agent"] = user_agent

r = Request(url, headers=headers, data=data, method=method)

try:
Expand Down
2 changes: 1 addition & 1 deletion testflows/github/hetzner/runners/scale_down.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
from .logger import logger
from .server import age
from .config import Config
from .hclient import HClient as Client

from github import Github
from github.Repository import Repository
from github.SelfHostedActionsRunner import SelfHostedActionsRunner

from hcloud import Client
from hcloud.servers.client import BoundServer
from hcloud.ssh_keys.domain import SSHKey

Expand Down
3 changes: 2 additions & 1 deletion testflows/github/hetzner/runners/scale_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
from .logger import logger
from .config import Config, check_image, check_startup_script, check_setup_script
from .config import standby_runner as StandbyRunner
from .hclient import HClient as Client

from .server import wait_ssh, ssh

from hcloud import Client, APIException
from hcloud import APIException
from hcloud.ssh_keys.domain import SSHKey
from hcloud.server_types.domain import ServerType
from hcloud.locations.domain import Location
Expand Down
2 changes: 1 addition & 1 deletion testflows/github/hetzner/runners/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
import os
import sys

from hcloud import Client
from hcloud.servers.client import BoundServer

from .actions import Action
from .config import Config
from .server import ssh_command
from .scale_up import server_name_prefix
from .hclient import HClient as Client


def list(args, config: Config):
Expand Down

0 comments on commit 8ac6398

Please sign in to comment.