|
10 | 10 | from cryptography.hazmat.backends import default_backend
|
11 | 11 | from six.moves.urllib.parse import unquote
|
12 | 12 |
|
13 |
| -from .exceptions import APIParsingException, ConfigurationException, APIConnectionException |
| 13 | +from .exceptions import APIParsingException, ConfigurationException, APIConnectionException, APIAuthException |
14 | 14 |
|
15 | 15 |
|
16 | 16 | class SessionWrapper:
|
@@ -49,21 +49,23 @@ def make_request(self, path):
|
49 | 49 | payload = '{}{}'.format(req.method, req.url.replace(self.aci_url, ''))
|
50 | 50 | payload = unquote(payload)
|
51 | 51 |
|
52 |
| - signature = self.cert_key.sign(payload, |
53 |
| - padding.PKCS1v15(), |
54 |
| - hashes.SHA256()) |
55 |
| - |
56 |
| - signature = base64.b64encode(signature) |
57 |
| - |
58 | 52 | prepped_request = req.prepare()
|
59 | 53 | if self.apic_cookie:
|
60 | 54 | prepped_request.headers['Cookie'] = self.apic_cookie
|
61 |
| - else: |
| 55 | + elif self.cert_key: |
| 56 | + signature = self.cert_key.sign(payload, |
| 57 | + padding.PKCS1v15(), |
| 58 | + hashes.SHA256()) |
| 59 | + |
| 60 | + signature = base64.b64encode(signature) |
62 | 61 | cookie = ('APIC-Request-Signature={}; '
|
63 | 62 | 'APIC-Certificate-Algorithm=v1.0; '
|
64 | 63 | 'APIC-Certificate-Fingerprint=fingerprint; '
|
65 | 64 | 'APIC-Certificate-DN={}').format(signature, self.certDn)
|
66 | 65 | prepped_request.headers['Cookie'] = cookie
|
| 66 | + else: |
| 67 | + self.warning("The Cisco ACI Integration requires either a cert or a username and password") |
| 68 | + raise APIAuthException("The Cisco ACI Integration requires either a cert or a username and password") |
67 | 69 |
|
68 | 70 | response = self.session.send(prepped_request, verify=self.verify, timeout=self.timeout)
|
69 | 71 | try:
|
|
0 commit comments