sergey-safarov commented on issue #1611:
URL: https://github.com/apache/couchdb/issues/1611#issuecomment-1986929659

   To display the status of security objects on my server I have created a 
script. Required to edit login and pass in the script.
   
   ```sh
   #!/bin/sh
   
   db_url=http://login:[email protected]:5984
   fix_db=false
   
   escape_dbname() {
        local DBNAME=$1
        echo $DBNAME | sed -e 's:/:%2f:g' -e 's:\+:%2B:'
   }
   
   security_json() {
   cat << EOF
   {"members":{"roles":["_admin"]},"admins":{"roles":["_admin"]}}
   EOF
   }
   
   get_db_list() {
   curl -s ${db_url}/_all_dbs | jq -r '.[]'
   }
   
   check_db_security() {
        local dbname=$1
        local esc_dbname=$(escape_dbname ${dbname})
        curl -s ${db_url}/${esc_dbname}/_security | jq 'if . == {} then false 
else true end'
   }
   
   maybe_fix_db_security() {
        local dbname=$1
        local esc_dbname=$(escape_dbname ${dbname})
        if [ "${fix_db}" == "false" ]; then
                echo "need to fix database: ${dbname}"
                return
        fi
        echo "fixing database: ${dbname}"
        security_json | curl -X PUT -H 'content-type: application/json' -H 
'accept: application/json' -d@- -s ${db_url}/${esc_dbname}/_security
   }
   
   for i in $(get_db_list)
   do
        sec_status=$(check_db_security $i)
        if [ "${sec_status}" == "false" ]; then
                maybe_fix_db_security $i
        fi
   done
   ```
   To fix security objects need to set "fix_db" variable to "true" value.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to