From 870722c55d33029b7fb7ac00f4881c6586f1a911 Mon Sep 17 00:00:00 2001 From: Eugene Davis Date: Fri, 27 Jan 2023 22:37:38 +0000 Subject: [PATCH] Updates 27.01.2023 (#58) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * general updates * update mypy to 0.991 and update code with Optional as needed * Bump version: 1.1.18 → 1.1.19 --- .bumpversion.cfg | 2 +- .github/workflows/release.yml | 2 +- poetry.lock | 21 ++++++++++--------- pyproject.toml | 4 ++-- vault_monitor/common/vault_authenticate.py | 8 +++---- .../entity_expiration_monitor.py | 11 ++++++++-- .../expiration_monitor/expiration_monitor.py | 6 ++++-- 7 files changed, 32 insertions(+), 22 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index e026b97..f88d278 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.1.18 +current_version = 1.1.19 commit = True tag = False message = Bump version: {current_version} → {new_version} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 712ee67..ced45c2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,7 +6,7 @@ on: workflow_dispatch: env: - VERSION: 1.1.18 + VERSION: 1.1.19 jobs: release: diff --git a/poetry.lock b/poetry.lock index e24dc9f..b04d23f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,6 +1,6 @@ [[package]] name = "astroid" -version = "2.13.2" +version = "2.13.3" description = "An abstract syntax tree for Python with inference support." category = "dev" optional = false @@ -8,7 +8,7 @@ python-versions = ">=3.7.2" [package.dependencies] lazy-object-proxy = ">=1.4.0" -typing-extensions = ">=4.0.0" +typing-extensions = {version = ">=4.0.0", markers = "python_version < \"3.11\""} wrapt = [ {version = ">=1.11,<2", markers = "python_version < \"3.11\""}, {version = ">=1.14,<2", markers = "python_version >= \"3.11\""}, @@ -124,7 +124,7 @@ python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7 [[package]] name = "coverage" -version = "7.0.5" +version = "7.1.0" description = "Code coverage measurement for Python" category = "dev" optional = false @@ -253,11 +253,11 @@ test = ["pytest (<5.4)", "pytest-cov"] [[package]] name = "mypy" -version = "0.971" +version = "0.991" description = "Optional static typing for Python" category = "dev" optional = false -python-versions = ">=3.6" +python-versions = ">=3.7" [package.dependencies] mypy-extensions = ">=0.4.3" @@ -266,6 +266,7 @@ typing-extensions = ">=3.10" [package.extras] dmypy = ["psutil (>=4.0)"] +install-types = ["pip"] python2 = ["typed-ast (>=1.4.0,<2)"] reports = ["lxml"] @@ -287,7 +288,7 @@ python-versions = ">=3.7" [[package]] name = "pathspec" -version = "0.10.3" +version = "0.11.0" description = "Utility library for gitignore style pattern matching of file paths." category = "dev" optional = false @@ -372,7 +373,7 @@ testutils = ["gitpython (>3)"] [[package]] name = "pytest" -version = "7.2.0" +version = "7.2.1" description = "pytest: simple powerful testing with Python" category = "dev" optional = false @@ -482,7 +483,7 @@ python-versions = ">=3.6" [[package]] name = "types-pyyaml" -version = "6.0.12.2" +version = "6.0.12.3" description = "Typing stubs for PyYAML" category = "dev" optional = false @@ -490,7 +491,7 @@ python-versions = "*" [[package]] name = "types-requests" -version = "2.28.11.7" +version = "2.28.11.8" description = "Typing stubs for requests" category = "dev" optional = false @@ -539,7 +540,7 @@ python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" [metadata] lock-version = "1.1" python-versions = "^3.8" -content-hash = "2141880b76c464293f0855e0527779a2f36aa82e7281cad7fbf43945b1d6ca49" +content-hash = "bcc8ae871b5a7fb2fd2fdfef1f84f2be409f7a0de993ecc769cdfc35a4ef26e1" [metadata.files] astroid = [] diff --git a/pyproject.toml b/pyproject.toml index c8dae51..74149eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "vault-assessment-prometheus-exporter" -version = "1.1.18" +version = "1.1.19" description = "Prometheus exporter to monitor custom metadata for KV2 secrets for (self-imposed) expiration." authors = ["Eugene Davis "] readme = "README.md" @@ -32,7 +32,7 @@ bandit = "^1.7.4" bump2version = "^1.0.1" pytest-mock = "^3.7.0" mock = "^4.0.3" -mypy = "^0.971" +mypy = "^0.991" [build-system] requires = ["poetry-core>=1.0.0"] diff --git a/vault_monitor/common/vault_authenticate.py b/vault_monitor/common/vault_authenticate.py index e1c49c2..b7cb9a4 100644 --- a/vault_monitor/common/vault_authenticate.py +++ b/vault_monitor/common/vault_authenticate.py @@ -5,14 +5,14 @@ import logging import warnings -from typing import Dict +from typing import Optional, Dict import hvac LOGGER = logging.getLogger("vault_authenticate") -def get_vault_client_for_user(url: str = None, namespace: str = None, vault_token: str = None) -> hvac.Client: +def get_vault_client_for_user(url: Optional[str] = None, namespace: Optional[str] = None, vault_token: Optional[str] = None) -> hvac.Client: """ Gets a HVAC Vault client instance configured against Vault, targeted towards end-user systems (checks for environmental variables and existing token in .vault-token) """ @@ -60,7 +60,7 @@ def get_authenticated_client(auth_config: Dict[str, Dict[str, str]], address: st return get_client_with_token_auth(token_auth_config, address, namespace) -def get_namespace(namespace: str = None) -> str: +def get_namespace(namespace: Optional[str] = None) -> str: """ In the event that namespace is None, return the value for VAULT_NAMESPACE if that is set """ @@ -70,7 +70,7 @@ def get_namespace(namespace: str = None) -> str: return namespace -def get_address(address: str = None) -> str: +def get_address(address: Optional[str] = None) -> str: """ If the Vault address isn't set, check the contents of the VAULT_ADDR environmental variable and return it. """ diff --git a/vault_monitor/expiration_monitor/entity_expiration_monitor.py b/vault_monitor/expiration_monitor/entity_expiration_monitor.py index 827a0c5..706cb96 100644 --- a/vault_monitor/expiration_monitor/entity_expiration_monitor.py +++ b/vault_monitor/expiration_monitor/entity_expiration_monitor.py @@ -2,7 +2,7 @@ Class for monitoring entity secret expiration information in HashiCorp Vault. """ -from typing import Dict +from typing import Optional, Dict import requests import hvac @@ -24,7 +24,14 @@ class EntityExpirationMonitor(ExpirationMonitor): expiration_gauge_description = "Timestamp for when an entity's secrets should be expired and rotated." def __init__( - self, mount_point: str, monitored_path: str, name: str, vault_client: hvac.Client, service: str, prometheus_labels: Dict[str, str] = None, metadata_fieldnames: Dict[str, str] = None + self, + mount_point: str, + monitored_path: str, + name: str, + vault_client: hvac.Client, + service: str, + prometheus_labels: Optional[Dict[str, str]] = None, + metadata_fieldnames: Optional[Dict[str, str]] = None, ) -> None: if prometheus_labels: prometheus_labels.update({"entity_name": name}) diff --git a/vault_monitor/expiration_monitor/expiration_monitor.py b/vault_monitor/expiration_monitor/expiration_monitor.py index fd4c665..196db27 100644 --- a/vault_monitor/expiration_monitor/expiration_monitor.py +++ b/vault_monitor/expiration_monitor/expiration_monitor.py @@ -2,7 +2,7 @@ Class for monitoring expiration information in HashiCorp Vault. """ from abc import ABC, abstractmethod -from typing import Dict, List, Type, TypeVar +from typing import Optional, Dict, List, Type, TypeVar import hvac from prometheus_client import Gauge @@ -25,7 +25,9 @@ class ExpirationMonitor(ABC): expiration_gauge_name: str expiration_gauge_description: str - def __init__(self, mount_point: str, monitored_path: str, vault_client: hvac.Client, service: str, prometheus_labels: Dict[str, str] = None, metadata_fieldnames: Dict[str, str] = None) -> None: + def __init__( + self, mount_point: str, monitored_path: str, vault_client: hvac.Client, service: str, prometheus_labels: Optional[Dict[str, str]] = None, metadata_fieldnames: Optional[Dict[str, str]] = None + ) -> None: """ Creates an instance of the ExpirationMonitor class. """