Monday, September 7, 2020

Oracle Integration /ICS/OIC Connection Credential Replace automated

 

The requirement was to do a find and replace connection credential in OIC .


There can be a scenario where the credentials in the connection that are setup in OIC expires and the security teams reset it to a different password.

It is difficult to know which connection is using that credential which needs to be changed.



We are achieving this using the rest APIs exposed by OIC to fetch and update the connection details.


Step 1 : Use the shell script in URL





It accepts 4 Parameters : 

ICS_CONNECTION_URL= https://xxxx-dev-xxxx.integration.ocp.oraclecloud.com

OIC_USERNAME= abc@oracle.com

OIC_PASS= welcome

replaceuser= This is the user you want to find and replace. - 123@oracle.com


Change the connection details in CONN.json file :


Step 2 : Load the shell script in a unix box with CONN.json which you want to load.


./main.sh "https://xxxx-dev-xxxx.integration.ocp.oraclecloud.com" "abc@oracle.com" "welcome" "123@oracle.com"

This will run the script.




Once you run the script , this will generate a file connections.txt which will contain all the connections replaced.




Shell Script (You can also find the same in git attached above) :

ICS_CONNECTION_URL=$1
OIC_USERNAME=$2
OIC_PASS=$3
replaceuser=$4
if [ -f "user_accounts.txt" ]
        then
           rm user_accounts.txt
    fi
if [ -f "connections.txt" ]
        then
           rm connections.txt
    fi
 #curl -k -v -X GET -u $OIC_USERNAME:$OIC_PASS -H Accept:application/json  $ICS_CONNECTION_URL/ic/api/integration/v1/connections?q={status:%27CONFIGURED%27} -o curl_result 2>&1 | tee curl_output
     curl -G -X GET -u $OIC_USERNAME:$OIC_PASS -H "Accept:application/json" --data-urlencode "q={status:  'CONFIGURED'}"  $ICS_CONNECTION_URL/ic/api/integration/v1/connections -o curl_result 2>&1 | tee curl_output
    Integr_count=$(jq '.items | length' curl_result )
for ((i=0; i < $Integr_count; i++))
               do
                err_message=""
               #Obtain the Integration artifacts from file
               id=$( jq -r '.items['$i'] | .id' curl_result )            
  
curl -X GET -u $OIC_USERNAME:$OIC_PASS -H "Accept:application/json" $ICS_CONNECTION_URL/ic/api/integration/v1/connections/$id -o curl_result_conn 2>&1 | tee curl_output_conn
            name=$( jq -r '.securityProperties[0] | .propertyName' curl_result_conn )
     value=$( jq -r '.securityProperties[0] | .propertyValue' curl_result_conn )
            
echo "$id | $name | $value">>user_accounts.txt
  if [ "$value" == "$replaceuser" ]
then
curl   -X POST  -u $OIC_USERNAME:$OIC_PASS -H "X-HTTP-Method-Override:PATCH" -H "Content-Type:application/json" -d @CONN.json $ICS_CONNECTION_URL/ic/api/integration/v1/connections/$id -o "curl_result_conn_$id" | tee "curl_output_conn_$id"
              # filenm=curl_output_conn_$id
             int_status=$( cat "curl_result_conn_$id" | jq -r .status ) 
    echo "*********$id   $int_status*********"
          if [ "$int_status" == 'CONFIGURED' ] 
  then
   echo "Connection Activated successfully"
   echo "$id | SUCCESS" >>connections.txt
  else
   echo "Failed while Updating the connection"
               echo "$id | FAILURE" >>connections.txt
          fi
fi

done
echo "*******************DONE !!!****************"






Oracle OIC Email Notification Template

 Oracle HTML template for email notification <html> <body style="margin: 0px; background-color: rgb(226, 229, 232);"> ...