python4cpm 1.0.19__tar.gz → 1.0.21__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.
- {python4cpm-1.0.19/src/python4cpm.egg-info → python4cpm-1.0.21}/PKG-INFO +27 -14
- {python4cpm-1.0.19 → python4cpm-1.0.21}/README.md +25 -12
- {python4cpm-1.0.19 → python4cpm-1.0.21}/pyproject.toml +2 -2
- {python4cpm-1.0.19 → python4cpm-1.0.21}/src/python4cpm/logger.py +5 -8
- {python4cpm-1.0.19 → python4cpm-1.0.21}/src/python4cpm/python4cpm.py +21 -9
- {python4cpm-1.0.19 → python4cpm-1.0.21/src/python4cpm.egg-info}/PKG-INFO +27 -14
- {python4cpm-1.0.19 → python4cpm-1.0.21}/LICENSE +0 -0
- {python4cpm-1.0.19 → python4cpm-1.0.21}/setup.cfg +0 -0
- {python4cpm-1.0.19 → python4cpm-1.0.21}/src/python4cpm/__init__.py +0 -0
- {python4cpm-1.0.19 → python4cpm-1.0.21}/src/python4cpm/args.py +0 -0
- {python4cpm-1.0.19 → python4cpm-1.0.21}/src/python4cpm/crypto.py +0 -0
- {python4cpm-1.0.19 → python4cpm-1.0.21}/src/python4cpm/nethelper.py +0 -0
- {python4cpm-1.0.19 → python4cpm-1.0.21}/src/python4cpm/secrets.py +0 -0
- {python4cpm-1.0.19 → python4cpm-1.0.21}/src/python4cpm.egg-info/SOURCES.txt +0 -0
- {python4cpm-1.0.19 → python4cpm-1.0.21}/src/python4cpm.egg-info/dependency_links.txt +0 -0
- {python4cpm-1.0.19 → python4cpm-1.0.21}/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.0.
|
|
3
|
+
Version: 1.0.21
|
|
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.
|
|
28
|
+
Requires-Python: >=3.10
|
|
29
29
|
Description-Content-Type: text/markdown
|
|
30
30
|
License-File: LICENSE
|
|
31
31
|
Dynamic: license-file
|
|
@@ -40,29 +40,41 @@ This platform allows you to duplicate it multiple times, simply changing its set
|
|
|
40
40
|
|
|
41
41
|
### Preparing Python
|
|
42
42
|
|
|
43
|
-
1. Install Python in CPM.
|
|
44
|
-
|
|
45
|
-
3.
|
|
43
|
+
1. Install Python in CPM.
|
|
44
|
+
- **Python must be installed for all users**. Follow the custom install steps from the installation wizard to check the checkbox.
|
|
45
|
+
3. Create a venv in CPM, by running `py -m venv c:\venv`. If desired, use a custom location and adjust any future references.
|
|
46
|
+
4. Install `python4cpm` in your venv:
|
|
46
47
|
- If your CPM can connect to the internet, install with `c:\venv\Scripts\pip install python4cpm`.
|
|
47
48
|
- If your CPM cannot connect to the internet:
|
|
48
|
-
- Download the latest
|
|
49
|
+
- Download the latest `python4cpm-*.whl` file from the [pypi project files](https://pypi.org/project/python4cpm/#files).
|
|
49
50
|
- Copy the file to CPM and extract to a temporary directory called `python4cpm-wheel`.
|
|
50
51
|
- From the parent directory of `python4cpm-wheel` run `c:\venv\Scripts\pip install --no-index --find-links=.\python4cpm-wheel python4cpm`.
|
|
51
52
|
|
|
52
53
|
|
|
53
54
|
### Importing the platform
|
|
54
55
|
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
#### If you are using CPM (SaaS or Self-Hosted):
|
|
57
|
+
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`). The files for this may already be present.
|
|
58
|
+
2. Download the `python4cpm-platform-*.zip` asset from the [release](https://github.com/gonatienza/python4cpm/releases).
|
|
57
59
|
3. Import the platform zip file into Privilege Cloud/PVWA `(Administration -> Platform Management -> Import platform)`.
|
|
58
|
-
4. Craft your python script and place it within
|
|
60
|
+
4. Craft your python script and place it within a folder in CPM (e.g., `C:\python4cpm-scripts`).
|
|
59
61
|
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).
|
|
60
|
-
6. Edit the duplicated platform and specify the path of your
|
|
61
|
-
7.
|
|
62
|
+
6. Edit the duplicated platform and specify the path of your script, under `Target Account Platform -> Automatic Platform Management -> Additional Policy Settings -> Parameters -> PythonScriptPath -> Value` (e.g., `C:\python4cpm-scripts\myapp.py`).
|
|
63
|
+
7. Also update `Target Account Platform -> Automatic Platform Management -> Additional Policy Settings -> Parameters -> PythonExePath -> Value` with the custom path for the venv's `python.exe` file (e.g., `c:\venv\Scripts\python.exe`).
|
|
62
64
|
8. If you want to disable logging, update `Target Account Platform -> Automatic Platform Management -> Additional Policy Settings -> Parameters -> PythonLogging -> Value` to `no`.
|
|
63
65
|
9. If you want to change the logging level to `debug`, update `Target Account Platform -> Automatic Platform Management -> Additional Policy Settings -> Parameters -> PythonLoggingLevel -> Value` to `debug`.
|
|
64
66
|
10. For new applications repeat steps from 4 to 9.
|
|
65
67
|
|
|
68
|
+
#### If you are using SRS (SaaS only):
|
|
69
|
+
1. Download the `python4cpm-platform-*.zip` asset from the [release](https://github.com/gonatienza/python4cpm/releases).
|
|
70
|
+
2. Import the platform zip file into Privilege Cloud `(Administration -> Platform Management -> Import platform)`.
|
|
71
|
+
3. Craft your python script and place it within a folder in the Cloud Connector (where the SRS Management Agent runs) (e.g., `C:\python4cpm-scripts`).
|
|
72
|
+
4. 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).
|
|
73
|
+
5. Edit the duplicated platform and specify the path of your script, under `Plugin Settings -> Additional Parameters -> PythonScriptPath` (e.g., `C:\python4cpm-scripts\myapp.py`).
|
|
74
|
+
6. Also update `Plugin Settings -> Additional Parameters -> PythonExePath` with the custom path for the venv's `python.exe` file (e.g., `c:\venv\Scripts\python.exe`).
|
|
75
|
+
7. If you want to disable logging, update `Plugin Settings -> Additional Parameters -> PythonLogging` to `no`.
|
|
76
|
+
8. If you want to change the logging level to `debug`, update `Plugin Settings -> Additional Parameters -> PythonLoggingLevel -> Value` to `debug`.
|
|
77
|
+
9. For new applications repeat steps from 3 to 8.
|
|
66
78
|
|
|
67
79
|
## Python Script
|
|
68
80
|
|
|
@@ -93,11 +105,12 @@ p4cpm.log_info("this is an info message") # logs info into Logs/ThirdParty/Pytho
|
|
|
93
105
|
# Logging level -> Will only log debug messages if Automatic Platform Management -> Additional Policy Settings -> Parameters -> PythonLoggingLevel is set to debug (default is info)
|
|
94
106
|
p4cpm.log_debug("this is an debug message") # logs info into Logs/ThirdParty/Python4CPM/MyApp.log if logging level is set to debug
|
|
95
107
|
|
|
96
|
-
# Terminate signals ->
|
|
108
|
+
# Terminate signals -> MUST use one of the following three signals to terminate the script:
|
|
97
109
|
## p4cpm.close_success() # terminate with success state
|
|
98
110
|
## p4cpm.close_fail() # terminate with recoverable failed state
|
|
99
111
|
## p4cpm.close_fail(unrecoverable=True) # terminate with unrecoverable failed state
|
|
100
|
-
#
|
|
112
|
+
# When calling a signal sys.exit is invoked and the script is terminated.
|
|
113
|
+
# 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
114
|
|
|
102
115
|
|
|
103
116
|
# Verification example -> verify the username and password are valid
|
|
@@ -171,7 +184,7 @@ if __name__ == "__main__":
|
|
|
171
184
|
When doing `verify`, `change` or `reconcile` from Privilege Cloud/PVWA:
|
|
172
185
|
1. Verify -> the sciprt will be executed once with the `p4cpm.args.action` as `Python4CPM.ACTION_VERIFY`.
|
|
173
186
|
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
|
|
187
|
+
- If all actions are not terminated with `p4cpm.close_success()` and the scripts terminates without any exception, it defaults to a successful return.
|
|
175
188
|
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
189
|
- If all actions are not terminated with `p4cpm.close_success()` the overall reconcile will fail.
|
|
177
190
|
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.
|
|
@@ -8,29 +8,41 @@ This platform allows you to duplicate it multiple times, simply changing its set
|
|
|
8
8
|
|
|
9
9
|
### Preparing Python
|
|
10
10
|
|
|
11
|
-
1. Install Python in CPM.
|
|
12
|
-
|
|
13
|
-
3.
|
|
11
|
+
1. Install Python in CPM.
|
|
12
|
+
- **Python must be installed for all users**. Follow the custom install steps from the installation wizard to check the checkbox.
|
|
13
|
+
3. Create a venv in CPM, by running `py -m venv c:\venv`. If desired, use a custom location and adjust any future references.
|
|
14
|
+
4. Install `python4cpm` in your venv:
|
|
14
15
|
- If your CPM can connect to the internet, install with `c:\venv\Scripts\pip install python4cpm`.
|
|
15
16
|
- If your CPM cannot connect to the internet:
|
|
16
|
-
- Download the latest
|
|
17
|
+
- Download the latest `python4cpm-*.whl` file from the [pypi project files](https://pypi.org/project/python4cpm/#files).
|
|
17
18
|
- Copy the file to CPM and extract to a temporary directory called `python4cpm-wheel`.
|
|
18
19
|
- From the parent directory of `python4cpm-wheel` run `c:\venv\Scripts\pip install --no-index --find-links=.\python4cpm-wheel python4cpm`.
|
|
19
20
|
|
|
20
21
|
|
|
21
22
|
### Importing the platform
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
#### If you are using CPM (SaaS or Self-Hosted):
|
|
25
|
+
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`). The files for this may already be present.
|
|
26
|
+
2. Download the `python4cpm-platform-*.zip` asset from the [release](https://github.com/gonatienza/python4cpm/releases).
|
|
25
27
|
3. Import the platform zip file into Privilege Cloud/PVWA `(Administration -> Platform Management -> Import platform)`.
|
|
26
|
-
4. Craft your python script and place it within
|
|
28
|
+
4. Craft your python script and place it within a folder in CPM (e.g., `C:\python4cpm-scripts`).
|
|
27
29
|
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).
|
|
28
|
-
6. Edit the duplicated platform and specify the path of your
|
|
29
|
-
7.
|
|
30
|
+
6. Edit the duplicated platform and specify the path of your script, under `Target Account Platform -> Automatic Platform Management -> Additional Policy Settings -> Parameters -> PythonScriptPath -> Value` (e.g., `C:\python4cpm-scripts\myapp.py`).
|
|
31
|
+
7. Also update `Target Account Platform -> Automatic Platform Management -> Additional Policy Settings -> Parameters -> PythonExePath -> Value` with the custom path for the venv's `python.exe` file (e.g., `c:\venv\Scripts\python.exe`).
|
|
30
32
|
8. If you want to disable logging, update `Target Account Platform -> Automatic Platform Management -> Additional Policy Settings -> Parameters -> PythonLogging -> Value` to `no`.
|
|
31
33
|
9. If you want to change the logging level to `debug`, update `Target Account Platform -> Automatic Platform Management -> Additional Policy Settings -> Parameters -> PythonLoggingLevel -> Value` to `debug`.
|
|
32
34
|
10. For new applications repeat steps from 4 to 9.
|
|
33
35
|
|
|
36
|
+
#### If you are using SRS (SaaS only):
|
|
37
|
+
1. Download the `python4cpm-platform-*.zip` asset from the [release](https://github.com/gonatienza/python4cpm/releases).
|
|
38
|
+
2. Import the platform zip file into Privilege Cloud `(Administration -> Platform Management -> Import platform)`.
|
|
39
|
+
3. Craft your python script and place it within a folder in the Cloud Connector (where the SRS Management Agent runs) (e.g., `C:\python4cpm-scripts`).
|
|
40
|
+
4. 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).
|
|
41
|
+
5. Edit the duplicated platform and specify the path of your script, under `Plugin Settings -> Additional Parameters -> PythonScriptPath` (e.g., `C:\python4cpm-scripts\myapp.py`).
|
|
42
|
+
6. Also update `Plugin Settings -> Additional Parameters -> PythonExePath` with the custom path for the venv's `python.exe` file (e.g., `c:\venv\Scripts\python.exe`).
|
|
43
|
+
7. If you want to disable logging, update `Plugin Settings -> Additional Parameters -> PythonLogging` to `no`.
|
|
44
|
+
8. If you want to change the logging level to `debug`, update `Plugin Settings -> Additional Parameters -> PythonLoggingLevel -> Value` to `debug`.
|
|
45
|
+
9. For new applications repeat steps from 3 to 8.
|
|
34
46
|
|
|
35
47
|
## Python Script
|
|
36
48
|
|
|
@@ -61,11 +73,12 @@ p4cpm.log_info("this is an info message") # logs info into Logs/ThirdParty/Pytho
|
|
|
61
73
|
# Logging level -> Will only log debug messages if Automatic Platform Management -> Additional Policy Settings -> Parameters -> PythonLoggingLevel is set to debug (default is info)
|
|
62
74
|
p4cpm.log_debug("this is an debug message") # logs info into Logs/ThirdParty/Python4CPM/MyApp.log if logging level is set to debug
|
|
63
75
|
|
|
64
|
-
# Terminate signals ->
|
|
76
|
+
# Terminate signals -> MUST use one of the following three signals to terminate the script:
|
|
65
77
|
## p4cpm.close_success() # terminate with success state
|
|
66
78
|
## p4cpm.close_fail() # terminate with recoverable failed state
|
|
67
79
|
## p4cpm.close_fail(unrecoverable=True) # terminate with unrecoverable failed state
|
|
68
|
-
#
|
|
80
|
+
# When calling a signal sys.exit is invoked and the script is terminated.
|
|
81
|
+
# 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
82
|
|
|
70
83
|
|
|
71
84
|
# Verification example -> verify the username and password are valid
|
|
@@ -139,7 +152,7 @@ if __name__ == "__main__":
|
|
|
139
152
|
When doing `verify`, `change` or `reconcile` from Privilege Cloud/PVWA:
|
|
140
153
|
1. Verify -> the sciprt will be executed once with the `p4cpm.args.action` as `Python4CPM.ACTION_VERIFY`.
|
|
141
154
|
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
|
|
155
|
+
- If all actions are not terminated with `p4cpm.close_success()` and the scripts terminates without any exception, it defaults to a successful return.
|
|
143
156
|
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
157
|
- If all actions are not terminated with `p4cpm.close_success()` the overall reconcile will fail.
|
|
145
158
|
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.
|
|
7
|
+
version = "1.0.21"
|
|
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.
|
|
13
|
+
requires-python = ">=3.10"
|
|
14
14
|
readme = { file = "README.md", content-type = "text/markdown" }
|
|
15
15
|
license = { file = "LICENSE" }
|
|
16
16
|
|
|
@@ -3,12 +3,12 @@ import logging
|
|
|
3
3
|
from logging.handlers import RotatingFileHandler
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
_LOGS_DIR = os.path.join("Logs", "ThirdParty"
|
|
6
|
+
_LOGS_DIR = os.path.join("Logs", "ThirdParty")
|
|
7
7
|
_LOGGING_ENABLED_VALUE = "yes"
|
|
8
8
|
_LOGGING_LEVELS = {
|
|
9
9
|
"info": logging.INFO,
|
|
10
10
|
"debug": logging.DEBUG
|
|
11
|
-
|
|
11
|
+
}
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
def get_logger(
|
|
@@ -16,17 +16,14 @@ def get_logger(
|
|
|
16
16
|
args_logging: str,
|
|
17
17
|
args_logging_level: str
|
|
18
18
|
) -> logging.Logger:
|
|
19
|
-
if args_logging is None:
|
|
20
|
-
return None
|
|
21
19
|
if args_logging.lower() != _LOGGING_ENABLED_VALUE:
|
|
22
20
|
return None
|
|
23
21
|
os.makedirs(_LOGS_DIR, exist_ok=True)
|
|
24
|
-
logs_file = os.path.join(_LOGS_DIR, f"{name}.log")
|
|
22
|
+
logs_file = os.path.join(_LOGS_DIR, f"{__name__}-{name}.log")
|
|
25
23
|
_id = os.urandom(4).hex()
|
|
26
24
|
logger = logging.getLogger(_id)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
logger.setLevel(_LOGGING_LEVELS[logging_level])
|
|
25
|
+
if args_logging_level.lower() in _LOGGING_LEVELS:
|
|
26
|
+
logger.setLevel(_LOGGING_LEVELS[args_logging_level.lower()])
|
|
30
27
|
else:
|
|
31
28
|
logger.setLevel(_LOGGING_LEVELS["info"])
|
|
32
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 =
|
|
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
|
-
|
|
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
|
-
|
|
40
|
-
self.
|
|
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
|
-
|
|
79
|
-
|
|
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
|
-
|
|
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.
|
|
3
|
+
Version: 1.0.21
|
|
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.
|
|
28
|
+
Requires-Python: >=3.10
|
|
29
29
|
Description-Content-Type: text/markdown
|
|
30
30
|
License-File: LICENSE
|
|
31
31
|
Dynamic: license-file
|
|
@@ -40,29 +40,41 @@ This platform allows you to duplicate it multiple times, simply changing its set
|
|
|
40
40
|
|
|
41
41
|
### Preparing Python
|
|
42
42
|
|
|
43
|
-
1. Install Python in CPM.
|
|
44
|
-
|
|
45
|
-
3.
|
|
43
|
+
1. Install Python in CPM.
|
|
44
|
+
- **Python must be installed for all users**. Follow the custom install steps from the installation wizard to check the checkbox.
|
|
45
|
+
3. Create a venv in CPM, by running `py -m venv c:\venv`. If desired, use a custom location and adjust any future references.
|
|
46
|
+
4. Install `python4cpm` in your venv:
|
|
46
47
|
- If your CPM can connect to the internet, install with `c:\venv\Scripts\pip install python4cpm`.
|
|
47
48
|
- If your CPM cannot connect to the internet:
|
|
48
|
-
- Download the latest
|
|
49
|
+
- Download the latest `python4cpm-*.whl` file from the [pypi project files](https://pypi.org/project/python4cpm/#files).
|
|
49
50
|
- Copy the file to CPM and extract to a temporary directory called `python4cpm-wheel`.
|
|
50
51
|
- From the parent directory of `python4cpm-wheel` run `c:\venv\Scripts\pip install --no-index --find-links=.\python4cpm-wheel python4cpm`.
|
|
51
52
|
|
|
52
53
|
|
|
53
54
|
### Importing the platform
|
|
54
55
|
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
#### If you are using CPM (SaaS or Self-Hosted):
|
|
57
|
+
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`). The files for this may already be present.
|
|
58
|
+
2. Download the `python4cpm-platform-*.zip` asset from the [release](https://github.com/gonatienza/python4cpm/releases).
|
|
57
59
|
3. Import the platform zip file into Privilege Cloud/PVWA `(Administration -> Platform Management -> Import platform)`.
|
|
58
|
-
4. Craft your python script and place it within
|
|
60
|
+
4. Craft your python script and place it within a folder in CPM (e.g., `C:\python4cpm-scripts`).
|
|
59
61
|
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).
|
|
60
|
-
6. Edit the duplicated platform and specify the path of your
|
|
61
|
-
7.
|
|
62
|
+
6. Edit the duplicated platform and specify the path of your script, under `Target Account Platform -> Automatic Platform Management -> Additional Policy Settings -> Parameters -> PythonScriptPath -> Value` (e.g., `C:\python4cpm-scripts\myapp.py`).
|
|
63
|
+
7. Also update `Target Account Platform -> Automatic Platform Management -> Additional Policy Settings -> Parameters -> PythonExePath -> Value` with the custom path for the venv's `python.exe` file (e.g., `c:\venv\Scripts\python.exe`).
|
|
62
64
|
8. If you want to disable logging, update `Target Account Platform -> Automatic Platform Management -> Additional Policy Settings -> Parameters -> PythonLogging -> Value` to `no`.
|
|
63
65
|
9. If you want to change the logging level to `debug`, update `Target Account Platform -> Automatic Platform Management -> Additional Policy Settings -> Parameters -> PythonLoggingLevel -> Value` to `debug`.
|
|
64
66
|
10. For new applications repeat steps from 4 to 9.
|
|
65
67
|
|
|
68
|
+
#### If you are using SRS (SaaS only):
|
|
69
|
+
1. Download the `python4cpm-platform-*.zip` asset from the [release](https://github.com/gonatienza/python4cpm/releases).
|
|
70
|
+
2. Import the platform zip file into Privilege Cloud `(Administration -> Platform Management -> Import platform)`.
|
|
71
|
+
3. Craft your python script and place it within a folder in the Cloud Connector (where the SRS Management Agent runs) (e.g., `C:\python4cpm-scripts`).
|
|
72
|
+
4. 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).
|
|
73
|
+
5. Edit the duplicated platform and specify the path of your script, under `Plugin Settings -> Additional Parameters -> PythonScriptPath` (e.g., `C:\python4cpm-scripts\myapp.py`).
|
|
74
|
+
6. Also update `Plugin Settings -> Additional Parameters -> PythonExePath` with the custom path for the venv's `python.exe` file (e.g., `c:\venv\Scripts\python.exe`).
|
|
75
|
+
7. If you want to disable logging, update `Plugin Settings -> Additional Parameters -> PythonLogging` to `no`.
|
|
76
|
+
8. If you want to change the logging level to `debug`, update `Plugin Settings -> Additional Parameters -> PythonLoggingLevel -> Value` to `debug`.
|
|
77
|
+
9. For new applications repeat steps from 3 to 8.
|
|
66
78
|
|
|
67
79
|
## Python Script
|
|
68
80
|
|
|
@@ -93,11 +105,12 @@ p4cpm.log_info("this is an info message") # logs info into Logs/ThirdParty/Pytho
|
|
|
93
105
|
# Logging level -> Will only log debug messages if Automatic Platform Management -> Additional Policy Settings -> Parameters -> PythonLoggingLevel is set to debug (default is info)
|
|
94
106
|
p4cpm.log_debug("this is an debug message") # logs info into Logs/ThirdParty/Python4CPM/MyApp.log if logging level is set to debug
|
|
95
107
|
|
|
96
|
-
# Terminate signals ->
|
|
108
|
+
# Terminate signals -> MUST use one of the following three signals to terminate the script:
|
|
97
109
|
## p4cpm.close_success() # terminate with success state
|
|
98
110
|
## p4cpm.close_fail() # terminate with recoverable failed state
|
|
99
111
|
## p4cpm.close_fail(unrecoverable=True) # terminate with unrecoverable failed state
|
|
100
|
-
#
|
|
112
|
+
# When calling a signal sys.exit is invoked and the script is terminated.
|
|
113
|
+
# 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
114
|
|
|
102
115
|
|
|
103
116
|
# Verification example -> verify the username and password are valid
|
|
@@ -171,7 +184,7 @@ if __name__ == "__main__":
|
|
|
171
184
|
When doing `verify`, `change` or `reconcile` from Privilege Cloud/PVWA:
|
|
172
185
|
1. Verify -> the sciprt will be executed once with the `p4cpm.args.action` as `Python4CPM.ACTION_VERIFY`.
|
|
173
186
|
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
|
|
187
|
+
- If all actions are not terminated with `p4cpm.close_success()` and the scripts terminates without any exception, it defaults to a successful return.
|
|
175
188
|
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
189
|
- If all actions are not terminated with `p4cpm.close_success()` the overall reconcile will fail.
|
|
177
190
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|