Ejemplo n.º 1
0
def delete_file(
    repo: Optional[str],
    package: Optional[str],
    version: Optional[str],
    filename: Optional[str],
):
    username, header = get_auth_header_and_username()
    if not username:
        return
    if not repo:
        repo = repositories.select_from_available_repo(subject=username)
    if not package:
        package = packages_core.select_from_available_packages(
            subject=username, repo=repo)
    if not version:
        version = select_from_available_versions(subject=username,
                                                 repo=repo,
                                                 package=package,
                                                 filename=filename)

    if not filename:
        filename = select_from_available_files(subject=username,
                                               repo=repo,
                                               package=package,
                                               version=version)
    print_message(f"Deleting file {filename} version {version}")
    url = get_url(f"/{username}/{repo}/{package}/{version}/{filename}")
    password = typer.prompt("Password", hide_input=True)
    response = httpx.delete(url=url,
                            auth=httpx.BasicAuth(username=username,
                                                 password=password))
    response_handler(response=response, return_model=FileDeleteResponseModel)
    return
Ejemplo n.º 2
0
def file_upload(repo: Optional[str], package: Optional[str], version: str,
                filename: str):
    username, header = get_auth_header_and_username()
    if not username:
        return
    if not repo:
        repo = repositories.select_from_available_repo(subject=username)
    if not package:
        package = packages_core.select_from_available_packages(
            subject=username, repo=repo)
    file_path: str = filename
    if os.path.isabs(file_path):
        filename = os.path.basename(file_path)

    url = get_url(f"/content/{username}/{repo}/{package}/{version}/{filename}")
    try:
        with open(file_path, "br") as file:
            data = file.read()
            headers = {
                "x-bintray-publish": "1",
                "content-type": "application/octet-stream",
                "x-bintray-override": "1",
            }
            headers.update(header)
            password = typer.prompt("Password", hide_input=True)
            response = httpx.put(
                url=url,
                data=data,
                headers=headers,
                auth=httpx.BasicAuth(username=username, password=password),
            )
            response_handler(response=response, return_with_out_model=True)
    except Exception as e:
        print_error(f"{e.args[0]}")
Ejemplo n.º 3
0
def get_device_list() -> None:
    username, header = get_auth_header_and_username()
    if not username:
        return
    url = get_url("/devices/")
    response = httpx.get(url=url, headers=header)
    response = response_handler(response=response, print_field="data")
Ejemplo n.º 4
0
def add_device() -> None:
    username, header = get_auth_header_and_username()
    if not username:
        return
    url = get_url("/devices/")
    body = pydantic_to_prompt(model=CreateDeviceModel)
    response = httpx.post(url=url, json=body.dict(), headers=header)
    response_handler(response=response, return_model=DeviceCreateResponseModel)
Ejemplo n.º 5
0
def get_device(mac_address: str) -> None:
    username, header = get_auth_header_and_username()
    if not username:
        return
    url = get_url(f"/devices/{mac_address}")
    response = httpx.get(url=url, headers=header)
    response_handler(response=response,
                     return_model=DeviceOutModel,
                     print_field="data")
Ejemplo n.º 6
0
def update_device(mac_address: str,
                  is_operation_confirmed: bool = False) -> None:
    username, header = get_auth_header_and_username()
    if not username:
        return
    url = get_url("/devices/{mac_address}")
    body = pydantic_to_prompt(model=UpdateDeviceModel)
    if not is_operation_confirmed and not is_operation_confirm():
        return
    response = httpx.patch(url=url, json=body.dict(), headers=header)
    response_handler(response=response, return_model=DeviceModel)
Ejemplo n.º 7
0
def delete_device(
    mac_address: str,
    is_operation_confirmed: bool = False,
) -> None:
    username, header = get_auth_header_and_username()
    if not username:
        return

    if not is_operation_confirmed and not is_operation_confirm():
        return
    url = get_url(f"/devices/{mac_address}")
    response = httpx.delete(url=url, headers=header)
    response_handler(response=response, return_model=DeviceDeleteResponseModel)