Skip to content

Commit

Permalink
Sync config models
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek committed Mar 22, 2021
1 parent 1e39718 commit ad0bff9
Show file tree
Hide file tree
Showing 5 changed files with 339 additions and 0 deletions.
18 changes: 18 additions & 0 deletions mesos_slave/datadog_checks/mesos_slave/config_models/__init__.py
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
168 changes: 168 additions & 0 deletions mesos_slave/datadog_checks/mesos_slave/config_models/defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# (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_connect_timeout(field, value):
return get_default_field_value(field, value)


def instance_empty_default_hostname(field, value):
return False


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_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_master_port(field, value):
return 5050


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_tasks(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)
96 changes: 96 additions & 0 deletions mesos_slave/datadog_checks/mesos_slave/config_models/instance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# (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]
connect_timeout: Optional[float]
empty_default_hostname: Optional[bool]
extra_headers: Optional[Mapping[str, Any]]
headers: Optional[Mapping[str, Any]]
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]
master_port: Optional[int]
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]
tags: Optional[Sequence[str]]
tasks: 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]
url: str
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))
54 changes: 54 additions & 0 deletions mesos_slave/datadog_checks/mesos_slave/config_models/shared.py
Original file line number Diff line number Diff line change
@@ -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))
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)

0 comments on commit ad0bff9

Please sign in to comment.