Skip to content

Commit

Permalink
Updates 27.01.2023 (#58)
Browse files Browse the repository at this point in the history
* general updates
*  update mypy to 0.991 and update code with Optional as needed
* Bump version: 1.1.18 → 1.1.19
  • Loading branch information
eugene-davis authored Jan 27, 2023
1 parent 3ce7bd8 commit 870722c
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -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}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
workflow_dispatch:

env:
VERSION: 1.1.18
VERSION: 1.1.19

jobs:
release:
Expand Down
21 changes: 11 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <eugene.davis@tomtom.com>"]
readme = "README.md"
Expand Down Expand Up @@ -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"]
Expand Down
8 changes: 4 additions & 4 deletions vault_monitor/common/vault_authenticate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"""
Expand Down Expand Up @@ -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
"""
Expand All @@ -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.
"""
Expand Down
11 changes: 9 additions & 2 deletions vault_monitor/expiration_monitor/entity_expiration_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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})
Expand Down
6 changes: 4 additions & 2 deletions vault_monitor/expiration_monitor/expiration_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
"""
Expand Down

0 comments on commit 870722c

Please sign in to comment.