From 0f7e994dc4bda25a58390d635704a083e0df37ee Mon Sep 17 00:00:00 2001 From: Devashish Patil Date: Mon, 2 Jan 2023 11:05:14 +0530 Subject: [PATCH 1/5] feat: added unsupported apis in report --- .../cmd/report/helpers/companies.sh | 62 +++++++++++++ .../cmd/report/helpers/companyapps.sh | 93 +++++++++++++++++++ .../cmd/report/helpers/ldapresources.sh | 55 +++++++++++ .../cmd/report/helpers/users.sh | 55 +++++++++++ tools/apigee-sackmesser/cmd/report/report.sh | 6 ++ 5 files changed, 271 insertions(+) create mode 100644 tools/apigee-sackmesser/cmd/report/helpers/companies.sh create mode 100644 tools/apigee-sackmesser/cmd/report/helpers/companyapps.sh create mode 100644 tools/apigee-sackmesser/cmd/report/helpers/ldapresources.sh create mode 100644 tools/apigee-sackmesser/cmd/report/helpers/users.sh diff --git a/tools/apigee-sackmesser/cmd/report/helpers/companies.sh b/tools/apigee-sackmesser/cmd/report/helpers/companies.sh new file mode 100644 index 000000000..8b1cdaec8 --- /dev/null +++ b/tools/apigee-sackmesser/cmd/report/helpers/companies.sh @@ -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 +# +# +# +# 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 "

Companies

" >> "$report_html" + +mkdir -p "$export_folder/$organization/config/resources/edge/env/$environment/company" + +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 "
" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" + +echo "" >> "$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 "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" + done +fi + +echo "
NameDisplay NameStatusApps
$name"$displayName"$status$apps
" >> "$report_html" diff --git a/tools/apigee-sackmesser/cmd/report/helpers/companyapps.sh b/tools/apigee-sackmesser/cmd/report/helpers/companyapps.sh new file mode 100644 index 000000000..7f3ab6ba5 --- /dev/null +++ b/tools/apigee-sackmesser/cmd/report/helpers/companyapps.sh @@ -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 +# +# +# +# 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 "

Company Apps

" >> "$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 "
" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" + +echo "" >> "$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 "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" + done +fi + +echo "
NameStatusCompany NameApp IDApp FamilyCallback URLAccess TypeCreated AtLast ModifiedCredentials LoadedScopes
$name$status$companyName$appId$appFamily$callbackUrl$accessType$createdAt$lastModifiedAt$credentialsLoaded$scopes
" >> "$report_html" \ No newline at end of file diff --git a/tools/apigee-sackmesser/cmd/report/helpers/ldapresources.sh b/tools/apigee-sackmesser/cmd/report/helpers/ldapresources.sh new file mode 100644 index 000000000..ce6d1c10b --- /dev/null +++ b/tools/apigee-sackmesser/cmd/report/helpers/ldapresources.sh @@ -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 +# +# +# +# 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 "

LDAP Resources

" >> "$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 "
" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" + +echo "" >> "$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') + connectPool=$(echo "$i" | jq -r '.connectPool') + connection=$(echo "$i" | jq -r '.connection') + + echo "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" + done +fi + +echo "
NameAdminConnect Poolconnection
$name$admin$connectPool$connection
" >> "$report_html" \ No newline at end of file diff --git a/tools/apigee-sackmesser/cmd/report/helpers/users.sh b/tools/apigee-sackmesser/cmd/report/helpers/users.sh new file mode 100644 index 000000000..8c527c746 --- /dev/null +++ b/tools/apigee-sackmesser/cmd/report/helpers/users.sh @@ -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 +# +# +# +# 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 "

Users

" >> "$report_html" + +mkdir -p "$export_folder/$organization/config/resources/edge/env/$environment/user" + +sackmesser list "users"| jq -r -c '.[]|.[]' | while read -r username; do + email=$(echo "$username" | jq -r '.name') + # loginfo "users/$(urlencode $email)" + # sackmesser list --opdk "users/test@bar.com" > "$export_folder/$organization/config/resources/edge/env/$environment/user/$email".json + echo '{"emailID": "'$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 "
" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" +# echo "" >> "$report_html" +# echo "" >> "$report_html" +echo "" >> "$report_html" + +echo "" >> "$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 "" >> "$report_html" + echo "" >> "$report_html" + # echo "" >> "$report_html" + # echo "" >> "$report_html" + echo "" >> "$report_html" + done +fi + +echo "
EmailFirst NameLast Name
$emailId$firstName$lastName
" >> "$report_html" \ No newline at end of file diff --git a/tools/apigee-sackmesser/cmd/report/report.sh b/tools/apigee-sackmesser/cmd/report/report.sh index 6b41307fb..9d2e29d8d 100755 --- a/tools/apigee-sackmesser/cmd/report/report.sh +++ b/tools/apigee-sackmesser/cmd/report/report.sh @@ -429,6 +429,12 @@ source $helper_dir/references.sh if [ "$opdk" == "T" ]; then source $helper_dir/virtualhosts.sh + + echo "

Unsupported API Configurations

" >> "$report_html" + source $helper_dir/companies.sh + source $helper_dir/companyapps.sh + source $helper_dir/ldapresources.sh + source $helper_dir/users.sh fi echo "

Organization Configurations

