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

Improved config file loading #340

Merged
merged 1 commit into from
Sep 2, 2021
Merged
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
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ ENV APP_SRC_DIR=/usr/local/src \
GOARCH=amd64 \
GOOS=linux \
CGO_ENABLED=0 \
NVD_EXCLUDE_TYPES="o,h" \
PATH=/usr/local/src/:${PATH}:/opt/gradle/bin:/opt/apache-maven/bin:/usr/local/go/bin:/opt/sl-cli:/opt/phpsast/vendor/bin:

COPY --from=builder /usr/local/bin/shiftleft /usr/local/bin
Expand Down
1 change: 1 addition & 0 deletions ci/Dockerfile-csharp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ ENV APP_SRC_DIR=/usr/local/src \
GOARCH=amd64 \
GOOS=linux \
CGO_ENABLED=0 \
NVD_EXCLUDE_TYPES="o,h" \
PATH=/usr/local/src/:${PATH}:/usr/local/go/bin:/opt/sl-cli:

COPY --from=builder /usr/local/bin/shiftleft /usr/local/bin
Expand Down
1 change: 1 addition & 0 deletions ci/Dockerfile-dynamic-lang
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ ENV APP_SRC_DIR=/usr/local/src \
DEPSCAN_CMD="/usr/local/bin/depscan" \
PMD_CMD="" \
PYTHONUNBUFFERED=1 \
NVD_EXCLUDE_TYPES="o,h" \
PATH=/usr/local/src/:${PATH}:

COPY --from=builder /usr/local/bin/shiftleft /usr/local/bin
Expand Down
1 change: 1 addition & 0 deletions ci/Dockerfile-java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ ENV APP_SRC_DIR=/usr/local/src \
GOARCH=amd64 \
GOOS=linux \
CGO_ENABLED=0 \
NVD_EXCLUDE_TYPES="o,h" \
PATH=/usr/local/src/:${PATH}:/opt/sbt/bin:/opt/gradle/bin:/opt/apache-maven/bin:/usr/local/go/bin:/opt/sl-cli:

COPY --from=builder /usr/local/bin/shiftleft /usr/local/bin
Expand Down
1 change: 1 addition & 0 deletions ci/Dockerfile-oss
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ ENV APP_SRC_DIR=/usr/local/src \
GOARCH=amd64 \
GOOS=linux \
CGO_ENABLED=0 \
NVD_EXCLUDE_TYPES="o,h" \
PATH=/usr/local/src/:${PATH}:/opt/gradle/bin:/opt/apache-maven/bin:/usr/local/go/bin:

COPY --from=builder /usr/local/bin/shiftleft /usr/local/bin
Expand Down
30 changes: 16 additions & 14 deletions lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def get(configName, default_value=None):
try:
value = runtimeValues.get(configName)
if value is None:
value = os.environ.get(configName.upper())
value = os.environ.get(configName.replace("-", "_").upper())
if value is None:
value = getattr(sys.modules[__name__], configName, None)
if value is None:
Expand Down Expand Up @@ -1591,18 +1591,20 @@ def __hash__(self):

def reload():
# Load any .sastscanrc file from the root
scanrc = os.path.join(os.getcwd(), ".sastscanrc")
if get("SAST_SCAN_SRC_DIR"):
scanrc = os.path.join(get("SAST_SCAN_SRC_DIR"), ".sastscanrc")
if os.path.exists(scanrc):
with open(scanrc, "r") as rcfile:
try:
new_config = json.loads(rcfile.read())
for key, value in new_config.items():
exis_config = get(key)
if isinstance(exis_config, dict):
exis_config.update(value)
set(key, exis_config)
else:
set(key, value)
except Exception:
print(".sastscanrc should be a valid json file")
if os.path.exists(scanrc):
with open(scanrc, "r") as rcfile:
try:
print("Overriding the config with .sastscanrc")
new_config = json.loads(rcfile.read())
for key, value in new_config.items():
exis_config = get(key)
if isinstance(exis_config, dict):
exis_config.update(value)
set(key, exis_config)
else:
set(key, value)
except Exception:
print(".sastscanrc should be a valid json file")