-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-link-perms
executable file
·43 lines (36 loc) · 1.36 KB
/
check-link-perms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
# Update the links address as required. This finds links that start with "http"
# Get the enterprise branch
PR_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
REPO_PATH="$(git rev-parse --show-toplevel)"
# Scrape all links from the webpage
#links=$(curl -s https://docs.openshift.com/container-platform/4.14/release_notes/ocp-4-14-release-notes.html | grep -o 'href="http[^"]*"' | sed 's/href="//' | sed 's/"//')
#protected_links=()
# Read the content from the local file
content=$(cat "$REPO_PATH/release_notes/ocp-4-14-release-notes.adoc")
echo "$REPO_PATH/release_notes/ocp-4-14-release-notes.adoc"
#echo "Content:"
#echo "$content"
# Extract links from the content
links=$(echo "$content" | grep -o 'https://issues[^]]*' | sed 's/\[.*//')
protected_links=()
# Iterate over the links and check their authorization status
for link in $links
do
response=$(curl -I "$link" 2>&1)
if echo "$response" | grep -q "permissionViolation"; then
echo "The link $link requires authentication."
protected_links+=("$link")
else
echo "The link $link does not require authentication."
fi
done
# Print the list of links that require authentication
if [ ${#protected_links[@]} -eq 0 ]; then
echo "No links require authentication."
exit 0
else
echo "Links that require authentication:"
printf '%s\n' "${protected_links[@]}"
exit 1
fi