Skip to content

Commit 8c63bc3

Browse files
authored
Housekeeping: lint remaining scripts in logging/bin (#784)
1 parent e4a36d1 commit 8c63bc3

10 files changed

+689
-716
lines changed

logging/bin/deploy_logging_azmonitor.sh

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@
33
# Copyright © 2020, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
44
# SPDX-License-Identifier: Apache-2.0
55

6-
cd "$(dirname $BASH_SOURCE)/../.."
6+
cd "$(dirname "$BASH_SOURCE")/../.." || exit 1
77
source logging/bin/common.sh
88

9-
# temp file used to capture command output
10-
tmpfile=$TMP_DIR/output.txt
11-
rm -f tmpfile
12-
13-
if [ "$(kubectl get ns $LOG_NS -o name 2>/dev/null)" == "" ]; then
14-
kubectl create ns $LOG_NS
9+
if [ "$(kubectl get ns "$LOG_NS" -o name 2> /dev/null)" == "" ]; then
10+
kubectl create ns "$LOG_NS"
1511
fi
1612

1713
set -e
@@ -25,6 +21,5 @@ log_notice "Deploying logging components to the [$LOG_NS] namespace [$(date)]"
2521
log_info "STEP 1: Deploying Fluent Bit"
2622
logging/bin/deploy_fluentbit_azmonitor.sh
2723

28-
2924
log_notice "The deployment of logging components has completed [$(date)]"
3025
echo ""

logging/bin/deploy_servicemonitors_openshift.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,37 @@
33
# Copyright © 2021, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
44
# SPDX-License-Identifier: Apache-2.0
55

6-
cd "$(dirname $BASH_SOURCE)/../.."
6+
cd "$(dirname "$BASH_SOURCE")/../.." || exit
77
source logging/bin/common.sh
88

9-
this_script=`basename "$0"`
9+
this_script=$(basename "$0")
1010

1111
log_debug "Script [$this_script] has started [$(date)]"
1212

1313
# Deploy ServiceMonitors?
1414
DEPLOY_SERVICEMONITORS=${DEPLOY_SERVICEMONITORS:-false}
1515

1616
if [ "$DEPLOY_SERVICEMONITORS" != "true" ]; then
17-
log_info "Environment variable [DEPLOY_SERVICEMONITORS] is not set to 'true'; exiting WITHOUT deploying ServiceMonitors"
18-
exit
17+
log_info "Environment variable [DEPLOY_SERVICEMONITORS] is not set to 'true'; exiting WITHOUT deploying ServiceMonitors"
18+
exit
1919
fi
2020

2121
EVENTROUTER_ENABLE=${EVENTROUTER_ENABLE:-true}
2222
if [ "$EVENTROUTER_ENABLE" == "true" ]; then
23-
# Eventrouter ServiceMonitor
24-
kubectl apply -n $LOG_NS -f monitoring/monitors/kube/podMonitor-eventrouter.yaml
23+
# Eventrouter ServiceMonitor
24+
kubectl apply -n "$LOG_NS" -f monitoring/monitors/kube/podMonitor-eventrouter.yaml
2525
fi
2626

2727
ELASTICSEARCH_ENABLE=${ELASTICSEARCH_ENABLE:-true}
2828
if [ "$ELASTICSEARCH_ENABLE" == "true" ]; then
29-
# Elasticsearch ServiceMonitor
30-
kubectl apply -n $LOG_NS -f monitoring/monitors/logging/serviceMonitor-elasticsearch.yaml
29+
# Elasticsearch ServiceMonitor
30+
kubectl apply -n "$LOG_NS" -f monitoring/monitors/logging/serviceMonitor-elasticsearch.yaml
3131
fi
3232

3333
FLUENT_BIT_ENABLED=${FLUENT_BIT_ENABLED:-true}
3434
if [ "$FLUENT_BIT_ENABLED" == "true" ]; then
35-
# Fluent Bit ServiceMonitors
36-
kubectl apply -n $LOG_NS -f monitoring/monitors/logging/serviceMonitor-fluent-bit-v2.yaml
35+
# Fluent Bit ServiceMonitors
36+
kubectl apply -n "$LOG_NS" -f monitoring/monitors/logging/serviceMonitor-fluent-bit-v2.yaml
3737
fi
3838

3939
log_info "ServiceMonitors have been deployed."

logging/bin/offboard.sh

Lines changed: 87 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -3,82 +3,78 @@
33
# Copyright © 2021, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
44
# SPDX-License-Identifier: Apache-2.0
55

6-
cd "$(dirname $BASH_SOURCE)/../.."
6+
cd "$(dirname "$BASH_SOURCE")/../.." || exit
77
source logging/bin/common.sh
88

99
source logging/bin/apiaccess-include.sh
1010
source logging/bin/secrets-include.sh
1111
source logging/bin/rbac-include.sh
1212

13-
this_script=`basename "$0"`
14-
13+
this_script=$(basename "$0")
1514

1615
function show_usage {
17-
log_message "Usage: $this_script --namespace NAMESPACE [--tenant TENANT] [OPTIONS]"
18-
log_message ""
19-
log_message "'Offboards' either the specified SAS Viya deployment (namespace) or the specified tenant within that deployment. This removes the ability to limit admins to the SAS Viya deployment (or a single tenant within a given deployment)."
20-
log_message "The offboarding process deletes the security access controls and the associated OpenSearch Dashboards tenant space (including any saved OpenSearch Dashboards content (e.g. visualizations, dashboards, etc.)."
21-
log_message ""
22-
log_message " Arguments:"
23-
log_message " -ns, --namespace NAMESPACE - (Required) The SAS Viya deployment/Kubernetes Namespace to which access should be removed."
24-
log_message " -t, --tenant TENANT - (Optional) The tenant within the specific SAS Viya deployment/Kubernetes Namespace to which access should be removed."
25-
log_message ""
26-
#log_message " Options:"
27-
#log_message ""
16+
log_message "Usage: $this_script --namespace NAMESPACE [--tenant TENANT] [OPTIONS]"
17+
log_message ""
18+
log_message "'Offboards' either the specified SAS Viya deployment (namespace) or the specified tenant within that deployment. This removes the ability to limit admins to the SAS Viya deployment (or a single tenant within a given deployment)."
19+
log_message "The offboarding process deletes the security access controls and the associated OpenSearch Dashboards tenant space (including any saved OpenSearch Dashboards content (e.g. visualizations, dashboards, etc.)."
20+
log_message ""
21+
log_message " Arguments:"
22+
log_message " -ns, --namespace NAMESPACE - (Required) The SAS Viya deployment/Kubernetes Namespace to which access should be removed."
23+
log_message " -t, --tenant TENANT - (Optional) The tenant within the specific SAS Viya deployment/Kubernetes Namespace to which access should be removed."
24+
log_message ""
25+
#log_message " Options:"
26+
#log_message ""
2827
}
2928

30-
3129
# set flag indicating wrapper/driver script being run
3230
export LOGGING_DRIVER=true
3331

34-
3532
#
3633
#Handle arguments and parameters
3734
#
3835
POS_PARMS=""
3936

40-
while (( "$#" )); do
41-
case "$1" in
42-
-ns|--namespace)
43-
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
44-
namespace=$2
45-
shift 2
46-
else
47-
log_error "A value for parameter [NAMESPACE] has not been provided." >&2
37+
while (("$#")); do
38+
case "$1" in
39+
-ns | --namespace)
40+
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
41+
namespace=$2
42+
shift 2
43+
else
44+
log_error "A value for parameter [NAMESPACE] has not been provided." >&2
45+
show_usage
46+
exit 2
47+
fi
48+
;;
49+
-t | --tenant)
50+
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
51+
tenant=$2
52+
shift 2
53+
else
54+
log_error "A value for parameter [TENANT] has not been provided." >&2
55+
show_usage
56+
exit 2
57+
fi
58+
;;
59+
-h | --help)
4860
show_usage
49-
exit 2
50-
fi
51-
;;
52-
-t|--tenant)
53-
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
54-
tenant=$2
55-
shift 2
56-
else
57-
log_error "A value for parameter [TENANT] has not been provided." >&2
61+
exit
62+
;;
63+
--*= | -*) # unsupported flags
64+
log_error "Unsupported flag $1" >&2
5865
show_usage
59-
exit 2
60-
fi
61-
;;
62-
-h|--help)
63-
show_usage
64-
exit
65-
;;
66-
-*|--*=) # unsupported flags
67-
log_error "Unsupported flag $1" >&2
68-
show_usage
69-
exit 1
70-
;;
66+
exit 1
67+
;;
7168
*) # preserve positional arguments
72-
POS_PARMS="$POS_PARMS $1"
73-
shift
74-
;;
75-
esac
69+
POS_PARMS="$POS_PARMS $1"
70+
shift
71+
;;
72+
esac
7673
done
7774

