dagster-dingtalk 0.1.11__py3-none-any.whl → 0.1.13__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- dagster_dingtalk/app_client.py +2 -9
- dagster_dingtalk/resources.py +110 -99
- dagster_dingtalk/version.py +1 -1
- dagster_dingtalk-0.1.13.dist-info/METADATA +210 -0
- dagster_dingtalk-0.1.13.dist-info/RECORD +8 -0
- dagster_dingtalk-0.1.11.dist-info/METADATA +0 -38
- dagster_dingtalk-0.1.11.dist-info/RECORD +0 -8
- {dagster_dingtalk-0.1.11.dist-info → dagster_dingtalk-0.1.13.dist-info}/WHEEL +0 -0
dagster_dingtalk/app_client.py
CHANGED
@@ -40,17 +40,10 @@ class DingTalkClient:
|
|
40
40
|
else:
|
41
41
|
try:
|
42
42
|
with open(access_token_cache, 'rb') as f:
|
43
|
-
|
43
|
+
all_access_token = pickle.loads(f.read())
|
44
44
|
except Exception as e:
|
45
45
|
logging.error(e)
|
46
|
-
|
47
|
-
renew_reason = "鉴权缓存读取错误"
|
48
|
-
|
49
|
-
if cache_file:
|
50
|
-
try:
|
51
|
-
all_access_token = pickle.loads(cache_file)
|
52
|
-
except pickle.PickleError:
|
53
|
-
renew_reason = f"鉴权缓存解析错误"
|
46
|
+
renew_reason = "鉴权缓存读取或解析错误"
|
54
47
|
|
55
48
|
if all_access_token:
|
56
49
|
app_access_token = all_access_token.get(self.app_id)
|
dagster_dingtalk/resources.py
CHANGED
@@ -44,7 +44,7 @@ class DingTalkWebhookResource(ConfigurableResource):
|
|
44
44
|
### 配置项:
|
45
45
|
|
46
46
|
- **access_token** (str):
|
47
|
-
|
47
|
+
机器人 Webhook 地址中的 access_token 值。
|
48
48
|
- **secret** (str, optional):
|
49
49
|
如使用加签安全配置,则需传签名密钥。默认值为 None。
|
50
50
|
- **alias** (str, optional):
|
@@ -54,46 +54,50 @@ class DingTalkWebhookResource(ConfigurableResource):
|
|
54
54
|
|
55
55
|
### 用例:
|
56
56
|
|
57
|
-
1. 使用单个资源:
|
58
|
-
|
57
|
+
##### 1. 使用单个资源:
|
59
58
|
```python
|
60
59
|
from dagster_dingtalk import DingTalkWebhookResource
|
60
|
+
from dagster import op, In, OpExecutionContext, job, Definitions
|
61
61
|
|
62
62
|
@op(required_resource_keys={"dingtalk_webhook"}, ins={"text": In(str)})
|
63
63
|
def op_send_text(context:OpExecutionContext, text:str):
|
64
64
|
dingtalk_webhook:DingTalkWebhookResource = context.resources.dingtalk_webhook
|
65
|
-
|
65
|
+
dingtalk_webhook.send_text(text)
|
66
66
|
|
67
67
|
@job
|
68
68
|
def job_send_text():
|
69
|
-
op_send_text
|
69
|
+
op_send_text()
|
70
70
|
|
71
71
|
defs = Definitions(
|
72
|
-
jobs=
|
72
|
+
jobs=[job_send_text],
|
73
73
|
resources={"dingtalk_webhook": DingTalkWebhookResource(access_token = "<access_token>", secret = "<secret>")}
|
74
74
|
)
|
75
75
|
```
|
76
76
|
|
77
|
-
2. 启动时动态构建企业内部应用资源, 可参考 [Dagster文档 | 在启动时配置资源](https://docs.dagster.io/concepts/resources#configuring-resources-at-launch-time)
|
77
|
+
##### 2. 启动时动态构建企业内部应用资源, 可参考 [Dagster文档 | 在启动时配置资源](https://docs.dagster.io/concepts/resources#configuring-resources-at-launch-time)
|
78
78
|
|
79
79
|
```python
|
80
80
|
from dagster_dingtalk import DingTalkWebhookResource
|
81
|
+
from dagster import op, In, OpExecutionContext, job, Definitions, schedule, RunRequest, RunConfig
|
81
82
|
|
82
83
|
@op(required_resource_keys={"dingtalk_webhook"}, ins={"text": In(str)})
|
83
84
|
def op_send_text(context:OpExecutionContext, text:str):
|
84
85
|
dingtalk_webhook:DingTalkWebhookResource = context.resources.dingtalk_webhook
|
85
|
-
|
86
|
+
dingtalk_webhook.send_text(text)
|
86
87
|
|
87
88
|
@job
|
88
89
|
def job_send_text():
|
89
|
-
op_send_text
|
90
|
+
op_send_text()
|
90
91
|
|
91
92
|
dingtalk_webhooks = {
|
92
93
|
"Group1" : DingTalkWebhookResource(access_token="<access_token>", secret="<secret>", alias="Group1"),
|
93
94
|
"Group2" : DingTalkWebhookResource(access_token="<access_token>", secret="<secret>", alias="Group2")
|
94
95
|
}
|
95
96
|
|
96
|
-
defs = Definitions(
|
97
|
+
defs = Definitions(
|
98
|
+
jobs=[job_send_text],
|
99
|
+
resources={"dingtalk_webhook": DingTalkWebhookResource.configure_at_launch()}
|
100
|
+
)
|
97
101
|
|
98
102
|
@schedule(cron_schedule="20 9 * * *", job=job_send_text)
|
99
103
|
def schedule_user_info():
|
@@ -109,16 +113,17 @@ class DingTalkWebhookResource(ConfigurableResource):
|
|
109
113
|
应当从环境变量中读取密钥。你可以在代码中注册临时的环境变量,或从系统中引入环境变量。
|
110
114
|
|
111
115
|
```python
|
116
|
+
|
112
117
|
import os
|
118
|
+
from dagster import EnvVar
|
113
119
|
from dagster_dingtalk import DingTalkWebhookResource
|
114
120
|
|
115
121
|
# 直接在代码中注册临时的环境变量
|
116
|
-
os.environ.update({'
|
117
|
-
os.environ.update({'
|
118
|
-
|
119
|
-
webhook = DingTalkWebhookResource(access_token=EnvVar("access_token"), secret=EnvVar("secret"))
|
120
|
-
|
122
|
+
os.environ.update({'access_token_name': "<your-access_token>"})
|
123
|
+
os.environ.update({'secret_name': "<your-secret>"})
|
121
124
|
|
125
|
+
webhook = DingTalkWebhookResource(access_token=EnvVar("access_token_name"), secret=EnvVar("secret_name"))
|
126
|
+
```
|
122
127
|
"""
|
123
128
|
|
124
129
|
access_token: str = Field(description="Webhook地址中的 access_token 部分")
|
@@ -298,94 +303,100 @@ class DingTalkWebhookResource(ConfigurableResource):
|
|
298
303
|
|
299
304
|
class DingTalkAppResource(ConfigurableResource):
|
300
305
|
"""
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
306
|
+
该 Dagster 资源允许定义一个钉钉的 API Client,更加便捷地调用钉钉服务端企业内部应用 API
|
307
|
+
|
308
|
+
[钉钉服务端 API](https://open.dingtalk.com/document/orgapp/api-overview) 企业内部应用部分的第三方封装。
|
309
|
+
|
310
|
+
通过此资源,可以调用部分钉钉服务端 API。具体封装的 API 可以在 IDE 中通过引入 `DingTalkAppClient` 类来查看 IDE 提示:
|
311
|
+
|
312
|
+
```python
|
313
|
+
from dagster_dingtalk import DingTalkAppClient
|
314
|
+
|
315
|
+
dingtalk: DingTalkAppClient
|
316
|
+
```
|
317
|
+
|
318
|
+
### 配置项:
|
319
|
+
|
320
|
+
- **AppID** (str):
|
321
|
+
应用应用唯一标识 AppID,作为缓存标识符使用。不传入则不缓存鉴权。
|
322
|
+
- **AgentID** (int, optional):
|
323
|
+
原企业内部应用 AgentId ,部分 API 会使用到。默认值为 None
|
324
|
+
- **AppName** (str, optional):
|
325
|
+
应用名。
|
326
|
+
- **ClientId** (str):
|
327
|
+
应用的 Client ID ,原 AppKey 和 SuiteKey
|
328
|
+
- **ClientSecret** (str):
|
329
|
+
应用的 Client Secret ,原 AppSecret 和 SuiteSecret
|
330
|
+
|
331
|
+
### 用例
|
332
|
+
|
333
|
+
##### 1. 使用单一的企业内部应用资源。
|
334
|
+
|
335
|
+
```python
|
336
|
+
from dagster_dingtalk import DingTalkAppResource, DingTalkAppClient
|
337
|
+
from dagster import op, In, OpExecutionContext, job, Definitions, EnvVar
|
338
|
+
|
339
|
+
@op(required_resource_keys={"dingtalk"}, ins={"user_id": In(str)})
|
340
|
+
def op_user_info(context:OpExecutionContext, user_id:str):
|
341
|
+
dingtalk:DingTalkAppClient = context.resources.dingtalk
|
342
|
+
result = dingtalk.通讯录管理.用户管理.查询用户详情(user_id).get('result')
|
343
|
+
context.log.info(result)
|
344
|
+
|
345
|
+
@job
|
346
|
+
def job_user_info():
|
347
|
+
op_user_info()
|
348
|
+
|
349
|
+
defs = Definitions(
|
350
|
+
jobs=[job_user_info],
|
351
|
+
resources={"dingtalk": DingTalkAppResource(
|
352
|
+
AppID = "<the-app-id>",
|
353
|
+
ClientId = "<the-client-id>",
|
354
|
+
ClientSecret = EnvVar("<the-client-secret-env-name>"),
|
355
|
+
)})
|
356
|
+
```
|
357
|
+
|
358
|
+
##### 2. 启动时动态构建企业内部应用资源, 可参考 [Dagster文档 | 在启动时配置资源](https://docs.dagster.io/concepts/resources#configuring-resources-at-launch-time)
|
359
|
+
|
360
|
+
```python
|
361
|
+
from dagster_dingtalk import DingTalkAppResource, DingTalkAppClient
|
362
|
+
from dagster import op, In, OpExecutionContext, job, Definitions, schedule, RunRequest, RunConfig, EnvVar
|
363
|
+
|
364
|
+
@op(required_resource_keys={"dingtalk"}, ins={"user_id": In(str)})
|
365
|
+
def op_user_info(context:OpExecutionContext, user_id:str):
|
366
|
+
dingtalk:DingTalkAppClient = context.resources.dingtalk
|
367
|
+
result = dingtalk.通讯录管理.用户管理.查询用户详情(user_id).get('result')
|
368
|
+
context.log.info(result)
|
369
|
+
|
370
|
+
@job
|
371
|
+
def job_user_info():
|
372
|
+
op_user_info()
|
373
|
+
|
374
|
+
dingtalk_apps = {
|
375
|
+
"App1" : DingTalkAppResource(
|
376
|
+
AppID = "<app-1-app-id>",
|
377
|
+
ClientId = "<app-1-client-id>",
|
378
|
+
ClientSecret = EnvVar("<app-1-client-secret-env-name>"),
|
379
|
+
),
|
380
|
+
"App2" : DingTalkAppResource(
|
381
|
+
AppID = "<app-2-app-id>",
|
382
|
+
ClientId = "<app-2-client-id>",
|
383
|
+
ClientSecret = EnvVar("<app-2-client-secret-env-name>"),
|
384
|
+
)
|
385
|
+
}
|
375
386
|
|
376
|
-
|
377
|
-
def schedule_user_info():
|
378
|
-
return RunRequest(run_config=RunConfig(
|
379
|
-
ops={"op_user_info": {"inputs": {"user_id": "<the-user-id>"}}},
|
380
|
-
resources={"dingtalk": dingtalk_apps["App1"]},
|
381
|
-
))
|
382
|
-
```
|
387
|
+
defs = Definitions(jobs=[job_user_info], resources={"dingtalk": DingTalkAppResource.configure_at_launch()})
|
383
388
|
|
384
|
-
|
389
|
+
@schedule(cron_schedule="20 9 * * *", job=job_user_info)
|
390
|
+
def schedule_user_info():
|
391
|
+
return RunRequest(run_config=RunConfig(
|
392
|
+
ops={"op_user_info": {"inputs": {"user_id": "<the-user-id>"}}},
|
393
|
+
resources={"dingtalk": dingtalk_apps["App1"]},
|
394
|
+
))
|
395
|
+
```
|
385
396
|
|
386
|
-
|
387
|
-
应当从环境变量中读取密钥。你可以在代码中注册临时的环境变量,或从系统中引入环境变量。
|
397
|
+
### 注意:
|
388
398
|
|
399
|
+
应该永远避免直接将密钥字符串直接配置给资源,这会导致在 dagster 前端用户界面暴露密钥。你可以在代码中注册临时的环境变量,或从系统中引入环境变量。
|
389
400
|
"""
|
390
401
|
|
391
402
|
AppID: str = Field(description="应用应用唯一标识 AppID,作为缓存标识符使用。不传入则不缓存鉴权。")
|
dagster_dingtalk/version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.1.
|
1
|
+
__version__ = "0.1.13"
|
@@ -0,0 +1,210 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: dagster-dingtalk
|
3
|
+
Version: 0.1.13
|
4
|
+
Summary: A dagster plugin for the DingTalk
|
5
|
+
Author: YiZixuan
|
6
|
+
Author-email: sqkkyzx@qq.com
|
7
|
+
Requires-Python: >=3.10,<3.13
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
12
|
+
Requires-Dist: dagster (>=1.8.10)
|
13
|
+
Requires-Dist: httpx (>=0.27.2,<0.28.0)
|
14
|
+
Requires-Dist: pydantic (>=2.9.2,<3.0.0)
|
15
|
+
Description-Content-Type: text/markdown
|
16
|
+
|
17
|
+
# 钉钉与 Dagster 集成
|
18
|
+
|
19
|
+
---
|
20
|
+
|
21
|
+
## 介绍
|
22
|
+
|
23
|
+
该 Dagster 集成是为了更便捷的调用钉钉(DingTalk)的API,集成提供了两个 Dagster Resource。
|
24
|
+
|
25
|
+
|
26
|
+
## DingTalkWebhookResource
|
27
|
+
|
28
|
+
该资源允许定义单个钉钉自定义机器人的 Webhook 端点,以便于发送文本、Markdown、Link、 ActionCard、FeedCard 消息,消息具体样式可参考
|
29
|
+
[钉钉开放平台 | 自定义机器人发送消息的消息类型](https://open.dingtalk.com/document/orgapp/custom-bot-send-message-type)。
|
30
|
+
|
31
|
+
### 配置项:
|
32
|
+
|
33
|
+
- **access_token** (str):
|
34
|
+
机器人 Webhook 地址中的 access_token 值。
|
35
|
+
- **secret** (str, optional):
|
36
|
+
如使用加签安全配置,则需传签名密钥。默认值为 None。
|
37
|
+
- **alias** (str, optional):
|
38
|
+
如提供别名,可以在使用 `MultiDingTalkWebhookResource` 中使用别名进行 webhook 选择。默认值为 None。
|
39
|
+
- **base_url** (str, optional):
|
40
|
+
通用地址,一般无需更改。默认值为 “https://oapi.dingtalk.com/robot/send”。
|
41
|
+
|
42
|
+
### 用例:
|
43
|
+
|
44
|
+
##### 1. 使用单个资源:
|
45
|
+
```python
|
46
|
+
from dagster_dingtalk import DingTalkWebhookResource
|
47
|
+
from dagster import op, In, OpExecutionContext, job, Definitions
|
48
|
+
|
49
|
+
@op(required_resource_keys={"dingtalk_webhook"}, ins={"text": In(str)})
|
50
|
+
def op_send_text(context:OpExecutionContext, text:str):
|
51
|
+
dingtalk_webhook:DingTalkWebhookResource = context.resources.dingtalk_webhook
|
52
|
+
dingtalk_webhook.send_text(text)
|
53
|
+
|
54
|
+
@job
|
55
|
+
def job_send_text():
|
56
|
+
op_send_text()
|
57
|
+
|
58
|
+
defs = Definitions(
|
59
|
+
jobs=[job_send_text],
|
60
|
+
resources={"dingtalk_webhook": DingTalkWebhookResource(access_token = "<access_token>", secret = "<secret>")}
|
61
|
+
)
|
62
|
+
```
|
63
|
+
|
64
|
+
##### 2. 启动时动态构建企业内部应用资源, 可参考 [Dagster文档 | 在启动时配置资源](https://docs.dagster.io/concepts/resources#configuring-resources-at-launch-time)
|
65
|
+
|
66
|
+
```python
|
67
|
+
from dagster_dingtalk import DingTalkWebhookResource
|
68
|
+
from dagster import op, In, OpExecutionContext, job, Definitions, schedule, RunRequest, RunConfig
|
69
|
+
|
70
|
+
@op(required_resource_keys={"dingtalk_webhook"}, ins={"text": In(str)})
|
71
|
+
def op_send_text(context:OpExecutionContext, text:str):
|
72
|
+
dingtalk_webhook:DingTalkWebhookResource = context.resources.dingtalk_webhook
|
73
|
+
dingtalk_webhook.send_text(text)
|
74
|
+
|
75
|
+
@job
|
76
|
+
def job_send_text():
|
77
|
+
op_send_text()
|
78
|
+
|
79
|
+
dingtalk_webhooks = {
|
80
|
+
"Group1" : DingTalkWebhookResource(access_token="<access_token>", secret="<secret>", alias="Group1"),
|
81
|
+
"Group2" : DingTalkWebhookResource(access_token="<access_token>", secret="<secret>", alias="Group2")
|
82
|
+
}
|
83
|
+
|
84
|
+
defs = Definitions(
|
85
|
+
jobs=[job_send_text],
|
86
|
+
resources={"dingtalk_webhook": DingTalkWebhookResource.configure_at_launch()}
|
87
|
+
)
|
88
|
+
|
89
|
+
@schedule(cron_schedule="20 9 * * *", job=job_send_text)
|
90
|
+
def schedule_user_info():
|
91
|
+
return RunRequest(run_config=RunConfig(
|
92
|
+
ops={"op_send_text": {"inputs": {"text": "This a test text."}}},
|
93
|
+
resources={"dingtalk": dingtalk_webhooks["Group1"]},
|
94
|
+
))
|
95
|
+
```
|
96
|
+
|
97
|
+
### 注意:
|
98
|
+
|
99
|
+
应该永远避免直接将密钥字符串直接配置给资源,这会导致在 dagster 前端用户界面暴露密钥。
|
100
|
+
应当从环境变量中读取密钥。你可以在代码中注册临时的环境变量,或从系统中引入环境变量。
|
101
|
+
|
102
|
+
```python
|
103
|
+
import os
|
104
|
+
from dagster import EnvVar
|
105
|
+
from dagster_dingtalk import DingTalkWebhookResource
|
106
|
+
|
107
|
+
# 直接在代码中注册临时的环境变量
|
108
|
+
os.environ.update({'access_token_name': "<your-access_token>"})
|
109
|
+
os.environ.update({'secret_name': "<your-secret>"})
|
110
|
+
|
111
|
+
webhook = DingTalkWebhookResource(access_token=EnvVar("access_token_name"), secret=EnvVar("secret_name"))
|
112
|
+
```
|
113
|
+
|
114
|
+
## DingTalkAppResource
|
115
|
+
|
116
|
+
该 Dagster 资源允许定义一个钉钉的 API Client,更加便捷地调用钉钉服务端企业内部应用 API
|
117
|
+
|
118
|
+
[钉钉服务端 API](https://open.dingtalk.com/document/orgapp/api-overview) 企业内部应用部分的第三方封装。
|
119
|
+
|
120
|
+
通过此资源,可以调用部分钉钉服务端 API。具体封装的 API 可以在 IDE 中通过引入 `DingTalkAppClient` 类来查看 IDE 提示:
|
121
|
+
|
122
|
+
```python
|
123
|
+
from dagster_dingtalk import DingTalkAppClient
|
124
|
+
|
125
|
+
dingtalk: DingTalkAppClient
|
126
|
+
```
|
127
|
+
|
128
|
+
### 配置项:
|
129
|
+
|
130
|
+
- **AppID** (str):
|
131
|
+
应用应用唯一标识 AppID,作为缓存标识符使用。不传入则不缓存鉴权。
|
132
|
+
- **AgentID** (int, optional):
|
133
|
+
原企业内部应用 AgentId ,部分 API 会使用到。默认值为 None
|
134
|
+
- **AppName** (str, optional):
|
135
|
+
应用名。
|
136
|
+
- **ClientId** (str):
|
137
|
+
应用的 Client ID ,原 AppKey 和 SuiteKey
|
138
|
+
- **ClientSecret** (str):
|
139
|
+
应用的 Client Secret ,原 AppSecret 和 SuiteSecret
|
140
|
+
|
141
|
+
### 用例
|
142
|
+
|
143
|
+
##### 1. 使用单一的企业内部应用资源。
|
144
|
+
|
145
|
+
```python
|
146
|
+
from dagster_dingtalk import DingTalkAppResource, DingTalkAppClient
|
147
|
+
from dagster import op, In, OpExecutionContext, job, Definitions, EnvVar
|
148
|
+
|
149
|
+
@op(required_resource_keys={"dingtalk"}, ins={"user_id": In(str)})
|
150
|
+
def op_user_info(context:OpExecutionContext, user_id:str):
|
151
|
+
dingtalk:DingTalkAppClient = context.resources.dingtalk
|
152
|
+
result = dingtalk.通讯录管理.用户管理.查询用户详情(user_id).get('result')
|
153
|
+
context.log.info(result)
|
154
|
+
|
155
|
+
@job
|
156
|
+
def job_user_info():
|
157
|
+
op_user_info()
|
158
|
+
|
159
|
+
defs = Definitions(
|
160
|
+
jobs=[job_user_info],
|
161
|
+
resources={"dingtalk": DingTalkAppResource(
|
162
|
+
AppID = "<the-app-id>",
|
163
|
+
ClientId = "<the-client-id>",
|
164
|
+
ClientSecret = EnvVar("<the-client-secret-env-name>"),
|
165
|
+
)})
|
166
|
+
```
|
167
|
+
|
168
|
+
##### 2. 启动时动态构建企业内部应用资源, 可参考 [Dagster文档 | 在启动时配置资源](https://docs.dagster.io/concepts/resources#configuring-resources-at-launch-time)
|
169
|
+
|
170
|
+
```python
|
171
|
+
from dagster_dingtalk import DingTalkAppResource, DingTalkAppClient
|
172
|
+
from dagster import op, In, OpExecutionContext, job, Definitions, schedule, RunRequest, RunConfig, EnvVar
|
173
|
+
|
174
|
+
@op(required_resource_keys={"dingtalk"}, ins={"user_id": In(str)})
|
175
|
+
def op_user_info(context:OpExecutionContext, user_id:str):
|
176
|
+
dingtalk:DingTalkAppClient = context.resources.dingtalk
|
177
|
+
result = dingtalk.通讯录管理.用户管理.查询用户详情(user_id).get('result')
|
178
|
+
context.log.info(result)
|
179
|
+
|
180
|
+
@job
|
181
|
+
def job_user_info():
|
182
|
+
op_user_info()
|
183
|
+
|
184
|
+
dingtalk_apps = {
|
185
|
+
"App1" : DingTalkAppResource(
|
186
|
+
AppID = "<app-1-app-id>",
|
187
|
+
ClientId = "<app-1-client-id>",
|
188
|
+
ClientSecret = EnvVar("<app-1-client-secret-env-name>"),
|
189
|
+
),
|
190
|
+
"App2" : DingTalkAppResource(
|
191
|
+
AppID = "<app-2-app-id>",
|
192
|
+
ClientId = "<app-2-client-id>",
|
193
|
+
ClientSecret = EnvVar("<app-2-client-secret-env-name>"),
|
194
|
+
)
|
195
|
+
}
|
196
|
+
|
197
|
+
defs = Definitions(jobs=[job_user_info], resources={"dingtalk": DingTalkAppResource.configure_at_launch()})
|
198
|
+
|
199
|
+
@schedule(cron_schedule="20 9 * * *", job=job_user_info)
|
200
|
+
def schedule_user_info():
|
201
|
+
return RunRequest(run_config=RunConfig(
|
202
|
+
ops={"op_user_info": {"inputs": {"user_id": "<the-user-id>"}}},
|
203
|
+
resources={"dingtalk": dingtalk_apps["App1"]},
|
204
|
+
))
|
205
|
+
```
|
206
|
+
|
207
|
+
### 注意:
|
208
|
+
|
209
|
+
应该永远避免直接将密钥字符串直接配置给资源,这会导致在 dagster 前端用户界面暴露密钥。你可以在代码中注册临时的环境变量,或从系统中引入环境变量。
|
210
|
+
|
@@ -0,0 +1,8 @@
|
|
1
|
+
dagster_dingtalk/__init__.py,sha256=X7r8JoydXOsT9Sis4rBpVSKQeKJnnZ_t_qFae-ASF7E,466
|
2
|
+
dagster_dingtalk/app_client.py,sha256=STTBxNzs2rhyHX7gsDuTpftJcctbTPKRAFIZV7zsF08,13800
|
3
|
+
dagster_dingtalk/operations.py,sha256=3cCZCxh-dAdzzb75WCTKVdzeMV8yu_JJpIeULS7XaNg,761
|
4
|
+
dagster_dingtalk/resources.py,sha256=EL-Q9MfRuAInLw7ZYcLl_5060zOvhBdV_QvvO4JKXQc,17621
|
5
|
+
dagster_dingtalk/version.py,sha256=khDKUuWafURKVs5EAZkpOMiUHI2-V7axlqrWLPUpuZo,23
|
6
|
+
dagster_dingtalk-0.1.13.dist-info/METADATA,sha256=w7mlRCT1mbj8sebZfUhy10eVklUTnYP31JpVDdjTiuo,7608
|
7
|
+
dagster_dingtalk-0.1.13.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
8
|
+
dagster_dingtalk-0.1.13.dist-info/RECORD,,
|
@@ -1,38 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: dagster-dingtalk
|
3
|
-
Version: 0.1.11
|
4
|
-
Summary: A dagster plugin for the DingTalk
|
5
|
-
Author: YiZixuan
|
6
|
-
Author-email: sqkkyzx@qq.com
|
7
|
-
Requires-Python: >=3.10,<3.13
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
9
|
-
Classifier: Programming Language :: Python :: 3.10
|
10
|
-
Classifier: Programming Language :: Python :: 3.11
|
11
|
-
Classifier: Programming Language :: Python :: 3.12
|
12
|
-
Requires-Dist: dagster (>=1.8.10,<2.0.0)
|
13
|
-
Requires-Dist: httpx (>=0.27.2,<0.28.0)
|
14
|
-
Requires-Dist: pydantic (>=2.9.2,<3.0.0)
|
15
|
-
Description-Content-Type: text/markdown
|
16
|
-
|
17
|
-
# 钉钉与 Dagster 集成
|
18
|
-
|
19
|
-
---
|
20
|
-
|
21
|
-
## 介绍
|
22
|
-
|
23
|
-
该 Dagster 集成是为了更便捷的调用钉钉(DingTalk)的API,集成提供了两个 Dagster Resource。
|
24
|
-
|
25
|
-
|
26
|
-
## Webhook 资源
|
27
|
-
|
28
|
-
### DingTalkWebhookResource
|
29
|
-
|
30
|
-
该资源允许定义单个钉钉自定义机器人的 Webhook 端点,以便于发送文本、Markdown
|
31
|
-
、Link、 ActionCard、FeedCard 消息,消息具体样式可参考
|
32
|
-
[钉钉开放平台 | 自定义机器人发送消息的消息类型](https://open.dingtalk.com/document/orgapp/custom-bot-send-message-type) 。
|
33
|
-
|
34
|
-
|
35
|
-
### DingTalkAppResource
|
36
|
-
|
37
|
-
该 Dagster 资源允许定义一个钉钉的 API Client,更加便捷地调用钉钉服务端企业内部应用 API
|
38
|
-
|
@@ -1,8 +0,0 @@
|
|
1
|
-
dagster_dingtalk/__init__.py,sha256=X7r8JoydXOsT9Sis4rBpVSKQeKJnnZ_t_qFae-ASF7E,466
|
2
|
-
dagster_dingtalk/app_client.py,sha256=xZ9NcVZuWvz7S2thm4B1h4aFiBXmUnkp5nK5N_k7HwE,14011
|
3
|
-
dagster_dingtalk/operations.py,sha256=3cCZCxh-dAdzzb75WCTKVdzeMV8yu_JJpIeULS7XaNg,761
|
4
|
-
dagster_dingtalk/resources.py,sha256=XXGRub47EZY2MfAsGhyEZ_Joh_D-BMFNh_jXCVPx6tU,17255
|
5
|
-
dagster_dingtalk/version.py,sha256=nllDrH0jyChMuuYrK0CC55iTBKUNTUjejtcwxyUF2EQ,23
|
6
|
-
dagster_dingtalk-0.1.11.dist-info/METADATA,sha256=AqQfS-lsnBW-PBoad9xIsZei9b995Yf4SJhaHq1YQ7c,1221
|
7
|
-
dagster_dingtalk-0.1.11.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
8
|
-
dagster_dingtalk-0.1.11.dist-info/RECORD,,
|
File without changes
|