Skip to content

Commit 1164eea

Browse files
authored
fixes cisco for username and password (DataDog#2267)
1 parent e243d6b commit 1164eea

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

cisco_aci/datadog_checks/cisco_aci/api.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from cryptography.hazmat.backends import default_backend
1111
from six.moves.urllib.parse import unquote
1212

13-
from .exceptions import APIParsingException, ConfigurationException, APIConnectionException
13+
from .exceptions import APIParsingException, ConfigurationException, APIConnectionException, APIAuthException
1414

1515

1616
class SessionWrapper:
@@ -49,21 +49,23 @@ def make_request(self, path):
4949
payload = '{}{}'.format(req.method, req.url.replace(self.aci_url, ''))
5050
payload = unquote(payload)
5151

52-
signature = self.cert_key.sign(payload,
53-
padding.PKCS1v15(),
54-
hashes.SHA256())
55-
56-
signature = base64.b64encode(signature)
57-
5852
prepped_request = req.prepare()
5953
if self.apic_cookie:
6054
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)
6261
cookie = ('APIC-Request-Signature={}; '
6362
'APIC-Certificate-Algorithm=v1.0; '
6463
'APIC-Certificate-Fingerprint=fingerprint; '
6564
'APIC-Certificate-DN={}').format(signature, self.certDn)
6665
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")
6769

6870
response = self.session.send(prepped_request, verify=self.verify, timeout=self.timeout)
6971
try:

cisco_aci/datadog_checks/cisco_aci/exceptions.py

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ class APIException(Exception):
77
pass
88

99

10+
class APIAuthException(Exception):
11+
pass
12+
13+
1014
class APIConnectionException(APIException):
1115
pass
1216

0 commit comments

Comments
 (0)