7875
# set positional arguments in their proper place
7976
eval set -- "$POS_PARMS"
8077

81-
8278
# No positional parameters are supported
8379
if [ "$#" -ge 1 ]; then
8480
log_error "Unexpected additional arguments were found; exiting."
@@ -87,36 +83,38 @@ if [ "$#" -ge 1 ]; then
8783
fi
8884

8985
# Convert namespace and tenant to all lower-case
90-
namespace=$(echo "$namespace"| tr '[:upper:]' '[:lower:]')
91-
tenant=$(echo "$tenant"| tr '[:upper:]' '[:lower:]')
86+
namespace=$(echo "$namespace" | tr '[:upper:]' '[:lower:]')
87+
tenant=$(echo "$tenant" | tr '[:upper:]' '[:lower:]')
9288

9389
# validation of input args
9490
if [ "$namespace" == "global" ]; then
95-
log_error "Invalid namespace value specified; you can NOT offboard the [global] namespace."
96-
exit 1
91+
log_error "Invalid namespace value specified; you can NOT offboard the [global] namespace."
92+
exit 1
9793
fi
9894

99-
validateNamespace $namespace
95+
validateNamespace "$namespace"
10096

10197
if [ -n "$tenant" ]; then
102-
validateTenantID $tenant
98+
validateTenantID "$tenant"
10399

