From 48264bd9a1bfd570d81b96dbfd7e5dbdd592be58 Mon Sep 17 00:00:00 2001 From: Philipp Homberger Date: Sat, 25 Nov 2023 08:52:41 +0000 Subject: [PATCH 01/11] add plattform check --- st2client/st2client/base.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/st2client/st2client/base.py b/st2client/st2client/base.py index 4dfd0e95ae..14e1128da7 100644 --- a/st2client/st2client/base.py +++ b/st2client/st2client/base.py @@ -37,11 +37,16 @@ from st2client.config import get_config from st2client.utils.date import parse as parse_isotime from st2client.utils.misc import merge_dicts +import platform __all__ = ["BaseCLIApp"] # Fix for "os.getlogin()) OSError: [Errno 2] No such file or directory" -os.getlogin = lambda: pwd.getpwuid(os.getuid())[0] +# Add Plattform Check to fix the Issue that PWD not exist on Windows and so the CLI not working. +if platform.system() == "Windows": + os.getlogin = lambda: os.environ.get("USERNAME") +else: + os.getlogin = lambda: pwd.getpwuid(os.getuid())[0] # How many seconds before the token actual expiration date we should consider the token as # expired. This is used to prevent the operation from failing durig the API request because the From 4f620a5dd35b2a4a40dce9d34193eaa65f88eb52 Mon Sep 17 00:00:00 2001 From: Philipp Homberger Date: Sat, 25 Nov 2023 22:03:05 +0100 Subject: [PATCH 02/11] Update base.py --- st2client/st2client/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/st2client/st2client/base.py b/st2client/st2client/base.py index 14e1128da7..6d654fc1e9 100644 --- a/st2client/st2client/base.py +++ b/st2client/st2client/base.py @@ -16,12 +16,12 @@ from __future__ import absolute_import import os -import pwd import json import logging import time import calendar import traceback +import platform import six import requests @@ -37,7 +37,6 @@ from st2client.config import get_config from st2client.utils.date import parse as parse_isotime from st2client.utils.misc import merge_dicts -import platform __all__ = ["BaseCLIApp"] @@ -46,6 +45,7 @@ if platform.system() == "Windows": os.getlogin = lambda: os.environ.get("USERNAME") else: + import pwd os.getlogin = lambda: pwd.getpwuid(os.getuid())[0] # How many seconds before the token actual expiration date we should consider the token as From 335c85bba0905e5d5bbc9473d89fafff999faf8b Mon Sep 17 00:00:00 2001 From: Philipp Homberger Date: Sat, 25 Nov 2023 22:07:55 +0100 Subject: [PATCH 03/11] Update CHANGELOG.rst --- CHANGELOG.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index efc47527fa..5e472fc056 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,9 @@ in development Fixed ~~~~~ +* ‎Fix ST2 Client for Windows Clients. PWD is a Unix only Libary. + Contributed by (@philipphomberger Schwarz IT KG) + * ‎Fix Snyk Security Finding Cross-site Scripting (XSS) in contrib/examples/sensors/echo_flask_app.py Contributed by (@philipphomberger Schwarz IT KG) From c0fbd8a789840494051b6a1bdf00c6af5b1b31c8 Mon Sep 17 00:00:00 2001 From: Philipp Homberger Date: Sat, 25 Nov 2023 22:12:10 +0100 Subject: [PATCH 04/11] Update base.py --- st2client/st2client/base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/st2client/st2client/base.py b/st2client/st2client/base.py index 6d654fc1e9..11bfced12b 100644 --- a/st2client/st2client/base.py +++ b/st2client/st2client/base.py @@ -41,7 +41,9 @@ __all__ = ["BaseCLIApp"] # Fix for "os.getlogin()) OSError: [Errno 2] No such file or directory" -# Add Plattform Check to fix the Issue that PWD not exist on Windows and so the CLI not working. +# Add Plattform Check to fix the Issue that PWD not exist on Windows and so the ST2 CLI not working. +# https://docs.python.org/3.8/library/pwd.html +# Windows Default ENVVARS -> https://www.computerhope.com/issues/ch000088.htm if platform.system() == "Windows": os.getlogin = lambda: os.environ.get("USERNAME") else: From 5bfa5efd62648a40a36101e55b5180470b5abe6b Mon Sep 17 00:00:00 2001 From: Philipp Homberger Date: Sun, 26 Nov 2023 09:37:49 +0100 Subject: [PATCH 05/11] Update base.py --- st2client/st2client/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/st2client/st2client/base.py b/st2client/st2client/base.py index 11bfced12b..7a187d6728 100644 --- a/st2client/st2client/base.py +++ b/st2client/st2client/base.py @@ -48,6 +48,7 @@ os.getlogin = lambda: os.environ.get("USERNAME") else: import pwd + os.getlogin = lambda: pwd.getpwuid(os.getuid())[0] # How many seconds before the token actual expiration date we should consider the token as From dfcdf21fcbf70320d35e9622a7aeede6cb3f365e Mon Sep 17 00:00:00 2001 From: Philipp Homberger Date: Sun, 26 Nov 2023 11:10:12 +0100 Subject: [PATCH 06/11] linting CHANGELOG.rst --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5e472fc056..ef79466c6d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,7 @@ in development Fixed ~~~~~ + * ‎Fix ST2 Client for Windows Clients. PWD is a Unix only Libary. Contributed by (@philipphomberger Schwarz IT KG) From dcbb600e8b3585d6fedaa32cf397b1601d796279 Mon Sep 17 00:00:00 2001 From: Philipp Homberger Date: Sun, 26 Nov 2023 16:50:02 +0100 Subject: [PATCH 07/11] Lint CHANGELOG.rst --- CHANGELOG.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ef79466c6d..c306072469 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,11 +6,10 @@ in development Fixed ~~~~~ - -* ‎Fix ST2 Client for Windows Clients. PWD is a Unix only Libary. +* Fix ST2 Client for Windows Clients. PWD is a Unix only Libary. #6071 Contributed by (@philipphomberger Schwarz IT KG) -* ‎Fix Snyk Security Finding Cross-site Scripting (XSS) in contrib/examples/sensors/echo_flask_app.py +* Fix Snyk Security Finding Cross-site Scripting (XSS) in contrib/examples/sensors/echo_flask_app.py #6070 Contributed by (@philipphomberger Schwarz IT KG) * Additional fixes for st2 client auth when proxy auth mode enabled #6049 From 0cd317f434fc575221c63cdc4d25fa19878b30d4 Mon Sep 17 00:00:00 2001 From: Philipp Homberger Date: Sun, 26 Nov 2023 17:01:51 +0100 Subject: [PATCH 08/11] retry linting From f6ea3441e7f73d80b9f0f3c89af5cd05984ca37b Mon Sep 17 00:00:00 2001 From: Philipp Homberger Date: Mon, 27 Nov 2023 20:53:40 +0100 Subject: [PATCH 09/11] Change Bugfix --- st2client/st2client/base.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/st2client/st2client/base.py b/st2client/st2client/base.py index 7a187d6728..90fad8cef2 100644 --- a/st2client/st2client/base.py +++ b/st2client/st2client/base.py @@ -43,10 +43,7 @@ # Fix for "os.getlogin()) OSError: [Errno 2] No such file or directory" # Add Plattform Check to fix the Issue that PWD not exist on Windows and so the ST2 CLI not working. # https://docs.python.org/3.8/library/pwd.html -# Windows Default ENVVARS -> https://www.computerhope.com/issues/ch000088.htm -if platform.system() == "Windows": - os.getlogin = lambda: os.environ.get("USERNAME") -else: +if platform.system() != "Windows": import pwd os.getlogin = lambda: pwd.getpwuid(os.getuid())[0] From 0e2ef9c423319e0beca7e2e16986e5832097b39b Mon Sep 17 00:00:00 2001 From: Philipp Homberger Date: Mon, 27 Nov 2023 20:55:12 +0100 Subject: [PATCH 10/11] move comment some lines down --- st2client/st2client/base.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/st2client/st2client/base.py b/st2client/st2client/base.py index 90fad8cef2..1389ada854 100644 --- a/st2client/st2client/base.py +++ b/st2client/st2client/base.py @@ -40,12 +40,11 @@ __all__ = ["BaseCLIApp"] -# Fix for "os.getlogin()) OSError: [Errno 2] No such file or directory" # Add Plattform Check to fix the Issue that PWD not exist on Windows and so the ST2 CLI not working. # https://docs.python.org/3.8/library/pwd.html if platform.system() != "Windows": import pwd - +# Fix for "os.getlogin()) OSError: [Errno 2] No such file or directory" os.getlogin = lambda: pwd.getpwuid(os.getuid())[0] # How many seconds before the token actual expiration date we should consider the token as From 62c0a88deac55cec47b0cc03ce5457ae3b7a3d3e Mon Sep 17 00:00:00 2001 From: Eugen C <1533818+armab@users.noreply.github.com> Date: Tue, 28 Nov 2023 13:13:02 +0000 Subject: [PATCH 11/11] Reformat with black --- st2client/st2client/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/st2client/st2client/base.py b/st2client/st2client/base.py index 1389ada854..6c2fa94b55 100644 --- a/st2client/st2client/base.py +++ b/st2client/st2client/base.py @@ -44,7 +44,8 @@ # https://docs.python.org/3.8/library/pwd.html if platform.system() != "Windows": import pwd -# Fix for "os.getlogin()) OSError: [Errno 2] No such file or directory" + + # Fix for "os.getlogin()) OSError: [Errno 2] No such file or directory" os.getlogin = lambda: pwd.getpwuid(os.getuid())[0] # How many seconds before the token actual expiration date we should consider the token as