#!/usr/bin/python3
# vim:fileencoding=utf-8:ts=2:sw=2:expandtab

# Setup the path
import os, os.path, sys; sys.path.insert(1, os.path.abspath(sys.path[0] + "/../Python"))
import argparse
import json

try:
  from DocStruct.Config import EnvironmentConfig
except ImportError:
  print()
  print("Seems like your environment is not setup up correctly.")
  print("Please make sure DocStruct.Config is importable before running this script.")
  print()
  sys.exit(1)

parser = argparse.ArgumentParser(description="Sets up a DocStruct environment.")
# Parse the credentials file name
parser.add_argument(
  "credsfilepath", type=lambda s: os.path.abspath(s),
  help="Path to the CSV file to use for credentials to access AWS"
  )
# Parse the environment name
parser.add_argument(
  "environment_id", type=str,
  help="Name of the environment within which we are going to launch the instance"
  )
# Parse arguments
args = parser.parse_args()

# Assert that the credentials file actually exists
try:
  assert os.path.exists(args.credsfilepath)
except AssertionError:
  print("Could not find credential file at {0}. Please make sure the file actually exists before continuing...".format(args.credsfilepath))
  sys.exit(1)

# Check if an environment with the given name already exists
envconf = EnvironmentConfig(CredsFilePath=args.credsfilepath, EnvironmentID=args.environment_id)
print(json.dumps(envconf.Data))
