python4cpm 1.1.4__tar.gz → 1.1.5__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.

Potentially problematic release.


This version of python4cpm might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python4cpm
3
- Version: 1.1.4
3
+ Version: 1.1.5
4
4
  Summary: Python for CPM
5
5
  Author-email: Gonzalo Atienza Rela <gonatienza@gmail.com>
6
6
  License-Expression: MIT
@@ -71,8 +71,6 @@ class CredManager(Python4CPMHandler):
71
71
  """
72
72
  Properties:
73
73
  target_account (TargetAccount): Account being managed.
74
- .policy_id (str): Platform name.
75
- .object_name (str): Account name.
76
74
  .username (str): Account username.
77
75
  .address (str): Target address.
78
76
  .port (str): Target port.
@@ -145,7 +143,7 @@ When doing `verify`, `change` or `reconcile` from Privilege Cloud/PVWA:
145
143
  6. If a reconcile account is not linked, `reconcile_account` will return `None`.
146
144
  7. Always use the `close_success` or `close_fail` methods to signal the proper termination for all actions.
147
145
  - If any action is not terminated with a termination method, CPM/SRS will see this as a `close_fail(unrecoverable=True)`, even if no exceptions are raised.
148
- 8. The python `Logger` places its logs in the `Logs/ThirdParty` directory. The filename will be based on `target_account.policy_id` and `target_account.object_name`.
146
+ 8. The python `Logger` places its logs in the `Logs/ThirdParty` directory.
149
147
 
150
148
 
151
149
  ### Installing dependencies in python venv
@@ -159,22 +157,23 @@ As with any python venv, you can install dependencies in your venv.
159
157
 
160
158
  ## Dev Helper:
161
159
 
162
- For dev purposes, `NETHelper` is a companion helper to test your scripts without CPM/SRS. It simplifies the instantiation of the `Python4CPM` or `Python4CPMHandler` objects by simulating how the plugin creates the environment context for the python module.
160
+ For dev purposes, `DevHelper` is a companion helper to test your scripts without CPM/SRS. It simplifies the instantiation of the `Python4CPM` or `Python4CPMHandler` objects by simulating how the plugin creates the environment context for the python module.
163
161
 
164
- **Note**: As CPM and the SRS management agent run in Windows, the plugin was built to encrypt secrets using DPAPI (a windows only library). For dev purposes in Linux/Mac dev workstations, those secrets put in the environment context by `NETHelper` will be in plaintext. In windows dev workstations, `NETHelper` encrypts the secrets as the .NET plugin does. This is informational only, **the module will use its encryption/decryption capabilities automatically based on the platform** it is running on and you do not have to do anything specific to enable it.
162
+ **Note**: As CPM and the SRS management agent run in Windows, the plugin was built to encrypt secrets using DPAPI (a windows only library). For dev purposes in Linux/Mac dev workstations, those secrets put in the environment context by `DevHelper` will be in plaintext. In windows dev workstations, `DevHelper` encrypts the secrets as the .NET plugin does. This is informational only, **the module will use its encryption/decryption capabilities automatically based on the platform** it is running on and you do not have to do anything specific to enable it.
165
163
 
166
164
  ### Example:
167
165
 
168
166
  #### Set your arguments and secrets:
169
167
 
170
168
  ```python
171
- from python4cpm import NETHelper, Python4CPM, Python4CPMHandler
169
+ from python4cpm import DevHelper, Python4CPM, Python4CPMHandler
172
170
 
173
- NETHelper.set(
171
+ DevHelper.set(
174
172
  action=Python4CPM.ACTION_CHANGE, # use actions from Python4CPM.ACTION_*
175
173
  logging_level="debug",
176
- target_policy_id="NETHelper",
177
- target_object_name="Objectname",
174
+ target_policy_id="DevHelper", # name of platform
175
+ target_safe_name="Safename", # name of safe
176
+ target_object_name="Objectname", # name of account
178
177
  target_username="jdoe",
179
178
  target_address="myapp.corp.local",
180
179
  target_port="8443",
@@ -212,5 +211,5 @@ CredManager().run()
212
211
 
213
212
  #### Remember for your final script:
214
213
 
215
- - Remove the import of `NETHelper`.
216
- - Remove the `NETHelper.set()` call.
214
+ - Remove the import of `DevHelper`.
215
+ - Remove the `DevHelper.set()` call.
@@ -60,8 +60,6 @@ class CredManager(Python4CPMHandler):
60
60
  """
