cognite-extractor-utils 7.2.2__py3-none-any.whl → 7.2.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of cognite-extractor-utils might be problematic. Click here for more details.

@@ -16,5 +16,5 @@
16
16
  Cognite extractor utils is a Python package that simplifies the development of new extractors.
17
17
  """
18
18
 
19
- __version__ = "7.2.2"
19
+ __version__ = "7.2.3"
20
20
  from .base import Extractor
@@ -20,7 +20,7 @@ from enum import Enum
20
20
  from logging.handlers import TimedRotatingFileHandler
21
21
  from time import sleep
22
22
  from typing import Any, Dict, List, Optional, Tuple, Union
23
- from urllib.parse import urljoin
23
+ from urllib.parse import urljoin, urlparse
24
24
 
25
25
  import yaml
26
26
  from prometheus_client import REGISTRY, start_http_server
@@ -70,7 +70,7 @@ class AuthenticatorConfig:
70
70
 
71
71
  client_id: str
72
72
  scopes: List[str]
73
- secret: Optional[str]
73
+ secret: Optional[str] = None
74
74
  tenant: Optional[str] = None
75
75
  token_url: Optional[str] = None
76
76
  resource: Optional[str] = None
@@ -264,6 +264,18 @@ class FileSizeConfig(yaml.YAMLObject):
264
264
  return self._expression
265
265
 
266
266
 
267
+ path_elem_regex = re.compile(r"^([a-zA-Z0-9.\-_~!$&'()*+,;=:@]|%[A-F0-9]{2})*$")
268
+
269
+
270
+ def _validate_https_url(value: str, name: str) -> None:
271
+ try:
272
+ url = urlparse(value)
273
+ except Exception as e:
274
+ raise InvalidConfigError(f"{name} ({value}) is not a valid URL") from e
275
+ if url.scheme != "https":
276
+ raise InvalidConfigError(f"{name} ({value}) must be HTTPS")
277
+
278
+
267
279
  @dataclass
268
280
  class CogniteConfig:
269
281
  """
@@ -272,10 +284,10 @@ class CogniteConfig:
272
284
 
273
285
  project: str
274
286
  idp_authentication: AuthenticatorConfig
275
- data_set: Optional[EitherIdConfig]
276
- data_set_id: Optional[int]
277
- data_set_external_id: Optional[str]
278
- extraction_pipeline: Optional[EitherIdConfig]
287
+ data_set: Optional[EitherIdConfig] = None
288
+ data_set_id: Optional[int] = None
289
+ data_set_external_id: Optional[str] = None
290
+ extraction_pipeline: Optional[EitherIdConfig] = None
279
291
  timeout: TimeIntervalConfig = TimeIntervalConfig("30s")
280
292
  connection: ConnectionConfig = field(default_factory=ConnectionConfig)
281
293
  security_categories: Optional[List[int]] = None
@@ -300,11 +312,20 @@ class CogniteConfig:
300
312
  global_config.disable_ssl = self.connection.disable_ssl
301
313
  global_config.proxies = self.connection.proxies
302
314
 
315
+ if not self.project:
316
+ raise InvalidConfigError("Project is not set")
317
+ if not path_elem_regex.match(self.project):
318
+ raise InvalidConfigError(f"Project ({self.project}) is not valid")
319
+
303
320
  credential_provider: CredentialProvider
304
321
  if self.idp_authentication.certificate:
305
322
  if self.idp_authentication.certificate.authority_url:
306
323
  authority_url = self.idp_authentication.certificate.authority_url
324
+ _validate_https_url(self.idp_authentication.certificate.authority_url, "Authority URL")
307
325
  elif self.idp_authentication.tenant:
326
+ _validate_https_url(self.idp_authentication.authority, "Authority")
327
+ if not path_elem_regex.match(self.idp_authentication.tenant):
328
+ raise InvalidConfigError(f"Tenant {self.idp_authentication.tenant} is not valid")
308
329
  authority_url = urljoin(self.idp_authentication.authority, self.idp_authentication.tenant)
309
330
  else:
310
331
  raise InvalidConfigError("Either authority-url or tenant is required for certificate authentication")
@@ -312,6 +333,8 @@ class CogniteConfig:
312
333
  self.idp_authentication.certificate.path,
313
334
  self.idp_authentication.certificate.password,
314
335
  )
336
+ if not self.idp_authentication.scopes:
337
+ _logger.warn("No scopes configured. Authenticating with CDF is unlikely to work correctly")
315
338
  credential_provider = OAuthClientCertificate(
316
339
  authority_url=authority_url,
317
340
  client_id=self.idp_authentication.client_id,
@@ -323,14 +346,20 @@ class CogniteConfig:
323
346
  elif self.idp_authentication.secret:
324
347
  kwargs: Dict[str, Any] = {}
325
348
  if self.idp_authentication.token_url:
349
+ _validate_https_url(self.idp_authentication.token_url, "Token URL")
326
350
  kwargs["token_url"] = self.idp_authentication.token_url
327
351
  elif self.idp_authentication.tenant:
352
+ _validate_https_url(self.idp_authentication.authority, "Authority")
353
+ if not path_elem_regex.match(self.idp_authentication.tenant):
354
+ raise InvalidConfigError(f"Tenant ({self.idp_authentication.tenant}) is not valid")
328
355
  base_url = urljoin(self.idp_authentication.authority, self.idp_authentication.tenant)
329
356
  kwargs["token_url"] = f"{base_url}/oauth2/v2.0/token"
330
357
  else:
331
358
  raise InvalidConfigError("Either token-url or tenant is required for client credentials authentication")
332
359
  kwargs["client_id"] = self.idp_authentication.client_id
333
360
  kwargs["client_secret"] = self.idp_authentication.secret
361
+ if not self.idp_authentication.scopes:
362
+ _logger.warning("No scopes configured. Authenticating with CDF is unlikely to work correctly")
334
363
  kwargs["scopes"] = self.idp_authentication.scopes
335
364
  if token_custom_args is None:
336
365
  token_custom_args = {}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cognite-extractor-utils
3
- Version: 7.2.2
3
+ Version: 7.2.3
4
4
  Summary: Utilities for easier development of extractors for CDF
5
5
  Home-page: https://github.com/cognitedata/python-extractor-utils
6
6
  License: Apache-2.0
@@ -1,9 +1,9 @@
1
- cognite/extractorutils/__init__.py,sha256=G-4E2RTr6EDXP2zRRAR3D2oyZLbluCvTFmL3cvy4IoE,739
1
+ cognite/extractorutils/__init__.py,sha256=No8QzFZvAX7DY63jX70dTCPGuk7k0Rd0k99nU_sqeTo,739
2
2
  cognite/extractorutils/_inner_util.py,sha256=gmz6aqS7jDNsg8z4RHgJjMFohDLOMiaU4gMWBhg3xcE,1558
3
3
  cognite/extractorutils/base.py,sha256=q6NU2bPec3WOasVnnIFoh-aUJudVZWZ2R6emz3IRj8Q,16391
4
4
  cognite/extractorutils/configtools/__init__.py,sha256=L-daaqInIsmHcjb2forJeY0fW8tz1mlteOUo7IsWnrU,3059
5
5
  cognite/extractorutils/configtools/_util.py,sha256=SZycZm_py9v9WZbDiDQbgS6_PiLtu-TtwuuH7tG2YCI,4739
6
- cognite/extractorutils/configtools/elements.py,sha256=k6q8NXZrV3efD_8BcTQvhb7lvTvsHbX30nshQgqeIQk,21703
6
+ cognite/extractorutils/configtools/elements.py,sha256=0q1DaQFeKpP8tQvgJ7sN4Tx8ryY0eR8kFolKvzoqSoM,23392
7
7
  cognite/extractorutils/configtools/loaders.py,sha256=_bMEb2_WaBL_G9w5IXU5UKwSu1VGge0PPAWgfSribYI,17647
8
8
  cognite/extractorutils/exceptions.py,sha256=XiwyNPSN0YxFYaPw7tfA63B94PL48xDK3EfdGdhgQgc,1084
9
9
  cognite/extractorutils/metrics.py,sha256=01ZMRbDisXPxrfCSyTSEkXMsslzmZwEqw18fuu9okdc,15509
@@ -25,7 +25,7 @@ cognite/extractorutils/uploader/time_series.py,sha256=HBtQdsQoIOaL-EG5lMsaY-ORwV
25
25
  cognite/extractorutils/uploader_extractor.py,sha256=E-mpVvbPg_Tk90U4S9JybV0duptJ2SXE88HB6npE3zI,7732
26
26
  cognite/extractorutils/uploader_types.py,sha256=wxfrsiKPTzG5lmoYtQsxt8Xyj-s5HnaLl8WDzJNrazg,1020
27
27
  cognite/extractorutils/util.py,sha256=UA6mUZ1caHd6vtA45gZXrk6cxo5cSB2PZ32bMwfEU0M,17229
28
- cognite_extractor_utils-7.2.2.dist-info/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
29
- cognite_extractor_utils-7.2.2.dist-info/METADATA,sha256=8cw9XRHtl8RAjaiaGQFwX4i0rBFgkRidxuitf9Cx00U,5486
30
- cognite_extractor_utils-7.2.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
31
- cognite_extractor_utils-7.2.2.dist-info/RECORD,,
28
+ cognite_extractor_utils-7.2.3.dist-info/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
29
+ cognite_extractor_utils-7.2.3.dist-info/METADATA,sha256=u-YGjhv1yLXR0t8OYCx07D7vp1_8Vg_yFwMke0HThZ8,5486
30
+ cognite_extractor_utils-7.2.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
31
+ cognite_extractor_utils-7.2.3.dist-info/RECORD,,