From c95c0fe00b30b6d2c3be06ade572599a72e07b6c Mon Sep 17 00:00:00 2001 From: Iurii Tatishchev Date: Wed, 19 May 2021 21:46:30 -0700 Subject: [PATCH] Delete unused `main/apiauth.py` --- docs/source/code.rst | 8 -------- main/apiauth.py | 49 -------------------------------------------- 2 files changed, 57 deletions(-) delete mode 100644 main/apiauth.py diff --git a/docs/source/code.rst b/docs/source/code.rst index 7479081..ac37e3d 100644 --- a/docs/source/code.rst +++ b/docs/source/code.rst @@ -33,14 +33,6 @@ Serializers :members: -*************** -API functions -*************** - -.. automodule:: main.apiauth - :members: - - ***** Views ***** diff --git a/main/apiauth.py b/main/apiauth.py deleted file mode 100644 index 08a018c..0000000 --- a/main/apiauth.py +++ /dev/null @@ -1,49 +0,0 @@ -import os - -from zenpy import Zenpy -from zenpy.lib.api_objects import User as ZenpyUser - -from access_controller.settings import ACTRL_ZENDESK_SUBDOMAIN, ACTRL_API_EMAIL, ACTRL_API_TOKEN, ACTRL_API_PASSWORD - - -def api_auth() -> dict: - """ - Функция создания пользователя с использованием Zendesk API. - - Получает из env Zendesk - email, token, password пользователя. - Если данные валидны и пользователь Zendesk с указанным email и токеном или паролем существует, - создается словарь данных пользователя, полученных через API c Zendesk. - - :return: данные пользователя - """ - credentials = { - 'subdomain': ACTRL_ZENDESK_SUBDOMAIN - } - email = ACTRL_API_EMAIL - token = ACTRL_API_TOKEN - password = ACTRL_API_PASSWORD - - if email is None: - raise ValueError('access_controller email not in env') - credentials['email'] = email - - # prefer token, use password if token not provided - if token: - credentials['token'] = token - elif password: - credentials['password'] = password - else: - raise ValueError('access_controller token or password not in env') - - zenpy_client = Zenpy(**credentials) - zenpy_user: ZenpyUser = zenpy_client.users.search(email).values[0] - - user = { - 'id': zenpy_user.id, - 'name': zenpy_user.name, # Zendesk doesn't have separate first and last name fields - 'email': zenpy_user.email, - 'role': zenpy_user.role, # str like 'admin' or 'agent', not id - 'photo': zenpy_user.photo['content_url'] if zenpy_user.photo is not None else None, - } - - return user