diff --git a/detect_secrets/plugins/ibm_cloud_iam.py b/detect_secrets/plugins/ibm_cloud_iam.py index 43655b542..f5bb18473 100644 --- a/detect_secrets/plugins/ibm_cloud_iam.py +++ b/detect_secrets/plugins/ibm_cloud_iam.py @@ -42,20 +42,25 @@ class IBMCloudIAMDetector(RegexBasedDetector): ] def verify(self, token, **kwargs): - if type(token) == bytes: - token = token.decode('UTF-8') - headers = { - 'Content-Type': 'application/x-www-form-urlencoded', - 'Accept': 'application/json', - } - response = requests.post( - 'https://iam.cloud.ibm.com/identity/token', - headers=headers, - data={ - 'grant_type': 'urn:ibm:params:oauth:grant-type:apikey', - 'apikey': token, - }, - ) + response = verify_cloud_iam_api_key(token) return VerifiedResult.VERIFIED_TRUE if response.status_code == 200 \ else VerifiedResult.VERIFIED_FALSE + + +def verify_cloud_iam_api_key(apikey): # pragma: no cover + if type(apikey) == bytes: + apikey = apikey.decode('UTF-8') + headers = { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Accept': 'application/json', + } + response = requests.post( + 'https://iam.cloud.ibm.com/identity/token', + headers=headers, + data={ + 'grant_type': 'urn:ibm:params:oauth:grant-type:apikey', + 'apikey': apikey, + }, + ) + return response