Instrumental | 9405361 | 2018-10-08 11:27:18 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copies of Repo data need to be added to "dats" dir for loading by push.sh |
| 4 | # |
| 5 | # Further, repo data has dates that are out of date and may have IDs not valid. We need to make |
| 6 | # sure the important data is consistent with Identities. |
| 7 | # |
| 8 | # This is expected to be run from a controlling Machine data "authz/auth/sample/cass_data" when a backup |
| 9 | # is created that is intended to be "Bootstrap Data" |
| 10 | # |
| 11 | # Date resets on key data load on the system at load time |
| 12 | # |
Instrumental | 28f5a47 | 2018-10-04 13:22:18 -0500 | [diff] [blame] | 13 | |
Instrumental | 9405361 | 2018-10-08 11:27:18 -0500 | [diff] [blame] | 14 | DIR=$(pwd) |
| 15 | ID_FILE=../data/sample.identities.dat |
Instrumental | 28f5a47 | 2018-10-04 13:22:18 -0500 | [diff] [blame] | 16 | |
Instrumental | 9405361 | 2018-10-08 11:27:18 -0500 | [diff] [blame] | 17 | if [ -e $ID_FILE ]; then |
| 18 | if [ "$(uname -s)" = "Darwin" ]; then |
Instrumental | c687ff5 | 2018-10-16 19:22:04 -0500 | [diff] [blame] | 19 | DATE=$(date -v "+6m" "+%Y-%m-%d %H:%M:%S.000+0000") |
Instrumental | 9405361 | 2018-10-08 11:27:18 -0500 | [diff] [blame] | 20 | else |
| 21 | DATE=$(date "+%Y-%m-%d %H:%M:%S.000+0000" -d "+6 months") |
| 22 | fi |
| 23 | echo $DATE |
Instrumental | 28f5a47 | 2018-10-04 13:22:18 -0500 | [diff] [blame] | 24 | |
Instrumental | 9405361 | 2018-10-08 11:27:18 -0500 | [diff] [blame] | 25 | #### CRED |
| 26 | # Enter for People |
| 27 | CRED="cred.dat" |
Instrumental | c687ff5 | 2018-10-16 19:22:04 -0500 | [diff] [blame] | 28 | rm cred.dat |
Instrumental | 9405361 | 2018-10-08 11:27:18 -0500 | [diff] [blame] | 29 | echo "Create default Passwords for all Identities in $CRED" |
| 30 | for ID in $(grep '|a|' $ID_FILE | sed -e "s/|.*//"); do |
| 31 | if [ "$ID" = "aaf" ]; then |
| 32 | DOMAIN="aaf.osaaf.org"; |
| 33 | else |
| 34 | DOMAIN="$ID.onap.org"; |
| 35 | fi |
| 36 | unset FIRST |
| 37 | for D in ${DOMAIN//./ }; do |
| 38 | if [ -z "$FIRST" ]; then |
| 39 | NS="$D" |
| 40 | FIRST="N" |
| 41 | else |
| 42 | NS="$D.$NS" |
| 43 | fi |
| 44 | done |
| 45 | echo "$ID@$DOMAIN|2|${DATE}|0xd993c5617486296f1b99d04de31633332b8ba1a550038e23860f9dbf0b2fcf95|Initial ID|$NS|53344|" >> $CRED |
| 46 | done |
Instrumental | 28f5a47 | 2018-10-04 13:22:18 -0500 | [diff] [blame] | 47 | |
Instrumental | 9405361 | 2018-10-08 11:27:18 -0500 | [diff] [blame] | 48 | for ID in $(grep '|e|' $ID_FILE | sed -e "s/|.*//"); do |
| 49 | echo "$ID@people.osaaf.org|2|${DATE}|0xd993c5617486296f1b99d04de31633332b8ba1a550038e23860f9dbf0b2fcf95|Initial ID|org.osaaf.people|53344|" >> $CRED |
| 50 | done |
| 51 | |
Instrumental | 9405361 | 2018-10-08 11:27:18 -0500 | [diff] [blame] | 52 | ##### USER_ROLE |
| 53 | echo "Scrubbing user_roles not in $ID_FILE" |
Instrumental | c687ff5 | 2018-10-16 19:22:04 -0500 | [diff] [blame] | 54 | |
| 55 | ## Covering for when scrubbing in cass_init versus a Backup |
| 56 | if [ -d "dats" ]; then |
| 57 | for D in ns ns_attrib perm role config artifact; do |
| 58 | if [ -e "dats/$D.dat" ]; then |
| 59 | cp dats/$D.dat . |
| 60 | fi |
| 61 | done |
| 62 | else |
| 63 | mkdir -p dats |
| 64 | cp user_role.dat dats |
| 65 | REMOVE_DATS=true |
| 66 | fi |
Instrumental | 9405361 | 2018-10-08 11:27:18 -0500 | [diff] [blame] | 67 | > user_role.dat |
| 68 | for ID in $(grep -v "#" $ID_FILE | awk -F\| '{print $1}' | grep -v "^$"); do |
| 69 | grep "$ID@" dats/user_role.dat >> user_role.dat |
| 70 | done |
| 71 | |
Instrumental | 9405361 | 2018-10-08 11:27:18 -0500 | [diff] [blame] | 72 | UR="$(mktemp)" |
| 73 | DUR="$(mktemp)" |
| 74 | |
| 75 | cat user_role.dat | awk -F\| '{print $1}' | sort -u > $UR |
| 76 | cat dats/user_role.dat | awk -F\| '{print $1}' | sort -u > $DUR |
| 77 | |
| 78 | echo "Removed IDs from user_roles" |
| 79 | diff $UR $DUR | grep "^>" | sort -u |
| 80 | |
| 81 | rm "$UR" "$DUR" |
| 82 | |
| 83 | mv user_role.dat tmp |
| 84 | sed "s/\(^.*|\)\(.*|\)\(.*|\)\(.*\)/\1${DATE}|\3\4/" tmp > user_role.dat |
| 85 | rm tmp |
Instrumental | c687ff5 | 2018-10-16 19:22:04 -0500 | [diff] [blame] | 86 | if [ -n "$REMOVE_DATS" ]; then |
| 87 | rm -Rf dats |
| 88 | fi |
Instrumental | 9405361 | 2018-10-08 11:27:18 -0500 | [diff] [blame] | 89 | else |
| 90 | echo $0 requires access to $ID_FILE |
| 91 | fi |
| 92 | |
| 93 | |