Skip to content

Commit 52406b6

Browse files
authored
Rename CertificateCredential's certificate_bytes -> certificate_data (#17090)
1 parent b432ace commit 52406b6

File tree

7 files changed

+29
-25
lines changed

7 files changed

+29
-25
lines changed

sdk/identity/azure-identity/CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Release History
22

33
## 1.6.0b2 (Unreleased)
4-
4+
### Breaking Changes
5+
> These changes do not impact the API of stable versions such as 1.5.0.
6+
> Only code written against a beta version such as 1.6.0b1 may be affected.
7+
- Renamed `CertificateCredential` keyword argument `certificate_bytes` to
8+
`certificate_data`
59

610
## 1.6.0b1 (2021-02-09)
711
### Changed

sdk/identity/azure-identity/azure/identity/_credentials/certificate.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ class CertificateCredential(ClientCredentialBase):
2626
:param str tenant_id: ID of the service principal's tenant. Also called its 'directory' ID.
2727
:param str client_id: the service principal's client ID
2828
:param str certificate_path: path to a PEM-encoded certificate file including the private key. If not provided,
29-
`certificate_bytes` is required.
29+
`certificate_data` is required.
3030
3131
:keyword str authority: Authority of an Azure Active Directory endpoint, for example 'login.microsoftonline.com',
3232
the authority for Azure Public Cloud (which is the default). :class:`~azure.identity.AzureAuthorityHosts`
3333
defines authorities for other clouds.
34-
:keyword bytes certificate_bytes: the bytes of a certificate in PEM format, including the private key
34+
:keyword bytes certificate_data: the bytes of a certificate in PEM format, including the private key
3535
:keyword password: The certificate's password. If a unicode string, it will be encoded as UTF-8. If the certificate
3636
requires a different encoding, pass appropriately encoded bytes instead.
3737
:paramtype password: str or bytes
@@ -68,34 +68,34 @@ def extract_cert_chain(pem_bytes):
6868
return b"".join(chain.splitlines())
6969

7070

71-
def get_client_credential(certificate_path, password=None, certificate_bytes=None, send_certificate_chain=False, **_):
71+
def get_client_credential(certificate_path, password=None, certificate_data=None, send_certificate_chain=False, **_):
7272
# type: (Optional[str], Optional[Union[bytes, str]], Optional[bytes], bool, **Any) -> dict
7373
"""Load a certificate from a filesystem path or bytes, return it as a dict suitable for msal.ClientApplication"""
7474

7575
if certificate_path:
7676
with open(certificate_path, "rb") as f:
77-
certificate_bytes = f.read()
78-
elif not certificate_bytes:
79-
raise ValueError('CertificateCredential requires a value for "certificate_path" or "certificate_bytes"')
77+
certificate_data = f.read()
78+
elif not certificate_data:
79+
raise ValueError('CertificateCredential requires a value for "certificate_path" or "certificate_data"')
8080

8181
if isinstance(password, six.text_type):
8282
password = password.encode(encoding="utf-8")
8383

84-
private_key = serialization.load_pem_private_key(certificate_bytes, password=password, backend=default_backend())
84+
private_key = serialization.load_pem_private_key(certificate_data, password=password, backend=default_backend())
8585
if not isinstance(private_key, RSAPrivateKey):
8686
raise ValueError("CertificateCredential requires an RSA private key because it uses RS256 for signing")
8787

88-
cert = x509.load_pem_x509_certificate(certificate_bytes, default_backend())
88+
cert = x509.load_pem_x509_certificate(certificate_data, default_backend())
8989
fingerprint = cert.fingerprint(hashes.SHA1()) # nosec
9090

91-
client_credential = {"private_key": certificate_bytes, "thumbprint": hexlify(fingerprint).decode("utf-8")}
91+
client_credential = {"private_key": certificate_data, "thumbprint": hexlify(fingerprint).decode("utf-8")}
9292
if password:
9393
client_credential["passphrase"] = password
9494

9595
if send_certificate_chain:
9696
try:
9797
# the JWT needs the whole chain but load_pem_x509_certificate deserializes only the signing cert
98-
chain = extract_cert_chain(certificate_bytes)
98+
chain = extract_cert_chain(certificate_data)
9999
client_credential["public_certificate"] = six.ensure_str(chain)
100100
except ValueError as ex:
101101
# we shouldn't land here--cryptography already loaded the cert and would have raised if it were malformed

sdk/identity/azure-identity/azure/identity/aio/_credentials/certificate.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ class CertificateCredential(AsyncContextManager):
2525
:param str tenant_id: ID of the service principal's tenant. Also called its 'directory' ID.
2626
:param str client_id: the service principal's client ID
2727
:param str certificate_path: path to a PEM-encoded certificate file including the private key. If not provided,
28-
`certificate_bytes` is required.
28+
`certificate_data` is required.
2929
3030
:keyword str authority: Authority of an Azure Active Directory endpoint, for example 'login.microsoftonline.com',
3131
the authority for Azure Public Cloud (which is the default). :class:`~azure.identity.AzureAuthorityHosts`
3232
defines authorities for other clouds.
33-
:keyword bytes certificate_bytes: the bytes of a certificate in PEM format, including the private key
33+
:keyword bytes certificate_data: the bytes of a certificate in PEM format, including the private key
3434
:keyword password: The certificate's password. If a unicode string, it will be encoded as UTF-8. If the certificate
3535
requires a different encoding, pass appropriately encoded bytes instead.
3636
:paramtype password: str or bytes

