-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# (C) Datadog, Inc. 2021-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
from .instance import InstanceConfig | ||
from .shared import SharedConfig | ||
|
||
|
||
class ConfigMixin: | ||
_config_model_instance: InstanceConfig | ||
_config_model_shared: SharedConfig | ||
|
||
@property | ||
def config(self) -> InstanceConfig: | ||
return self._config_model_instance | ||
|
||
@property | ||
def shared_config(self) -> SharedConfig: | ||
return self._config_model_shared |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# (C) Datadog, Inc. 2021-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
from datadog_checks.base.utils.models.fields import get_default_field_value | ||
|
||
|
||
def shared_allowed_versions(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def shared_fetch_intermediate_certs(field, value): | ||
return False | ||
|
||
|
||
def shared_service(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_allowed_versions(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_days_critical(field, value): | ||
return 7.0 | ||
|
||
|
||
def instance_days_warning(field, value): | ||
return 14.0 | ||
|
||
|
||
def instance_empty_default_hostname(field, value): | ||
return False | ||
|
||
|
||
def instance_fetch_intermediate_certs(field, value): | ||
return False | ||
|
||
|
||
def instance_intermediate_cert_refresh_interval(field, value): | ||
return 60 | ||
|
||
|
||
def instance_local_cert_path(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_min_collection_interval(field, value): | ||
return 15 | ||
|
||
|
||
def instance_name(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_port(field, value): | ||
return 443 | ||
|
||
|
||
def instance_seconds_critical(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_seconds_warning(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_server_hostname(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_service(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_tags(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_timeout(field, value): | ||
return 10 | ||
|
||
|
||
def instance_tls_ca_cert(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_tls_cert(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_tls_private_key(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_tls_private_key_password(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_tls_validate_hostname(field, value): | ||
return True | ||
|
||
|
||
def instance_tls_verify(field, value): | ||
return True | ||
|
||
|
||
def instance_transport(field, value): | ||
return 'TCP' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# (C) Datadog, Inc. 2021-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
from __future__ import annotations | ||
|
||
from typing import Optional, Sequence | ||
|
||
from pydantic import BaseModel, root_validator, validator | ||
|
||
from datadog_checks.base.utils.functions import identity | ||
from datadog_checks.base.utils.models import validation | ||
|
||
from . import defaults, validators | ||
|
||
|
||
class InstanceConfig(BaseModel): | ||
class Config: | ||
allow_mutation = False | ||
|
||
allowed_versions: Optional[Sequence[str]] | ||
days_critical: Optional[float] | ||
days_warning: Optional[float] | ||
empty_default_hostname: Optional[bool] | ||
fetch_intermediate_certs: Optional[bool] | ||
intermediate_cert_refresh_interval: Optional[float] | ||
local_cert_path: Optional[str] | ||
min_collection_interval: Optional[float] | ||
name: Optional[str] | ||
port: Optional[int] | ||
seconds_critical: Optional[int] | ||
seconds_warning: Optional[int] | ||
server: str | ||
server_hostname: Optional[str] | ||
service: Optional[str] | ||
tags: Optional[Sequence[str]] | ||
timeout: Optional[int] | ||
tls_ca_cert: Optional[str] | ||
tls_cert: Optional[str] | ||
tls_private_key: Optional[str] | ||
tls_private_key_password: Optional[str] | ||
tls_validate_hostname: Optional[bool] | ||
tls_verify: Optional[bool] | ||
transport: Optional[str] | ||
|
||
@root_validator(pre=True) | ||
def _initial_validation(cls, values): | ||
return validation.core.initialize_config(getattr(validators, 'initialize_instance', identity)(values)) | ||
|
||
@validator('*', pre=True, always=True) | ||
def _ensure_defaults(cls, v, field): | ||
if v is not None or field.required: | ||
return v | ||
|
||
return getattr(defaults, f'instance_{field.name}')(field, v) | ||
|
||
@validator('*') | ||
def _run_validations(cls, v, field): | ||
if not v: | ||
return v | ||
|
||
return getattr(validators, f'instance_{field.name}', identity)(v, field=field) | ||
|
||
@root_validator(pre=False) | ||
def _final_validation(cls, values): | ||
return validation.core.finalize_config(getattr(validators, 'finalize_instance', identity)(values)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# (C) Datadog, Inc. 2021-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
from __future__ import annotations | ||
|
||
from typing import Optional, Sequence | ||
|
||
from pydantic import BaseModel, root_validator, validator | ||
|
||
from datadog_checks.base.utils.functions import identity | ||
from datadog_checks.base.utils.models import validation | ||
|
||
from . import defaults, validators | ||
|
||
|
||
class SharedConfig(BaseModel): | ||
class Config: | ||
allow_mutation = False | ||
|
||
allowed_versions: Optional[Sequence[str]] | ||
fetch_intermediate_certs: Optional[bool] | ||
service: Optional[str] | ||
|
||
@root_validator(pre=True) | ||
def _initial_validation(cls, values): | ||
return validation.core.initialize_config(getattr(validators, 'initialize_shared', identity)(values)) | ||
|
||
@validator('*', pre=True, always=True) | ||
def _ensure_defaults(cls, v, field): | ||
if v is not None or field.required: | ||
return v | ||
|
||
return getattr(defaults, f'shared_{field.name}')(field, v) | ||
|
||
@validator('*') | ||
def _run_validations(cls, v, field): | ||
if not v: | ||
return v | ||
|
||
return getattr(validators, f'shared_{field.name}', identity)(v, field=field) | ||
|
||
@root_validator(pre=False) | ||
def _final_validation(cls, values): | ||
return validation.core.finalize_config(getattr(validators, 'finalize_shared', identity)(values)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# (C) Datadog, Inc. 2021-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) |