def get_access_token(): ''' get ding api access token ''' ding_config = DingConfig.get_current() token_manager = AccessTokenManager( app_key=ding_config.app_key, app_secret=ding_config.app_secret, ) return token_manager.get_access_token()
def __init__(self, app_key=None, app_secret=None, app_version=None, agent_id=None): """ 初始化钉钉相关参数 """ if app_key and app_secret and app_version and agent_id: self.token_manager = AccessTokenManager(app_key, app_secret, app_version) else: ding_config = DingConfig.get_current() self.token_manager = AccessTokenManager(ding_config.app_key, ding_config.app_secret, DINGDING_APP_VERSION) self.user_manager = UserManager(self.token_manager) self.dept_manager = DepartmentManager(self.token_manager) self.role_manager = RoleManager(self.token_manager) self.agent_id = AGENT_ID
def check_valid(self): ''' 检查配置是否有效 ''' accesser = AccessTokenManager(app_key=self.qr_app_id,\ app_secret=self.qr_app_secret, token_version=TOKEN_FROM_APPID_QR_APP_SECRET) try: accesser.get_access_token() return True except ServerException as exce: print(exce) return False except RuntimeError: return True
def setUp(self): self.token_patcher = mock.patch('thirdparty_data_sdk.dingding.dingsdk.accesstoken_manager') self.request_patcher = mock.patch('thirdparty_data_sdk.dingding.dingsdk.request_manager') self.mock_token_manager = self.token_patcher.start() self.mock_request_manager = self.request_patcher.start() self.role_manager = RoleManager(AccessTokenManager(TEST_APP_KEY, TEST_APP_SECRET)) self.role_manager.token_manager = self.mock_token_manager self.role_manager.request_manager = self.mock_request_manager self.role_manager.token = lambda *args, **kwargs: TEST_TOKEN
def __init__(self, app_key=None, app_secret=None, app_version=None, agent_id=None): """ 初始化钉钉相关参数 """ if app_key and app_secret and app_version and agent_id: self.token_manager = AccessTokenManager(app_key, app_secret, app_version) else: ding_config = DingConfig.get_current() self.token_manager = AccessTokenManager( ding_config.app_key, ding_config.app_secret, TOKEN_FROM_APPKEY_APPSECRET) self.user_manager = UserManager(self.token_manager) self.dept_manager = DepartmentManager(self.token_manager) self.role_manager = RoleManager(self.token_manager)
def entrypoint(): ''' import dingding data ''' ding_config = DingConfig.get_current() token_manager = AccessTokenManager(ding_config.app_key, ding_config.app_secret, DINGDING_APP_VERSION) department_manager = DepartmentManager(token_manager) user_manager = UserManager(token_manager) role_manager = RoleManager(token_manager) db_executer = cli_factory(EXECUTERS)(User.objects.get(username='******')) root_dep = Dept.objects.get(uid=DEPARTMENT_ROOT_UID) build_department_user_rawdata(db_executer, user_manager, department_manager, DEPARTMENT_ROOT_ID, root_dep) build_group_rawdata(db_executer, role_manager)
def entrypoint(): ''' override dingding data ''' ding_config = DingConfig.get_current() token_manager = AccessTokenManager(ding_config.app_key, ding_config.app_secret, DINGDING_APP_VERSION) department_manager = DepartmentManager(token_manager) user_manager = UserManager(token_manager) override_ding_dept(department_manager) override_ding_role(department_manager) override_ding_user(user_manager)
def validate_corp_config(instance): ''' validate corp_id, corp_secret :rtype: bool ''' try: AccessTokenManager( app_key=instance.corp_id, app_secret=instance.corp_secret, token_version=constants.TOKEN_FROM_CORPID_CORPSECRET, ).get_access_token() return True except APICallError: return False
def validate_qr_app_config(instance): ''' validate qr_app_id, qr_app_secret :rtype:bool ''' try: AccessTokenManager( app_key=instance.qr_app_id, app_secret=instance.qr_app_secret, token_version=constants.TOKEN_FROM_APPID_QR_APP_SECRET ).get_access_token() return True except APICallError: return False