Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## 0.20.0 [unreleased]

### Others

1. [#215](https://github.com/InfluxCommunity/influxdb3-python/pull/215):
- Remove cookie/session-based signin/signout support from the writing client.
- Remove basic authentication with a username and password.

### Features

1. [#208](https://github.com/InfluxCommunity/influxdb3-python/pull/208): Add `influx3 query` CLI support for executing SQL/InfluxQL queries with JSON/JSONL/CSV/pretty output, including module execution via `python -m influxdb_client_3`.
Expand Down
5 changes: 0 additions & 5 deletions influxdb_client_3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,6 @@ def __init__(
Defaults to "multiprocessing.cpu_count() * 5".
:key urllib3.util.retry.Retry retries: Set the default retry strategy that is used for all HTTP requests
except batching writes. As a default there is no one retry strategy.
:key bool auth_basic: Set this to true to enable basic authentication when talking to a InfluxDB 1.8.x that
does not use auth-enabled but is protected by a reverse proxy with basic authentication.
(defaults to false, don't set to true when talking to InfluxDB 2)
:key str username: ``username`` to authenticate via username and password credentials to the InfluxDB 2.x
:key str password: ``password`` to authenticate via username and password credentials to the InfluxDB 2.x
:key str query_timeout: int value used to set the client query API timeout in milliseconds.
:key str write_timeout: int value used to set the client write API timeout in milliseconds.
:key bool write_accept_partial: allow partial writes when some lines fail.
Expand Down
3 changes: 0 additions & 3 deletions influxdb_client_3/write_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
from influxdb_client_3.write_client.client.write.point import Point

from influxdb_client_3.write_client.service.write_service import WriteService
Comment thread
NguyenHoangSon96 marked this conversation as resolved.
from influxdb_client_3.write_client.service.signin_service import SigninService
from influxdb_client_3.write_client.service.signout_service import SignoutService


Comment thread
NguyenHoangSon96 marked this conversation as resolved.
Comment thread
NguyenHoangSon96 marked this conversation as resolved.
from influxdb_client_3.write_client.domain.write_precision import WritePrecision

Expand Down
22 changes: 1 addition & 21 deletions influxdb_client_3/write_client/_sync/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@
from urllib.parse import quote

import influxdb_client_3.write_client.domain
from influxdb_client_3.write_client import SigninService
from influxdb_client_3.write_client import SignoutService
from influxdb_client_3.write_client._sync import rest
from influxdb_client_3.write_client.configuration import Configuration
from influxdb_client_3.write_client.rest import _requires_create_user_session, _requires_expire_user_session


class ApiClient(object):
Expand All @@ -25,8 +22,6 @@ class ApiClient(object):
:param header_name: a header to pass when making calls to the API.
:param header_value: a header value to pass when making calls to
the API.
:param cookie: a cookie to include in the header when making calls
to the API
:param pool_threads: The number of threads to use for async requests
to the API. More threads means more concurrent API requests.
"""
Expand All @@ -45,7 +40,7 @@ class ApiClient(object):
_pool = None

def __init__(self, configuration=None, header_name=None, header_value=None,
cookie=None, pool_threads=None, retries=False):
pool_threads=None, retries=False):
"""Initialize generic API client."""
Comment thread
NguyenHoangSon96 marked this conversation as resolved.
if configuration is None:
configuration = Configuration()
Comment thread
NguyenHoangSon96 marked this conversation as resolved.
Expand All @@ -56,14 +51,12 @@ def __init__(self, configuration=None, header_name=None, header_value=None,
self.default_headers = {}
if header_name is not None:
self.default_headers[header_name] = header_value
self.cookie = cookie
# Set default User-Agent.
from influxdb_client_3.version import USER_AGENT
self.user_agent = USER_AGENT

def __del__(self):
"""Dispose pools."""
self._signout()
if self._pool:
self._pool.close()
self._pool.join()
Expand Down Expand Up @@ -134,7 +127,6 @@ def __call_api(
_preload_content=True, _request_timeout=None, urlopen_kw=None):

config = self.configuration
self._signin(resource_path=resource_path)

# body
should_gzip = False
Expand All @@ -147,8 +139,6 @@ def __call_api(
header_params = header_params or {}
config.update_request_header_params(resource_path, header_params, should_gzip)
header_params.update(self.default_headers)
if self.cookie:
header_params['Cookie'] = self.cookie
if header_params:
Comment thread
NguyenHoangSon96 marked this conversation as resolved.
header_params = self.sanitize_for_serialization(header_params)
header_params = dict(self.parameters_to_tuples(header_params,
Expand Down Expand Up @@ -670,13 +660,3 @@ def __deserialize_model(self, data, klass):
if klass_name:
instance = self.__deserialize(data, klass_name)
return instance

def _signin(self, resource_path: str):
if _requires_create_user_session(self.configuration, self.cookie, resource_path):
http_info = SigninService(self).post_signin_with_http_info()
self.cookie = http_info[2]['set-cookie']

def _signout(self):
if _requires_expire_user_session(self.configuration, self.cookie):
SignoutService(self).post_signout()
self.cookie = None
2 changes: 0 additions & 2 deletions influxdb_client_3/write_client/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@
from __future__ import absolute_import

# import apis into api package
from influxdb_client_3.write_client.service.signin_service import SigninService
from influxdb_client_3.write_client.service.signout_service import SignoutService
from influxdb_client_3.write_client.service.write_service import WriteService
25 changes: 2 additions & 23 deletions influxdb_client_3/write_client/client/_base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Commons function for Sync and Async client."""
from __future__ import absolute_import

import base64
import configparser
import logging
import os
Expand Down Expand Up @@ -66,8 +65,6 @@ def __init__(self, url, token, debug=None, timeout=10_000, enable_gzip=False, or
self.conf.loggers[client_logger] = logging.getLogger(client_logger)
self.conf.debug = debug
Comment thread
NguyenHoangSon96 marked this conversation as resolved.

Comment thread
NguyenHoangSon96 marked this conversation as resolved.
self.conf.username = kwargs.get('username', None)
self.conf.password = kwargs.get('password', None)
# defaults
self.auth_header_name = None
self.auth_header_value = None
Expand All @@ -76,15 +73,6 @@ def __init__(self, url, token, debug=None, timeout=10_000, enable_gzip=False, or
auth_scheme = kwargs.get('auth_scheme', "Token")
self.auth_header_name = "Authorization"
self.auth_header_value = f"{auth_scheme} {token}"
Comment thread
NguyenHoangSon96 marked this conversation as resolved.
# by HTTP basic
auth_basic = kwargs.get('auth_basic', False)
if auth_basic:
self.auth_header_name = "Authorization"
self.auth_header_value = "Basic " + base64.b64encode(token.encode()).decode()
# by username, password
if self.conf.username and self.conf.password:
self.auth_header_name = None
self.auth_header_value = None

self.retries = kwargs.get('retries', False)

Expand Down Expand Up @@ -149,10 +137,6 @@ def _has_section(key: str):
if _has_option('connection_pool_maxsize'):
connection_pool_maxsize = _config_value('connection_pool_maxsize')

auth_basic = False
if _has_option('auth_basic'):
auth_basic = _config_value('auth_basic')

default_tags = None
if _has_section('tags'):
if is_json:
Expand All @@ -172,8 +156,7 @@ def _has_section(key: str):
return cls(url, token, debug=debug, timeout=_to_int(timeout), org=org, default_tags=default_tags,
enable_gzip=enable_gzip, verify_ssl=_to_bool(verify_ssl), ssl_ca_cert=ssl_ca_cert,
cert_file=cert_file, cert_key_file=cert_key_file, cert_key_password=cert_key_password,
connection_pool_maxsize=_to_int(connection_pool_maxsize), auth_basic=_to_bool(auth_basic),
profilers=profilers, proxy=proxy, **kwargs)
connection_pool_maxsize=_to_int(connection_pool_maxsize), profilers=profilers, proxy=proxy, **kwargs)

@classmethod
@deprecated('Use InfluxDBClient3.from_env() instead.')
Expand All @@ -188,7 +171,6 @@ def _from_env_properties(cls, debug=None, enable_gzip=False, **kwargs):
cert_key_file = os.getenv('INFLUXDB_V2_CERT_KEY_FILE', None)
cert_key_password = os.getenv('INFLUXDB_V2_CERT_KEY_PASSWORD', None)
connection_pool_maxsize = os.getenv('INFLUXDB_V2_CONNECTION_POOL_MAXSIZE', None)
auth_basic = os.getenv('INFLUXDB_V2_AUTH_BASIC', "False")

prof = os.getenv("INFLUXDB_V2_PROFILERS", None)
profilers = None
Expand All @@ -204,8 +186,7 @@ def _from_env_properties(cls, debug=None, enable_gzip=False, **kwargs):
return cls(url, token, debug=debug, timeout=_to_int(timeout), org=org, default_tags=default_tags,
enable_gzip=enable_gzip, verify_ssl=_to_bool(verify_ssl), ssl_ca_cert=ssl_ca_cert,
cert_file=cert_file, cert_key_file=cert_key_file, cert_key_password=cert_key_password,
connection_pool_maxsize=_to_int(connection_pool_maxsize), auth_basic=_to_bool(auth_basic),
profilers=profilers, **kwargs)
connection_pool_maxsize=_to_int(connection_pool_maxsize), profilers=profilers, **kwargs)


class _BaseWriteApi(object):
Expand Down Expand Up @@ -276,8 +257,6 @@ class _Configuration(Configuration):
def __init__(self):
Configuration.__init__(self)
self.enable_gzip = False
self.username = None
self.password = None

def update_request_header_params(self, path: str, params: dict, should_gzip: bool = False):
super().update_request_header_params(path, params, should_gzip)
Expand Down
10 changes: 0 additions & 10 deletions influxdb_client_3/write_client/client/influxdb_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ def __init__(self, url, token: str = None, debug=None, timeout=10_000, enable_gz
Defaults to "multiprocessing.cpu_count() * 5".
:key urllib3.util.retry.Retry retries: Set the default retry strategy that is used for all HTTP requests
except batching writes. As a default there is no one retry strategy.
:key bool auth_basic: Set this to true to enable basic authentication when talking to a InfluxDB 1.8.x that
does not use auth-enabled but is protected by a reverse proxy with basic authentication.
(defaults to false, don't set to true when talking to InfluxDB 2)
:key str username: ``username`` to authenticate via username and password credentials to the InfluxDB 2.x
:key str password: ``password`` to authenticate via username and password credentials to the InfluxDB 2.x
:key list[str] profilers: list of enabled Flux profilers
"""
super().__init__(url=url, token=token, debug=debug, timeout=timeout, enable_gzip=enable_gzip,
Expand Down Expand Up @@ -109,7 +104,6 @@ def from_config_file(cls, config_file: str = "config.ini", debug=None, enable_gz
- cert_key_file
- cert_key_password
- connection_pool_maxsize
- auth_basic
- profilers
- proxy

Expand All @@ -122,7 +116,6 @@ def from_config_file(cls, config_file: str = "config.ini", debug=None, enable_gz
token=my-token
timeout=6000
connection_pool_maxsize=25
auth_basic=false
profilers=query,operator
proxy=http:proxy.domain.org:8080

Expand All @@ -139,7 +132,6 @@ def from_config_file(cls, config_file: str = "config.ini", debug=None, enable_gz
org = "my-org"
timeout = 6000
connection_pool_maxsize = 25
auth_basic = false
profilers="query, operator"
proxy = "http://proxy.domain.org:8080"

Expand All @@ -157,7 +149,6 @@ def from_config_file(cls, config_file: str = "config.ini", debug=None, enable_gz
"active": true,
"timeout": 6000,
"connection_pool_maxsize": 55,
"auth_basic": false,
"profilers": "query, operator",
"tags": {
"id": "132-987-655",
Expand Down Expand Up @@ -198,7 +189,6 @@ def from_env_properties(cls, debug=None, enable_gzip=False, **kwargs):
- INFLUXDB_V2_CERT_KEY_FILE
- INFLUXDB_V2_CERT_KEY_PASSWORD
- INFLUXDB_V2_CONNECTION_POOL_MAXSIZE
- INFLUXDB_V2_AUTH_BASIC
- INFLUXDB_V2_PROFILERS
- INFLUXDB_V2_TAG
"""
Expand Down
2 changes: 0 additions & 2 deletions influxdb_client_3/write_client/client/write/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@
from __future__ import absolute_import

# import apis into api package
from influxdb_client_3.write_client.service.signin_service import SigninService
from influxdb_client_3.write_client.service.signout_service import SignoutService
from influxdb_client_3.write_client.service.write_service import WriteService
25 changes: 0 additions & 25 deletions influxdb_client_3/write_client/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import multiprocessing
import sys

import urllib3


class TypeWithDefault(type):

Expand Down Expand Up @@ -42,10 +40,6 @@ def __init__(self):
self.api_key = {}
# dict to store API prefix (e.g. Bearer)
self.api_key_prefix = {}
# Username for HTTP basic authentication
self.username = ""
# Password for HTTP basic authentication
self.password = ""

# Logging Settings
self.loggers = {}
Expand Down Expand Up @@ -88,9 +82,6 @@ def __init__(self):
# It can also be a pair (tuple) of (connection, read) timeouts.
self.timeout = None

# Set to True/False to enable basic authentication when using proxied InfluxDB 1.8.x with no auth-enabled
self.auth_basic = False

# Proxy URL
self.proxy = None
# A dictionary containing headers that will be sent to the proxy
Expand Down Expand Up @@ -204,28 +195,12 @@ def get_api_key_with_prefix(self, identifier):
elif self.api_key.get(identifier):
return self.api_key[identifier]

def get_basic_auth_token(self):
"""Get HTTP basic authentication header (string).

:return: The token for basic HTTP authentication.
"""
return urllib3.util.make_headers(
basic_auth=self.username + ':' + self.password
).get('authorization')

def auth_settings(self):
"""Get Auth Settings dict for api client.

:return: The Auth Settings information dict.
"""
return {
'BasicAuthentication':
{
'type': 'basic',
'in': 'header',
'key': 'Authorization',
'value': self.get_basic_auth_token()
},
'TokenAuthentication':
{
'type': 'api_key',
Expand Down
10 changes: 0 additions & 10 deletions influxdb_client_3/write_client/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import Dict

from influxdb_client_3.exceptions import InfluxDBError
from influxdb_client_3.write_client.configuration import Configuration

_UTF_8_encoding = 'utf-8'

Expand Down Expand Up @@ -63,12 +62,3 @@ def log_headers(headers: Dict[str, str], prefix: str):
if 'authorization' == key.lower():
value = '***'
_BaseRESTClient.logger.debug(f"{prefix} {key}: {value}")


def _requires_create_user_session(configuration: Configuration, cookie: str, resource_path: str):
_unauthorized = ['/api/v2/signin', '/api/v2/signout']
return configuration.username and configuration.password and not cookie and resource_path not in _unauthorized


def _requires_expire_user_session(configuration: Configuration, cookie: str):
return configuration.username and configuration.password and cookie
4 changes: 1 addition & 3 deletions influxdb_client_3/write_client/service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@
from __future__ import absolute_import

# import apis into api package
from influxdb_client_3.write_client.service.write_service import WriteService
from influxdb_client_3.write_client.service.signin_service import SigninService
from influxdb_client_3.write_client.service.signout_service import SignoutService
from influxdb_client_3.write_client.service.write_service import WriteService
Loading
Loading