dagster-dingtalk 0.1.5__py3-none-any.whl → 0.1.5b1__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- dagster_dingtalk/resources.py +15 -14
- {dagster_dingtalk-0.1.5.dist-info → dagster_dingtalk-0.1.5b1.dist-info}/METADATA +1 -1
- dagster_dingtalk-0.1.5b1.dist-info/RECORD +7 -0
- dagster_dingtalk-0.1.5.dist-info/RECORD +0 -7
- {dagster_dingtalk-0.1.5.dist-info → dagster_dingtalk-0.1.5b1.dist-info}/WHEEL +0 -0
dagster_dingtalk/resources.py
CHANGED
@@ -141,7 +141,7 @@ class MultiDingTalkWebhookResource(ConfigurableResource):
|
|
141
141
|
raise f"该 AccessToken 或 别名 <{key}> 不存在于提供的 Webhooks 中。请使用 DingTalkWebhookResource 定义单个 Webhook 后,将其加入 Webhooks 。"
|
142
142
|
|
143
143
|
|
144
|
-
class
|
144
|
+
class DingTalkClient:
|
145
145
|
def __init__(self, access_token: str, app_id: str, agent_id: int, robot_code: str) -> None:
|
146
146
|
self.access_token: str = access_token
|
147
147
|
self.app_id: str = app_id
|
@@ -165,15 +165,15 @@ class DingTalkResource(ConfigurableResource):
|
|
165
165
|
AppName: Optional[str] = Field(default=None, description="应用名。")
|
166
166
|
ClientId: str = Field(description="应用的 Client ID (原 AppKey 和 SuiteKey)")
|
167
167
|
ClientSecret: str = Field(description="应用的 Client Secret (原 AppSecret 和 SuiteSecret)")
|
168
|
-
RobotCode: Optional[str] = Field(default=None, description="应用的机器人 RobotCode")
|
168
|
+
RobotCode: Optional[str] = Field(default=None, description="应用的机器人 RobotCode,不传时使用 self.ClientId ")
|
169
169
|
|
170
|
-
_client:
|
170
|
+
_client: DingTalkClient = PrivateAttr()
|
171
171
|
|
172
172
|
@classmethod
|
173
173
|
def _is_dagster_maintained(cls) -> bool:
|
174
174
|
return False
|
175
175
|
|
176
|
-
def _get_access_token(self
|
176
|
+
def _get_access_token(self) -> str:
|
177
177
|
access_token_cache = Path("~/.dingtalk_cache")
|
178
178
|
|
179
179
|
if access_token_cache.exists():
|
@@ -187,7 +187,7 @@ class DingTalkResource(ConfigurableResource):
|
|
187
187
|
if access_token and expire_in < int(time.time()):
|
188
188
|
return access_token
|
189
189
|
else:
|
190
|
-
|
190
|
+
print(f"应用{self.AppName}<{self.AppID}> 鉴权缓存过期或不存在,正在重新获取...")
|
191
191
|
response = httpx.post(
|
192
192
|
url="https://api.dingtalk.com/v1.0/oauth2/accessToken",
|
193
193
|
json={"appKey": self.ClientId, "appSecret": self.ClientSecret},
|
@@ -200,24 +200,25 @@ class DingTalkResource(ConfigurableResource):
|
|
200
200
|
return access_token
|
201
201
|
|
202
202
|
def setup_for_execution(self, context: InitResourceContext) -> None:
|
203
|
-
self._client =
|
204
|
-
self._get_access_token(context),
|
205
|
-
self.AppID,
|
206
|
-
self.AgentID,
|
207
|
-
self.RobotCode,
|
208
|
-
)
|
203
|
+
self._client = DingTalkClient(self._get_access_token(), self.AppID, self.AgentID, self.RobotCode or self.ClientId)
|
209
204
|
|
210
205
|
def teardown_after_execution(self, context: InitResourceContext) -> None:
|
211
206
|
self._client.api.close()
|
212
207
|
self._client.oapi.close()
|
213
208
|
|
214
209
|
def 智能人事(self):
|
210
|
+
if not hasattr(self, '_client'):
|
211
|
+
self._client = DingTalkClient(self._get_access_token(), self.AppID, self.AgentID, self.RobotCode or self.ClientId)
|
215
212
|
return API_智能人事(self._client)
|
216
213
|
|
217
214
|
def 通讯录管理(self):
|
215
|
+
if not hasattr(self, '_client'):
|
216
|
+
self._client = DingTalkClient(self._get_access_token(), self.AppID, self.AgentID, self.RobotCode or self.ClientId)
|
218
217
|
return API_通讯录管理(self._client)
|
219
218
|
|
220
219
|
def 文档文件(self):
|
220
|
+
if not hasattr(self, '_client'):
|
221
|
+
self._client = DingTalkClient(self._get_access_token(), self.AppID, self.AgentID, self.RobotCode or self.ClientId)
|
221
222
|
return API_文档文件(self._client)
|
222
223
|
|
223
224
|
|
@@ -274,7 +275,7 @@ class MultiDingTalkResource(ConfigurableResource):
|
|
274
275
|
|
275
276
|
# noinspection NonAsciiCharacters
|
276
277
|
class API_智能人事:
|
277
|
-
def __init__(self, _client:
|
278
|
+
def __init__(self, _client:DingTalkClient):
|
278
279
|
self._client = _client
|
279
280
|
|
280
281
|
def 花名册_获取花名册元数据(self):
|
@@ -332,7 +333,7 @@ class API_智能人事:
|
|
332
333
|
|
333
334
|
# noinspection NonAsciiCharacters
|
334
335
|
class API_通讯录管理:
|
335
|
-
def __init__(self, _client:
|
336
|
+
def __init__(self, _client:DingTalkClient):
|
336
337
|
self._client = _client
|
337
338
|
|
338
339
|
def 查询用户详情(self, user_id:str, language:str = "zh_CN"):
|
@@ -349,7 +350,7 @@ class API_通讯录管理:
|
|
349
350
|
|
350
351
|
# noinspection NonAsciiCharacters
|
351
352
|
class API_文档文件:
|
352
|
-
def __init__(self, _client:
|
353
|
+
def __init__(self, _client:DingTalkClient):
|
353
354
|
self._client = _client
|
354
355
|
|
355
356
|
def 媒体文件_上传媒体文件(self, file_path:Path|str, media_type:Literal['image', 'voice', 'video', 'file']):
|
@@ -0,0 +1,7 @@
|
|
1
|
+
dagster_dingtalk/__init__.py,sha256=ktvoURpkJwIzcyQfUvnel1KA4DukRgavAgLl7f0Cy_0,440
|
2
|
+
dagster_dingtalk/operations.py,sha256=xJJlOVmFjpaDTMkHZXxj5LbXqRtIQwREl9ZJdXIMOyE,788
|
3
|
+
dagster_dingtalk/resources.py,sha256=6S8pVSz0ZMumaibfsJ_ZTxJVUZOleotg1c4hzt_VPDk,15156
|
4
|
+
dagster_dingtalk/version.py,sha256=sXLh7g3KC4QCFxcZGBTpG2scR7hmmBsMjq6LqRptkRg,22
|
5
|
+
dagster_dingtalk-0.1.5b1.dist-info/METADATA,sha256=JeVAne_YvTbPe_Av_NPbuu5KpsKCsO0uJzNvarEfvLo,1661
|
6
|
+
dagster_dingtalk-0.1.5b1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
7
|
+
dagster_dingtalk-0.1.5b1.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
dagster_dingtalk/__init__.py,sha256=ktvoURpkJwIzcyQfUvnel1KA4DukRgavAgLl7f0Cy_0,440
|
2
|
-
dagster_dingtalk/operations.py,sha256=xJJlOVmFjpaDTMkHZXxj5LbXqRtIQwREl9ZJdXIMOyE,788
|
3
|
-
dagster_dingtalk/resources.py,sha256=v1LYKK1GLFPHysUhs05KxDQm9DJT42V7jYQyhIhaz5E,14718
|
4
|
-
dagster_dingtalk/version.py,sha256=sXLh7g3KC4QCFxcZGBTpG2scR7hmmBsMjq6LqRptkRg,22
|
5
|
-
dagster_dingtalk-0.1.5.dist-info/METADATA,sha256=weNe_Bxiwh3dRsO_QA7PU0QphW5dgdpk23c4Hbc5rfc,1659
|
6
|
-
dagster_dingtalk-0.1.5.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
7
|
-
dagster_dingtalk-0.1.5.dist-info/RECORD,,
|
File without changes
|