Skip to content

Commit 58e01df

Browse files
committed
sp-cert2
1 parent b976aa4 commit 58e01df

4 files changed

Lines changed: 8 additions & 34 deletions

File tree

src/azure-cli-core/azure/cli/core/auth/identity.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@
3737
"Select the account you want to log in with. "
3838
"For more information on login with Azure CLI, see https://go.microsoft.com/fwlink/?linkid=2271136")
3939

40-
PASSWORD_CERTIFICATE_WARNING = (
41-
"Passing the service principal certificate with `--password` is deprecated and will be removed "
42-
"by version 2.74. Please use `--certificate` instead.")
43-
4440
logger = get_logger(__name__)
4541

4642

@@ -307,7 +303,7 @@ def build_from_credential(cls, tenant_id, client_id, credential):
307303
return ServicePrincipalAuth(entry)
308304

309305
@classmethod
310-
def build_credential(cls, secret_or_certificate=None,
306+
def build_credential(cls, client_secret=None,
311307
certificate=None, use_cert_sn_issuer=None,
312308
client_assertion=None):
313309
"""Build credential from user input. The credential looks like below, but only one key can exist.
@@ -318,20 +314,12 @@ def build_credential(cls, secret_or_certificate=None,
318314
}
319315
"""
320316
entry = {}
321-
if certificate:
317+
if client_secret:
318+
entry[_CLIENT_SECRET] = client_secret
319+
elif certificate:
322320
entry[_CERTIFICATE] = os.path.expanduser(certificate)
323321
if use_cert_sn_issuer:
324322
entry[_USE_CERT_SN_ISSUER] = use_cert_sn_issuer
325-
elif secret_or_certificate:
326-
# TODO: Make secret_or_certificate secret only
327-
user_expanded = os.path.expanduser(secret_or_certificate)
328-
if os.path.isfile(user_expanded):
329-
logger.warning(PASSWORD_CERTIFICATE_WARNING)
330-
entry[_CERTIFICATE] = user_expanded
331-
if use_cert_sn_issuer:
332-
entry[_USE_CERT_SN_ISSUER] = use_cert_sn_issuer
333-
else:
334-
entry[_CLIENT_SECRET] = secret_or_certificate
335323
elif client_assertion:
336324
entry[_CLIENT_ASSERTION] = client_assertion
337325
return entry

src/azure-cli-core/azure/cli/core/auth/tests/test_identity.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -264,20 +264,10 @@ def test_service_principal_auth_client_assertion(self):
264264
assert client_credential == {'client_assertion': 'test_jwt'}
265265

266266
def test_build_credential(self):
267-
# secret
268-
cred = ServicePrincipalAuth.build_credential(secret_or_certificate="test_secret")
267+
# client_secret
268+
cred = ServicePrincipalAuth.build_credential(client_secret="test_secret")
269269
assert cred == {"client_secret": "test_secret"}
270270

271-
# secret with '~', which is preserved as-is
272-
cred = ServicePrincipalAuth.build_credential(secret_or_certificate="~test_secret")
273-
assert cred == {"client_secret": "~test_secret"}
274-
275-
# certificate as password (deprecated)
276-
current_dir = os.path.dirname(os.path.realpath(__file__))
277-
test_cert_file = os.path.join(current_dir, 'sp_cert.pem')
278-
cred = ServicePrincipalAuth.build_credential(secret_or_certificate=test_cert_file)
279-
assert cred == {'certificate': test_cert_file}
280-
281271
# certificate
282272
current_dir = os.path.dirname(os.path.realpath(__file__))
283273
test_cert_file = os.path.join(current_dir, 'sp_cert.pem')
@@ -297,7 +287,7 @@ def test_build_credential(self):
297287
cred = ServicePrincipalAuth.build_credential(certificate=test_cert_file, use_cert_sn_issuer=True)
298288
assert cred == {'certificate': test_cert_file, 'use_cert_sn_issuer': True}
299289

300-
# client assertion
290+
# client_assertion
301291
cred = ServicePrincipalAuth.build_credential(client_assertion="test_jwt")
302292
assert cred == {"client_assertion": "test_jwt"}
303293

src/azure-cli/azure/cli/command_modules/profile/_help.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
For more details, see https://go.microsoft.com/fwlink/?linkid=2276314
2222
2323
24-
[WARNING] Passing the service principal certificate with `--password` is deprecated and will be removed
25-
by version 2.74. Please use `--certificate` instead.
26-
27-
2824
To log in with a service principal, specify --service-principal.
2925
3026

src/azure-cli/azure/cli/command_modules/profile/custom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def login(cmd, username=None, password=None, tenant=None, scopes=None, allow_no_
159159
if service_principal:
160160
from azure.cli.core.auth.identity import ServicePrincipalAuth
161161
password = ServicePrincipalAuth.build_credential(
162-
secret_or_certificate=password,
162+
client_secret=password,
163163
certificate=certificate, use_cert_sn_issuer=use_cert_sn_issuer,
164164
client_assertion=client_assertion)
165165

0 commit comments

Comments
 (0)