Skip to content
This repository has been archived by the owner on Apr 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #214 from Bidaya0/bugfix/saas_method_pool-store-he…
Browse files Browse the repository at this point in the history
…ader-alltime-instead-of-only-in-replay

Bugfix/saas method pool store header alltime instead of only in replay
  • Loading branch information
Bidaya0 authored Feb 11, 2022
2 parents ba06894 + ec9a580 commit 33a3d8a
Show file tree
Hide file tree
Showing 8 changed files with 852 additions and 8 deletions.
18 changes: 18 additions & 0 deletions .batect/agent_deco.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env sh

######################################################################
# @author : bidaya0 (bidaya0@$HOSTNAME)
# @file : agent_deco
# @created : 星期二 1月 25, 2022 18:17:45 CST
#
# @description :
######################################################################



if [ "$PYTHONAGENT" = "TRUE" ]; then
curl -X GET "${DONGTAI_IAST_BASE_URL}/api/v1/agent/download?url=${DONGTAI_IAST_BASE_URL}&language=python&projectName=${PROJECT_NAME}" -H "Authorization: Token ${DONGTAI_AGNET_TOKEN}" -o dongtai-agent-python.tar.gz -k
pip install dongtai-agent-python.tar.gz
fi

sh $@
11 changes: 11 additions & 0 deletions .batect/manage_run_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env sh

######################################################################
# @author : bidaya0 (bidaya0@$HOSTNAME)
# @file : manage_run_server
# @created : 星期二 1月 25, 2022 10:39:21 CST
#
# @description :
######################################################################

python manage.py runserver 0.0.0.0:8000
11 changes: 11 additions & 0 deletions .batect/manage_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env sh

######################################################################
# @author : bidaya0 (bidaya0@$HOSTNAME)
# @file : manage_run_server
# @created : 星期二 1月 25, 2022 10:39:21 CST
#
# @description :
######################################################################

python manage.py test
21 changes: 21 additions & 0 deletions DockerfileDev
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.7-slim
ARG VERSION
ENV DEBIAN_FRONTEND=noninteractive
ENV LANG=en_US.UTF-8
ENV TZ=Asia/Shanghai
ENV debug=true

RUN apt-get update -y \
&& apt install -y gcc make cmake libmariadb-dev curl



COPY requirements-test.txt /opt/dongtai/openapi/requirements.txt
RUN pip3 install -r /opt/dongtai/openapi/requirements.txt && mkdir -p /tmp/iast_cache/package

#COPY . /opt/dongtai/openapi
#RUN mv /opt/dongtai/openapi/*.jar /tmp/iast_cache/package/ && mv /opt/dongtai/openapi/*.tar.gz /tmp/

WORKDIR /opt/dongtai/openapi

