python4cpm 1.0.18__tar.gz → 1.0.20__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python4cpm
3
- Version: 1.0.18
3
+ Version: 1.0.20
4
4
  Summary: Python for CPM
5
5
  Author-email: Gonzalo Atienza Rela <gonatienza@gmail.com>
6
6
  License: MIT License
@@ -25,7 +25,7 @@ License: MIT License
25
25
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
26
  THE SOFTWARE.
27
27
 
28
- Requires-Python: >=3.8
28
+ Requires-Python: >=3.10
29
29
  Description-Content-Type: text/markdown
30
30
  License-File: LICENSE
31
31
  Dynamic: license-file
@@ -45,7 +45,7 @@ This platform allows you to duplicate it multiple times, simply changing its set
45
45
  3. Install `python4cpm` in your venv:
46
46
  - If your CPM can connect to the internet, install with `c:\venv\Scripts\pip install python4cpm`.
47
47
  - If your CPM cannot connect to the internet:
48
- - Download the latest `*.whl` file from the [pypi project files](https://pypi.org/project/python4cpm/#files).
48
+ - Download the latest `python4cpm-*.whl` file from the [pypi project files](https://pypi.org/project/python4cpm/#files).
49
49
  - Copy the file to CPM and extract to a temporary directory called `python4cpm-wheel`.
50
50
  - From the parent directory of `python4cpm-wheel` run `c:\venv\Scripts\pip install --no-index --find-links=.\python4cpm-wheel python4cpm`.
51
51
 
@@ -53,7 +53,7 @@ This platform allows you to duplicate it multiple times, simply changing its set
53
53
  ### Importing the platform
54
54
 
55
55
  1. Download the latest [Credential Management .NET SDK](https://community.cyberark.com/marketplace/s/#a3550000000EkA0AAK-a3950000000jjoOAAQ) and place its content in the bin folder of CPM (`C:\Program Files (x86)\CyberArk\Password Manager\bin`).
56
- 2. Download the `python4cpm-platform.zip` asset from the [release](https://github.com/gonatienza/python4cpm/releases).
56
+ 2. Download the `python4cpm-platform-*.zip` asset from the [release](https://github.com/gonatienza/python4cpm/releases).
57
57
  3. Import the platform zip file into Privilege Cloud/PVWA `(Administration -> Platform Management -> Import platform)`.
58
58
  4. Craft your python script and place it within the bin folder of CPM (`C:\Program Files (x86)\CyberArk\Password Manager\bin`).
59
59
  5. Duplicate the imported platform in Privilege Cloud/PVWA `(Administration -> Platform Management -> Application -> Python for CPM)` and name it after your application (e.g., My App).
@@ -93,11 +93,12 @@ p4cpm.log_info("this is an info message") # logs info into Logs/ThirdParty/Pytho
93
93
  # Logging level -> Will only log debug messages if Automatic Platform Management -> Additional Policy Settings -> Parameters -> PythonLoggingLevel is set to debug (default is info)
94
94
  p4cpm.log_debug("this is an debug message") # logs info into Logs/ThirdParty/Python4CPM/MyApp.log if logging level is set to debug
95
95
 
96
- # Terminate signals -> ALWAYS use one of the following three signals to terminate the script
96
+ # Terminate signals -> MUST use one of the following three signals to terminate the script:
97
97
  ## p4cpm.close_success() # terminate with success state
98
98
  ## p4cpm.close_fail() # terminate with recoverable failed state
99
99
  ## p4cpm.close_fail(unrecoverable=True) # terminate with unrecoverable failed state
100
- # If no signal is call, CPM will not know if the action was successful and display an error
100
+ # When calling a signal sys.exit is invoked and the script is terminated.
101
+ # If no signal is called, and the script finishes without any exception, it will behave like p4cpm.close_fail(unrecoverable=True) and log an error message.
101
102
 
102
103
 
103
104
  # Verification example -> verify the username and password are valid
@@ -171,7 +172,7 @@ if __name__ == "__main__":
171
172
  When doing `verify`, `change` or `reconcile` from Privilege Cloud/PVWA:
172
173
  1. Verify -> the sciprt will be executed once with the `p4cpm.args.action` as `Python4CPM.ACTION_VERIFY`.
173
174
  2. Change -> the sciprt will be executed twice, once with the action `p4cpm.args.action` as `Python4CPM.ACTION_LOGON` and once as `Python4CPM.ACTION_CHANGE`.
174
- - If all actions are not terminated with `p4cpm.close_success()` the overall change will fail.
175
+ - If all actions are not terminated with `p4cpm.close_success()` and the scripts terminates without any exception, it defaults to a successful return.
175
176
  3. Reconcile -> the sciprt will be executed twice, once with the `p4cpm.args.action` as `Python4CPM.ACTION_PRERECONCILE` and once as `Python4CPM.ACTION_RECONCILE`.
176
177
  - If all actions are not terminated with `p4cpm.close_success()` the overall reconcile will fail.
177
178
  4. When `p4cpm.args.action` comes as `Python4CPM.ACTION_VERIFY`, `Python4CPM.ACTION_LOGON` or `Python4CPM.ACTION_PRERECONCILE`: `p4cpm.secrets.new_password.get()` will always return an empty string.
@@ -13,7 +13,7 @@ This platform allows you to duplicate it multiple times, simply changing its set
13
13
  3. Install `python4cpm` in your venv:
14
14
  - If your CPM can connect to the internet, install with `c:\venv\Scripts\pip install python4cpm`.
15
15
  - If your CPM cannot connect to the internet:
16
- - Download the latest `*.whl` file from the [pypi project files](https://pypi.org/project/python4cpm/#files).
16
+ - Download the latest `python4cpm-*.whl` file from the [pypi project files](https://pypi.org/project/python4cpm/#files).
17
17
  - Copy the file to CPM and extract to a temporary directory called `python4cpm-wheel`.
18
18
  - From the parent directory of `python4cpm-wheel` run `c:\venv\Scripts\pip install --no-index --find-links=.\python4cpm-wheel python4cpm`.
19
19
 
@@ -21,7 +21,7 @@ This platform allows you to duplicate it multiple times, simply changing its set
21
21
  ### Importing the platform
22
22
 
23
23
  1. Download the latest [Credential Management .NET SDK](https://community.cyberark.com/marketplace/s/#a3550000000EkA0AAK-a3950000000jjoOAAQ) and place its content in the bin folder of CPM (`C:\Program Files (x86)\CyberArk\Password Manager\bin`).
24
- 2. Download the `python4cpm-platform.zip` asset from the [release](https://github.com/gonatienza/python4cpm/releases).
24
+ 2. Download the `python4cpm-platform-*.zip` asset from the [release](https://github.com/gonatienza/python4cpm/releases).
25
25
  3. Import the platform zip file into Privilege Cloud/PVWA `(Administration -> Platform Management -> Import platform)`.
26
26
  4. Craft your python script and place it within the bin folder of CPM (`C:\Program Files (x86)\CyberArk\Password Manager\bin`).
27
27
  5. Duplicate the imported platform in Privilege Cloud/PVWA `(Administration -> Platform Management -> Application -> Python for CPM)` and name it after your application (e.g., My App).
@@ -61,11 +61,12 @@ p4cpm.log_info("this is an info message") # logs info into Logs/ThirdParty/Pytho
61
61
  # Logging level -> Will only log debug messages if Automatic Platform Management -> Additional Policy Settings -> Parameters -> PythonLoggingLevel is set to debug (default is info)
62
62
  p4cpm.log_debug("this is an debug message") # logs info into Logs/ThirdParty/Python4CPM/MyApp.log if logging level is set to debug
63
63
 
64
- # Terminate signals -> ALWAYS use one of the following three signals to terminate the script
64
+ # Terminate signals -> MUST use one of the following three signals to terminate the script:
65
65
  ## p4cpm.close_success() # terminate with success state
66
66
  ## p4cpm.close_fail() # terminate with recoverable failed state
67
67
  ## p4cpm.close_fail(unrecoverable=True) # terminate with unrecoverable failed state
68
- # If no signal is call, CPM will not know if the action was successful and display an error
68
+ # When calling a signal sys.exit is invoked and the script is terminated.
69
+ # If no signal is called, and the script finishes without any exception, it will behave like p4cpm.close_fail(unrecoverable=True) and log an error message.
69
70
 
70
71
 
71
72
  # Verification example -> verify the username and password are valid
@@ -139,7 +140,7 @@ if __name__ == "__main__":
139
140
  When doing `verify`, `change` or `reconcile` from Privilege Cloud/PVWA:
140
141
  1. Verify -> the sciprt will be executed once with the `p4cpm.args.action` as `Python4CPM.ACTION_VERIFY`.
141
142
  2. Change -> the sciprt will be executed twice, once with the action `p4cpm.args.action` as `Python4CPM.ACTION_LOGON` and once as `Python4CPM.ACTION_CHANGE`.
142
- - If all actions are not terminated with `p4cpm.close_success()` the overall change will fail.
143
+ - If all actions are not terminated with `p4cpm.close_success()` and the scripts terminates without any exception, it defaults to a successful return.
143
144
  3. Reconcile -> the sciprt will be executed twice, once with the `p4cpm.args.action` as `Python4CPM.ACTION_PRERECONCILE` and once as `Python4CPM.ACTION_RECONCILE`.
144
145
  - If all actions are not terminated with `p4cpm.close_success()` the overall reconcile will fail.
145
146
  4. When `p4cpm.args.action` comes as `Python4CPM.ACTION_VERIFY`, `Python4CPM.ACTION_LOGON` or `Python4CPM.ACTION_PRERECONCILE`: `p4cpm.secrets.new_password.get()` will always return an empty string.
@@ -4,13 +4,13 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "python4cpm"
7
- version = "1.0.18"
7
+ version = "1.0.20"
8
8
  description = "Python for CPM"
9
9
  authors = [
10
10
  { name = "Gonzalo Atienza Rela", email = "gonatienza@gmail.com" }
11
11
  ]
12
12
  dependencies = []
13
- requires-python = ">=3.8"
13
+ requires-python = ">=3.10"
14
14
  readme = { file = "README.md", content-type = "text/markdown" }
15
15
  license = { file = "LICENSE" }
16
16
 
@@ -4,9 +4,6 @@ from logging.handlers import RotatingFileHandler
4
4
 
5
5
 
6
6
  _LOGS_DIR = os.path.join("Logs", "ThirdParty", "Python4CPM")
7
- _CPM_ROOT_DIR = "C:\\Program Files (x86)\\CyberArk\\Password Manager"
8
- if os.path.exists(_CPM_ROOT_DIR):
9
- _LOGS_DIR = os.path.join(_CPM_ROOT_DIR, _LOGS_DIR)
10
7
  _LOGGING_ENABLED_VALUE = "yes"
11
8
  _LOGGING_LEVELS = {
12
9
  "info": logging.INFO,
@@ -19,17 +16,14 @@ def get_logger(
19
16
  args_logging: str,
20
17
  args_logging_level: str
21
18
  ) -> logging.Logger:
22
- if args_logging is None:
23
- return None
24
19
  if args_logging.lower() != _LOGGING_ENABLED_VALUE:
25
20
  return None
26
21
  os.makedirs(_LOGS_DIR, exist_ok=True)
27
22
  logs_file = os.path.join(_LOGS_DIR, f"{name}.log")
28
23
  _id = os.urandom(4).hex()
29
24
  logger = logging.getLogger(_id)
30
- logging_level = args_logging_level.lower()
31
- if logging_level in _LOGGING_LEVELS:
32
- logger.setLevel(_LOGGING_LEVELS[logging_level])
25
+ if args_logging_level.lower() in _LOGGING_LEVELS:
26
+ logger.setLevel(_LOGGING_LEVELS[args_logging_level.lower()])
33
27
  else:
34
28
  logger.setLevel(_LOGGING_LEVELS["info"])
35
29
  handler = RotatingFileHandler(
@@ -1,5 +1,6 @@
1
1
  import os
2
2
  import sys
3
+ import atexit
3
4
  import logging
4
5
  from python4cpm.secrets import Secrets
5
6
  from python4cpm.args import Args
@@ -19,15 +20,14 @@ class Python4CPM:
19
20
  ACTION_PRERECONCILE,
20
21
  ACTION_RECONCILE,
21
22
  )
22
- _SUCCESS_CODE = 0
23
+ _SUCCESS_CODE = 10
23
24
  _FAILED_RECOVERABLE_CODE = 81
24
25
  _FAILED_UNRECOVERABLE_CODE = 89
25
26
  _ENV_PREFIX = "PYTHON4CPM_"
26
27
 
27
28
  def __init__(self, name: str) -> None:
28
29
  self._name = name
29
- args = self._get_args()
30
- self._args = Args(**args)
30
+ self._args = self._get_args()
31
31
  self._logger = get_logger(
32
32
  self._name,
33
33
  self._args.logging,
@@ -36,8 +36,9 @@ class Python4CPM:
36
36
  self.log_info("Python4CPM.__init__: initiating...")
37
37
  self._log_args()
38
38
  self._verify_action()
39
- secrets = self._get_secrets()
40
- self._secrets = Secrets(**secrets)
39
+ self._secrets = self._get_secrets()
40
+ self._closed = False
41
+ atexit.register(self._on_exit)
41
42
 
42
43
  @property
43
44
  def args(self) -> Args:
@@ -75,19 +76,21 @@ class Python4CPM:
75
76
  def _get_args(cls) -> dict:
76
77
  args = {}
77
78
  for arg in Args.ARGS:
78
- args[arg] = os.environ.get(cls._get_env_key(arg))
79
- return args
79
+ _arg = os.environ.get(cls._get_env_key(arg))
80
+ args[arg] = _arg if _arg is not None else ""
81
+ return Args(**args)
80
82
 
81
83
  def _get_secrets(self) -> dict:
82
84
  secrets = {}
83
85
  for secret in Secrets.SECRETS:
84
- secrets[secret] = os.environ.get(self._get_env_key(secret))
86
+ _secret = os.environ.get(self._get_env_key(secret))
87
+ secrets[secret] = _secret if _secret is not None else ""
85
88
  common_message = f"Python4CPM._get_secrets: {secret} ->"
86
89
  if secrets[secret]:
87
90
  self.log_info(f"{common_message} [*******]")
88
91
  else:
89
92
  self.log_info(f"{common_message} [NOT SET]")
90
- return secrets
93
+ return Secrets(**secrets)
91
94
 
92
95
  def _verify_action(self) -> None:
93
96
  if self.args.action not in self._VALID_ACTIONS:
@@ -109,10 +112,19 @@ class Python4CPM:
109
112
  else:
110
113
  code = self._FAILED_UNRECOVERABLE_CODE
111
114
  self.log_error(f"Python4CPM.close_fail: closing with code {code}")
115
+ self._closed = True
112
116
  sys.exit(code)
113
117
 
114
118
  def close_success(self) -> None:
115
119
  self.log_info(
116
120
  f"Python4CPM.close_success: closing with code {self._SUCCESS_CODE}"
117
121
  )
122
+ self._closed = True
118
123
  sys.exit(self._SUCCESS_CODE)
124
+
125
+ def _on_exit(self):
126
+ if self._closed is False:
127
+ message = "Python4CPM._on_exit: no close signal called"
128
+ self.log_error(message)
129
+ sys.stderr.write(message)
130
+ sys.stderr.flush()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python4cpm
3
- Version: 1.0.18
3
+ Version: 1.0.20
4
4
  Summary: Python for CPM
5
5
  Author-email: Gonzalo Atienza Rela <gonatienza@gmail.com>
6
6
  License: MIT License
@@ -25,7 +25,7 @@ License: MIT License
25
25
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
26
  THE SOFTWARE.
27
27
 
28
- Requires-Python: >=3.8
28
+ Requires-Python: >=3.10
29
29
  Description-Content-Type: text/markdown
30
30
  License-File: LICENSE
31
31
  Dynamic: license-file
@@ -45,7 +45,7 @@ This platform allows you to duplicate it multiple times, simply changing its set
45
45
  3. Install `python4cpm` in your venv:
46
46
  - If your CPM can connect to the internet, install with `c:\venv\Scripts\pip install python4cpm`.
47
47
  - If your CPM cannot connect to the internet:
48
- - Download the latest `*.whl` file from the [pypi project files](https://pypi.org/project/python4cpm/#files).
48
+ - Download the latest `python4cpm-*.whl` file from the [pypi project files](https://pypi.org/project/python4cpm/#files).
49
49
  - Copy the file to CPM and extract to a temporary directory called `python4cpm-wheel`.
50
50
  - From the parent directory of `python4cpm-wheel` run `c:\venv\Scripts\pip install --no-index --find-links=.\python4cpm-wheel python4cpm`.
51
51
 
@@ -53,7 +53,7 @@ This platform allows you to duplicate it multiple times, simply changing its set
53
53
  ### Importing the platform
54
54
 
55
55
  1. Download the latest [Credential Management .NET SDK](https://community.cyberark.com/marketplace/s/#a3550000000EkA0AAK-a3950000000jjoOAAQ) and place its content in the bin folder of CPM (`C:\Program Files (x86)\CyberArk\Password Manager\bin`).
56
- 2. Download the `python4cpm-platform.zip` asset from the [release](https://github.com/gonatienza/python4cpm/releases).
56
+ 2. Download the `python4cpm-platform-*.zip` asset from the [release](https://github.com/gonatienza/python4cpm/releases).
57
57
  3. Import the platform zip file into Privilege Cloud/PVWA `(Administration -> Platform Management -> Import platform)`.
58
58
  4. Craft your python script and place it within the bin folder of CPM (`C:\Program Files (x86)\CyberArk\Password Manager\bin`).
59
59
  5. Duplicate the imported platform in Privilege Cloud/PVWA `(Administration -> Platform Management -> Application -> Python for CPM)` and name it after your application (e.g., My App).
@@ -93,11 +93,12 @@ p4cpm.log_info("this is an info message") # logs info into Logs/ThirdParty/Pytho
93
93
  # Logging level -> Will only log debug messages if Automatic Platform Management -> Additional Policy Settings -> Parameters -> PythonLoggingLevel is set to debug (default is info)
94
94
  p4cpm.log_debug("this is an debug message") # logs info into Logs/ThirdParty/Python4CPM/MyApp.log if logging level is set to debug
95
95
 
96
- # Terminate signals -> ALWAYS use one of the following three signals to terminate the script
96
+ # Terminate signals -> MUST use one of the following three signals to terminate the script:
97
97
  ## p4cpm.close_success() # terminate with success state
98
98
  ## p4cpm.close_fail() # terminate with recoverable failed state
99
99
  ## p4cpm.close_fail(unrecoverable=True) # terminate with unrecoverable failed state
100
- # If no signal is call, CPM will not know if the action was successful and display an error
100
+ # When calling a signal sys.exit is invoked and the script is terminated.
101
+ # If no signal is called, and the script finishes without any exception, it will behave like p4cpm.close_fail(unrecoverable=True) and log an error message.
101
102
 
102
103
 
103
104
  # Verification example -> verify the username and password are valid
@@ -171,7 +172,7 @@ if __name__ == "__main__":
171
172
  When doing `verify`, `change` or `reconcile` from Privilege Cloud/PVWA:
172
173
  1. Verify -> the sciprt will be executed once with the `p4cpm.args.action` as `Python4CPM.ACTION_VERIFY`.
173
174
  2. Change -> the sciprt will be executed twice, once with the action `p4cpm.args.action` as `Python4CPM.ACTION_LOGON` and once as `Python4CPM.ACTION_CHANGE`.
174
- - If all actions are not terminated with `p4cpm.close_success()` the overall change will fail.
175
+ - If all actions are not terminated with `p4cpm.close_success()` and the scripts terminates without any exception, it defaults to a successful return.
175
176
  3. Reconcile -> the sciprt will be executed twice, once with the `p4cpm.args.action` as `Python4CPM.ACTION_PRERECONCILE` and once as `Python4CPM.ACTION_RECONCILE`.
176
177
  - If all actions are not terminated with `p4cpm.close_success()` the overall reconcile will fail.
177
178
  4. When `p4cpm.args.action` comes as `Python4CPM.ACTION_VERIFY`, `Python4CPM.ACTION_LOGON` or `Python4CPM.ACTION_PRERECONCILE`: `p4cpm.secrets.new_password.get()` will always return an empty string.
File without changes
File without changes