Beispiel #1
0
def create_auth_context():
    try:
        run_client = RunClient()
    except PolyaxonClientException as e:
        raise PolyaxonContainerException(e)

    retry = 1
    done = False
    exp = None
    while not done and retry <= 3:
        try:
            impersonate(
                owner=run_client.owner,
                project=run_client.project,
                run_uuid=run_client.run_uuid,
                client=run_client.client,
            )
            print("Auth context initialized.")
            return
        except PolyaxonClientException as e:
            retry += 1
            print("Could not establish connection, retrying ...")
            exp = "Polyaxon auth initialized failed authenticating the operation: {}\n{}".format(
                repr(e), traceback.format_exc())
            time.sleep(retry)
    run_client.log_failed("Could not create an auth context.", traceback=exp)
    raise PolyaxonContainerException(
        "Init job did not succeed authenticating job.")
    def test_login_impersonate(self, create_context, get_user,
                               impersonate_token):

        impersonate(owner="owner",
                    project="project",
                    run_uuid=uuid.uuid4().hex)
        assert impersonate_token.call_count == 1
        assert get_user.call_count == 1
        assert create_context.call_count == 1
Beispiel #3
0
def create_auth_context():
    try:
        owner, project, run_uuid = get_run_info()
    except PolyaxonClientException as e:
        raise PolyaxonContainerException(e)

    retry = 1
    done = False
    while not done and retry <= 3:
        try:
            impersonate(owner=owner, project=project, run_uuid=run_uuid)
            print("Auth context initialized.")
            return
        except PolyaxonClientException:
            retry += 1
            print("Could not establish connection, retrying ...")
            time.sleep(1 * retry)

    raise PolyaxonContainerException("Init job did not succeed authenticating job.")