python4cpm 1.1.7__tar.gz → 1.1.8__tar.gz

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.
Files changed (20) hide show
  1. {python4cpm-1.1.7/src/python4cpm.egg-info → python4cpm-1.1.8}/PKG-INFO +1 -1
  2. {python4cpm-1.1.7 → python4cpm-1.1.8}/pyproject.toml +1 -1
  3. {python4cpm-1.1.7 → python4cpm-1.1.8}/src/python4cpm/accounts.py +5 -5
  4. python4cpm-1.1.8/src/python4cpm/exithandler.py +27 -0
  5. python4cpm-1.1.7/src/python4cpm/logger.py → python4cpm-1.1.8/src/python4cpm/loggerhandler.py +7 -1
  6. {python4cpm-1.1.7 → python4cpm-1.1.8}/src/python4cpm/python4cpm.py +6 -15
  7. python4cpm-1.1.7/src/python4cpm/secret.py → python4cpm-1.1.8/src/python4cpm/secrets.py +11 -3
  8. {python4cpm-1.1.7 → python4cpm-1.1.8/src/python4cpm.egg-info}/PKG-INFO +1 -1
  9. {python4cpm-1.1.7 → python4cpm-1.1.8}/src/python4cpm.egg-info/SOURCES.txt +3 -2
  10. {python4cpm-1.1.7 → python4cpm-1.1.8}/LICENSE +0 -0
  11. {python4cpm-1.1.7 → python4cpm-1.1.8}/README.md +0 -0
  12. {python4cpm-1.1.7 → python4cpm-1.1.8}/setup.cfg +0 -0
  13. {python4cpm-1.1.7 → python4cpm-1.1.8}/src/python4cpm/__init__.py +0 -0
  14. {python4cpm-1.1.7 → python4cpm-1.1.8}/src/python4cpm/args.py +0 -0
  15. {python4cpm-1.1.7 → python4cpm-1.1.8}/src/python4cpm/crypto.py +0 -0
  16. {python4cpm-1.1.7 → python4cpm-1.1.8}/src/python4cpm/devhelper.py +0 -0
  17. {python4cpm-1.1.7 → python4cpm-1.1.8}/src/python4cpm/envhandler.py +0 -0
  18. {python4cpm-1.1.7 → python4cpm-1.1.8}/src/python4cpm/python4cpmhandler.py +0 -0
  19. {python4cpm-1.1.7 → python4cpm-1.1.8}/src/python4cpm.egg-info/dependency_links.txt +0 -0
  20. {python4cpm-1.1.7 → python4cpm-1.1.8}/src/python4cpm.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python4cpm
3
- Version: 1.1.7
3
+ Version: 1.1.8
4
4
  Summary: Python for CPM
5
5
  Author-email: Gonzalo Atienza Rela <gonatienza@gmail.com>
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "python4cpm"
7
- version = "1.1.7"
7
+ version = "1.1.8"
8
8
  description = "Python for CPM"
9
9
  authors = [
10
10
  { name = "Gonzalo Atienza Rela", email = "gonatienza@gmail.com" }
@@ -1,5 +1,5 @@
1
1
  from python4cpm.envhandler import EnvHandler, Props
2
- from python4cpm.secret import Secret
2
+ from python4cpm.secrets import Password, NewPassword
3
3
 
4
4
 
5
5
  class BaseAccount(EnvHandler):
@@ -11,7 +11,7 @@ class BaseAccount(EnvHandler):
11
11
  password: str | None
12
12
  ) -> None:
13
13
  self._username = username
14
- self._password = Secret.from_env_var(password)
14
+ self._password = Password.from_env_var(password)
15
15
 
16
16
  @classmethod
17
17
  def get(cls) -> object | None:
@@ -25,7 +25,7 @@ class BaseAccount(EnvHandler):
25
25
  return self._username
26
26
 
27
27
  @property
28
- def password(self) -> Secret:
28
+ def password(self) -> Password:
29
29
  return self._password
30
30
 
31
31
 
@@ -62,7 +62,7 @@ class TargetAccount(BaseAccount):
62
62
  self._object_name = object_name
63
63
  self._address = address
64
64
  self._port = port
65
- self._new_password = Secret.from_env_var(new_password)
65
+ self._new_password = NewPassword.from_env_var(new_password)
66
66
 
67
67
  @property
68
68
  def policy_id(self) -> str | None:
@@ -85,7 +85,7 @@ class TargetAccount(BaseAccount):
85
85
  return self._port
86
86
 
87
87
  @property
88
- def new_password(self) -> Secret:
88
+ def new_password(self) -> NewPassword:
89
89
  return self._new_password
90
90
 
91
91
 
@@ -0,0 +1,27 @@
1
+ from python4cpm.loggerhandler import LoggerHandler
2
+ import atexit
3
+ import sys
4
+
5
+
6
+ class ExitHandler:
7
+ _ERROR_MESSAGE = "No close signal called"
8
+ _closed = False
9
+
10
+ @classmethod
11
+ def reset(cls) -> None:
12
+ cls._closed = False
13
+
14
+ @classmethod
15
+ def set_closed(cls) -> None:
16
+ cls._closed = True
17
+
18
+ @classmethod
19
+ def on_exit(cls) -> None:
20
+ if cls._closed is False:
21
+ for logger in LoggerHandler.get_all_loggers():
22
+ logger.error(cls._ERROR_MESSAGE)
23
+ sys.stderr.write(cls._ERROR_MESSAGE)
24
+ sys.stderr.flush()
25
+
26
+
27
+ atexit.register(ExitHandler.on_exit)
@@ -3,7 +3,7 @@ import logging
3
3
  from logging.handlers import RotatingFileHandler