sdk/identity/azure-identity/tests/test_certificate_credential.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_non_rsa_key():
5050
with pytest.raises(ValueError, match=".*RS256.*"):
5151
CertificateCredential("tenant-id", "client-id", EC_CERT_PATH)
5252
with pytest.raises(ValueError, match=".*RS256.*"):
53-
CertificateCredential("tenant-id", "client-id", certificate_bytes=open(EC_CERT_PATH, "rb").read())
53+
CertificateCredential("tenant-id", "client-id", certificate_data=open(EC_CERT_PATH, "rb").read())
5454

5555

5656
def test_tenant_id_validation():
@@ -145,9 +145,9 @@ def test_requires_certificate():
145145
with pytest.raises(ValueError):
146146
CertificateCredential("tenant", "client-id", certificate_path="")
147147
with pytest.raises(ValueError):
148-
CertificateCredential("tenant", "client-id", certificate_bytes=None)
148+
CertificateCredential("tenant", "client-id", certificate_data=None)
149149
with pytest.raises(ValueError):
150-
CertificateCredential("tenant", "client-id", certificate_path="", certificate_bytes=None)
150+
CertificateCredential("tenant", "client-id", certificate_path="", certificate_data=None)
151151

152152

153153
@pytest.mark.parametrize("cert_path,cert_password", BOTH_CERTS)
@@ -190,7 +190,7 @@ def mock_send(request, **kwargs):
190190
cred = CertificateCredential(
191191
tenant_id,
192192
client_id,
193-
certificate_bytes=cert_bytes,
193+
certificate_data=cert_bytes,
194194
password=cert_password,
195195
transport=Mock(send=mock_send),
196196
authority=authority,

sdk/identity/azure-identity/tests/test_certificate_credential_async.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_non_rsa_key():
2323
with pytest.raises(ValueError, match=".*RS256.*"):
2424
CertificateCredential("tenant-id", "client-id", EC_CERT_PATH)
2525
with pytest.raises(ValueError, match=".*RS256.*"):
26-
CertificateCredential("tenant-id", "client-id", certificate_bytes=open(EC_CERT_PATH, "rb").read())
26+
CertificateCredential("tenant-id", "client-id", certificate_data=open(EC_CERT_PATH, "rb").read())
2727

2828

2929
def test_tenant_id_validation():
@@ -141,9 +141,9 @@ def test_requires_certificate():
141141
with pytest.raises(ValueError):
142142
CertificateCredential("tenant", "client-id", certificate_path="")
143143
with pytest.raises(ValueError):
144-
CertificateCredential("tenant", "client-id", certificate_bytes=None)
144+
CertificateCredential("tenant", "client-id", certificate_data=None)
145145
with pytest.raises(ValueError):
146-
CertificateCredential("tenant", "client-id", certificate_path="", certificate_bytes=None)
146+
CertificateCredential("tenant", "client-id", certificate_path="", certificate_data=None)
147147

148148

149149
@pytest.mark.asyncio
@@ -177,7 +177,7 @@ async def mock_send(request, **kwargs):
177177
cred = CertificateCredential(
178178
tenant_id,
179179
client_id,
180-
certificate_bytes=cert_bytes,
180+
certificate_data=cert_bytes,
181181
password=cert_password,
182182
transport=Mock(send=mock_send),
183183
authority=authority,

sdk/identity/azure-identity/tests/test_live.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ def test_certificate_credential(live_certificate):
3636
)
3737
get_token(credential)
3838

39-
credential = CertificateCredential(tenant_id, client_id, certificate_bytes=live_certificate["cert_bytes"])
39+
credential = CertificateCredential(tenant_id, client_id, certificate_data=live_certificate["cert_bytes"])
4040
get_token(credential)
4141

4242
credential = CertificateCredential(
4343
tenant_id,
4444
client_id,
45-
certificate_bytes=live_certificate["cert_with_password_bytes"],
45+
certificate_data=live_certificate["cert_with_password_bytes"],
4646
password=live_certificate["password"],
4747
)
4848
get_token(credential)

sdk/identity/azure-identity/tests/test_live_async.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ async def test_certificate_credential(live_certificate):
2929
)
3030
await get_token(credential)
3131

32-
credential = CertificateCredential(tenant_id, client_id, certificate_bytes=live_certificate["cert_bytes"])
32+
credential = CertificateCredential(tenant_id, client_id, certificate_data=live_certificate["cert_bytes"])
3333
await get_token(credential)
3434

3535
credential = CertificateCredential(
3636
tenant_id,
3737
client_id,
38-
certificate_bytes=live_certificate["cert_with_password_bytes"],
38+
certificate_data=live_certificate["cert_with_password_bytes"],
3939
password=live_certificate["password"],
4040
)
4141
await get_token(credential)

0 commit comments

Comments
 (0)