Commit ea7ad5ae authored by root's avatar root
Browse files

Merge branch 'master' of https://github.com/tribe29/checkmk

parents 03f8ac51 aa65e346
......@@ -66,6 +66,7 @@ pyls-isort = "*" # isort plugin for python-lsp-server
pylsp-mypy = "*" # mypy plugin for python-lsp-server
mypy-protobuf = "==3.0.0" # for mypy
pipfile = "*" # for generating import names during int tests
py-import-cycles = "*" # used in tests/Makefile
[packages]
setuptools_scm = "==4.1.2" # needed by various setup.py
......
{
"_meta": {
"hash": {
"sha256": "e97421e5800f8073531196d0c0fda78aaef911bd7d6ad1ce37af2def74ad7c5b"
"sha256": "b02fc8f3c6addec123ee126aba5a89911b82404fa00ed7feee794955eb66fd87"
},
"pipfile-spec": 6,
"requires": {
......@@ -2331,7 +2331,7 @@
"hashes": [
"sha256:b1bead90b70cf6ec3f0710ae53a525360fa360d306a86583adc6bf83a4db537d"
],
"markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2'",
"markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'",
"version": "==0.18.2"
},
"gitdb": {
......@@ -2356,6 +2356,14 @@
],
"version": "==2021.2.21"
},
"graphviz": {
"hashes": [
"sha256:62c5f48bcc534a45b4588c548ff75e419c1f1f3a33d31a91796ae80a7f581e4a",
"sha256:76bdfb73f42e72564ffe9c7299482f9d72f8e6cb8d54bce7b48ab323755e9ba5"
],
"markers": "python_version >= '3.7'",
"version": "==0.20"
},
"greenlet": {
"hashes": [
"sha256:0051c6f1f27cb756ffc0ffbac7d2cd48cb0362ac1736871399a739b2885134d3",
......@@ -2921,6 +2929,13 @@
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
"version": "==1.11.0"
},
"py-import-cycles": {
"hashes": [
"sha256:14c916b9e4ed78e1886dcb660570fdd4ab3c201f20211ebbd56483b8167977f2"
],
"index": "pypi",
"version": "==0.1.1"
},
"pycodestyle": {
"hashes": [
"sha256:720f8b39dde8b293825e7ff02c475f3077124006db4f440dcbc9a20b76548a20",
......@@ -3325,7 +3340,7 @@
"sha256:d13c6c90c42e24eb7ce660db397e8c398edd58acb7f92a2a88a95572b838aaa4",
"sha256:d239001c0fb7de985e21ec9a4bb542b5150350330bbc1849f835b9cbc8923b91"
],
"markers": "python_full_version >= '3.6.3' and python_version < '4'",
"markers": "python_full_version < '4.0.0' and python_full_version >= '3.6.3'",
"version": "==12.4.1"
},
"secretstorage": {
......@@ -3488,7 +3503,7 @@
"sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b",
"sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"
],
"markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2'",
"markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'",
"version": "==0.10.2"
},
"tomli": {
......@@ -3496,7 +3511,7 @@
"sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc",
"sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"
],
"markers": "python_version >= '3.7'",
"markers": "python_version < '3.11'",
"version": "==2.0.1"
},
"tox": {
......@@ -3735,7 +3750,7 @@
"sha256:73aae30359291c14fa3b956f8b5ca31960e420c28c1bec002547fb04928cf89b",
"sha256:b64ef5141be559cfade448f044fa45c2260351edcb6a8ef6b7e00c7dcef0c323"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'",
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
"version": "==1.8.7"
},
"websocket-client": {
......
......@@ -7,6 +7,7 @@ SCRIPTS := ../scripts
FIND_PYTHON_FILES := $(SCRIPTS)/find-python-files
PIPENV := $(SCRIPTS)/run-pipenv
PYTEST := $(PIPENV) run py.test $(PYTEST_ARGS)
CYCLES := $(PIPENV) run py_import_cycles
PYTEST_UNIT_TEST_OPTS = \
-T unit \
--doctest-modules \
......@@ -60,7 +61,7 @@ PYTHON_VERSIONS := 2.7 3.3 3.4 3.5 3.6 3.7 3.8 3.9
test-integration test-integration-docker test-integration-docker-debug \
test-mypy test-mypy-raw itest-mypy-docker test-packaging test-pipenv-deps test-pylint test-pylint-docker \
test-unit test-unit-docker test-unit-resilience test-unit-resilience-docker test-unit-coverage-html \
test-unit-shell test-unit-shell-docker test-shellcheck \
test-unit-shell test-unit-shell-docker test-shellcheck test-cycles \
test-tidy-livestatus test-tidy-core test-tidy-docker test-iwyu-livestatus test-iwyu-core test-iwyu-docker \
test-unit-livestatus test-unit-core %-livestatus-docker %-core-docker \
test-cargo-check test-cargo-check-docker test-cargo-test test-cargo-test-docker \
......@@ -301,6 +302,14 @@ test-pylint-docker:
test-shellcheck:
cd .. && shellcheck $(SHELLCHECK_OUTPUT_ARGS) $(SHELL_FILES_REL)
test-cycles:
$(CYCLES) \
--folders cmk enterprise managed plus \
--graph no \
--map enterprise:cee managed:cme plus:cpe \
--project-path $$(realpath -L ..) \
--strategy dfs
test-unit: prepare-protobuf-files
$(PYTEST) \
$(PYTEST_ADDITIONAL_UNIT_TEST_OPTS) \
......
import logging
import time
from typing import Any, List, NamedTuple, NewType, Optional
from typing import Any, NamedTuple, Optional, Union
import requests
......@@ -61,11 +61,15 @@ class CMKOpenApiSession(requests.Session):
def set_authentication_header(self, user: str, password: str):
self.headers["Authorization"] = f"Bearer {user} {password}"
def request(self, method: str, url: str, *args, **kwargs) -> requests.Response: # type: ignore
def request(
self, method: Union[str, bytes], url: Union[str, bytes], *args, **kwargs
) -> requests.Response:
"""
Suggested method to use a base url with a requests.Session
see https://github.com/psf/requests/issues/2554#issuecomment-109341010
"""
assert isinstance(method, str) # HACK
assert isinstance(url, str) # HACK
url = f"http://{self.host}:{self.port}/{self.site}/check_mk/api/{self.api_version}/{url.strip('/')}"
logger.debug("> [%s] %s (%s, %s)", method, url, args, kwargs)
......@@ -73,6 +77,7 @@ class CMKOpenApiSession(requests.Session):
logger.debug("< [%s] %s", response.status_code, response.text)
if response.status_code == 401:
assert isinstance(self.headers["Authorization"], str) # HACK
raise AuthorizationFailed(self.headers["Authorization"], self.site)
return response
......@@ -134,7 +139,7 @@ class CMKOpenApiSession(requests.Session):
return True
def create_user(
self, username: str, fullname: str, password: str, email: str, contactgroups: List[str]
self, username: str, fullname: str, password: str, email: str, contactgroups: list[str]
) -> None:
response = self.post(
"domain-types/user_config/collections/all",
......@@ -154,7 +159,7 @@ class CMKOpenApiSession(requests.Session):
if response.status_code != 200:
raise UnexpectedResponse.from_response(response)
def get_all_users(self) -> List[User]:
def get_all_users(self) -> list[User]:
response = self.get("domain-types/user_config/collections/all")
if response.status_code != 200:
raise UnexpectedResponse.from_response(response)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment