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 |
| 19 | DATE=$(date "+%Y-%m-%d %H:%M:%S.000+0000" -v "+6m") |
| 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 | 28f5a47 | 2018-10-04 13:22:18 -0500 | [diff] [blame] | 25 | |
Instrumental | 9405361 | 2018-10-08 11:27:18 -0500 | [diff] [blame] | 26 | #### CRED |
| 27 | # Enter for People |
| 28 | CRED="cred.dat" |
| 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 | |
| 52 | |
| 53 | ##### USER_ROLE |
| 54 | echo "Scrubbing user_roles not in $ID_FILE" |
| 55 | > user_role.dat |
| 56 | for ID in $(grep -v "#" $ID_FILE | awk -F\| '{print $1}' | grep -v "^$"); do |
| 57 | grep "$ID@" dats/user_role.dat >> user_role.dat |
| 58 | done |
| 59 | |
| 60 | for D in ns ns_attrib perm role config artifact; do |
| 61 | cp dats/$D.dat . |
| 62 | done |
| 63 | |
| 64 | UR="$(mktemp)" |
| 65 | DUR="$(mktemp)" |
| 66 | |
| 67 | cat user_role.dat | awk -F\| '{print $1}' | sort -u > $UR |
| 68 | cat dats/user_role.dat | awk -F\| '{print $1}' | sort -u > $DUR |
| 69 | |
| 70 | echo "Removed IDs from user_roles" |
| 71 | diff $UR $DUR | grep "^>" | sort -u |
| 72 | |
| 73 | rm "$UR" "$DUR" |
| 74 | |
| 75 | mv user_role.dat tmp |
| 76 | sed "s/\(^.*|\)\(.*|\)\(.*|\)\(.*\)/\1${DATE}|\3\4/" tmp > user_role.dat |
| 77 | rm tmp |
| 78 | |
| 79 | else |
| 80 | echo $0 requires access to $ID_FILE |
| 81 | fi |
| 82 | |
| 83 | |