104-
nst="${namespace}_${tenant}"
105-
index_nst="${namespace}-__${tenant}__"
100+
nst="${namespace}_${tenant}"
101+
index_nst="${namespace}-__${tenant}__"
106102
else
107-
nst="$namespace"
108-
index_nst="${namespace}"
103+
nst="$namespace"
104+
# shellcheck disable=SC2034
105+
index_nst="${namespace}"
109106
fi
110107

111108
# OpenSearch Dashboards tenant space
112109
ktenant=$nst
113110

114111
if [ -n "$tenant" ]; then
115-
tenant_description="An OpenSearch Dashboards tenant space for tenant [$tenant] within SAS Viya deployment (namespace) [$namespace]."
116-
log_notice "Offboarding tenant [$tenant] within namespace [$namespace] [$(date)]"
112+
tenant_description="An OpenSearch Dashboards tenant space for tenant [$tenant] within SAS Viya deployment (namespace) [$namespace]."
113+
log_notice "Offboarding tenant [$tenant] within namespace [$namespace] [$(date)]"
117114
else
118-
tenant_description="An OpenSearch Dashboards tenant space for SAS Viya deployment (namespace) [$namespace]."
119-
log_notice "Offboarding namespace [$namespace] [$(date)]"
115+
# shellcheck disable=SC2034
116+
tenant_description="An OpenSearch Dashboards tenant space for SAS Viya deployment (namespace) [$namespace]."
117+
log_notice "Offboarding namespace [$namespace] [$(date)]"
120118
fi
121119

122120
#
@@ -134,53 +132,52 @@ get_sec_api_url
134132

135133
# Delete OpenSearch Dashboards tenant space (if it exists)
136134
if kibana_tenant_exists "$ktenant"; then
137-
delete_kibana_tenant "$ktenant"
138-
rc=$?
139-
if [ "$rc" == "0" ]; then
140-
add_notice " "
141-
add_notice " The OpenSearch Dashboards tenant space [$ktenant] has been deleted. "
142-
add_notice " "
143-
else
144-
log_error "Problems were encountered while attempting to delete tenant space [$ktenant]."
145-
exit 1
146-
fi
135+
delete_kibana_tenant "$ktenant"
136+
rc=$?
137+
if [ "$rc" == "0" ]; then
138+
add_notice " "
139+
add_notice " The OpenSearch Dashboards tenant space [$ktenant] has been deleted. "
140+
add_notice " "
141+
else
142+
log_error "Problems were encountered while attempting to delete tenant space [$ktenant]."
143+
exit 1
144+
fi
147145
else
148-
log_warn "The OpenSearch Dashboards tenant space [$ktenant] does not exist and, therefore, could not be deleted."
146+
log_warn "The OpenSearch Dashboards tenant space [$ktenant] does not exist and, therefore, could not be deleted."
149147
fi
150148

