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

feat: added unsupported apis in report #637

Merged
merged 5 commits into from
Feb 8, 2023
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
62 changes: 62 additions & 0 deletions tools/apigee-sackmesser/cmd/report/helpers/companies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# <http://www.apache.org/licenses/LICENSE-2.0>
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

echo "<h3>Companies</h3>" >> "$report_html"

mkdir -p "$export_folder/$organization/config/resources/edge/env/$environment/company"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/company instead of /companies but I see the existing implementation has an inconsistent approach for dir names of other resources, so I won't request this change

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raised #644 to track this later


sackmesser list "organizations/$organization/companies"| jq -r -c '.[]|.' | while read -r companyname; do
sackmesser list "organizations/$organization/companies/$(urlencode "$companyname")" > "$export_folder/$organization/config/resources/edge/env/$environment/company/$(urlencode "$companyname")".json
done

if ls "$export_folder/$organization/config/resources/edge/env/$environment/company"/*.json 1> /dev/null 2>&1; then
jq -n '[inputs]' "$export_folder/$organization/config/resources/edge/env/$environment/company"/*.json > "$export_folder/$organization/config/resources/edge/env/$environment/companies".json
fi

echo "<div><table id=\"company-lint\" data-toggle=\"table\" class=\"table\">" >> "$report_html"
echo "<thead class=\"thead-dark\"><tr>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"id\">Name</th>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"name\">Display Name</th>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"status\">Status</th>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"apps\">Apps</th>" >> "$report_html"
echo "</tr></thead>" >> "$report_html"

echo "<tbody class=\"mdc-data-table__content\">" >> "$report_html"

if [ -f "$export_folder/$organization/config/resources/edge/env/$environment/companies".json ]; then
jq -c '.[]' "$export_folder/$organization/config/resources/edge/env/$environment/companies".json | while read i; do
name=$(echo "$i" | jq -r '.name')
displayName=$(echo "$i" | jq -r '.displayName')
_status=$(echo "$i" | jq -r '.status')
apps=$(echo "$i" | jq -r '.apps[]?')

if [ $_status = "active" ]
then
status="✅"
else
status="❌"
fi

echo "<tr class=\"$highlightclass\">" >> "$report_html"
echo "<td>$name</td>" >> "$report_html"
echo "<td>"$displayName"</td>" >> "$report_html"
echo "<td>$status</td>" >> "$report_html"
echo "<td>$apps</td>" >> "$report_html"
echo "</tr>" >> "$report_html"
done
fi

echo "</tbody></table></div>" >> "$report_html"
93 changes: 93 additions & 0 deletions tools/apigee-sackmesser/cmd/report/helpers/companyapps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash

# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# <http://www.apache.org/licenses/LICENSE-2.0>
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

echo "<h3>Company Apps</h3>" >> "$report_html"

mkdir -p "$export_folder/$organization/config/resources/edge/env/$environment/companyapps"

sackmesser list "organizations/$organization/companies" | jq -r -c '.[]|.' | while read -r companyname; do
loginfo "download company: $companyname"
mkdir "$export_folder/$organization/config/resources/edge/env/$environment/companyapps/$companyname"
sackmesser list "organizations/$organization/companies/$companyname/apps" | jq -r -c '.[]|.' | while read -r appId; do
loginfo "download company app: $appId for company: $companyname"
full_app=$(sackmesser list "organizations/$organization/companies/$companyname/apps/$(urlencode "$appId")")
echo "$full_app" | jq 'del(.credentials)' > "$export_folder/$organization/config/resources/edge/env/$environment/companyapps/$appId".json
echo "$full_app" | jq -r -c '.credentials[]' | while read -r credential; do
appkey=$(echo "$credential" | jq -r '.consumerKey')
done
done
done

if ls "$export_folder/$organization/config/resources/edge/env/$environment/companyapps"/*.json 1> /dev/null 2>&1; then
jq -n '[inputs]' "$export_folder/$organization/config/resources/edge/env/$environment/companyapps"/*.json > "$export_folder/$organization/config/resources/edge/env/$environment/companyapps".json
fi

echo "<div><table id=\"ts-lint\" data-toggle=\"table\" class=\"table\">" >> "$report_html"
echo "<thead class=\"thead-dark\"><tr>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"name\">Name</th>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"status\">Status</th>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"company\">Company Name</th>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"app_id\">App ID</th>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"app_fam\">App Family</th>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"callback\">Callback URL</th>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"access\">Access Type</th>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"created\">Created At</th>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"modified\">Last Modified</th>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"credentialsLoaded\">Credentials Loaded</th>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"scopes\">Scopes</th>" >> "$report_html"
echo "</tr></thead>" >> "$report_html"

echo "<tbody class=\"mdc-data-table__content\">" >> "$report_html"

if [ -f "$export_folder/$organization/config/resources/edge/env/$environment/companyapps".json ]; then
jq -c '.[]' "$export_folder/$organization/config/resources/edge/env/$environment/companyapps".json | while read i; do
name=$(echo "$i" | jq -r '.name')
status=$(echo "$i" | jq -r '.status')
companyName=$(echo "$i" | jq -r '.companyName')
appId=$(echo "$i" | jq -r '.appId')
appFamily=$(echo "$i" | jq -r '.appFamily')
callbackUrl=$(echo "$i" | jq -r '.callbackUrl')
accessType=$(echo "$i" | jq -r '.accessType')
createdAt=$(echo "$i" | jq -r '.createdAt' | date -u)
lastModifiedAt=$(echo "$i" | jq -r '.lastModifiedAt' | date -u)
_credentialsLoaded=$(echo "$i" | jq -r '.credentialsLoaded')
scopes=$(echo "$i" | jq -r '.scopes')


if [ $_credentialsLoaded = true ]
then
credentialsLoaded="✅"
else
credentialsLoaded="❌"
fi

echo "<tr class=\"$highlightclass\">" >> "$report_html"
echo "<td>$name</td>" >> "$report_html"
echo "<td>$status</td>" >> "$report_html"
echo "<td>$companyName</td>" >> "$report_html"
echo "<td>$appId</td>" >> "$report_html"
echo "<td>$appFamily</td>" >> "$report_html"
echo "<td>$callbackUrl</td>" >> "$report_html"
echo "<td>$accessType</td>" >> "$report_html"
echo "<td>$createdAt</td>" >> "$report_html"
echo "<td>$lastModifiedAt</td>" >> "$report_html"
echo "<td>$credentialsLoaded</td>" >> "$report_html"
echo "<td>$scopes</td>" >> "$report_html"
echo "</tr>" >> "$report_html"
done
fi

echo "</tbody></table></div>" >> "$report_html"
55 changes: 55 additions & 0 deletions tools/apigee-sackmesser/cmd/report/helpers/ldapresources.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# <http://www.apache.org/licenses/LICENSE-2.0>
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

echo "<h3>LDAP Resources</h3>" >> "$report_html"

mkdir -p "$export_folder/$organization/config/resources/edge/env/$environment/ldapresource"

sackmesser list "organizations/$organization/environments/$environment/ldapresources"| jq -r -c '.[]|.' | while read -r ldapresourcename; do
sackmesser list "organizations/$organization/environments/$environment/ldapresources/$(urlencode "$ldapresourcename")" > "$export_folder/$organization/config/resources/edge/env/$environment/ldapresource/$(urlencode "$ldapresourcename")".json
done

if ls "$export_folder/$organization/config/resources/edge/env/$environment/ldapresource"/*.json 1> /dev/null 2>&1; then
jq -n '[inputs]' "$export_folder/$organization/config/resources/edge/env/$environment/ldapresource"/*.json > "$export_folder/$organization/config/resources/edge/env/$environment/ldapresources".json
fi

echo "<div><table id=\"ldapresource-lint\" data-toggle=\"table\" class=\"table\">" >> "$report_html"
echo "<thead class=\"thead-dark\"><tr>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"id\">Name</th>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"admin\">Admin</th>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"connectPool\">Connect Pool</th>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"connection\">connection</th>" >> "$report_html"
echo "</tr></thead>" >> "$report_html"

echo "<tbody class=\"mdc-data-table__content\">" >> "$report_html"

if [ -f "$export_folder/$organization/config/resources/edge/env/$environment/ldapresources".json ]; then
jq -c '.[]' "$export_folder/$organization/config/resources/edge/env/$environment/ldapresources".json | while read i; do
name=$(echo "$i" | jq -r '.name')
admin=$(echo "$i" | jq -r '.admin' | jq -r 'keys[] as $k | "<li>\($k): \(.[$k] | .)</li>"')
connectPool=$(echo "$i" | jq -r '.connectPool' | jq -r 'keys[] as $k | "<li>\($k): \(.[$k] | .)</li>"')
connection=$(echo "$i" | jq -r '.connection' | jq -r 'keys[] as $k | "<li>\($k): \(.[$k] | .)</li>"')

echo "<tr class=\"$highlightclass\">" >> "$report_html"
echo "<td>$name</td>" >> "$report_html"
echo "<td><ul>$admin</ul></td>" >> "$report_html"
echo "<td><ul>$connectPool</ul></td>" >> "$report_html"
echo "<td><ul>$connection</ul></td>" >> "$report_html"
echo "</tr>" >> "$report_html"
done
fi

echo "</tbody></table></div>" >> "$report_html"
53 changes: 53 additions & 0 deletions tools/apigee-sackmesser/cmd/report/helpers/users.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# <http://www.apache.org/licenses/LICENSE-2.0>
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

echo "<h3>Users</h3>" >> "$report_html"

mkdir -p "$export_folder/$organization/config/resources/edge/env/$environment/user"

sackmesser list "users"| jq -r -c '.[]|.[]' | while read -r userdetail; do
email=$(echo "$userdetail" | jq -r '.name')
sackmesser list "users/$email" > "$export_folder/$organization/config/resources/edge/env/$environment/user/$email".json
done

if ls "$export_folder/$organization/config/resources/edge/env/$environment/user"/*.json 1> /dev/null 2>&1; then
jq -n '[inputs]' "$export_folder/$organization/config/resources/edge/env/$environment/user"/*.json > "$export_folder/$organization/config/resources/edge/env/$environment/users".json
fi

echo "<div><table id=\"user-lint\" data-toggle=\"table\" class=\"table\">" >> "$report_html"
echo "<thead class=\"thead-dark\"><tr>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"id\">Email</th>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"firstname\">First Name</th>" >> "$report_html"
echo "<th data-sortable=\"true\" data-field=\"lastname\">Last Name</th>" >> "$report_html"
echo "</tr></thead>" >> "$report_html"

echo "<tbody class=\"mdc-data-table__content\">" >> "$report_html"

if [ -f "$export_folder/$organization/config/resources/edge/env/$environment/users".json ]; then
jq -c '.[]' "$export_folder/$organization/config/resources/edge/env/$environment/users".json | while read i; do
emailId=$(echo "$i" | jq -r '.emailId')
firstName=$(echo "$i" | jq -r '.firstName')
lastName=$(echo "$i" | jq -r '.lastName')

echo "<tr class=\"$highlightclass\">" >> "$report_html"
echo "<td>$emailId</td>" >> "$report_html"
echo "<td>$firstName</td>" >> "$report_html"
echo "<td>$lastName</td>" >> "$report_html"
echo "</tr>" >> "$report_html"
done
fi

echo "</tbody></table></div>" >> "$report_html"
4 changes: 4 additions & 0 deletions tools/apigee-sackmesser/cmd/report/report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ source $helper_dir/references.sh

if [ "$opdk" == "T" ]; then
source $helper_dir/virtualhosts.sh
source $helper_dir/companies.sh
source $helper_dir/companyapps.sh
source $helper_dir/ldapresources.sh
source $helper_dir/users.sh
fi

echo "<h2>Organization Configurations</h2>" >> "$report_html"
Expand Down