зеркало из
1
0
Форкнуть 0

Use service principal name as creator (#13)

This commit is contained in:
Mariana Cardoso 2018-03-08 10:37:20 -08:00 коммит произвёл Troy Dai
Родитель 92cc2c3396
Коммит 543114d8c7
2 изменённых файлов: 15 добавлений и 2 удалений

Просмотреть файл

@ -57,6 +57,10 @@ class AuthSettings(object):
def user_id(self) -> str:
return self._get_token_value('userId')
@property
def service_principal_id(self) -> str:
return self._get_token_value('_clientId')
@property
def refresh_token(self) -> str:
return self._get_token_value('refreshToken')
@ -213,3 +217,10 @@ def get_user_id() -> str:
except AuthenticationError:
print('You need to login. Usage: a01 login.')
sys.exit(1)
def get_service_principal_id() -> str:
try:
return AuthSettings().service_principal_id
except AuthenticationError:
print('You need to login. Usage: a01 login.')
sys.exit(1)

Просмотреть файл

@ -24,7 +24,7 @@ import a01.models
from a01.common import get_logger, A01Config, COMMON_IMAGE_PULL_SECRET
from a01.cli import cmd, arg
from a01.communication import session
from a01.auth import get_user_id
from a01.auth import get_user_id, get_service_principal_id
from a01.output import output_in_table
logger = get_logger(__name__) # pylint: disable=invalid-name
@ -107,6 +107,8 @@ def create_run(image: str, from_failures: str = None, live: bool = False, parall
remark: str = '', email: bool = False, secret: str = None, mode: str = None,
reset_run: str = None) -> None:
remark = remark or ''
creator = get_user_id() if email else get_service_principal_id()
try:
if not reset_run:
run_model = a01.models.Run(name=f'Azure CLI Test @ {image}',
@ -124,7 +126,7 @@ def create_run(image: str, from_failures: str = None, live: bool = False, parall
'a01.reserved.fromrunfailure': from_failures,
},
details={
'a01.reserved.creator': get_user_id(),
'a01.reserved.creator': creator,
'a01.reserved.client': 'A01 CLI'
})