CMD ["/usr/local/bin/uwsgi","--ini", "/opt/dongtai/openapi/conf/uwsgi.ini"]
16 changes: 8 additions & 8 deletions apiserver/report/handler/saas_method_pool_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ def save(self):
如果agent存在,保存数据
:return:
"""
headers = SaasMethodPoolHandler.parse_headers(self.http_req_header)
objs = [
ProjectSaasMethodPoolHeader(key=key,
agent_id=self.agent_id,
header_type=HeaderType.REQUEST)
for key in headers.keys()
]
ProjectSaasMethodPoolHeader.objects.bulk_create(objs, ignore_conflicts=True)
if self.http_replay:
# 保存数据至重放请求池
headers = SaasMethodPoolHandler.parse_headers(self.http_req_header)
objs = [
ProjectSaasMethodPoolHeader(key=key,
agent_id=self.agent_id,
header_type=HeaderType.REQUEST)
for key in headers.keys()
]
ProjectSaasMethodPoolHeader.objects.bulk_create(objs, ignore_conflicts=True)
replay_id = headers.get('dongtai-replay-id')
replay_type = headers.get('dongtai-replay-type')
relation_id = headers.get('dongtai-relation-id')
Expand Down
205 changes: 205 additions & 0 deletions batect
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
#!/usr/bin/env bash

{
set -euo pipefail

# This file is part of Batect.
# Do not modify this file. It will be overwritten next time you upgrade Batect.
# You should commit this file to version control alongside the rest of your project. It should not be installed globally.
# For more information, visit https://github.com/batect/batect.

VERSION="0.78.0"
CHECKSUM="${BATECT_DOWNLOAD_CHECKSUM:-bc65ac8e00dd23dd9d68130e2109e429993b769b79e081d262a79798c8c3784b}"
DOWNLOAD_URL_ROOT=${BATECT_DOWNLOAD_URL_ROOT:-"https://updates.batect.dev/v1/files"}
DOWNLOAD_URL=${BATECT_DOWNLOAD_URL:-"$DOWNLOAD_URL_ROOT/$VERSION/batect-$VERSION.jar"}
QUIET_DOWNLOAD=${BATECT_QUIET_DOWNLOAD:-false}

BATECT_WRAPPER_CACHE_DIR=${BATECT_CACHE_DIR:-"$HOME/.batect/cache"}
VERSION_CACHE_DIR="$BATECT_WRAPPER_CACHE_DIR/$VERSION"
JAR_PATH="$VERSION_CACHE_DIR/batect-$VERSION.jar"
BATECT_WRAPPER_DID_DOWNLOAD=false

SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

function main() {
if ! haveVersionCachedLocally; then
download
BATECT_WRAPPER_DID_DOWNLOAD=true
fi

checkChecksum
runApplication "$@"
}

function haveVersionCachedLocally() {
[ -f "$JAR_PATH" ]
}

function download() {
checkForCurl

mkdir -p "$VERSION_CACHE_DIR"
temp_file=$(mktemp)

if [[ $QUIET_DOWNLOAD == 'true' ]]; then
curl --silent --fail --show-error --location --output "$temp_file" "$DOWNLOAD_URL"
else
echo "Downloading Batect version $VERSION from $DOWNLOAD_URL..."
curl -# --fail --show-error --location --output "$temp_file" "$DOWNLOAD_URL"
fi

mv "$temp_file" "$JAR_PATH"
}

function checkChecksum() {
local_checksum=$(getLocalChecksum)

if [[ "$local_checksum" != "$CHECKSUM" ]]; then
echo "The downloaded version of Batect does not have the expected checksum. Delete '$JAR_PATH' and then re-run this script to download it again."
exit 1
fi
}

function getLocalChecksum() {
if [[ "$(uname)" == "Darwin" ]]; then
shasum -a 256 "$JAR_PATH" | cut -d' ' -f1
else
sha256sum "$JAR_PATH" | cut -d' ' -f1
fi
}

function runApplication() {
java_path=$(getPathToJava)
checkForJava "$java_path"

java_version_info=$(getJavaVersionInfo "$java_path")
checkJavaVersion "$java_version_info"

java_version=$(extractJavaVersion "$java_version_info")
java_version_major=$(extractJavaMajorVersion "$java_version")

if (( java_version_major >= 9 )); then
JAVA_OPTS=(--add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED)
else
JAVA_OPTS=()
fi

if [[ "$(uname -o 2>&1)" == "Msys" ]] && hash winpty 2>/dev/null && [ -t /dev/stdin ]; then
GIT_BASH_PTY_WORKAROUND=(winpty)
else
GIT_BASH_PTY_WORKAROUND=()
fi

BATECT_WRAPPER_SCRIPT_DIR="$SCRIPT_PATH" \
BATECT_WRAPPER_CACHE_DIR="$BATECT_WRAPPER_CACHE_DIR" \
BATECT_WRAPPER_DID_DOWNLOAD="$BATECT_WRAPPER_DID_DOWNLOAD" \
HOSTNAME="$HOSTNAME" \
exec \
${GIT_BASH_PTY_WORKAROUND[@]+"${GIT_BASH_PTY_WORKAROUND[@]}"} \
"$java_path" \
-Djava.net.useSystemProxies=true \
${JAVA_OPTS[@]+"${JAVA_OPTS[@]}"} \
-jar "$JAR_PATH" \
"$@"
}

function checkForCurl() {
if ! hash curl 2>/dev/null; then
echo "curl is not installed or not on your PATH. Please install it and try again." >&2
exit 1
fi
}

function getPathToJava() {
if useJavaHome; then
echo "$JAVA_HOME/bin/java"
else
echo "java"
fi
}

function useJavaHome() {
test -n "${JAVA_HOME+x}"
}

function checkForJava() {
local java_path="$1"

if ! hash "$java_path" 2>/dev/null; then
showJavaNotInstalledError
fi
}

function showJavaNotInstalledError() {
if useJavaHome; then
echo "JAVA_HOME is set to '$JAVA_HOME', but there is no Java executable at '$JAVA_HOME/bin/java'." >&2
else
echo "Java is not installed or not on your PATH. Please install it and try again." >&2
fi

exit 1
}

function checkJavaVersion() {
java_version_info="$1"
java_version=$(extractJavaVersion "$java_version_info")
java_version_major=$(extractJavaMajorVersion "$java_version")
java_version_minor=$(extractJavaMinorVersion "$java_version")

if (( java_version_major < 1 || ( java_version_major == 1 && java_version_minor <= 7 ) )); then
if useJavaHome; then
echo "The version of Java that is available in JAVA_HOME is version $java_version, but version 1.8 or greater is required." >&2
echo "If you have a newer version of Java installed, please make sure JAVA_HOME is set correctly." >&2
echo "JAVA_HOME takes precedence over any versions of Java available on your PATH." >&2
else
echo "The version of Java that is available on your PATH is version $java_version, but version 1.8 or greater is required." >&2
echo "If you have a newer version of Java installed, please make sure your PATH is set correctly." >&2
fi

exit 1
fi

if ! javaIs64Bit "$java_version_info"; then
if useJavaHome; then
echo "The version of Java that is available in JAVA_HOME is a 32-bit version, but Batect requires a 64-bit Java runtime." >&2
echo "If you have a 64-bit version of Java installed, please make sure JAVA_HOME is set correctly." >&2
echo "JAVA_HOME takes precedence over any versions of Java available on your PATH." >&2
else
echo "The version of Java that is available on your PATH is a 32-bit version, but Batect requires a 64-bit Java runtime." >&2
echo "If you have a 64-bit version of Java installed, please make sure your PATH is set correctly." >&2
fi

exit 1
fi
}

function getJavaVersionInfo() {
local java_path="$1"

"$java_path" -version 2>&1 || showJavaNotInstalledError
}

function extractJavaVersion() {
echo "$1" | grep version | sed -En ';s/.* version "([0-9]+)(\.([0-9]+))?.*".*/\1.\3/p;'
}

function extractJavaMajorVersion() {
java_version=$1

echo "${java_version%.*}"
}

function extractJavaMinorVersion() {
java_version=$1
java_version_minor="${java_version#*.}"

echo "${java_version_minor:-0}"
}

function javaIs64Bit() {
echo "$1" | grep -q '64-[Bb]it'
}

main "$@"
exit $?
}
Loading

0 comments on commit 33a3d8a

Please sign in to comment.