Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow defining arbitrary python interpreter for newer distros #108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
225 changes: 217 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,231 @@
# Created by https://www.gitignore.io/api/java,gradle
# Created by https://www.toptal.com/developers/gitignore/api/python,java,gradle
# Edit at https://www.toptal.com/developers/gitignore?templates=python,java,gradle

### Java ###
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml

# ruff
.ruff_cache/

# LSP config files
pyrightconfig.json

### Gradle ###
.gradle
.idea
/build/
/docker/rundeck/plugins/py-winrm-plugin-*
/docker/resources/*.xml
**/build/
!src/**/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Avoid ignore Gradle wrappper properties
!gradle-wrapper.properties

# Cache of project
.gradletasknamecache

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties
# Eclipse Gradle plugin generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath

### Gradle Patch ###
# Java heap dump
*.hprof

# End of https://www.gitignore.io/api/java,gradle
# End of https://www.toptal.com/developers/gitignore/api/python,java,gradle

/docker/rundeck/plugins/py-winrm-plugin-*
/docker/resources/*.xml
69 changes: 57 additions & 12 deletions contents/winrm-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import colored_formatter
from colored_formatter import ColoredFormatter
import kerberosauth

import sysconfig
import os.path

#checking and importing dependencies
ISPY3 = sys.version_info[0] == 3
Expand All @@ -19,6 +20,7 @@
HAS_NTLM = False
HAS_CREDSSP = False
HAS_PEXPECT = False
SYSTEM_INTERPRETER = False

if ISPY3:
from inspect import getfullargspec as getargspec
Expand Down Expand Up @@ -70,6 +72,12 @@
except ImportError as e:
HAS_PEXPECT = False

try:
externally_managed_path = os.path.join(sysconfig.get_path("stdlib"), "EXTERNALLY-MANAGED")
SYSTEM_INTERPRETER = os.path.exists(externally_managed_path)
except:
SYSTEM_INTERPRETER = False

log_level = 'INFO'
if os.environ.get('RD_JOB_LOGLEVEL') == 'DEBUG':
log_level = 'DEBUG'
Expand Down Expand Up @@ -207,28 +215,65 @@
log.debug("------------------------------------------")


URLLIB_ERRORMESSAGE_BASE = "requests and urllib3 not installed"
WINRM_ERRORMESSAGE_BASE = "pywinrm not installed"
KRB_ERRORMESSAGE_BASE = "requests-kerberos not installed"
PEXPECT_ERRORMESSAGE_BASE = "pexpect not installed"
CREDSSP_ERRORMESSAGE_BASE = "pywinrm[credssp] not installed"
NTLM_ERRORMESSAGE_BASE = "requests-ntlm not installed"

if SYSTEM_INTERPRETER:
import configparser
externally_managed_file = configparser.RawConfigParser()
externally_managed_file.read(externally_managed_path)
SYSTEM_INTERPRETER_ERRORMESSAGE=externally_managed_file.get("externally-managed", "Error")

ERRORMESSAGE = ", please install it using your systems package manager or consider using a virtual environment.\n{}".format(SYSTEM_INTERPRETER_ERRORMESSAGE)
URLLIB_ERRORMESSAGE = "{}{}".format(URLLIB_ERRORMESSAGE_BASE, ERRORMESSAGE)
WINRM_ERRORMESSAGE = "{}{}".format(WINRM_ERRORMESSAGE_BASE, ERRORMESSAGE)
KRB_ERRORMESSAGE = "{}{}".format(KRB_ERRORMESSAGE_BASE, ERRORMESSAGE)
PEXPECT_ERRORMESSAGE = "{}{}".format(PEXPECT_ERRORMESSAGE_BASE, ERRORMESSAGE)
CREDSSP_ERRORMESSAGE = "{}{}".format(CREDSSP_ERRORMESSAGE_BASE, ERRORMESSAGE)
NTLM_ERRORMESSAGE = "{}{}".format(NTLM_ERRORMESSAGE_BASE, ERRORMESSAGE)
else:
URLLIB_ERRORMESSAGE = "{}, try: {} -m pip install requests urllib3".format(URLLIB_ERRORMESSAGE_BASE, sys.executable)
WINRM_ERRORMESSAGE = "{}, try: {} -m pip install pywinrm".format(WINRM_ERRORMESSAGE_BASE, sys.executable)
KRB_ERRORMESSAGE = "{}, try: {} -m pip install requests-kerberos".format(KRB_ERRORMESSAGE_BASE, sys.executable)
PEXPECT_ERRORMESSAGE = "{}, try: {} -m pip install pexpect".format(PEXPECT_ERRORMESSAGE_BASE, sys.executable)
CREDSSP_ERRORMESSAGE = "{}, try: {} -m pip install pywinrm[credssp]".format(CREDSSP_ERRORMESSAGE_BASE, sys.executable)
NTLM_ERRORMESSAGE = "{}, try: {} -m pip install requests-ntlm".format(NTLM_ERRORMESSAGE_BASE, sys.executable)


if enabledHttpDebug:
httpclient_logging_patch(logging.DEBUG)

PACKAGE_ERROR = False

if not URLLIB_INSTALLED:
log.error("request and urllib3 not installed, try: pip install requests && pip install urllib3")
sys.exit(1)
log.error(URLLIB_ERRORMESSAGE)
PACKAGE_ERROR = True

if not WINRM_INSTALLED:
log.error("winrm not installed, try: pip install pywinrm")
sys.exit(1)
log.error(WINRM_ERRORMESSAGE)
PACKAGE_ERROR = True

if authentication == "kerberos" and not KRB_INSTALLED:
log.error("Kerberos not installed, try: pip install requests-kerberos")
sys.exit(1)
log.error(KRB_ERRORMESSAGE)
PACKAGE_ERROR = True

if authentication == "kerberos" and not HAS_PEXPECT:
log.error("pexpect not installed, try: pip install pexpect")
sys.exit(1)
log.error(PEXPECT_ERRORMESSAGE)
PACKAGE_ERROR = True

if authentication == "credssp" and not HAS_CREDSSP:
log.error("CredSSP not installed, try: pip install pywinrm[credssp]")
sys.exit(1)
log.error(CREDSSP_ERRORMESSAGE)
PACKAGE_ERROR = True

if authentication == "ntlm" and not HAS_NTLM:
log.error("NTLM not installed, try: pip install requests_ntlm")
log.error(NTLM_ERRORMESSAGE)
PACKAGE_ERROR = True

if PACKAGE_ERROR:
sys.exit(1)

arguments={}
Expand Down
Loading