From f5a7294bc904f46342c58b2b9b2fa2771f5d8e67 Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Mon, 22 Mar 2021 13:16:53 -0400 Subject: [PATCH] Sync config models --- .../envoy/config_models/__init__.py | 18 ++ .../envoy/config_models/defaults.py | 172 ++++++++++++++++++ .../envoy/config_models/instance.py | 97 ++++++++++ .../envoy/config_models/shared.py | 54 ++++++ .../envoy/config_models/validators.py | 3 + 5 files changed, 344 insertions(+) create mode 100644 envoy/datadog_checks/envoy/config_models/__init__.py create mode 100644 envoy/datadog_checks/envoy/config_models/defaults.py create mode 100644 envoy/datadog_checks/envoy/config_models/instance.py create mode 100644 envoy/datadog_checks/envoy/config_models/shared.py create mode 100644 envoy/datadog_checks/envoy/config_models/validators.py diff --git a/envoy/datadog_checks/envoy/config_models/__init__.py b/envoy/datadog_checks/envoy/config_models/__init__.py new file mode 100644 index 0000000000000..ba42dbdc7ffb0 --- /dev/null +++ b/envoy/datadog_checks/envoy/config_models/__init__.py @@ -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 diff --git a/envoy/datadog_checks/envoy/config_models/defaults.py b/envoy/datadog_checks/envoy/config_models/defaults.py new file mode 100644 index 0000000000000..0e798ab64dac1 --- /dev/null +++ b/envoy/datadog_checks/envoy/config_models/defaults.py @@ -0,0 +1,172 @@ +# (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_proxy(field, value): + return get_default_field_value(field, value) + + +def shared_service(field, value): + return get_default_field_value(field, value) + + +def shared_skip_proxy(field, value): + return False + + +def shared_timeout(field, value): + return 10 + + +def instance_auth_token(field, value): + return get_default_field_value(field, value) + + +def instance_auth_type(field, value): + return 'basic' + + +def instance_aws_host(field, value): + return get_default_field_value(field, value) + + +def instance_aws_region(field, value): + return get_default_field_value(field, value) + + +def instance_aws_service(field, value): + return get_default_field_value(field, value) + + +def instance_cache_metrics(field, value): + return True + + +def instance_connect_timeout(field, value): + return get_default_field_value(field, value) + + +def instance_empty_default_hostname(field, value): + return False + + +def instance_excluded_metrics(field, value): + return get_default_field_value(field, value) + + +def instance_extra_headers(field, value): + return get_default_field_value(field, value) + + +def instance_headers(field, value): + return get_default_field_value(field, value) + + +def instance_included_metrics(field, value): + return get_default_field_value(field, value) + + +def instance_kerberos_auth(field, value): + return 'disabled' + + +def instance_kerberos_cache(field, value): + return get_default_field_value(field, value) + + +def instance_kerberos_delegate(field, value): + return False + + +def instance_kerberos_force_initiate(field, value): + return False + + +def instance_kerberos_hostname(field, value): + return get_default_field_value(field, value) + + +def instance_kerberos_keytab(field, value): + return get_default_field_value(field, value) + + +def instance_kerberos_principal(field, value): + return get_default_field_value(field, value) + + +def instance_log_requests(field, value): + return False + + +def instance_min_collection_interval(field, value): + return 15 + + +def instance_ntlm_domain(field, value): + return get_default_field_value(field, value) + + +def instance_password(field, value): + return get_default_field_value(field, value) + + +def instance_persist_connections(field, value): + return False + + +def instance_proxy(field, value): + return get_default_field_value(field, value) + + +def instance_read_timeout(field, value): + return get_default_field_value(field, value) + + +def instance_service(field, value): + return get_default_field_value(field, value) + + +def instance_skip_proxy(field, value): + return False + + +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_ignore_warning(field, value): + return False + + +def instance_tls_private_key(field, value): + return get_default_field_value(field, value) + + +def instance_tls_use_host_header(field, value): + return False + + +def instance_tls_verify(field, value): + return True + + +def instance_use_legacy_auth_encoding(field, value): + return True + + +def instance_username(field, value): + return get_default_field_value(field, value) diff --git a/envoy/datadog_checks/envoy/config_models/instance.py b/envoy/datadog_checks/envoy/config_models/instance.py new file mode 100644 index 0000000000000..9dd8295057ca9 --- /dev/null +++ b/envoy/datadog_checks/envoy/config_models/instance.py @@ -0,0 +1,97 @@ +# (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 Any, Mapping, 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 AuthToken(BaseModel): + class Config: + allow_mutation = False + + reader: Optional[Mapping[str, Any]] + writer: Optional[Mapping[str, Any]] + + +class Proxy(BaseModel): + class Config: + allow_mutation = False + + http: Optional[str] + https: Optional[str] + no_proxy: Optional[Sequence[str]] + + +class InstanceConfig(BaseModel): + class Config: + allow_mutation = False + + auth_token: Optional[AuthToken] + auth_type: Optional[str] + aws_host: Optional[str] + aws_region: Optional[str] + aws_service: Optional[str] + cache_metrics: Optional[bool] + connect_timeout: Optional[float] + empty_default_hostname: Optional[bool] + excluded_metrics: Optional[Sequence[str]] + extra_headers: Optional[Mapping[str, Any]] + headers: Optional[Mapping[str, Any]] + included_metrics: Optional[Sequence[str]] + kerberos_auth: Optional[str] + kerberos_cache: Optional[str] + kerberos_delegate: Optional[bool] + kerberos_force_initiate: Optional[bool] + kerberos_hostname: Optional[str] + kerberos_keytab: Optional[str] + kerberos_principal: Optional[str] + log_requests: Optional[bool] + min_collection_interval: Optional[float] + ntlm_domain: Optional[str] + password: Optional[str] + persist_connections: Optional[bool] + proxy: Optional[Proxy] + read_timeout: Optional[float] + service: Optional[str] + skip_proxy: Optional[bool] + stats_url: str + tags: Optional[Sequence[str]] + timeout: Optional[float] + tls_ca_cert: Optional[str] + tls_cert: Optional[str] + tls_ignore_warning: Optional[bool] + tls_private_key: Optional[str] + tls_use_host_header: Optional[bool] + tls_verify: Optional[bool] + use_legacy_auth_encoding: Optional[bool] + username: 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)) diff --git a/envoy/datadog_checks/envoy/config_models/shared.py b/envoy/datadog_checks/envoy/config_models/shared.py new file mode 100644 index 0000000000000..4fc6216ab6c2f --- /dev/null +++ b/envoy/datadog_checks/envoy/config_models/shared.py @@ -0,0 +1,54 @@ +# (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 Proxy(BaseModel): + class Config: + allow_mutation = False + + http: Optional[str] + https: Optional[str] + no_proxy: Optional[Sequence[str]] + + +class SharedConfig(BaseModel): + class Config: + allow_mutation = False + + proxy: Optional[Proxy] + service: Optional[str] + skip_proxy: Optional[bool] + timeout: Optional[float] + + @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)) diff --git a/envoy/datadog_checks/envoy/config_models/validators.py b/envoy/datadog_checks/envoy/config_models/validators.py new file mode 100644 index 0000000000000..9d0b0155542cb --- /dev/null +++ b/envoy/datadog_checks/envoy/config_models/validators.py @@ -0,0 +1,3 @@ +# (C) Datadog, Inc. 2021-present +# All rights reserved +# Licensed under a 3-clause BSD style license (see LICENSE)