blob: 2bf12d14e12c177637434077f9e8a2ced4c6277f [file] [log] [blame]
Instrumental94053612018-10-08 11:27:18 -05001#!/bin/bash
Instrumental7a1817b2018-11-05 11:11:15 -06002#########
3# ============LICENSE_START====================================================
4# org.onap.aaf
5# ===========================================================================
6# Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
7# ===========================================================================
8# Licensed under the Apache License, Version 2.0 (the "License");
9# you may not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS,
16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19# ============LICENSE_END====================================================
20#
Instrumental94053612018-10-08 11:27:18 -050021#
22# Copies of Repo data need to be added to "dats" dir for loading by push.sh
23#
24# Further, repo data has dates that are out of date and may have IDs not valid. We need to make
25# sure the important data is consistent with Identities.
26#
27# This is expected to be run from a controlling Machine data "authz/auth/sample/cass_data" when a backup
28# is created that is intended to be "Bootstrap Data"
29#
30# Date resets on key data load on the system at load time
31#
Instrumental28f5a472018-10-04 13:22:18 -050032
Instrumental94053612018-10-08 11:27:18 -050033DIR=$(pwd)
34ID_FILE=../data/sample.identities.dat
Instrumental28f5a472018-10-04 13:22:18 -050035
Instrumental94053612018-10-08 11:27:18 -050036if [ -e $ID_FILE ]; then
37 if [ "$(uname -s)" = "Darwin" ]; then
Instrumentalc687ff52018-10-16 19:22:04 -050038 DATE=$(date -v "+6m" "+%Y-%m-%d %H:%M:%S.000+0000")
Instrumental94053612018-10-08 11:27:18 -050039 else
40 DATE=$(date "+%Y-%m-%d %H:%M:%S.000+0000" -d "+6 months")
41 fi
42 echo $DATE
Instrumental28f5a472018-10-04 13:22:18 -050043
Instrumental94053612018-10-08 11:27:18 -050044 #### CRED
45 # Enter for People
46 CRED="cred.dat"
Instrumentalc687ff52018-10-16 19:22:04 -050047 rm cred.dat
Instrumental94053612018-10-08 11:27:18 -050048 echo "Create default Passwords for all Identities in $CRED"
49 for ID in $(grep '|a|' $ID_FILE | sed -e "s/|.*//"); do
50 if [ "$ID" = "aaf" ]; then
51 DOMAIN="aaf.osaaf.org";
52 else
53 DOMAIN="$ID.onap.org";
54 fi
55 unset FIRST
56 for D in ${DOMAIN//./ }; do
57 if [ -z "$FIRST" ]; then
58 NS="$D"
59 FIRST="N"
60 else
61 NS="$D.$NS"
62 fi
63 done
64 echo "$ID@$DOMAIN|2|${DATE}|0xd993c5617486296f1b99d04de31633332b8ba1a550038e23860f9dbf0b2fcf95|Initial ID|$NS|53344|" >> $CRED
65 done
Instrumental28f5a472018-10-04 13:22:18 -050066
Instrumental94053612018-10-08 11:27:18 -050067 for ID in $(grep '|e|' $ID_FILE | sed -e "s/|.*//"); do
68 echo "$ID@people.osaaf.org|2|${DATE}|0xd993c5617486296f1b99d04de31633332b8ba1a550038e23860f9dbf0b2fcf95|Initial ID|org.osaaf.people|53344|" >> $CRED
69 done
70
Instrumental94053612018-10-08 11:27:18 -050071 ##### USER_ROLE
72 echo "Scrubbing user_roles not in $ID_FILE"
Instrumentalc687ff52018-10-16 19:22:04 -050073
74 ## Covering for when scrubbing in cass_init versus a Backup
75 if [ -d "dats" ]; then
76 for D in ns ns_attrib perm role config artifact; do
77 if [ -e "dats/$D.dat" ]; then
78 cp dats/$D.dat .
79 fi
80 done
81 else
82 mkdir -p dats
83 cp user_role.dat dats
84 REMOVE_DATS=true
85 fi
Instrumental94053612018-10-08 11:27:18 -050086 > user_role.dat
87 for ID in $(grep -v "#" $ID_FILE | awk -F\| '{print $1}' | grep -v "^$"); do
88 grep "$ID@" dats/user_role.dat >> user_role.dat
89 done
90
Instrumental94053612018-10-08 11:27:18 -050091 UR="$(mktemp)"
92 DUR="$(mktemp)"
93
94 cat user_role.dat | awk -F\| '{print $1}' | sort -u > $UR
95 cat dats/user_role.dat | awk -F\| '{print $1}' | sort -u > $DUR
96
97 echo "Removed IDs from user_roles"
98 diff $UR $DUR | grep "^>" | sort -u
99
100 rm "$UR" "$DUR"
101
102 mv user_role.dat tmp
103 sed "s/\(^.*|\)\(.*|\)\(.*|\)\(.*\)/\1${DATE}|\3\4/" tmp > user_role.dat
104 rm tmp
Instrumentalc687ff52018-10-16 19:22:04 -0500105 if [ -n "$REMOVE_DATS" ]; then
106 rm -Rf dats
107 fi
Instrumental94053612018-10-08 11:27:18 -0500108else
109 echo $0 requires access to $ID_FILE
110fi
111
112