Beispiel #1
0
def impersonate(owner: str, project: str, run_uuid: str, client: PolyaxonClient = None):
    try:
        client = client or PolyaxonClient()
        response = client.runs_v1.impersonate_token(owner, project, run_uuid)
        polyaxon_client = PolyaxonClient(token=response.token)
        user = polyaxon_client.users_v1.get_user()
        access_token = AccessTokenConfig(username=user.username, token=response.token)
        create_context_auth(access_token)
    except (ApiException, HTTPError) as e:
        raise PolyaxonClientException(
            "This worker is not allowed to run this job %s." % e
        )
 def test_from_settings(self):
     settings.CLIENT_CONFIG.is_managed = True
     settings.CLIENT_CONFIG.host = "api_host"
     client = PolyaxonClient(token="token")
     assert client.config.is_managed is True
     assert client.config.host == "api_host"
     assert client.config.token == "token"
     assert client.config.base_url == "api_host/api/v1"
    def test_client_services(self):
        settings.AUTH_CONFIG.token = None
        client = PolyaxonClient(token=None)
        assert client.config.token is None

        assert isinstance(client.config, ClientConfig)

        assert isinstance(client.auth_v1, polyaxon_sdk.AuthV1Api)
        assert isinstance(client.versions_v1, polyaxon_sdk.VersionsV1Api)
        assert isinstance(client.projects_v1, polyaxon_sdk.ProjectsV1Api)
        assert isinstance(client.runs_v1, polyaxon_sdk.RunsV1Api)
        assert isinstance(client.users_v1, polyaxon_sdk.UsersV1Api)
Beispiel #4
0
    def __init__(
        self,
        owner: str = None,
        project: str = None,
        client: PolyaxonClient = None,
    ):
        if not owner and project:
            owner, project = get_entity_info(
                get_entity_full_name(owner=owner, entity=project)
            )

        if not owner:
            raise PolyaxonClientException("Please provide a valid owner.")

        self.client = client
        if not (self.client or settings.CLIENT_CONFIG.is_offline):
            self.client = PolyaxonClient()

        self._owner = owner or DEFAULT
        self._project = project
        self._project_data = polyaxon_sdk.V1Project()
Beispiel #5
0
 def client(self):
     if self._client:
         return self._client
     self._client = PolyaxonClient()
     return self._client
 def test_from_config(self):
     settings.CLIENT_CONFIG.host = "localhost"
     client = PolyaxonClient(config=ClientConfig())
     assert client.config.is_managed is False
     assert client.config.host == "https://cloud.polyaxon.com"
     assert client.config.token is None