|
| 1 | +# Copyright VyOS maintainers and contributors <maintainers@vyos.io> |
| 2 | +# |
| 3 | +# This library is free software; you can redistribute it and/or |
| 4 | +# modify it under the terms of the GNU Lesser General Public |
| 5 | +# License as published by the Free Software Foundation; either |
| 6 | +# version 2.1 of the License, or (at your option) any later version. |
| 7 | +# |
| 8 | +# This library is distributed in the hope that it will be useful, |
| 9 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | +# Lesser General Public License for more details. |
| 12 | +# |
| 13 | +# You should have received a copy of the GNU Lesser General Public License |
| 14 | +# along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 15 | + |
| 16 | +# T4251: |
| 17 | +# - drop "tls enable" node (make "tls" a standalone key) |
| 18 | +# - split "tls permitted-peers" list by commas into multiple "tls permitted-peer" entries |
| 19 | + |
| 20 | +from vyos.configtree import ConfigTree |
| 21 | + |
| 22 | +base = ['system', 'syslog', 'remote'] |
| 23 | + |
| 24 | + |
| 25 | +def migrate(config: ConfigTree) -> None: |
| 26 | + if not config.exists(base): |
| 27 | + return |
| 28 | + |
| 29 | + # Iterate over all remote syslog server entries (like 172.18.0.5) |
| 30 | + for remote_addr in config.list_nodes(base): |
| 31 | + remote_base = base + [remote_addr] |
| 32 | + tls_base = remote_base + ['tls'] |
| 33 | + |
| 34 | + # (1) Remove "tls enable" -> migrate to simple "tls" |
| 35 | + enable_path = tls_base + ['enable'] |
| 36 | + if config.exists(enable_path): |
| 37 | + # Remove obsolete "enable" node |
| 38 | + config.delete(enable_path) |
| 39 | + |
| 40 | + # (2) Split "tls permitted-peers" (comma-separated string) |
| 41 | + permitted_peers_path = tls_base + ['permitted-peers'] |
| 42 | + if config.exists(permitted_peers_path): |
| 43 | + peers_str = config.return_value(permitted_peers_path) |
| 44 | + # Split CSV values and normalize whitespace |
| 45 | + peers = [p.strip() for p in peers_str.split(',') if p.strip()] |
| 46 | + |
| 47 | + # Create a new "permitted-peer" entry per item |
| 48 | + for peer in peers: |
| 49 | + config.set(tls_base + ['permitted-peer'], value=peer, replace=False) |
| 50 | + |
| 51 | + # Remove the old combined node |
| 52 | + config.delete(permitted_peers_path) |
0 commit comments