dagster-dingtalk 0.1.5__tar.gz → 0.1.5b2__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dagster-dingtalk
3
- Version: 0.1.5
3
+ Version: 0.1.5b2
4
4
  Summary: A dagster plugin for the DingTalk
5
5
  Author: YiZixuan
6
6
  Author-email: sqkkyzx@qq.com
@@ -141,7 +141,7 @@ class MultiDingTalkWebhookResource(ConfigurableResource):
141
141
  raise f"该 AccessToken 或 别名 <{key}> 不存在于提供的 Webhooks 中。请使用 DingTalkWebhookResource 定义单个 Webhook 后,将其加入 Webhooks 。"
142
142
 
143
143
 
144
- class DingTalkMultiClient:
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,16 +165,16 @@ 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: DingTalkMultiClient = PrivateAttr()
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, context) -> str:
177
- access_token_cache = Path("~/.dingtalk_cache")
176
+ def _get_access_token(self) -> str:
177
+ access_token_cache = Path("/tmp/.dingtalk_cache")
178
178
 
179
179
  if access_token_cache.exists():
180
180
  with open(access_token_cache, 'rb') as f:
@@ -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
- context.log.info(f"应用{self.AppName}<{self.AppID}> 鉴权缓存过期或不存在,正在重新获取...")
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 = DingTalkMultiClient(
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:DingTalkMultiClient):
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:DingTalkMultiClient):
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:DingTalkMultiClient):
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']):
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "dagster-dingtalk"
3
- version = "0.1.5"
3
+ version = "0.1.5.b2"
4
4
  description = "A dagster plugin for the DingTalk"
5
5
  authors = ["YiZixuan <sqkkyzx@qq.com>"]
6
6
  readme = "README.md"