def radlabauth()

in radlab-launcher/radlab.py [0:0]


def radlabauth(currentusr):
    try:
        token = subprocess.Popen(["gcloud auth application-default print-access-token"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout.read().strip().decode('utf-8')
        r = requests.get('https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=' + token)
        currentusr = r.json()["email"]

        # Setting Credentials for non Cloud Shell CLI
        if (platform.system() != 'Linux' and platform.processor() != '' and not platform.system().startswith('cs-')):
            # countdown(5)

            # Adding Execution handling if GOOGLE_APPLICATION_CREDENTIALS is set to Empty.
            try:
                del os.environ['GOOGLE_APPLICATION_CREDENTIALS']
            except:
                pass

            x = input("\nWould you like to proceed the RAD Lab deployment with user - " + Fore.YELLOW + currentusr + Style.RESET_ALL + ' ?\n[1] Yes\n[2] No\n' + Fore.YELLOW + Style.BRIGHT + 'Choose a number : ' + Style.RESET_ALL).strip()
            if (x == '1'):
                pass
            elif (x == '2'):
                print("\nLogin with User account with which you would like to deploy RAD Lab Modules...\n")
                os.system("gcloud auth application-default login")
            else:
                currentusr = '0'

    except:
        # Adding Execution handling if GOOGLE_APPLICATION_CREDENTIALS is set to Empty.
        if (platform.system() != 'Linux' and platform.processor() != '' and not platform.system().startswith('cs-')):
            try:
                del os.environ['GOOGLE_APPLICATION_CREDENTIALS']
            except:
                pass
        print("\nLogin with User account with which you would like to deploy RAD Lab Modules...\n")
        os.system("gcloud auth application-default login")

    finally:
        if (currentusr == '0'):
            sys.exit(Fore.RED + "\nError Occured - INVALID choice.\n")
        else:
            token = subprocess.Popen(["gcloud auth application-default print-access-token"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout.read().strip().decode('utf-8')
            r = requests.get('https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=' + token)
            currentusr = r.json()["email"]
            os.system("gcloud config set account " + currentusr)
            print(
                "\nUser to deploy RAD Lab Modules (Selected) : " + Fore.GREEN + Style.BRIGHT + currentusr + Style.RESET_ALL)
            return currentusr