61
61
  Properties:
62
62
  target_account (TargetAccount): Account being managed.
63
- .policy_id (str): Platform name.
64
- .object_name (str): Account name.
65
63
  .username (str): Account username.
66
64
  .address (str): Target address.
67
65
  .port (str): Target port.
@@ -134,7 +132,7 @@ When doing `verify`, `change` or `reconcile` from Privilege Cloud/PVWA:
134
132
  6. If a reconcile account is not linked, `reconcile_account` will return `None`.
135
133
  7. Always use the `close_success` or `close_fail` methods to signal the proper termination for all actions.
136
134
  - If any action is not terminated with a termination method, CPM/SRS will see this as a `close_fail(unrecoverable=True)`, even if no exceptions are raised.
137
- 8. The python `Logger` places its logs in the `Logs/ThirdParty` directory. The filename will be based on `target_account.policy_id` and `target_account.object_name`.
135
+ 8. The python `Logger` places its logs in the `Logs/ThirdParty` directory.
138
136
 
139
137
 
140
138
  ### Installing dependencies in python venv
@@ -148,22 +146,23 @@ As with any python venv, you can install dependencies in your venv.
148
146
 
149
147
  ## Dev Helper:
150
148
 
151
- For dev purposes, `NETHelper` is a companion helper to test your scripts without CPM/SRS. It simplifies the instantiation of the `Python4CPM` or `Python4CPMHandler` objects by simulating how the plugin creates the environment context for the python module.
149
+ For dev purposes, `DevHelper` is a companion helper to test your scripts without CPM/SRS. It simplifies the instantiation of the `Python4CPM` or `Python4CPMHandler` objects by simulating how the plugin creates the environment context for the python module.
152
150
 
153
- **Note**: As CPM and the SRS management agent run in Windows, the plugin was built to encrypt secrets using DPAPI (a windows only library). For dev purposes in Linux/Mac dev workstations, those secrets put in the environment context by `NETHelper` will be in plaintext. In windows dev workstations, `NETHelper` encrypts the secrets as the .NET plugin does. This is informational only, **the module will use its encryption/decryption capabilities automatically based on the platform** it is running on and you do not have to do anything specific to enable it.
151
+ **Note**: As CPM and the SRS management agent run in Windows, the plugin was built to encrypt secrets using DPAPI (a windows only library). For dev purposes in Linux/Mac dev workstations, those secrets put in the environment context by `DevHelper` will be in plaintext. In windows dev workstations, `DevHelper` encrypts the secrets as the .NET plugin does. This is informational only, **the module will use its encryption/decryption capabilities automatically based on the platform** it is running on and you do not have to do anything specific to enable it.
154
152
 
155
153
  ### Example:
156
154
 
157
155
  #### Set your arguments and secrets:
158
156
 
