python4cpm 1.1.4__py3-none-any.whl → 1.1.6__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.
python4cpm/__init__.py CHANGED
@@ -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
  ]
python4cpm/accounts.py CHANGED
@@ -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()
python4cpm/logger.py CHANGED
@@ -23,7 +23,7 @@ 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])
@@ -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 | %(name)s | %(levelname)s | "
39
39
  "%(module)s | %(funcName)s | %(message)s"
40
40
  )
41
41
  datefmt = "%Y-%m-%d %H:%M:%S"
python4cpm/python4cpm.py CHANGED
@@ -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.6
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.
@@ -0,0 +1,15 @@
1
+ python4cpm/__init__.py,sha256=GQvsXZY2escF3zucv3d68s2ydqHSIYi5tnNDCkhTjcM,302
2
+ python4cpm/accounts.py,sha256=tzLr6kFeHD6jDF-dZXjp2FeoABFsWn2hp4bO5uYN2Zg,2201
3
+ python4cpm/args.py,sha256=PQDDlMakP-YsDLd3HdwIZtxVpIM4m4aHl2GuRj9kHpI,504
4
+ python4cpm/crypto.py,sha256=AKjmCVkuQRxomhuQJ8b5IN5QPc8n9aAMui99ZEgnGAg,2388
5
+ python4cpm/devhelper.py,sha256=iv5zHSMyMNMdksGkkTh_8c_ObocJfQormQ4S3nZzo0Y,2609
6
+ python4cpm/envhandler.py,sha256=mNDOaYVemmxKREXyOf7IuQdFDXrvZ7f_7sNaqWV7TsI,678
7
+ python4cpm/logger.py,sha256=66lkgsGsSyXJLeMfn8zq6DinTPJWRfFyMBiUYySM2Ec,1461
8
+ python4cpm/python4cpm.py,sha256=-zgvLHnnnvwnmSxTwizdtHwKJPK7DcsUZIHES5Q6sR8,3449
9
+ python4cpm/python4cpmhandler.py,sha256=SXKsnFAwUp8cHEhv2TygpNpptUkN3bVQZt1i-3TWql4,935
10
+ python4cpm/secret.py,sha256=Z2K8H406lViOLPJKklffScug6sdWoxt0T5jhX0EA_gI,572
11
+ python4cpm-1.1.6.dist-info/licenses/LICENSE,sha256=vF2wZA3GchZjH5lUmhonEwd4snuBc6o0ytpZNxVFyCw,1077
12
+ python4cpm-1.1.6.dist-info/METADATA,sha256=_UTFPdxldaU9RACjdD_15mPNuUiF6vayWjT_btCwuJE,11193
13
+ python4cpm-1.1.6.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
14
+ python4cpm-1.1.6.dist-info/top_level.txt,sha256=EhbshwpANmL0wYXaET8_6V9ZENtSwIyAd-kM3jGhUlE,11
15
+ python4cpm-1.1.6.dist-info/RECORD,,
@@ -1,15 +0,0 @@
1
- python4cpm/__init__.py,sha256=Z5UI6SPWKeegUkQ_YqMKTuYNIiDvgg5BmynCMJxpPaI,302
2
- python4cpm/accounts.py,sha256=GwP1DXNyKKgB1mHOAju8-tZNMjudiudamqzrftKM6us,2028
3
- python4cpm/args.py,sha256=PQDDlMakP-YsDLd3HdwIZtxVpIM4m4aHl2GuRj9kHpI,504
4
- python4cpm/crypto.py,sha256=AKjmCVkuQRxomhuQJ8b5IN5QPc8n9aAMui99ZEgnGAg,2388
5
- python4cpm/envhandler.py,sha256=mNDOaYVemmxKREXyOf7IuQdFDXrvZ7f_7sNaqWV7TsI,678
6
- python4cpm/logger.py,sha256=02ABEXY1Kty_iNbIP_svsBcs_o8AwJM49_RajnI9nNI,1437
7
- python4cpm/nethelper.py,sha256=P-s0GHKq9_J7sOb17A7zg2txPr6oc2xQqNBhSRpCkqE,2591
8
- python4cpm/python4cpm.py,sha256=rC86lgBOPPG8XTVXepewADlj8qXAoBGmpqhdUbKDUcM,3267
9
- python4cpm/python4cpmhandler.py,sha256=SXKsnFAwUp8cHEhv2TygpNpptUkN3bVQZt1i-3TWql4,935
10
- python4cpm/secret.py,sha256=Z2K8H406lViOLPJKklffScug6sdWoxt0T5jhX0EA_gI,572
11
- python4cpm-1.1.4.dist-info/licenses/LICENSE,sha256=vF2wZA3GchZjH5lUmhonEwd4snuBc6o0ytpZNxVFyCw,1077
12
- python4cpm-1.1.4.dist-info/METADATA,sha256=x_NiD5sqb64GSz0L40wkNT3EuQ8i1Li9ebHgUtm1xhY,11291
13
- python4cpm-1.1.4.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
14
- python4cpm-1.1.4.dist-info/top_level.txt,sha256=EhbshwpANmL0wYXaET8_6V9ZENtSwIyAd-kM3jGhUlE,11
15
- python4cpm-1.1.4.dist-info/RECORD,,