Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support username/password as alternative to user/pass #9340

Merged
merged 6 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clickhouse/assets/configuration/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ files:
value:
type: integer
example: 9000
- name: user
- name: username
description: The database user to authenticate as.
value:
type: string
Expand Down
4 changes: 3 additions & 1 deletion clickhouse/datadog_checks/clickhouse/clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, name, init_config, instances):
self._server = self.instance.get('server', '')
self._port = self.instance.get('port')
self._db = self.instance.get('db', 'default')
self._user = self.instance.get('user', 'default')
self._user = self.instance.get('username', self.instance.get('user', 'default'))
self._password = self.instance.get('password', '')
self._connect_timeout = float(self.instance.get('connect_timeout', 10))
self._read_timeout = float(self.instance.get('read_timeout', 10))
Expand Down Expand Up @@ -80,6 +80,8 @@ def ping_clickhouse(self):
return self._client.connection.ping()

def connect(self):
if self.instance.get('user'):
self._log_deprecation('_config_renamed', 'user', 'username')
if self._client is not None:
self.log.debug('Clickhouse client already exists. Pinging Clickhouse Server.')
try:
Expand Down
4 changes: 2 additions & 2 deletions clickhouse/datadog_checks/clickhouse/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ instances:
#
# port: 9000

## @param user - string - optional - default: default
## @param username - string - optional - default: default
## The database user to authenticate as.
#
# user: default
# username: default

## @param password - string - optional
## The password of `username`.
Expand Down
7 changes: 7 additions & 0 deletions datadog_checks_base/datadog_checks/base/checks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ def __init__(self, *args, **kwargs):
'The default will become `true` and cannot be changed in Agent version 8.'
),
),
'_config_renamed': (
False,
(
'DEPRECATION NOTICE: The `%s` config option has been renamed '
'to `%s` and will be removed in a future release.'
),
),
} # type: Dict[str, Tuple[bool, str]]

# Setup metric limits
Expand Down
4 changes: 2 additions & 2 deletions mysql/assets/configuration/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ files:
example: localhost
display_default: null

- name: user
- name: username
description: |
Username used to connect to MySQL.
enabled: true
Expand All @@ -35,7 +35,7 @@ files:
example: datadog
display_default: null

- name: pass
- name: password
description: |
Password associated to the MySQL user.
enabled: true
Expand Down
4 changes: 2 additions & 2 deletions mysql/datadog_checks/mysql/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def __init__(self, instance):
self.tags = list(instance.get('tags', []))
self.mysql_sock = instance.get('sock', '')
self.defaults_file = instance.get('defaults_file', '')
self.user = instance.get('user', '')
self.password = str(instance.get('pass', ''))
self.user = instance.get('username', instance.get('user', ''))
self.password = str(instance.get('password', instance.get('pass', '')))
self.tags = self._build_tags(instance.get('tags', []))
self.options = instance.get('options', {}) or {} # options could be None if empty in the YAML
replication_channel = self.options.get('replication_channel')
Expand Down
4 changes: 2 additions & 2 deletions mysql/datadog_checks/mysql/config_models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def instance_options(field, value):
return get_default_field_value(field, value)


def instance_pass_(field, value):
def instance_password(field, value):
return get_default_field_value(field, value)


Expand Down Expand Up @@ -88,5 +88,5 @@ def instance_use_global_custom_queries(field, value):
return 'true'


def instance_user(field, value):
def instance_username(field, value):
return 'datadog'
6 changes: 3 additions & 3 deletions mysql/datadog_checks/mysql/config_models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from typing import Any, Mapping, Optional, Sequence

from pydantic import BaseModel, Field, root_validator, validator
from pydantic import BaseModel, root_validator, validator

from datadog_checks.base.utils.functions import identity
from datadog_checks.base.utils.models import validation
Expand Down Expand Up @@ -80,7 +80,7 @@ class Config:
max_custom_queries: Optional[int]
min_collection_interval: Optional[float]
options: Optional[Options]
pass_: Optional[str] = Field(None, alias='pass')
password: Optional[str]
port: Optional[float]
queries: Optional[Sequence[Mapping[str, Any]]]
service: Optional[str]
Expand All @@ -89,7 +89,7 @@ class Config:
statement_samples: Optional[StatementSamples]
tags: Optional[Sequence[str]]
use_global_custom_queries: Optional[str]
user: Optional[str]
username: Optional[str]

@root_validator(pre=True)
def _initial_validation(cls, values):
Expand Down
8 changes: 4 additions & 4 deletions mysql/datadog_checks/mysql/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ instances:
#
- host: localhost

## @param user - string - optional
## @param username - string - optional
## Username used to connect to MySQL.
#
user: datadog
username: datadog

## @param pass - string - optional
## @param password - string - optional
## Password associated to the MySQL user.
#
pass: <PASS>
password: <PASSWORD>

## @param port - number - optional - default: 3306
## Port to use when connecting to MySQL.
Expand Down
6 changes: 6 additions & 0 deletions mysql/datadog_checks/mysql/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ def get_library_versions(cls):
return {'pymysql': pymysql.__version__}

def check(self, _):
if self.instance.get('user'):
self._log_deprecation('_config_renamed', 'user', 'username')

if self.instance.get('pass'):
self._log_deprecation('_config_renamed', 'pass', 'password')