159
157
  ```python
160
- from python4cpm import NETHelper, Python4CPM, Python4CPMHandler
158
+ from python4cpm import DevHelper, Python4CPM, Python4CPMHandler
161
159
 
162
- NETHelper.set(
160
+ DevHelper.set(
163
161
  action=Python4CPM.ACTION_CHANGE, # use actions from Python4CPM.ACTION_*
164
162
  logging_level="debug",
165
- target_policy_id="NETHelper",
166
- target_object_name="Objectname",
163
+ target_policy_id="DevHelper", # name of platform
164
+ target_safe_name="Safename", # name of safe
165
+ target_object_name="Objectname", # name of account
167
166
  target_username="jdoe",
168
167
  target_address="myapp.corp.local",
169
168
  target_port="8443",
@@ -201,5 +200,5 @@ CredManager().run()
201
200
 
202
201
  #### Remember for your final script:
203
202
 
204
- - Remove the import of `NETHelper`.
205
- - Remove the `NETHelper.set()` call.
203
+ - Remove the import of `DevHelper`.
204
+ - Remove the `DevHelper.set()` call.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "python4cpm"
7
- version = "1.1.4"
7
+ version = "1.1.5"
8
8
  description = "Python for CPM"
9
9
  authors = [
10
10
  { name = "Gonzalo Atienza Rela", email = "gonatienza@gmail.com" }
@@ -1,6 +1,6 @@
1
1
  from python4cpm.python4cpm import Python4CPM
2
2
  from python4cpm.python4cpmhandler import Python4CPMHandler
3
- from python4cpm.nethelper import NETHelper
3
+ from python4cpm.devhelper import DevHelper
4
4
  from importlib.metadata import version as __version
5
5
 
6
6
  __version__ = __version(__name__)
@@ -8,5 +8,5 @@ __version__ = __version(__name__)
8
8
  __all__ = [
9
9
  Python4CPM,
10
10
  Python4CPMHandler,
11
- NETHelper
11
+ DevHelper
12
12
  ]
@@ -33,6 +33,7 @@ class TargetAccount(BaseAccount):
33
33
  OBJ_PREFIX = "target_"
34
34
  PROPS = Props(
35
35
  "policy_id",
36
+ "safe_name",
36
37
  "object_name",
37
38
  "username",
38
39
  "password",
@@ -44,6 +45,7 @@ class TargetAccount(BaseAccount):
44
45
  def __init__(
45
46
  self,
46
47
  policy_id: str | None,
48
+ safe_name: str | None,
47
49
  object_name: str | None,
48
50
  username: str | None,
49
51
  password: str | None,
@@ -56,6 +58,7 @@ class TargetAccount(BaseAccount):
56
58
  password
57
59
  )
58
60
  self._policy_id = policy_id
61
+ self._safe_name = safe_name
59
62
  self._object_name = object_name
60
63
  self._address = address
61
64
  self._port = port
@@ -65,6 +68,10 @@ class TargetAccount(BaseAccount):
65
68
  def policy_id(self) -> str | None:
66
69
  return self._policy_id
67
70
 
71
+ @property
72
+ def safe_name(self) -> str | None:
73
+ return self._safe_name
74
+
68
75
  @property
69
76
  def object_name(self) -> str | None:
70
77
  return self._object_name
@@ -1,17 +1,17 @@
1
- from python4cpm.python4cpm import Python4CPM
2
1
  from python4cpm.args import Args
3
2
  from python4cpm.accounts import TargetAccount, LogonAccount, ReconcileAccount
4
3
  from python4cpm.crypto import Crypto
5
4
  import os
6
5
 
7
6
 
8
- class NETHelper:
7
+ class DevHelper:
9
8
  @classmethod
10
9
  def set(
11
10
  cls,
12
11
  action: str | None = None,
13
12
  logging_level: str | None = None,
14
13
  target_policy_id: str | None = None,
14
+ target_safe_name: str | None = None,
15
15
  target_object_name: str | None = None,
16
16
  target_username: str | None = None,
17
17
  target_address: str | None = None,
@@ -32,6 +32,7 @@ class NETHelper:
32
32
  Args.get_key(Args.PROPS.action),
33
33
  Args.get_key(Args.PROPS.logging_level),
34
34
  TargetAccount.get_key(TargetAccount.PROPS.policy_id),
35
+ TargetAccount.get_key(TargetAccount.PROPS.safe_name),
35
36
  TargetAccount.get_key(TargetAccount.PROPS.object_name),
36
37
  TargetAccount.get_key(TargetAccount.PROPS.username),
37
38
  TargetAccount.get_key(TargetAccount.PROPS.address),
@@ -47,6 +48,7 @@ class NETHelper:
47
48
  action,
48
49
  logging_level,
49
50
  target_policy_id,
51
+ target_safe_name,
50
52
  target_object_name,
51
53
  target_username,
52
54
  target_address,
@@ -61,7 +63,3 @@ class NETHelper:
61
63
  for i, key in enumerate(keys):
62
64
  if values[i] is not None:
63
65
  os.environ.update({key: values[i]})
64
-
65
- @classmethod
66
- def get(cls) -> Python4CPM:
67
- return Python4CPM()
@@ -23,11 +23,11 @@ class Logger:
23
23
  os.makedirs(cls._LOGS_DIR, exist_ok=True)
24
24
  uid = os.urandom(4).hex()
25
25
  logger = logging.getLogger(uid)
26
- _logging_level = logging_level.lower()
26
+ _logging_level = (logging_level or cls._DEFAULT_LEVEL).lower()
27
27
  if _logging_level not in cls._LOGGING_LEVELS:
28
28
  _logging_level = cls._DEFAULT_LEVEL
29
29
  logger.setLevel(cls._LOGGING_LEVELS[_logging_level])
30
- file_name = f"{__name__}_{_logging_level}_{name}.log"
30
+ file_name = f"{__name__}_{_logging_level}_{name}_{uid}.log"
31
31
  logs_file = os.path.join(cls._LOGS_DIR, file_name)
32
32
  handler = RotatingFileHandler(
33
33
  filename=logs_file,
@@ -35,7 +35,7 @@ class Logger:
35
35
  backupCount=1
36
36
  )
37
37
  fmt = (
38
- "%(asctime)s.%(msecs)03d | %(levelname)s | %(name)s | "
38
+ "%(asctime)s.%(msecs)03d | %(levelname)s | "
39
39
  "%(module)s | %(funcName)s | %(message)s"
40
40
  )
41
41
  datefmt = "%Y-%m-%d %H:%M:%S"
@@ -29,10 +29,7 @@ class Python4CPM:
29
29
  self._target_account = TargetAccount.get()
30
30
  self._logon_account = LogonAccount.get()
31
31
  self._reconcile_account = ReconcileAccount.get()
32
- self._logger = Logger.get_logger(
33
- f"{self._target_account.policy_id}-{self._target_account.object_name}",
34
- self._args.logging_level
35
- )
32
+ self._logger = self._get_logger()
36
33
  self._logger.debug("Initiating...")
37
34
  self._log_obj(self._args)
38
35
  self._verify_action()
@@ -62,6 +59,15 @@ class Python4CPM:
62
59
  def reconcile_account(self) -> ReconcileAccount:
63
60
  return self._reconcile_account
64
61
 
62
+ def _get_logger(self) -> logging.Logger:
63
+ name_parts = (
64
+ self._target_account.policy_id,
65
+ self._target_account.safe_name,
66
+ self._target_account.object_name
67
+ )
68
+ name = "-".join(name_parts)
69
+ return Logger.get_logger(name, self._args.logging_level)
70
+
65
71
  def _verify_action(self) -> None:
66
72
  if self._args.action not in self._VALID_ACTIONS:
67
73
  self._logger.warning(f"Unkonwn action -> '{self._args.action}'")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python4cpm
3
- Version: 1.1.4
3
+ Version: 1.1.5
4
4
  Summary: Python for CPM
5
5
  Author-email: Gonzalo Atienza Rela <gonatienza@gmail.com>
6
6
  License-Expression: MIT
@@ -71,8 +71,6 @@ class CredManager(Python4CPMHandler):
71
71
  """
72
72
  Properties:
73
73
  target_account (TargetAccount): Account being managed.
74
- .policy_id (str): Platform name.
75
- .object_name (str): Account name.
76
74
  .username (str): Account username.
77
75
  .address (str): Target address.
78
76
  .port (str): Target port.
@@ -145,7 +143,7 @@ When doing `verify`, `change` or `reconcile` from Privilege Cloud/PVWA:
145
143
  6. If a reconcile account is not linked, `reconcile_account` will return `None`.
146
144
  7. Always use the `close_success` or `close_fail` methods to signal the proper termination for all actions.
147
145
  - If any action is not terminated with a termination method, CPM/SRS will see this as a `close_fail(unrecoverable=True)`, even if no exceptions are raised.
148
- 8. The python `Logger` places its logs in the `Logs/ThirdParty` directory. The filename will be based on `target_account.policy_id` and `target_account.object_name`.
146
+ 8. The python `Logger` places its logs in the `Logs/ThirdParty` directory.
149
147
 
150
148
 
151
149
  ### Installing dependencies in python venv
@@ -159,22 +157,23 @@ As with any python venv, you can install dependencies in your venv.
159
157
 
160
158
  ## Dev Helper:
161
159
 
162
- For dev purposes, `NETHelper` is a companion helper to test your scripts without CPM/SRS. It simplifies the instantiation of the `Python4CPM` or `Python4CPMHandler` objects by simulating how the plugin creates the environment context for the python module.
160
+ For dev purposes, `DevHelper` is a companion helper to test your scripts without CPM/SRS. It simplifies the instantiation of the `Python4CPM` or `Python4CPMHandler` objects by simulating how the plugin creates the environment context for the python module.
163
161
 
164
- **Note**: As CPM and the SRS management agent run in Windows, the plugin was built to encrypt secrets using DPAPI (a windows only library). For dev purposes in Linux/Mac dev workstations, those secrets put in the environment context by `NETHelper` will be in plaintext. In windows dev workstations, `NETHelper` encrypts the secrets as the .NET plugin does. This is informational only, **the module will use its encryption/decryption capabilities automatically based on the platform** it is running on and you do not have to do anything specific to enable it.
162
+ **Note**: As CPM and the SRS management agent run in Windows, the plugin was built to encrypt secrets using DPAPI (a windows only library). For dev purposes in Linux/Mac dev workstations, those secrets put in the environment context by `DevHelper` will be in plaintext. In windows dev workstations, `DevHelper` encrypts the secrets as the .NET plugin does. This is informational only, **the module will use its encryption/decryption capabilities automatically based on the platform** it is running on and you do not have to do anything specific to enable it.
165
163
 
166
164
  ### Example:
167
165
 
168
166
  #### Set your arguments and secrets:
169
167
 
170
168
  ```python