151149
# Delete ES index containing tenant content
152-
kibana_index_name=".kibana_*_$(echo "$ktenant"|tr -d _)"
153-
response=$(curl -s -o /dev/null -w "%{http_code}" -XDELETE "${es_api_url}/$kibana_index_name" --user $ES_ADMIN_USER:$ES_ADMIN_PASSWD --insecure)
150+
kibana_index_name=".kibana_*_$(echo "$ktenant" | tr -d _)"
151+
response=$(curl -s -o /dev/null -w "%{http_code}" -XDELETE "${es_api_url}/$kibana_index_name" --user "$ES_ADMIN_USER":"$ES_ADMIN_PASSWD" --insecure)
154152
if [[ $response == 2* ]]; then
155-
log_info "Deleted index [$kibana_index_name]. [$response]"
153+
log_info "Deleted index [$kibana_index_name]. [$response]"
156154
else
157-
log_warn "There was an issue deleting the index [$kibana_index_name] holding content related to OpenSearch Dashboards tenant space [$ktenant]. You may need to manually delete this index. [$response]"
155+
log_warn "There was an issue deleting the index [$kibana_index_name] holding content related to OpenSearch Dashboards tenant space [$ktenant]. You may need to manually delete this index. [$response]"
158156
fi
159157

160-
response=$(curl -s -o /dev/null -w "%{http_code}" -XDELETE "${es_api_url}/${kibana_index_name}_*" --user $ES_ADMIN_USER:$ES_ADMIN_PASSWD --insecure)
158+
response=$(curl -s -o /dev/null -w "%{http_code}" -XDELETE "${es_api_url}/${kibana_index_name}_*" --user "$ES_ADMIN_USER":"$ES_ADMIN_PASSWD" --insecure)
161159
if [[ $response == 2* ]]; then
162-
log_info "Deleted index [${kibana_index_name}_*]. [$response]"
160+
log_info "Deleted index [${kibana_index_name}_*]. [$response]"
163161
else
164-
log_warn "There was an issue deleting the index [${kibana_index_name}_*] holding content related to OpenSearch Dashboards tenant space [$ktenant]. You may need to manually delete this index. [$response]"
162+
log_warn "There was an issue deleting the index [${kibana_index_name}_*] holding content related to OpenSearch Dashboards tenant space [$ktenant]. You may need to manually delete this index. [$response]"
165163
fi
166164

167-
168165
# Delete access controls
169-
./logging/bin/security_delete_rbac.sh $namespace $tenant
166+
./logging/bin/security_delete_rbac.sh "$namespace" "$tenant"
170167

171168
# Delete Grafana Datasource utility user (if exists)
172169
grfds_user="${nst}_grafana_ds"
173-
if user_exists $grfds_user; then
174-
log_verbose "Removing the [$grfds_user] utility account."
175-
delete_user $grfds_user
170+
if user_exists "$grfds_user"; then
171+
log_verbose "Removing the [$grfds_user] utility account."
172+
delete_user "$grfds_user"
176173
fi
177174

178175
# Reminder that users are not deleted
179176
add_notice " "
180177
add_notice " The off-boarding process does NOT remove any users. If there "
181178
add_notice " are users which are no longer needed after off-boarding the "
182179
if [ -n "$tenant" ]; then
183-
add_notice " tenant [$tenant] within the "
180+
add_notice " tenant [$tenant] within the "
184181
fi
185182
add_notice " SAS Viya deployment/namespace of [$namespace] "
186183
add_notice " you must delete those users manually, either through the "
@@ -197,7 +194,7 @@ echo ""
197194

198195
# Exit with an overall success/failure message
199196
if [ -n "$tenant" ]; then
200-
log_notice "Successfully offboarded tenant [$tenant] within namespace [$namespace] [$(date)]"
197+
log_notice "Successfully offboarded tenant [$tenant] within namespace [$namespace] [$(date)]"
201198
else
202-
log_notice "Successfully offboarded namespace [$namespace] [$(date)]"
199+
log_notice "Successfully offboarded namespace [$namespace] [$(date)]"
203200
fi

0 commit comments

Comments
 (0)