|
| 1 | +# MIT License |
| 2 | +# (C) Copyright 2021 Hewlett Packard Enterprise Development LP. |
| 3 | +# |
| 4 | +# customCerts : Custom CA Certificate Trust Store |
| 5 | + |
| 6 | + |
| 7 | +def get_custom_certs(self) -> list: |
| 8 | + """Returns list of custom CA certificates from Orchestrator |
| 9 | +
|
| 10 | + .. list-table:: |
| 11 | + :header-rows: 1 |
| 12 | +
|
| 13 | + * - Swagger Section |
| 14 | + - Method |
| 15 | + - Endpoint |
| 16 | + * - customCerts |
| 17 | + - GET |
| 18 | + - /customCert |
| 19 | +
|
| 20 | + :return: Returns list of custom certificates in Orchestrator \n |
| 21 | + * keyword **alias** (`str`): Alias used to identify the CA |
| 22 | + Certificate |
| 23 | + * keyword **key** (`str`): The CA Certificate |
| 24 | + * keyword **lastUpdatedTimestamp** (`str`): The timestamp of the |
| 25 | + last time the CA Certificate was updated in Orchestrator |
| 26 | + * keyword **expiration** (`str`): CA Certificate's expiration |
| 27 | + date |
| 28 | + * keyword **issuer** (`str`): CA Certificate's issuer |
| 29 | + * keyword **issuedTo** (`str`): CA Certificate's issued to |
| 30 | + :rtype: list |
| 31 | + """ |
| 32 | + return self._get("/customCert") |
| 33 | + |
| 34 | + |
| 35 | +def update_custom_certs( |
| 36 | + self, |
| 37 | + alias: str, |
| 38 | + key: str, |
| 39 | + expiration: str, |
| 40 | + issuer: str, |
| 41 | + issued_to: str, |
| 42 | + last_timestamp: str = "", |
| 43 | +) -> bool: |
| 44 | + """Add new or update existing custom CA certificate |
| 45 | +
|
| 46 | + .. list-table:: |
| 47 | + :header-rows: 1 |
| 48 | +
|
| 49 | + * - Swagger Section |
| 50 | + - Method |
| 51 | + - Endpoint |
| 52 | + * - customCerts |
| 53 | + - POST |
| 54 | + - /customCert |
| 55 | +
|
| 56 | + :param alias: Alias used to identify the CA Certificate |
| 57 | + :type alias: str |
| 58 | + :param key: The CA Certificate |
| 59 | + :type key: str |
| 60 | + :param expiration: CA Certificate's expiration date |
| 61 | + :type expiration: str |
| 62 | + :param issuer: CA Certificate's issuer |
| 63 | + :type issuer: str |
| 64 | + :param issued_to: CA Certificate's issued to |
| 65 | + :type issued_to: str |
| 66 | + :param last_timestamp: The timestamp of the last time the CA |
| 67 | + Certificate was updated in Orchestrator |
| 68 | + :type last_timestamp: str, optional |
| 69 | + :return: Returns True/False based on successful call |
| 70 | + :rtype: bool |
| 71 | + """ |
| 72 | + data = { |
| 73 | + "alias": alias, |
| 74 | + "key": key, |
| 75 | + "lastUpdatedTimestamp": last_timestamp, |
| 76 | + "expiration": expiration, |
| 77 | + "issuer": issuer, |
| 78 | + "issuedTo": issued_to, |
| 79 | + } |
| 80 | + |
| 81 | + return self._post( |
| 82 | + "/customCert", |
| 83 | + data=data, |
| 84 | + expected_status=[204], |
| 85 | + return_type="bool", |
| 86 | + ) |
| 87 | + |
| 88 | + |
| 89 | +def delete_custom_cert( |
| 90 | + self, |
| 91 | + alias: str, |
| 92 | +) -> bool: |
| 93 | + """Delete custom CA certificate |
| 94 | +
|
| 95 | + .. list-table:: |
| 96 | + :header-rows: 1 |
| 97 | +
|
| 98 | + * - Swagger Section |
| 99 | + - Method |
| 100 | + - Endpoint |
| 101 | + * - customCerts |
| 102 | + - DELETE |
| 103 | + - /customCert/{alias} |
| 104 | +
|
| 105 | + :param alias: Alias used to identify the CA Certificate |
| 106 | + :type alias: str |
| 107 | + :return: Returns True/False based on successful call |
| 108 | + :rtype: bool |
| 109 | + """ |
| 110 | + return self._delete( |
| 111 | + "/customCert/{}".format(alias), |
| 112 | + expected_status=[204], |
| 113 | + return_type="bool", |
| 114 | + ) |
| 115 | + |
| 116 | + |
| 117 | +def get_custom_certs_enabled(self) -> dict: |
| 118 | + """Returns whether or not Orchestrator is currently using custom CA |
| 119 | + certificate trust store |
| 120 | +
|
| 121 | + .. list-table:: |
| 122 | + :header-rows: 1 |
| 123 | +
|
| 124 | + * - Swagger Section |
| 125 | + - Method |
| 126 | + - Endpoint |
| 127 | + * - customCerts |
| 128 | + - GET |
| 129 | + - /customCert/enable |
| 130 | +
|
| 131 | + :return: Returns dictionary of custom certificates status \n |
| 132 | + * keyword **enabled** (`bool`): ``True`` if custom CA |
| 133 | + certificate trust store is in use, ``False`` if not in use |
| 134 | + :rtype: dict |
| 135 | + """ |
| 136 | + return self._get("/customCert/enable") |
| 137 | + |
| 138 | + |
| 139 | +def set_custom_certs_enabled( |
| 140 | + self, |
| 141 | + enabled: bool, |
| 142 | +) -> dict: |
| 143 | + """Enable or disable custom CA certificate trust store |
| 144 | +
|
| 145 | + .. list-table:: |
| 146 | + :header-rows: 1 |
| 147 | +
|
| 148 | + * - Swagger Section |
| 149 | + - Method |
| 150 | + - Endpoint |
| 151 | + * - customCerts |
| 152 | + - POST |
| 153 | + - /customCert/enable |
| 154 | +
|
| 155 | + :param enabled: Set to ``True`` to enable use of custom CA |
| 156 | + certificates trust store, ``False`` to use default certificates |
| 157 | + trust store |
| 158 | + :type enabled: bool |
| 159 | + :return: Returns True/False based on successful call |
| 160 | + :rtype: bool |
| 161 | + """ |
| 162 | + data = {"Enabled": enabled} |
| 163 | + |
| 164 | + return self._post( |
| 165 | + "/customCert/enable", |
| 166 | + data=data, |
| 167 | + expected_status=[204], |
| 168 | + return_type="bool", |
| 169 | + ) |
| 170 | + |
| 171 | + |
| 172 | +def check_custom_certs_orchestrator_to_portal( |
| 173 | + self, |
| 174 | + custom_certs: bool, |
| 175 | +) -> dict: |
| 176 | + """Checks whether Orchestrator can connect to Portal using the |
| 177 | + default or custom CA certificates |
| 178 | +
|
| 179 | + .. list-table:: |
| 180 | + :header-rows: 1 |
| 181 | +
|
| 182 | + * - Swagger Section |
| 183 | + - Method |
| 184 | + - Endpoint |
| 185 | + * - customCerts |
| 186 | + - GET |
| 187 | + - /customCert/orchestratorConnectivity/{custom} |
| 188 | +
|
| 189 | + :return: TBD |
| 190 | + :rtype: TBD |
| 191 | + """ |
| 192 | + return self._get( |
| 193 | + "/customCert/orchestratorConnectivity/{}".format(custom_certs) |
| 194 | + ) |
| 195 | + |
| 196 | + |
| 197 | +def check_custom_certs_appliances_to_portal( |
| 198 | + self, |
| 199 | + custom_certs: bool, |
| 200 | +) -> dict: |
| 201 | + """Checks whether appliances can connect to Portal and Orchestrator |
| 202 | + using the default or custom CA certificates |
| 203 | +
|
| 204 | + .. list-table:: |
| 205 | + :header-rows: 1 |
| 206 | +
|
| 207 | + * - Swagger Section |
| 208 | + - Method |
| 209 | + - Endpoint |
| 210 | + * - customCerts |
| 211 | + - GET |
| 212 | + - /customCert/applianceConnectivity/{custom} |
| 213 | +
|
| 214 | + :return: TBD |
| 215 | + :rtype: TBD |
| 216 | + """ |
| 217 | + return self._get( |
| 218 | + "/customCert/applianceConnectivity/{}".format(custom_certs) |
| 219 | + ) |
| 220 | + |
| 221 | + |
| 222 | +def verify_custom_cert( |
| 223 | + self, |
| 224 | + alias: str, |
| 225 | + key: str, |
| 226 | + expiration: str, |
| 227 | + issuer: str, |
| 228 | + issued_to: str, |
| 229 | + last_timestamp: str = "", |
| 230 | +) -> bool: |
| 231 | + """Verify the custom CA certificate |
| 232 | +
|
| 233 | + .. list-table:: |
| 234 | + :header-rows: 1 |
| 235 | +
|
| 236 | + * - Swagger Section |
| 237 | + - Method |
| 238 | + - Endpoint |
| 239 | + * - customCerts |
| 240 | + - POST |
| 241 | + - /customCert/verify |
| 242 | +
|
| 243 | + :param alias: Alias used to identify the CA Certificate |
| 244 | + :type alias: str |
| 245 | + :param key: The CA Certificate |
| 246 | + :type key: str |
| 247 | + :param expiration: CA Certificate's expiration date |
| 248 | + :type expiration: str |
| 249 | + :param issuer: CA Certificate's issuer |
| 250 | + :type issuer: str |
| 251 | + :param issued_to: CA Certificate's issued to |
| 252 | + :type issued_to: str |
| 253 | + :param last_timestamp: The timestamp of the last time the CA |
| 254 | + Certificate was updated in Orchestrator |
| 255 | + :type last_timestamp: str, optional |
| 256 | + :return: Returns True/False based on successful call |
| 257 | + :rtype: bool |
| 258 | + """ |
| 259 | + data = { |
| 260 | + "alias": alias, |
| 261 | + "key": key, |
| 262 | + "lastUpdatedTimestamp": last_timestamp, |
| 263 | + "expiration": expiration, |
| 264 | + "issuer": issuer, |
| 265 | + "issuedTo": issued_to, |
| 266 | + } |
| 267 | + |
| 268 | + return self._post( |
| 269 | + "/customCert/verify", |
| 270 | + data=data, |
| 271 | + expected_status=[204], |
| 272 | + return_type="bool", |
| 273 | + ) |
0 commit comments