171
- from python4cpm import NETHelper, Python4CPM, Python4CPMHandler
169
+ from python4cpm import DevHelper, Python4CPM, Python4CPMHandler
172
170
 
173
- NETHelper.set(
171
+ DevHelper.set(
174
172
  action=Python4CPM.ACTION_CHANGE, # use actions from Python4CPM.ACTION_*
175
173
  logging_level="debug",
176
- target_policy_id="NETHelper",
177
- target_object_name="Objectname",
174
+ target_policy_id="DevHelper", # name of platform
175
+ target_safe_name="Safename", # name of safe
176
+ target_object_name="Objectname", # name of account
178
177
  target_username="jdoe",
179
178
  target_address="myapp.corp.local",
180
179
  target_port="8443",
@@ -212,5 +211,5 @@ CredManager().run()
212
211
 
213
212
  #### Remember for your final script:
214
213
 
215
- - Remove the import of `NETHelper`.
216
- - Remove the `NETHelper.set()` call.
214
+ - Remove the import of `DevHelper`.
215
+ - Remove the `DevHelper.set()` call.
@@ -5,9 +5,9 @@ src/python4cpm/__init__.py
5
5
  src/python4cpm/accounts.py
6
6
  src/python4cpm/args.py
7
7
  src/python4cpm/crypto.py
8
+ src/python4cpm/devhelper.py
8
9
  src/python4cpm/envhandler.py
9
10
  src/python4cpm/logger.py
10
- src/python4cpm/nethelper.py
11
11
  src/python4cpm/python4cpm.py
12
12
  src/python4cpm/python4cpmhandler.py
13
13
  src/python4cpm/secret.py
File without changes
File without changes