-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse flow filter configs and use it to update manifest
Signed-off-by: Mohamed Mahmoud <[email protected]>
- Loading branch information
1 parent
984b8e5
commit 4b21561
Showing
4 changed files
with
170 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/bin/bash | ||
|
||
MANIFEST_FILE="flow-capture.yml" | ||
MANIFEST_PATH="res" | ||
MANIFEST_OUTPUT_PATH="output" | ||
|
||
if ! command -v yq &> /dev/null | ||
then | ||
echo "yq binary not found, installing... " | ||
go install -mod='' github.com/mikefarah/yq/[email protected] | ||
fi | ||
|
||
function edit_manifest() { | ||
echo "Editing manifest file..." | ||
if [[ ! -d ${MANIFEST_OUTPUT_PATH} ]]; then | ||
mkdir -p ${MANIFEST_OUTPUT_PATH} > /dev/null | ||
cp ${MANIFEST_PATH}/${MANIFEST_FILE} ${MANIFEST_OUTPUT_PATH}/${MANIFEST_FILE} | ||
fi | ||
## replace the env variable in the manifest file | ||
echo "env: $1, env_value: $2" | ||
case "$1" in | ||
"interfaces") | ||
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"INTERFACES\").value|=\"$2\"" ${MANIFEST_OUTPUT_PATH}/${MANIFEST_FILE} | ||
;; | ||
"filter_enable") | ||
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"ENABLE_FLOW_FILTER\").value|=\"$2\"" ${MANIFEST_OUTPUT_PATH}/${MANIFEST_FILE} | ||
;; | ||
"filter_direction") | ||
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FLOW_FILTER_DIRECTION\").value|=\"$2\"" ${MANIFEST_OUTPUT_PATH}/${MANIFEST_FILE} | ||
;; | ||
"filter_cidr") | ||
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FLOW_FILTER_IP_CIDR\").value|=\"$2\"" ${MANIFEST_OUTPUT_PATH}/${MANIFEST_FILE} | ||
;; | ||
"filter_protocol") | ||
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FLOW_FILTER_PROTOCOL\").value|=\"$2\"" ${MANIFEST_OUTPUT_PATH}/${MANIFEST_FILE} | ||
;; | ||
"filter_sport") | ||
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FLOW_FILTER_SOURCE_PORT\").value|=\"$2\"" ${MANIFEST_OUTPUT_PATH}/${MANIFEST_FILE} | ||
;; | ||
"filter_dport") | ||
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FLOW_FILTER_DESTINATION_PORT\").value|=\"$2\"" ${MANIFEST_OUTPUT_PATH}/${MANIFEST_FILE} | ||
;; | ||
"filter_port") | ||
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FLOW_FILTER_PORT\").value|=\"$2\"" ${MANIFEST_OUTPUT_PATH}/${MANIFEST_FILE} | ||
;; | ||
"filter_sport_range") | ||
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FLOW_FILTER_SOURCE_PORT_RANGE\").value|=\"$2\"" ${MANIFEST_OUTPUT_PATH}/${MANIFEST_FILE} | ||
;; | ||
"filter_dport_range") | ||
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FLOW_FILTER_DESTINATION_PORT_RANGE\").value|=\"$2\"" ${MANIFEST_OUTPUT_PATH}/${MANIFEST_FILE} | ||
;; | ||
"filter_port_range") | ||
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FLOW_FILTER_PORT_RANGE\").value|=\"$2\"" ${MANIFEST_OUTPUT_PATH}/${MANIFEST_FILE} | ||
;; | ||
"filter_icmp_type") | ||
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FLOW_FILTER_ICMP_TYPE\").value|=\"$2\"" ${MANIFEST_OUTPUT_PATH}/${MANIFEST_FILE} | ||
;; | ||
"filter_icmp_code") | ||
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FLOW_FILTER_ICMP_CODE\").value|=\"$2\"" ${MANIFEST_OUTPUT_PATH}/${MANIFEST_FILE} | ||
;; | ||
"filter_peer_ip") | ||
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FLOW_FILTER_PEER_IP\").value|=\"$2\"" ${MANIFEST_OUTPUT_PATH}/${MANIFEST_FILE} | ||
;; | ||
"filter_action") | ||
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FLOW_FILTER_ACTION\").value|=\"$2\"" ${MANIFEST_OUTPUT_PATH}/${MANIFEST_FILE} | ||
;; | ||
esac | ||
|
||
} |