1
+ from .rest import RestClient
2
+
3
+
4
+ class Actions (object ):
5
+ """Auth0 Actions endpoints
6
+
7
+ Args:
8
+ domain (str): Your Auth0 domain, e.g: 'username.auth0.com'
9
+
10
+ token (str): Management API v2 Token
11
+
12
+ telemetry (bool, optional): Enable or disable Telemetry
13
+ (defaults to True)
14
+
15
+ timeout (float or tuple, optional): Change the requests
16
+ connect and read timeout. Pass a tuple to specify
17
+ both values separately or a float to set both to it.
18
+ (defaults to 5.0 for both)
19
+
20
+ rest_options (RestClientOptions): Pass an instance of
21
+ RestClientOptions to configure additional RestClient
22
+ options, such as rate-limit retries.
23
+ (defaults to None)
24
+ """
25
+
26
+ def __init__ (self , domain , token , telemetry = True , timeout = 5.0 , protocol = "https" , rest_options = None ):
27
+ self .domain = domain
28
+ self .protocol = protocol
29
+ self .client = RestClient (jwt = token , telemetry = telemetry , timeout = timeout , options = rest_options )
30
+
31
+ def _url (self , * args ):
32
+ url = '{}://{}/api/v2/actions' .format (self .protocol , self .domain )
33
+ for p in args :
34
+ if p is not None :
35
+ url = '{}/{}' .format (url , p )
36
+ return url
37
+
38
+ def get_actions (self , trigger_id = None , action_name = None , deployed = False , installed = False , page = None , per_page = None ):
39
+ """Get all actions.
40
+
41
+ Args:
42
+ trigger_id (str, optional): Filter the results to only actions associated
43
+ with this trigger ID.
44
+
45
+ action_name (str, optional): Filter the results to only actions with this name.
46
+
47
+ deployed (bool, optional): True to filter the results to only deployed actions.
48
+ Defaults to False.
49
+
50
+ installed (bool, optional): True to filter the results to only installed actions.
51
+ Defaults to False.
52
+
53
+ page (int, optional): The result's page number (zero based). When not set,
54
+ the default value is up to the server.
55
+
56
+ per_page (int, optional): The amount of entries per page. When not set,
57
+ the default value is up to the server.
58
+
59
+ See: https://auth0.com/docs/api/management/v2#!/Actions/get_actions
60
+ """
61
+ params = {
62
+ 'triggerId' : trigger_id ,
63
+ 'actionName' : action_name ,
64
+ 'deployed' : str (deployed ).lower (),
65
+ 'installed' : str (installed ).lower (),
66
+ 'page' : page ,
67
+ 'per_page' : per_page
68
+ }
69
+
70
+ return self .client .get (self ._url ('actions' ), params = params )
71
+
72
+ def create_action (self , body ):
73
+ """Create a new action.
74
+
75
+ Args:
76
+ body (dict): Attributes for the new action.
77
+
78
+ See: https://auth0.com/docs/api/management/v2#!/Actions/post_action
79
+ """
80
+
81
+ return self .client .post (self ._url ('actions' ), data = body )
82
+
83
+ def update_action (self , id , body ):
84
+ """Updates an action.
85
+
86
+ Args:
87
+ id (str): the ID of the action.
88
+
89
+ body (dict): Attributes to modify.
90
+
91
+ See: https://auth0.com/docs/api/management/v2#!/Actions/patch_action
92
+ """
93
+
94
+ return self .client .patch (self ._url ('actions' , id ), data = body )
95
+
96
+ def get_action (self , id ):
97
+ """Retrieves an action by its ID.
98
+
99
+ Args:
100
+ id (str): Id of action to retrieve.
101
+
102
+ See: https://auth0.com/docs/api/management/v2#!/Actions/get_action
103
+ """
104
+ params = {}
105
+
106
+ return self .client .get (self ._url ('actions' , id ), params = params )
107
+
108
+ def delete_action (self , id , force = False ):
109
+ """Deletes an action and all of its associated versions.
110
+
111
+ Args:
112
+ id (str): ID of the action to delete.
113
+
114
+ force (bool, optional): True to force action deletion detaching bindings,
115
+ False otherwise. Defaults to False.
116
+
117
+ See: https://auth0.com/docs/api/management/v2#!/Actions/delete_action
118
+ """
119
+ params = {
120
+ 'force' : str (force ).lower ()
121
+ }
122
+
123
+ return self .client .delete (self ._url ('actions' , id ), params = params )
124
+
125
+ def get_triggers (self ):
126
+ """Retrieve the set of triggers currently available within actions.
127
+
128
+ See: https://auth0.com/docs/api/management/v2#!/Actions/get_triggers
129
+ """
130
+ params = {}
131
+
132
+ return self .client .get (self ._url ('triggers' ), params = params )
133
+
134
+ def get_execution (self , id ):
135
+ """Get information about a specific execution of a trigger.
136
+
137
+ Args:
138
+ id (str): The ID of the execution to retrieve.
139
+
140
+ See: https://auth0.com/docs/api/management/v2#!/Actions/get_execution
141
+ """
142
+ params = {}
143
+
144
+ return self .client .get (self ._url ('executions' , id ), params = params )
145
+
146
+ def get_action_versions (self , id , page = None , per_page = None ):
147
+ """Get all of an action's versions.
148
+
149
+ Args:
150
+ id (str): The ID of the action.
151
+
152
+ page (int, optional): The result's page number (zero based). When not set,
153
+ the default value is up to the server.
154
+
155
+ per_page (int, optional): The amount of entries per page. When not set,
156
+ the default value is up to the server.
157
+
158
+ See: https://auth0.com/docs/api/management/v2#!/Actions/get_action_versions
159
+ """
160
+ params = {
161
+ 'page' : page ,
162
+ 'per_page' : per_page
163
+ }
164
+
165
+ return self .client .get (self ._url ('actions' , id , 'versions' ), params = params )
166
+
167
+ def get_trigger_bindings (self , id , page = None , per_page = None ):
168
+ """Get the actions that are bound to a trigger.
169
+
170
+ Args:
171
+ id (str): The trigger ID.
172
+
173
+ page (int, optional): The result's page number (zero based). When not set,
174
+ the default value is up to the server.
175
+
176
+ per_page (int, optional): The amount of entries per page. When not set,
177
+ the default value is up to the server.
178
+
179
+ See: https://auth0.com/docs/api/management/v2#!/Actions/get_bindings
180
+ """
181
+ params = {
182
+ 'page' : page ,
183
+ 'per_page' : per_page
184
+ }
185
+ return self .client .get (self ._url ('triggers' , id , 'bindings' ), params = params )
186
+
187
+ def get_action_version (self , action_id , version_id ):
188
+ """Retrieve a specific version of an action.
189
+
190
+ Args:
191
+ action_id (str): The ID of the action.
192
+
193
+ version_id (str): The ID of the version to retrieve.
194
+
195
+ See: https://auth0.com/docs/api/management/v2#!/Actions/get_action_version
196
+ """
197
+ params = {}
198
+
199
+ return self .client .get (self ._url ('actions' , action_id , 'versions' , version_id ), params = params )
200
+
201
+ def deploy_action (self , id ):
202
+ """Deploy an action.
203
+
204
+ Args:
205
+ id (str): The ID of the action to deploy.
206
+
207
+ See: https://auth0.com/docs/api/management/v2#!/Actions/post_deploy_action
208
+ """
209
+ return self .client .post (self ._url ('actions' , id , 'deploy' ))
210
+
211
+ def rollback_action_version (self , action_id , version_id ):
212
+ """Roll back to a previous version of an action.
213
+
214
+ Args:
215
+ action_id (str): The ID of the action.
216
+
217
+ version_id (str): The ID of the version.
218
+
219
+ See: https://auth0.com/docs/api/management/v2#!/Actions/post_deploy_draft_version
220
+ """
221
+ params = {}
222
+ return self .client .post (self ._url ('actions' , action_id , 'versions' , version_id , 'deploy' ), data = {})
223
+
224
+ def update_trigger_bindings (self , id , body ):
225
+ """Update a trigger's bindings.
226
+
227
+ Args:
228
+ id (str): The ID of the trigger to update.
229
+
230
+ body (dict): Attributes for the updated trigger binding.
231
+
232
+ See: https://auth0.com/docs/api/management/v2#!/Actions/patch_bindings
233
+ """
234
+ return self .client .patch (self ._url ('triggers' , id , 'bindings' ), data = body )
0 commit comments