APIPythonOpen-Source Solutions

  • 1.  Elevation privilege script

    Posted 06-01-2017 02:30:00 PM
    Hi,

    Trying to create a script for my Elevation privilege on my engine, but i'm stuck on how to create a script with multilines.

    How to indecate new line when for example you set the contect of privilege script at the cli

    eg. LandsharkEngine host privilegeElevation profileScript 'msa_commande' update *> set contents=


    Regards,

    Mouhssine
    #DemoEnvironment


  • 2.  RE: Elevation privilege script
    Best Answer

    Posted 06-01-2017 04:17:00 PM
    Hello Mouhssine,

    The multiline have some challenges in CLI. You can achieve this by writing a bash shell function to extract the file contents for elevation profile script (e.g. dlpx_pfexec, dlpx_mkdir...)

    Code snippet:
    extract_contents()  {     PROFILE_NAME="${1}"     SCRIPT_FILE="${2}"     CONTENTS=""     row=""       PFEXEC_FILE="${BASEDIR}/${PROFILE_NAME}/${SCRIPT_FILE}"       if [ ! -f ${PFEXEC_FILE} ]; then        echo "Error: Can't read file ${PFEXEC_FILE}"        exit 1     fi     IFS=''     while read line  || [ -n "${line}" ]     do        row='echo "${row}\n${line}"'     done < ${PFEXEC_FILE}       CONTENTS=$(echo "${row}" | sed -e 's/\"/\\\"/g' | sed -e 's/\$/'\$'/g' | sed -e 's/\t/    /g' )    }
    Then pass the CONTENTS to a WebAPI call
    create_profile_script()
    {
       URL="${1}"
       PROFILE_REF="${2}"
       NAME="${3}"
       CONTENTS="${4}"
       echo "Creating profile script ${NAME}"
       RESULT='curl -s -X POST -k --data @- ${URL}/resources/json/delphix/host/privilegeElevation/profileScript \
          -b ${COOKIE_FILE} -H "Content-Type: application/json" <<EOF
       {
          "type": "HostPrivilegeElevationProfileScript",
          "profile": "${PROFILE_REF}",
          "name": "${NAME}",
          "contents": "${CONTENTS}"
       }
    EOF'

    Here are the additional reference to Elevation Profile
    Hope this helps.

    - Edward


  • 3.  RE: Elevation privilege script

    Posted 06-01-2017 04:39:00 PM
    Hi Edward, It's a great workaround will try it, but still find that we need to get facilities on using also cli without passing via the API call. For example introduce escape chars our allow to interpret \n as new line when setting content. Anyway many thanks for the advice. Regards, Mouhssine