tags = list(self._config.tags)
self._set_qcache_stats()
with self._connect() as db:
Expand Down
2 changes: 1 addition & 1 deletion oracle/assets/configuration/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ files:
required: true
value:
type: string
- name: user
- name: username
description: The username for the Datadog user account.
required: true
value:
Expand Down
2 changes: 1 addition & 1 deletion oracle/datadog_checks/oracle/config_models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Config:
service_name: str
tags: Optional[Sequence[str]]
use_global_custom_queries: Optional[str]
user: str
username: str

@root_validator(pre=True)
def _initial_validation(cls, values):
Expand Down
4 changes: 2 additions & 2 deletions oracle/datadog_checks/oracle/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ instances:
#
service_name: <SERVICE_NAME>

## @param user - string - required
## @param username - string - required
## The username for the Datadog user account.
#
user: <USER>
username: <USERNAME>

## @param password - string - required
## The password for the Datadog user account.
Expand Down
5 changes: 4 additions & 1 deletion oracle/datadog_checks/oracle/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Oracle(AgentCheck):
def __init__(self, name, init_config, instances):
super(Oracle, self).__init__(name, init_config, instances)
self._server = self.instance.get('server')
self._user = self.instance.get('user')
self._user = self.instance.get('username') or self.instance.get('user')
self._password = self.instance.get('password')
self._service = self.instance.get('service_name')
self._jdbc_driver = self.instance.get('jdbc_driver_path')
Expand Down Expand Up @@ -99,6 +99,9 @@ def handle_query_error(self, error):
return error

def check(self, _):
if self.instance.get('user'):
self._log_deprecation('_config_renamed', 'user', 'username')

self._current_errors = 0

self._query_manager.execute()
Expand Down
2 changes: 1 addition & 1 deletion snowflake/assets/configuration/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ files:
value:
type: string
example: <ACCOUNT>
- name: user
- name: username
required: true
description: Login name for the user.
value:
Expand Down
3 changes: 3 additions & 0 deletions snowflake/datadog_checks/snowflake/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def __init__(self, *args, **kwargs):
self.check_initializations.append(self._query_manager.compile_queries)

def check(self, _):
if self.instance.get('user'):
self._log_deprecation('_config_renamed', 'user', 'username')

self.connect()

if self._conn is not None:
Expand Down
2 changes: 1 addition & 1 deletion snowflake/datadog_checks/snowflake/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, instance=None):
instance = {}

account = instance.get('account')
user = instance.get('user')
user = instance.get('user') or instance.get('username')
password = instance.get('password')
role = instance.get('role')
database = instance.get('database', 'SNOWFLAKE')
Expand Down
4 changes: 2 additions & 2 deletions snowflake/datadog_checks/snowflake/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ instances:
#
- account: <ACCOUNT>

## @param user - string - required
## @param username - string - required
## Login name for the user.
#
user: <USER>
username: <USER>

## @param password - string - required
## Password for the user
Expand Down
4 changes: 2 additions & 2 deletions supervisord/assets/configuration/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ files:
value:
type: string
example: <SOCKETFILE_PATH>
- name: user
- name: username
description: Required only if a username is configured.
value:
type: string
example: <USERNAME>
- name: pass
- name: password
description: Required only if a password is configured.
value:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def instance_min_collection_interval(field, value):
return 15


def instance_pass_(field, value):
def instance_password(field, value):
return get_default_field_value(field, value)


Expand Down Expand Up @@ -48,5 +48,5 @@ def instance_tags(field, value):
return get_default_field_value(field, value)


def instance_user(field, value):
def instance_username(field, value):
return get_default_field_value(field, value)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from typing import Optional, Sequence

from pydantic import BaseModel, Field, root_validator, validator
from pydantic import BaseModel, root_validator, validator

from datadog_checks.base.utils.functions import identity
from datadog_checks.base.utils.models import validation
Expand All @@ -21,14 +21,14 @@ class Config:
host: Optional[str]
min_collection_interval: Optional[float]
name: str
pass_: Optional[str] = Field(None, alias='pass')
password: Optional[str]
port: Optional[int]
proc_names: Optional[Sequence[str]]
proc_regex: Optional[Sequence[str]]
service: Optional[str]
socket: Optional[str]
tags: Optional[Sequence[str]]
user: Optional[str]
username: Optional[str]

@root_validator(pre=True)
def _initial_validation(cls, values):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ instances:
#
# socket: <SOCKETFILE_PATH>

## @param user - string - optional
## @param username - string - optional
## Required only if a username is configured.
#
# user: <USERNAME>
# username: <USERNAME>

## @param pass - string - optional
## @param password - string - optional
## Required only if a password is configured.
#
# pass: <PASSWORD>
# password: <PASSWORD>

## @param proc_regex - list of strings - optional
## Regex pattern[s] matching the names of processes to monitor.
Expand Down
9 changes: 7 additions & 2 deletions supervisord/datadog_checks/supervisord/supervisord.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@

class SupervisordCheck(AgentCheck):
def check(self, instance):
if instance.get('user'):
self._log_deprecation('_config_renamed', 'user', 'username')
if instance.get('pass'):
self._log_deprecation('_config_renamed', 'pass', 'password')

server_name = instance.get('name')

if not server_name or not server_name.strip():
Expand Down Expand Up @@ -163,8 +168,8 @@ def check(self, instance):
@staticmethod
def _connect(instance):
sock = instance.get('socket')
user = instance.get('user')
password = instance.get('pass')
user = instance.get('user') or instance.get('username')
password = instance.get('pass') or instance.get('password')
if sock is not None:
host = instance.get('host', DEFAULT_SOCKET_IP)
transport = supervisor.xmlrpc.SupervisorTransport(user, password, sock)
Expand Down