github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/deploy/dev/k8s/utils/parse_cld.sh (about)

     1  
     2  export LOCAL_AWS="/tmp/credentials"
     3  touch $LOCAL_AWS
     4  export AIS_BACKEND_PROVIDERS="" # See deploy.sh for more information about empty AIS_BACKEND_PROVIDERS.
     5  source ../utils.sh
     6  parse_backend_providers
     7  
     8  if [[ "${AIS_BACKEND_PROVIDERS}" == *aws* ]]; then
     9      echo "Enter the location of your AWS configuration and credentials files:"
    10      echo "Note: No input will result in using the default AWS dir (~/.aws/)"
    11      read -r aws_env
    12  
    13      if [ -z "$aws_env" ]; then
    14          aws_env="~/.aws/"
    15      fi
    16      # to get proper tilde expansion
    17      aws_env="${aws_env/#\~/$HOME}"
    18      if [[ -d ${aws_env} ]]; then # Directory that contains `credentials` and `config` files.
    19          temp_file="$aws_env/credentials"
    20          if [ -f $"$temp_file" ]; then
    21              cp $"$temp_file"  ${LOCAL_AWS}
    22          else
    23              echo "No AWS credentials file found in specified directory. Exiting..."
    24              exit 1
    25          fi
    26  
    27          # By default, the region field is found in the aws config file.
    28          # Sometimes it is found in the credentials file.
    29          if [ $(cat "$temp_file" | grep -c "region") -eq 0 ]; then
    30              temp_file="$aws_env/config"
    31              if [ -f $"$temp_file" ] && [ $(cat $"$temp_file" | grep -c "region") -gt 0 ]; then
    32                  grep region "$temp_file" >> ${LOCAL_AWS}
    33              else
    34                  echo "No region config field found in aws directory. Exiting..."
    35                  exit 1
    36              fi
    37          fi
    38  
    39          # TODO: The following should happen only for AWS. This is because
    40          # in the yaml templates this field is hardcoded. Can be solved if
    41          # templating engine like helm, kustomize is used.
    42          if kubectl get secrets | grep aws > /dev/null 2>&1; then
    43              kubectl delete secret aws-credentials
    44          fi
    45          kubectl create secret generic aws-credentials --from-file=$LOCAL_AWS
    46      elif [[ -f $aws_env ]]; then # File contains env variables.
    47          source ${aws_env}
    48          cat > ${LOCAL_AWS} <<- EOM
    49  [default]
    50  aws_access_key_id = ${AWS_ACCESS_KEY_ID}
    51  aws_secret_access_key = ${AWS_SECRET_ACCESS_KEY}
    52  region = ${AWS_REGION}
    53  output = json
    54  EOM
    55  
    56          if kubectl get secret | grep aws > /dev/null 2>&1; then
    57              kubectl delete secret aws-credentials
    58          fi
    59          kubectl create secret generic aws-credentials --from-file=${LOCAL_AWS}
    60      else
    61        echo "File nor directory exists under: ${aws_env}"
    62      fi
    63  fi
    64  
    65  rm -rf ${LOCAL_AWS}