bneradt commented on code in PR #11583:
URL: https://github.com/apache/trafficserver/pull/11583#discussion_r1698797333


##########
tools/remap/convert_remap_actions_to_10x:
##########
@@ -0,0 +1,172 @@
+#!/usr/bin/env python3
+'''Convert allow and deny @actions to add_allow and add_deny.'''
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import argparse
+import os
+import shutil
+import sys
+import tempfile
+from typing import Optional, TextIO, Tuple
+
+help = '''Convert allow and deny @actions to add_allow and add_deny.
+
+This script is used to convert a pre-10.x remap.config file to be functionally
+equivalent to a 10.x remap.config file. In 10.x, the pre-10.x @action=allow and
+@action=deny actions are renamed to @action=add_allow and @action=add_deny,
+respectively. This script will convert the former to the latter. For further
+details, see the remap.config documentation.
+'''
+
+
+def convert_line(input_line: str) -> str:
+    '''Convert an input line to an output line.
+
+    This function modifies the input line for that of the new 9.2.x format.
+
+    :param input_line: The line to convert.
+    :return: The converted line.
+
+    :examples:
+        >>> convert_line('# nothing to convert')
+        '# nothing to convert'
+        >>> convert_line('map http://example.com http://backend.example.com')
+        'map http://example.com http://backend.example.com'
+
+        >>> convert_line('map http://example.com http://backend.example.com 
@action=allow @method=GET')
+        'map http://example.com http://backend.example.com @action=add_allow 
@method=GET'
+        >>> convert_line('map http://example.com http://backend.example.com 
@action=deny @method=PUT')
+        'map http://example.com http://backend.example.com @action=add_deny 
@method=PUT'
+
+        # Verify that add_allow and add_deny are not converted.
+        >>> convert_line('map http://example.com http://backend.example.com 
@action=add_deny @method=PUT')
+        'map http://example.com http://backend.example.com @action=add_deny 
@method=PUT'
+        >>> convert_line('map http://example.com http://backend.example.com 
@action=add_allow @method=GET')
+        'map http://example.com http://backend.example.com @action=add_allow 
@method=GET'
+
+        # Comments should be converted too.
+        >>> convert_line('# Using @action=allow is nice.')
+        '# Using @action=add_allow is nice.'
+        >>> convert_line('# map http://example.com http://backend.example.com 
@action=allow @method=GET')
+        '# map http://example.com http://backend.example.com @action=add_allow 
@method=GET'
+    '''
+    output_line = input_line.replace('@action=allow', '@action=add_allow')
+    output_line = output_line.replace('@action=deny', '@action=add_deny')

Review Comment:
   I intentionally wanted those replaced. Shouldn't they be? A comment that 
references `@action=allow` will be broken unless set to `@action=add_allow` for 
instance. At least that was my logic.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to