Login if passed a secret on the command line. (#238)

Use exit codes to propagate failure to the shell.
This commit is contained in:
Marc Greisen 2021-09-01 13:51:49 -07:00 коммит произвёл GitHub
Родитель 0804e358e5
Коммит 687fa7d522
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 14 добавлений и 1 удалений

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

@ -5,6 +5,7 @@ import json
import os
import uuid
import textwrap
import sys
import raft_sdk.raft_common
from raft_sdk.raft_service import RaftCLI, RaftJobConfig
@ -574,5 +575,7 @@ Identifies the webhook hook event, for example JobStatus or BugFound'''))
if __name__ == "__main__":
try:
main()
sys.exit(0)
except Exception as ex:
print(ex)
sys.exit(1)

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

@ -75,10 +75,18 @@ class RaftServiceCLI():
if not secret:
self.is_logged_in()
else:
# If we are given a secret on the command line, then we assume that
# we are running in some automation context and need
# to login this way.
az(f'login --service-principal -u {self.context["clientId"]} -p {secret} --tenant {self.context["tenantId"]}')
az(f'account set --subscription {self.definitions.subscription}')
def is_logged_in(self):
# If your not logged in this command will throw
# an exception and say in the error message
# that you need to login.
az('ad signed-in-user show')
def hash(self, txt):

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

@ -35,7 +35,9 @@ CLI //root folder where you downloaded the CLI
* The `storage` folder will contain all of the data produced by RAFT job runs.
* The `secrets` folder is a user maintained folder. </br>
The files in this folder are the names of the secret used in the job definition file.
These files should not have an extension.
These files should not have an extension.</br>
**Note:** The contents of the secret file must not contain line breaks. This data is passed
on the docker command line. Line breaks will cause the docker command to fail.
For example if my RAFT job configuration requires a text token.
I can store the token in file `MyToken` under `CLI/local/secrets/MyToken` and use `MyToken`