4
4
 
5
5
 
6
- class Logger:
6
+ class LoggerHandler:
7
7
  _LOGS_DIR = os.path.join("Logs", "ThirdParty")
8
8
  _LOGGING_LEVELS = {
9
9
  "critical": logging.CRITICAL,
@@ -13,6 +13,7 @@ class Logger:
13
13
  "debug": logging.DEBUG
14
14
  }
15
15
  _DEFAULT_LEVEL = "error"
16
+ _all_loggers = []
16
17
 
17
18
  @classmethod
18
19
  def get_logger(
@@ -42,4 +43,9 @@ class Logger:
42
43
  formatter = logging.Formatter(fmt=fmt, datefmt=datefmt)
43
44
  handler.setFormatter(formatter)
44
45
  logger.addHandler(handler)
46
+ cls._all_loggers.append(logger)
45
47
  return logger
48
+
49
+ @classmethod
50
+ def get_all_loggers(cls):
51
+ return cls._all_loggers
@@ -1,10 +1,10 @@
1
1
  import sys
2
- import atexit
3
2
  import logging
4
- from python4cpm.secret import Secret
3
+ from python4cpm.secrets import Secret
5
4
  from python4cpm.args import Args
6
- from python4cpm.logger import Logger
5
+ from python4cpm.loggerhandler import LoggerHandler
7
6
  from python4cpm.accounts import TargetAccount, LogonAccount, ReconcileAccount
7
+ from python4cpm.exithandler import ExitHandler
8
8
 
9
9
 
10
10
  class Python4CPM:
@@ -36,8 +36,6 @@ class Python4CPM:
36
36
  self._log_obj(self._target_account)
37
37
  self._log_obj(self._logon_account)
38
38
  self._log_obj(self._reconcile_account)
39
- self._closed = False
40
- atexit.register(self._on_exit)
41
39
 
42
40
  @property
43
41
  def args(self) -> Args:
@@ -66,7 +64,7 @@ class Python4CPM:
66
64
  self._target_account.object_name
67
65
  )
68
66
  name = "-".join(name_parts)
69
- return Logger.get_logger(name, self._args.logging_level)
67
+ return LoggerHandler.get_logger(name, self._args.logging_level)
70
68
 
71
69
  def _verify_action(self) -> None:
72
70
  if self._args.action not in self._VALID_ACTIONS:
@@ -91,17 +89,10 @@ class Python4CPM:
91
89
  else:
92
90
  code = self._FAILED_UNRECOVERABLE_CODE
93
91
  self._logger.error(f"Closing with code {code}")
94
- self._closed = True
92
+ ExitHandler.set_closed()
95
93
  sys.exit(code)
96
94
 
97
95
  def close_success(self) -> None:
98
96
  self._logger.debug(f"Closing with code {self._SUCCESS_CODE}")
99
- self._closed = True
97
+ ExitHandler.set_closed()
100
98
  sys.exit(self._SUCCESS_CODE)
101
-
102
- def _on_exit(self):
103
- if self._closed is False:
104
- message = "No close signal called"
105
- self._logger.error(message)
106
- sys.stderr.write(message)
107
- sys.stderr.flush()
@@ -3,7 +3,7 @@ from python4cpm.crypto import Crypto
3
3
 
4
4
  class Secret:
5
5
  def __init__(self, secret: str) -> None:
6
- self._secret = secret
6
+ self._value = secret
7
7
 
8
8
  @classmethod
9
9
  def from_env_var(cls, secret: str | None) -> object | None:
@@ -18,5 +18,13 @@ class Secret:
18
18
 
19
19
  def get(self) -> str:
20
20
  if Crypto.ENABLED:
21
- return Crypto.decrypt(self._secret)
22
- return self._secret
21
+ return Crypto.decrypt(self._value)
22
+ return self._value
23
+
24
+
25
+ class Password(Secret):
26
+ pass
27
+
28
+
29
+ class NewPassword(Secret):
30
+ pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python4cpm
3
- Version: 1.1.7
3
+ Version: 1.1.8
4
4
  Summary: Python for CPM
5
5
  Author-email: Gonzalo Atienza Rela <gonatienza@gmail.com>
6
6
  License-Expression: MIT
@@ -7,10 +7,11 @@ src/python4cpm/args.py
7
7
  src/python4cpm/crypto.py
8
8
  src/python4cpm/devhelper.py
9
9
  src/python4cpm/envhandler.py
10
- src/python4cpm/logger.py
10
+ src/python4cpm/exithandler.py
11
+ src/python4cpm/loggerhandler.py
11
12
  src/python4cpm/python4cpm.py
12
13
  src/python4cpm/python4cpmhandler.py
13
- src/python4cpm/secret.py
14
+ src/python4cpm/secrets.py
14
15
  src/python4cpm.egg-info/PKG-INFO
15
16
  src/python4cpm.egg-info/SOURCES.txt
16
17
  src/python4cpm.egg-info/dependency_links.txt
File without changes
File without changes
File without changes