diff mbox series

send-error-report: Respect URL scheme in server name if exists

Message ID 20250410102401.122070-1-jaeyoon.jung@lge.com
State New
Headers show
Series send-error-report: Respect URL scheme in server name if exists | expand

Commit Message

jaeyoon.jung@lge.com April 10, 2025, 10:24 a.m. UTC
From: Jaeyoon Jung <jaeyoon.jung@lge.com>

If a server name with -s or --server flag contains the URL scheme such
as http:// or https:// it takes precedence over --no-ssl flag. This will
allow us to use the same command line option for different servers with
http:// and https:// schemes mixed.

Signed-off-by: Jaeyoon Jung <jaeyoon.jung@lge.com>
---
 scripts/send-error-report | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

Comments

Alexander Kanavin April 10, 2025, 7:44 p.m. UTC | #1
Thanks, this looks good and will be taken into patch testing queue,
but I wonder if we can simplify this further, and drop --no-ssl option
altogether. It would be a breaking change, but in master it's
possible. If you would like, you can send a second patch on top of
this one, with the option removal.

Alex

On Thu, 10 Apr 2025 at 12:24, Jaeyoon Jung (LGE) via
lists.openembedded.org <jaeyoon.jung=lge.com@lists.openembedded.org>
wrote:
>
> From: Jaeyoon Jung <jaeyoon.jung@lge.com>
>
> If a server name with -s or --server flag contains the URL scheme such
> as http:// or https:// it takes precedence over --no-ssl flag. This will
> allow us to use the same command line option for different servers with
> http:// and https:// schemes mixed.
>
> Signed-off-by: Jaeyoon Jung <jaeyoon.jung@lge.com>
> ---
>  scripts/send-error-report | 30 +++++++++++++++++++++++-------
>  1 file changed, 23 insertions(+), 7 deletions(-)
>
> diff --git a/scripts/send-error-report b/scripts/send-error-report
> index cfbcaa52cb..1e973f1cb2 100755
> --- a/scripts/send-error-report
> +++ b/scripts/send-error-report
> @@ -65,7 +65,7 @@ def edit_content(json_file_path):
>
>  def prepare_data(args):
>      # attempt to get the max_log_size from the server's settings
> -    max_log_size = getPayloadLimit(args.protocol+args.server+"/ClientPost/JSON")
> +    max_log_size = getPayloadLimit(args.server+"/ClientPost/JSON")
>
>      if not os.path.isfile(args.error_file):
>          log.error("No data file found.")
> @@ -135,9 +135,9 @@ def send_data(data, args):
>      headers={'Content-type': 'application/json', 'User-Agent': "send-error-report/"+version}
>
>      if args.json:
> -        url = args.protocol+args.server+"/ClientPost/JSON/"
> +        url = args.server+"/ClientPost/JSON/"
>      else:
> -        url = args.protocol+args.server+"/ClientPost/"
> +        url = args.server+"/ClientPost/"
>
>      req = urllib.request.Request(url, data=data, headers=headers)
>      try:
> @@ -149,6 +149,23 @@ def send_data(data, args):
>      print(response.read().decode('utf-8'))
>
>
> +def determine_server_url(args):
> +    # Get the error report server from the environment variable
> +    server = args.server or 'errors.yoctoproject.org'
> +
> +    # The scheme contained in the given URL takes precedence over --no-ssl flag
> +    scheme = args.protocol
> +    if server.startswith('http://'):
> +        server = server[len('http://'):]
> +        scheme = 'http://'
> +    elif server.startswith('https://'):
> +        server = server[len('https://'):]
> +        scheme = 'https://'
> +
> +    # Construct the final URL
> +    return f"{scheme}{server}"
> +
> +
>  if __name__ == '__main__':
>      arg_parse = argparse_oe.ArgumentParser(description="This scripts will send an error report to your specified error-report-web server.")
>
> @@ -164,8 +181,7 @@ if __name__ == '__main__':
>      arg_parse.add_argument("-s",
>                             "--server",
>                             help="Server to send error report to",
> -                           type=str,
> -                           default="errors.yoctoproject.org")
> +                           type=str)
>
>      arg_parse.add_argument("-e",
>                             "--email",
> @@ -195,10 +211,10 @@ if __name__ == '__main__':
>                             dest="protocol",
>                             action="store_const", const="http://", default="https://")
>
> -
> -
>      args = arg_parse.parse_args()
>
> +    args.server = determine_server_url(args)
> +
>      if (args.json == False):
>          print("Preparing to send errors to: "+args.server)
>
> --
> 2.43.0
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#214640): https://lists.openembedded.org/g/openembedded-core/message/214640
> Mute This Topic: https://lists.openembedded.org/mt/112188628/1686489
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [alex.kanavin@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
diff mbox series

Patch

diff --git a/scripts/send-error-report b/scripts/send-error-report
index cfbcaa52cb..1e973f1cb2 100755
--- a/scripts/send-error-report
+++ b/scripts/send-error-report
@@ -65,7 +65,7 @@  def edit_content(json_file_path):
 
 def prepare_data(args):
     # attempt to get the max_log_size from the server's settings
-    max_log_size = getPayloadLimit(args.protocol+args.server+"/ClientPost/JSON")
+    max_log_size = getPayloadLimit(args.server+"/ClientPost/JSON")
 
     if not os.path.isfile(args.error_file):
         log.error("No data file found.")
@@ -135,9 +135,9 @@  def send_data(data, args):
     headers={'Content-type': 'application/json', 'User-Agent': "send-error-report/"+version}
 
     if args.json:
-        url = args.protocol+args.server+"/ClientPost/JSON/"
+        url = args.server+"/ClientPost/JSON/"
     else:
-        url = args.protocol+args.server+"/ClientPost/"
+        url = args.server+"/ClientPost/"
 
     req = urllib.request.Request(url, data=data, headers=headers)
     try:
@@ -149,6 +149,23 @@  def send_data(data, args):
     print(response.read().decode('utf-8'))
 
 
+def determine_server_url(args):
+    # Get the error report server from the environment variable
+    server = args.server or 'errors.yoctoproject.org'
+
+    # The scheme contained in the given URL takes precedence over --no-ssl flag
+    scheme = args.protocol
+    if server.startswith('http://'):
+        server = server[len('http://'):]
+        scheme = 'http://'
+    elif server.startswith('https://'):
+        server = server[len('https://'):]
+        scheme = 'https://'
+
+    # Construct the final URL
+    return f"{scheme}{server}"
+
+
 if __name__ == '__main__':
     arg_parse = argparse_oe.ArgumentParser(description="This scripts will send an error report to your specified error-report-web server.")
 
@@ -164,8 +181,7 @@  if __name__ == '__main__':
     arg_parse.add_argument("-s",
                            "--server",
                            help="Server to send error report to",
-                           type=str,
-                           default="errors.yoctoproject.org")
+                           type=str)
 
     arg_parse.add_argument("-e",
                            "--email",
@@ -195,10 +211,10 @@  if __name__ == '__main__':
                            dest="protocol",
                            action="store_const", const="http://", default="https://")
 
-
-
     args = arg_parse.parse_args()
 
+    args.server = determine_server_url(args)
+
     if (args.json == False):
         print("Preparing to send errors to: "+args.server)