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: pip causing app inspect failures and NOTICE #224

Merged
merged 4 commits into from
Jun 14, 2021
Merged
Changes from 3 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
45 changes: 28 additions & 17 deletions splunk_add_on_ucc_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import argparse
import json
from defusedxml import cElementTree as defused_et
from pathlib import Path
import stat

from .uccrestbuilder.global_config import (
GlobalConfigBuilderSchema,
GlobalConfigPostProcessor,
Expand Down Expand Up @@ -299,23 +302,31 @@ def _install_libs(requirements, ucc_target, installer="python3"):
else:
logging.info(f" Not using common requirements")

if os.path.exists(os.path.join(path,"lib","py2", "requirements.txt")):
logging.info(f" Uses py2 requirements")
_install_libs(requirements=os.path.join(path,"lib","py2", "requirements.txt"), installer="python2", ucc_target=os.path.join(ucc_lib_target, "py2"))
elif os.path.exists(os.path.join(os.path.abspath(os.path.join(path, os.pardir)), "requirements_py2.txt")):
logging.info(f" Uses py2 requirements")
_install_libs(requirements=os.path.join(os.path.abspath(os.path.join(path, os.pardir)), "requirements_py2.txt"), installer="python2", ucc_target=os.path.join(ucc_lib_target, "py2"))
else:
logging.info(f" Not using py2 requirements")

if os.path.exists(os.path.join(path, "lib","py3","requirements.txt")):
logging.info(f" Uses py3 requirements")
_install_libs(requirements=os.path.join(path,"lib", "py3","requirements.txt"), ucc_target=os.path.join(ucc_lib_target, "py3"))
elif os.path.exists(os.path.join(os.path.abspath(os.path.join(path, os.pardir)), "requirements_py3.txt")):
logging.info(f" Uses py3 requirements")
_install_libs(requirements=os.path.join(os.path.abspath(os.path.join(path, os.pardir)), "requirements_py3.txt"), installer="python3", ucc_target=os.path.join(ucc_lib_target, "py2"))
else:
logging.info(f" Not using py3 requirements")

#Prevent certain packages from being included pip could be dangerous others are just wasted space
noshipdirs = ['setuptools', 'bin', 'pip', 'distribute', 'wheel']
p = Path(ucc_lib_target)
for nsd in noshipdirs:
try:
#Glob can return FileNotFoundError exception if no match
for o in p.glob(nsd + '*'):
if o.is_dir():
logging.info(f" removing directory {o} from output must not ship")
shutil.rmtree(o)
ryanfaircloth marked this conversation as resolved.
Show resolved Hide resolved
except FileNotFoundError:
pass

#Remove execute bit from any object in lib
NO_USER_EXEC = ~stat.S_IEXEC
NO_GROUP_EXEC = ~stat.S_IXGRP
NO_OTHER_EXEC = ~stat.S_IXOTH
NO_EXEC = NO_USER_EXEC & NO_GROUP_EXEC & NO_OTHER_EXEC

for o in p.rglob("*"):
if not o.is_dir() and os.access(o, os.X_OK):
logging.info(f" fixing {o} execute bit")
current_permissions = stat.S_IMODE(os.lstat(o).st_mode)
os.chmod(o, current_permissions & NO_EXEC)
ryanfaircloth marked this conversation as resolved.
Show resolved Hide resolved


def remove_files(path):
Expand Down