<commit_before>#!/bin/sh

PREFIX=`etcdctl get /_arken.io/key`
USERNAME=${PREFIX}-${ENV_TECH_ID}

# Creating S3 user/bucket if needed
/opt/data/tools/awscli iam get-user --user-name $USERNAME &> /dev/null
if [ ! $? -eq 0 ]; then
  RAND=`openssl rand -hex 5`
  BUCKET=${PREFIX}-${ENV_TECH_ID}-${RAND}

  echo "Creating a new bucket $BUCKET for $USERNAME"

  # User/Bucket do not exists yet
  /opt/data/tools/awscli iam create-user --user-name $USERNAME --path /container/${PREFIX}/
  /opt/data/tools/awscli s3api create-bucket --bucket ${BUCKET}

  USER_POLICY="{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"${RAND}1\",\"Effect\":\"Allow\",\"Action\":[\"s3:*\"],\"Resource\":[\"arn:aws:s3:::${BUCKET}\"]},{\"Sid\":\"${RAND}2\",\"Effect\":\"Allow\",\"Action\":[\"s3:*\"],\"Resource\":[\"arn:aws:s3:::${BUCKET}/*\"]},{\"Sid\":\"${RAND}3\",\"Effect\":\"Allow\",\"Action\":[\"s3:ListAllMyBuckets\"],\"Resource\":[\"arn:aws:s3:::*\"]}]}"<commit_msg>NXIO-306: ensure to not try to create bucket when awscli is not ok<commit_after>#!/bin/sh

PREFIX=`etcdctl get /_arken.io/key`
USERNAME=${PREFIX}-${ENV_TECH_ID}

/opt/data/tools/awscli &> /dev/null
if [ ! $? -eq 2 ]; then
  echo "AWSCLI is missing."
  exit 1
fi

# Creating S3 user/bucket if needed
/opt/data/tools/awscli iam get-user --user-name $USERNAME &> /dev/null
if [ ! $? -eq 0 ]; then
  RAND=`openssl rand -hex 5`
  BUCKET=${PREFIX}-${ENV_TECH_ID}-${RAND}

  echo "Creating a new bucket $BUCKET for $USERNAME"

  # User/Bucket do not exists yet
  /opt/data/tools/awscli iam create-user --user-name $USERNAME --path /container/${PREFIX}/
  /opt/data/tools/awscli s3api create-bucket --bucket ${BUCKET}

  USER_POLICY="{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"${RAND}1\",\"Effect\":\"Allow\",\"Action\":[\"s3:*\"],\"Resource\":[\"arn:aws:s3:::${BUCKET}\"]},{\"Sid\":\"${RAND}2\",\"Effect\":\"Allow\",\"Action\":[\"s3:*\"],\"Resource\":[\"arn:aws:s3:::${BUCKET}/*\"]},{\"Sid\":\"${RAND}3\",\"Effect\":\"Allow\",\"Action\":[\"s3:ListAllMyBuckets\"],\"Resource\":[\"arn:aws:s3:::*\"]}]}"
{'fraction_non_alphanumeric': 0.29308666017526774, 'fraction_numerical': 0.022882181110029213, 'mean_word_length': 4.2025316455696204, 'pattern_counts': {'":': 28, '<': 3, '<?xml version=': 0, '>': 6, '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': '2458413', 'n_tokens_mistral': 848, 'n_tokens_neox': 814, 'n_words': 126}