" >> "$report_html" From 173c65c9bce404109b440cbe3d6348d1bcee7633 Mon Sep 17 00:00:00 2001 From: Devashish Patil Date: Mon, 2 Jan 2023 16:46:57 +0530 Subject: [PATCH 2/5] fix: user details in report --- .../cmd/report/helpers/users.sh | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tools/apigee-sackmesser/cmd/report/helpers/users.sh b/tools/apigee-sackmesser/cmd/report/helpers/users.sh index 8c527c746..83fed0dc3 100644 --- a/tools/apigee-sackmesser/cmd/report/helpers/users.sh +++ b/tools/apigee-sackmesser/cmd/report/helpers/users.sh @@ -18,11 +18,9 @@ echo "

Users

" >> "$report_html" mkdir -p "$export_folder/$organization/config/resources/edge/env/$environment/user" -sackmesser list "users"| jq -r -c '.[]|.[]' | while read -r username; do - email=$(echo "$username" | jq -r '.name') - # loginfo "users/$(urlencode $email)" - # sackmesser list --opdk "users/test@bar.com" > "$export_folder/$organization/config/resources/edge/env/$environment/user/$email".json - echo '{"emailID": "'$email'"}' > "$export_folder/$organization/config/resources/edge/env/$environment/user/$email".json +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 @@ -32,22 +30,22 @@ fi echo "
" >> "$report_html" echo "" >> "$report_html" echo "" >> "$report_html" -# echo "" >> "$report_html" -# echo "" >> "$report_html" +echo "" >> "$report_html" +echo "" >> "$report_html" echo "" >> "$report_html" echo "" >> "$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') + emailId=$(echo "$i" | jq -r '.emailId') + firstName=$(echo "$i" | jq -r '.firstName') + lastName=$(echo "$i" | jq -r '.lastName') echo "" >> "$report_html" echo "" >> "$report_html" - # echo "" >> "$report_html" - # echo "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" echo "" >> "$report_html" done fi From 35cd4ca13d694a602bb142e335081684aa68050b Mon Sep 17 00:00:00 2001 From: Devashish Patil Date: Mon, 2 Jan 2023 17:15:08 +0530 Subject: [PATCH 3/5] fix: report data representation changed --- .../cmd/report/helpers/ldapresources.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/apigee-sackmesser/cmd/report/helpers/ldapresources.sh b/tools/apigee-sackmesser/cmd/report/helpers/ldapresources.sh index ce6d1c10b..26ac40cf1 100644 --- a/tools/apigee-sackmesser/cmd/report/helpers/ldapresources.sh +++ b/tools/apigee-sackmesser/cmd/report/helpers/ldapresources.sh @@ -39,15 +39,15 @@ echo "" >> "$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') - connectPool=$(echo "$i" | jq -r '.connectPool') - connection=$(echo "$i" | jq -r '.connection') + admin=$(echo "$i" | jq -r '.admin' | jq -r 'keys[] as $k | "
  • \($k): \(.[$k] | .)
  • "') + connectPool=$(echo "$i" | jq -r '.connectPool' | jq -r 'keys[] as $k | "
  • \($k): \(.[$k] | .)
  • "') + connection=$(echo "$i" | jq -r '.connection' | jq -r 'keys[] as $k | "
  • \($k): \(.[$k] | .)
  • "') echo "" >> "$report_html" echo "" >> "$report_html" - echo "" >> "$report_html" - echo "" >> "$report_html" - echo "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" + echo "" >> "$report_html" echo "" >> "$report_html" done fi From c7b960f448b2c3006e43a131bbff1f4d4e002fd1 Mon Sep 17 00:00:00 2001 From: Devashish Patil Date: Wed, 8 Feb 2023 15:08:24 +0530 Subject: [PATCH 4/5] fix: remove heading named unsupported --- tools/apigee-sackmesser/cmd/report/report.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/apigee-sackmesser/cmd/report/report.sh b/tools/apigee-sackmesser/cmd/report/report.sh index 9d2e29d8d..8280f8b54 100755 --- a/tools/apigee-sackmesser/cmd/report/report.sh +++ b/tools/apigee-sackmesser/cmd/report/report.sh @@ -429,8 +429,6 @@ source $helper_dir/references.sh if [ "$opdk" == "T" ]; then source $helper_dir/virtualhosts.sh - - echo "

    Unsupported API Configurations

    " >> "$report_html" source $helper_dir/companies.sh source $helper_dir/companyapps.sh source $helper_dir/ldapresources.sh From 130e19f05d496fa49afde2895181aedabd3f8e5f Mon Sep 17 00:00:00 2001 From: Omid Tahouri Date: Wed, 8 Feb 2023 16:29:17 +0000 Subject: [PATCH 5/5] chore: removing an extra space --- tools/apigee-sackmesser/cmd/report/helpers/companies.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/apigee-sackmesser/cmd/report/helpers/companies.sh b/tools/apigee-sackmesser/cmd/report/helpers/companies.sh index 8b1cdaec8..9cf2b37bd 100644 --- a/tools/apigee-sackmesser/cmd/report/helpers/companies.sh +++ b/tools/apigee-sackmesser/cmd/report/helpers/companies.sh @@ -54,7 +54,7 @@ if [ -f "$export_folder/$organization/config/resources/edge/env/$environment/com echo "
    " >> "$report_html" echo "" >> "$report_html" echo "" >> "$report_html" - echo "" >> "$report_html" + echo "" >> "$report_html" echo "" >> "$report_html" done fi
    EmailFirst NameLast NameFirst NameLast Name
    $emailId$firstName$lastName$firstName$lastName
    $name$admin$connectPool$connection
      $admin
      $connectPool
      $connection
    $name"$displayName"$status$apps$apps