<commit_before>#! /bin/bash
#oo-register-developer <username> <gearProfile>
#
#SETUP
# simple set the broker host variable below to the correct url for the broker and [OPTIONAL] set the logfile where to send stdout & stderr
#
#PARAMETERS
#username: username of the developer to add. script will create developer with name "dev[username]"
#gearProfile: gear profile to be used in the developers domain eg. small, medium
#
#
#VARIABLES
#logFile: where the stderr and stdout get redirected to
#brokerhost: url of the OSE broker
#
#
#EXAMPLES
# ./oo-register-developer.sh Jsmith small
# ./oo-register-developer.sh Bnye medium
#
#
logFile=/var/log/openshift/broker/ose-utils.log
brokerhost="localhost"

function usage {
  echo "oo-register-developer.sh {username} {gearProfile}"
}

function json {
  echo "{
        'returnCode':'$1',
        'returnDesc':'$2'
}"
}

if [ "$#" -le 1 ]
  then
  usage
  json 255 "Invalid usage"
  exit 255
fi

username="$1"
gearProfile="$2"

if [ -z ${username+x} ];then
  usage
  json 2 "No Username supplied"
  exit 255
fi

if [ -z ${gearProfile+x} ];then
  $gearProfile=small
fi
#1. Check if developer account already exists in OpenShift E1
#   (API TBD, Java RA and Red Hat working on this one). If it does not, then:

#check if user exists and catch output(should produce a not found error since the user shouldnt exist)
oo-admin-ctl-user -l $username &>>$logFile
code=$?
if [[ "$code" = "5" ]]; then

  #Do nothing here but bash doesnt like empty if statement go on to create new account.
  sleep 0

elif [[ "$code" = "0" ]]; then
  #already exists do nothing return 1

  json 1 "User already exists. Exiting..."
  exit 1
else<commit_msg>error validating gears<commit_after>#! /bin/bash
#oo-register-developer <username> <gearProfile>
#
#SETUP
# simple set the broker host variable below to the correct url for the broker and [OPTIONAL] set the logfile where to send stdout & stderr
#
#PARAMETERS
#username: username of the developer to add. script will create developer with name "dev[username]"
#gearProfile: gear profile to be used in the developers domain eg. small, medium
#
#
#VARIABLES
#logFile: where the stderr and stdout get redirected to
#brokerhost: url of the OSE broker
#
#
#EXAMPLES
# ./oo-register-developer.sh Jsmith small
# ./oo-register-developer.sh Bnye medium
#
#
logFile=/var/log/openshift/broker/ose-utils.log
brokerhost="localhost"
gearProfileDefault="small"

function usage {
  echo "oo-register-developer.sh {username} {gearProfile}"
}

function json {
  echo "{
        'returnCode':'$1',
        'returnDesc':'$2'
}"
}

function validGear {
  valid=$(grep "VALID_GEAR_SIZES=" /etc/openshift/broker.conf) &>>$logFile
#  sed 's/"//g' <<< $valid &>>$logFile
#  sed 's/"//g' <<< $1 &>>$logFile
  IFS='='; read -r -a raw <<< "$valid"
  IFS=','; read -r -a sizes <<< ${raw[1]}
  for size in ${sizes[*]}
  do

    if [[ $size == $1 ]]; then
      echo 1
      return
    fi
    echo "$size did not equal $1"
  done
  echo 0
  return

}

if [ "$#" -lt 1 ]
  then
  usage
  json 255 "Invalid usage"
  exit 255
fi

username="$1"
gearProfile="$2"

if [ -z ${gearProfile+x} ];then
  $gearProfile=$gearProfileDefault
else
  checkGear=$(validGear "$gearProfile")
  echo "checkgear=$checkGear"
  if [ "$checkGear" != "1" ];then
    json 255 "Invalid Gear Size."
    exit 255
  fi
fi

if [ -z ${username+x} ];then
  usage
  json 2 "No Username supplied"
  exit 255
fi





#1. Check if developer account already exists in OpenShift E1
#   (API TBD, Java RA and Red Hat working on this one). If it does not, then:

#check if user exists and catch output(should produce a not found error since the user shouldnt exist)
oo-admin-ctl-user -l $username &>>$logFile
code=$?
if [[ "$code" = "5" ]]; then

  #Do nothing here but bash doesnt like empty if statement go on to create new account.
  sleep 0

elif [[ "$code" = "0" ]]; then
  #already exists do nothing return 1

  json 1 "User already exists. Exiting..."
  exit 1
else
{'fraction_non_alphanumeric': 0.12651209677419356, 'fraction_numerical': 0.014868951612903226, 'mean_word_length': 3.6694117647058824, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7357509', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1336, 'n_words': 500}