def __init__(self, api_server: str=None, api_token: str=None):
    self._access_token = None
    self._refresh_token = None
    self._access_token_expires_at = pendulum.now()
    self._active_tenant_id = None
    self._attached_headers = {}
    self.logger = create_diagnostic_logger('Diagnostics')
    self.api_server = (api_server or prefect.context.config.cloud.get('graphql'))
    self._api_token = (api_token or prefect.context.config.cloud.get('auth_token', None))
    if (prefect.config.backend == 'cloud'):
        if (not self._api_token):
            settings = self._load_local_settings()
            self._api_token = settings.get('api_token')
            if self._api_token:
                self._active_tenant_id = settings.get('active_tenant_id')
            if self._active_tenant_id:
                try:
                    self.login_to_tenant(tenant_id=self._active_tenant_id)
                except AuthorizationError:
                    self.logout_from_tenant()
    elif (not self._active_tenant_id):
        tenant_info = self.graphql({'query': {'tenant': {'id'}}})
        if tenant_info.data.tenant:
            self._active_tenant_id = tenant_info.data.tenant[0].id
def __init__(self, api_server: str=None, api_token: str=None):
    self._access_token = None
    self._refresh_token = None
    self._access_token_expires_at = pendulum.now()
    self._active_tenant_id = None
    self._attached_headers = {}
    self.logger = create_diagnostic_logger('Diagnostics')
    self.api_server = (api_server or prefect.context.config.cloud.get('graphql'))
    self._api_token = (api_token or prefect.context.config.cloud.get('auth_token', None))
    if (prefect.config.backend == 'cloud'):
        if (not self._api_token):
            settings = self._load_local_settings()
            self._api_token = settings.get('api_token')
            if self._api_token:
                self._active_tenant_id = settings.get('active_tenant_id')
            if self._active_tenant_id:
                try:
                    self.login_to_tenant(tenant_id=self._active_tenant_id)
                except AuthorizationError:
                    self.logout_from_tenant()
    elif (not self._active_tenant_id):
        tenant_info = self.graphql({'query': {'tenant': {'id'}}})
        if tenant_info.data.tenant:
            self._active_tenant_id = tenant_info.data.tenant[0].id