Mercurial > libervia-backend
comparison doc/libervia-cli/pubsub.rst @ 3488:c80a0f864b5d
doc: updated doc following global renaming
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 21 Mar 2021 18:23:58 +0100 |
parents | doc/jp/pubsub.rst@cea52c9ddfd9 |
children | 4705f80b6e23 |
comparison
equal
deleted
inserted
replaced
3487:75427f0a5445 | 3488:c80a0f864b5d |
---|---|
1 .. _libervia-cli_pubsub: | |
2 | |
3 ========================= | |
4 pubsub: PubSub management | |
5 ========================= | |
6 | |
7 PubSub commands are low level command to handle a PubSub Service. | |
8 They are using the generic pubsub arguments | |
9 | |
10 For most of those commands, :ref:`pubsub_common` commands are used to specify the | |
11 destination item. | |
12 | |
13 set | |
14 === | |
15 | |
16 Publish a pubsub item. | |
17 | |
18 ``stdin`` is used to get the raw XML of the payload of the item to publish. | |
19 | |
20 ``-f KEY VALUE, --field KEY VALUE`` can be used to specify publish options, i.e. option | |
21 which must be set if the node already exists, or used if the node is to be created, see | |
22 `XEP-0060 §7.1.5`_ for details. | |
23 | |
24 In the same way as for :ref:`libervia-cli_pubsub_node_create`, ``-F, --full-prefix`` can be used if | |
25 you need to specify the full option name. | |
26 | |
27 .. _XEP-0060 §7.1.5: https://xmpp.org/extensions/xep-0060.html#publisher-publish-options | |
28 | |
29 example | |
30 ------- | |
31 | |
32 Create an item with a custom note XML:: | |
33 | |
34 $ echo '<note xmlns="http://example.net/mynotes">this is a note</note>' | li pubsub set -n "notes" | |
35 | |
36 get | |
37 === | |
38 | |
39 Retrieve items from specified node. Default output is prettified and highlighted XML. | |
40 | |
41 example | |
42 ------- | |
43 | |
44 Retrieve the last 5 notes from our custom notes node:: | |
45 | |
46 $ li pubsub get -n notes -m 5 | |
47 | |
48 delete | |
49 ====== | |
50 | |
51 Delete an item from a node. If ``-N, --notify`` is specified, subscribers will be notified | |
52 of the item retraction. | |
53 | |
54 By default a confirmation is requested before deletion is requested to the PubSub service, | |
55 but you can override this behaviour by using ``-f, --force`` option. | |
56 | |
57 example | |
58 ------- | |
59 | |
60 Delete item with id ``123456`` from a node:: | |
61 | |
62 $ li pubsub delete -n test_node -i 123456 | |
63 | |
64 edit | |
65 ==== | |
66 | |
67 Edit the raw XML of an item payload using your local editor (the one set in ``$EDITOR``). | |
68 | |
69 If you don't change anything or publish an empty blog post, the edition will be cancelled. | |
70 | |
71 :ref:`draft_common` commands can be used. | |
72 | |
73 example | |
74 ------- | |
75 | |
76 Edit the last note in our custom node:: | |
77 | |
78 $ li pubsub edit -n notes -L | |
79 | |
80 subscribe | |
81 ========= | |
82 | |
83 Subscribe to a node. | |
84 | |
85 Subscription is used to get notifications from the node in case of new/updated item or | |
86 deletion. | |
87 | |
88 example | |
89 ------- | |
90 | |
91 Subscribe to an information blog:: | |
92 | |
93 $ li pubsub subscribe -n informations -s pubsub.example.net | |
94 | |
95 unsubscribe | |
96 =========== | |
97 | |
98 Unsubscribe from a node. | |
99 | |
100 example | |
101 ------- | |
102 | |
103 Unsubscribe from an information blog:: | |
104 | |
105 $ li pubsub unsubscribe -n informations -s pubsub.example.net | |
106 | |
107 subscriptions | |
108 ============= | |
109 | |
110 Retrieve subscriptions for all nodes on a service. | |
111 | |
112 ``-n NODE, --node NODE`` can be used to request subscriptions for a specific node (e.g. if | |
113 it has subscription with multiple subIDs). | |
114 | |
115 example | |
116 ------- | |
117 | |
118 Retrieve all subscriptions on a pubsub service:: | |
119 | |
120 $ li pubsub subscriptions -s pubsub@example.net | |
121 | |
122 affiliations | |
123 ============= | |
124 | |
125 Retrieve affiliations for all nodes at a service. | |
126 | |
127 ``-n NODE, --node NODE`` can be used to request affiliation for a specific node. | |
128 | |
129 examples | |
130 -------- | |
131 | |
132 Retrieve all affiliations at a pubsub service:: | |
133 | |
134 $ li pubsub affiliations -s pubsub@example.net | |
135 | |
136 Retrieve affiliation for the ``notes`` node:: | |
137 | |
138 $ li pubsub affiliations -s pubsub@example.net -n notes | |
139 | |
140 search | |
141 ====== | |
142 | |
143 Search items corresponding to one or more filter(s). | |
144 | |
145 ``search`` will check all items (or some of them according to options used) from one or | |
146 several nodes (several nodes can be checked if recursion is used, see below). For each | |
147 item the given filters will be checked, and all corresponding items will be returned. | |
148 | |
149 This is a resource intensive method (both for server and client), use with caution, and | |
150 use MAM to do searching when suitable. | |
151 | |
152 filters | |
153 ------- | |
154 | |
155 To do a search you one or more filters. Filters are checked in the order in which they are | |
156 specified. You can use 4 kinds of filters: | |
157 | |
158 ``-t TEXT, --text TEXT`` | |
159 do a full-text search. If *TEXT* is appearing anywhere in the item (including in XML | |
160 tags or arguments), the item is selected | |
161 | |
162 ``-r EXPRESSION, --regex EXPRESSION`` | |
163 do a regular expression search. `Python standard re module`_ is used internally, so you | |
164 can use its syntax. | |
165 | |
166 ``-x XPATH, --xpath XPATH`` | |
167 use an `XPath version 1.0`_ expression to filter the query. You can have a look at | |
168 `Wikipedia XPath page`_ for a user friendly introduction. | |
169 | |
170 ``-P PYTHON_CODE, --python PYTHON_CODE`` | |
171 use a Python expression to do a test. The expression must return a boolean (``True`` to | |
172 keep item, ``False`` otherwise). From within the Python expression 3 variables are | |
173 defined: ``item`` which contain the raw item as a string, and ``item_xml`` which is the | |
174 parsed XML as an lxml ``etree.Element`` and ``etree`` which is the ``lxml.etree`` module. | |
175 | |
176 .. _Python standard re module: https://docs.python.org/3.7/library/re.html | |
177 .. _XPath version 1.0: https://www.w3.org/TR/1999/REC-xpath-19991116/ | |
178 .. _Wikipedia XPath page: https://en.wikipedia.org/wiki/XPath | |
179 | |
180 filter modifiers | |
181 ---------------- | |
182 | |
183 Before each filter you can specify one or more filter modifiers. A modifier will change | |
184 filter behaviour, it's a flag which can be used either without argument (then it will | |
185 activate the flag), or with an explicit boolean value (i.e. ``true`` or ``false``). | |
186 | |
187 The available filters are: | |
188 | |
189 ``-C [BOOLEAN], --ignore-case [BOOLEAN]`` | |
190 (don't) ignore case. Filters are normally case sensitive, this modifier change this | |
191 behaviour. | |
192 | |
193 ``-I [BOOLEAN], --invert [BOOLEAN]`` | |
194 (don't) invert effect of following filters. This is applying a logical ``NOT`` to the | |
195 filter. This means that instead of keeping item matching the filter, it will keep the | |
196 items which are **not** matching the filter. | |
197 | |
198 ``-A [BOOLEAN], --dot-all [BOOLEAN]`` | |
199 (don't) use `DOTALL`_ option for regex. This filter only makes sense before a | |
200 ``--regex`` expression. | |
201 | |
202 ``-k [BOOLEAN], --only-matching [BOOLEAN]`` | |
203 (don't) keep only the matching part of the item. Normally the whole item is returned, | |
204 with this flag, only the part matching the filters are kept. | |
205 | |
206 .. _DOTALL: https://docs.python.org/3.7/library/re.html#re.DOTALL | |
207 | |
208 actions | |
209 ------- | |
210 | |
211 Once filters are set, you may indicate what do to with the found items. By default they | |
212 are printed, but you can also use an other li command, or even an external tool. | |
213 | |
214 The following actions are available: | |
215 | |
216 ``print`` (default) | |
217 pretty print the found items. | |
218 | |
219 ``exec`` | |
220 use the given li command on each found item. Everything after the ``exec`` is used to | |
221 indicate the command and arguments to use (you must not specify ``li``, use the command | |
222 directly). The service, node and item will be set to match the found item. | |
223 | |
224 ``external`` | |
225 pipe the raw XML of each item to the given command. Everything after the ``external`` | |
226 action is used to indicate the command and arguments to use. | |
227 | |
228 recursive search | |
229 ---------------- | |
230 | |
231 By default, only items in the given node will be filtered, but if you specify a recursion | |
232 depth > 0 (using ``-D MAX_DEPTH, --max-depth MAX_DEPTH``), every node linked in item will | |
233 be checked too, then node linked in linked item and so on until depth level is reached. | |
234 | |
235 For instance, if you want to find all comments of a blog node containing an http(s) link, | |
236 you can do that:: | |
237 | |
238 $ li pubsub search -n urn:xmpp:microblog:0 -s user@example.net -D 1 -r 'https?://' | |
239 | |
240 examples | |
241 -------- | |
242 | |
243 Finding all items containing the text "something interesting" in personal blog:: | |
244 | |
245 $ li pubsub search -n urn:xmpp:microblog:0 -M -1 -t "something interesting" | |
246 | |
247 Find which blog items in the last 20 have a body with less than 200 characters (note that | |
248 body can be either ``<title>`` or ``<content>``, see `XEP-0277`_ for details). Here we use | |
249 a python expression on the text of the body to count the number of characters:: | |
250 | |
251 $ li pubsub search -n urn:xmpp:microblog:0 -M 20 --python "len((item_xml.find('.//{http://www.w3.org/2005/Atom}content[@type=\"text\"]') or item_xml.find('.//{http://www.w3.org/2005/Atom}title[@type=\"text\"]')).text) < 200" | |
252 | |
253 Find items published by ``toto@example.net`` among last 30 on a blog node, and use | |
254 ``pubsub blog`` command to retrieve id and title. We use ``-N`` to specify the ``pubsub`` | |
255 namespace which is used in the XPath expression, then we use ``exec`` to run ``blog get -k | |
256 title -k id`` on found items:: | |
257 | |
258 $ li pubsub search -n some_blog_node -s pubsub.example.net -M 30 -N pubsub http://jabber.org/protocol/pubsub -x '/pubsub:item[starts-with(@publisher, "toto@example.net")]' exec blog get -k title -k id | |
259 | |
260 Find items which have **NOT** a title among last 30 items in our personal blog. As | |
261 explained in `XEP-0277`_ Atom's ``<title>`` is always used (even if there is only a body | |
262 and no title), so we actually look for items without ``<content>``. We do that with an | |
263 XPath looking for this ``atom:content`` element, then we use the ``-I [BOOLEAN], --invert | |
264 [BOOLEAN]`` to filter out elements which match.:: | |
265 | |
266 $ li pubsub search -n urn:xmpp:microblog:0 -M 30 -I -x //atom:content -N atom http://www.w3.org/2005/Atom | |
267 | |
268 Display authors names from last 10 items and their comments, using the ``-k [BOOLEAN], | |
269 --only-matching [BOOLEAN]`` modifier to only display the data we need. We use ``-D 1`` to | |
270 do a recursive search of level 1, which will also look into comments nodes (using last 10 | |
271 items there too):: | |
272 | |
273 $ li pubsub search -n urn:xmpp:microblog:0 -M 10 --only-matching -x //atom:author/atom:name -N atom http://www.w3.org/2005/Atom -D 1 | |
274 | |
275 .. _XEP-0277: https://xmpp.org/extensions/xep-0277.html | |
276 | |
277 transform | |
278 ========= | |
279 | |
280 Modify items using an external command. | |
281 | |
282 ``transform`` will retrieve requested items, and will send each of them to the standard | |
283 input (stdin) of the specified command. The output of the command will be used, it can be | |
284 3 things: | |
285 | |
286 - a raw XML of the modified item, in which case the item will be republished | |
287 - the string ``SKIP``, in which case the item will be ignored | |
288 - the string ``DELETE``, in which case the item will be retracted | |
289 | |
290 By default a dry run is done, which means that no item is modified or deleted. To actually | |
291 do the transformation, you have to use ``--apply`` argument. | |
292 | |
293 If you have to modify the ``publisher`` of an item, you need specific privileges. The | |
294 ``--admin`` allows you do to that, but it must be supported by your PubSub service | |
295 (currently only ``SàT PubSub`` supports this non standard feature). | |
296 | |
297 To modify all items of a node, use the ``-A, --all`` option. This will use `RSM`_ | |
298 repetitively until all items are treated. Of course that means that your PubSub service | |
299 must support RSM. The items being republished, they will reappear on top of your node, | |
300 that's why it is recommended to use ``--order-by creation`` option when supported by the | |
301 service, to keep consistent order and avoid transforming the same items several times. | |
302 | |
303 If the command you're using exit with a non zero code, the process will stop. Use ``-I, | |
304 --ignore_errors`` if you want to continue transformation even if an non zero code is | |
305 returned. | |
306 | |
307 .. _RSM: https://xmpp.org/extensions/xep-0059.html | |
308 | |
309 example | |
310 ------- | |
311 | |
312 Imagine that you want to replace all occurrences of "sàt" by "Salut à Toi" in your personal blog. You first create a Python script like this: | |
313 | |
314 .. sourcecode:: python | |
315 | |
316 #!/usr/bin/env python3 | |
317 | |
318 import sys | |
319 item_raw = sys.stdin.read() | |
320 if not "sàt" in item_raw: | |
321 print("SKIP") | |
322 else: | |
323 print(item_raw.replace("sàt", "Salut à Toi")) | |
324 | |
325 And save it a some location, e.g. ``~/expand_sat.py`` (don't forget to make is executable | |
326 with ``chmod +x ~/expand_sat.py``). | |
327 | |
328 To be sure it's safe, you can first do a dry-run and check the result:: | |
329 | |
330 $ li pubsub transform -n urn:xmpp:microblog:0 -A -o creation ~/expand_sat.py | |
331 | |
332 Once you have checked that you have the expected behaviour, you can apply the | |
333 transformations:: | |
334 | |
335 $ li pubsub transform -n urn:xmpp:microblog:0 -A -o creation --apply ~/expand_sat.py | |
336 | |
337 And that's it. You can use the same technique for more complex transformations, including | |
338 modifying the XML (with Python, you can easily do that with standard | |
339 ``xml.etree.ElementTree`` module or with ``lxml.etree``). | |
340 | |
341 uri | |
342 === | |
343 | |
344 Build an XMPP URI linking to a PubSub node or item. | |
345 | |
346 example | |
347 ------- | |
348 | |
349 Build a link to personal blog:: | |
350 | |
351 $ li pubsub uri -n urn:xmpp:microblog:0 | |
352 | |
353 node | |
354 ==== | |
355 | |
356 Subcommands for node management. Please check :ref:`libervia-cli_pubsub_node`. | |
357 | |
358 hook | |
359 ==== | |
360 | |
361 Subcommands for hooks management. Please check :ref:`libervia-cli_pubsub_hook`. |