Handled a particular error.
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
What will happen on your system on first run? well, SecDep will create a `.env` file in the root directory of the project. This file is needed to store the authentication values needed to access the cloud providers. You will be asked for every needed value for every supported provider and if you don't need one you should just press enter to leave it's respecting values empty.
|
||||
|
||||
You can also run `python3 secdep.py --init <provider>` where `<provider>` is either gce, azure or aws to initialize the `.env` file for a specific provider only.
|
||||
|
||||
### Configuration ⚙️
|
||||
|
||||
Should you ever change your mind you can always edit the `.env` file manually or run `python3 secdep.py -v` or `python3 secdep.py --values` to change the values you want.
|
||||
|
||||
57
secdep.py
57
secdep.py
@@ -72,6 +72,7 @@ parser.add_argument('-p', '--print', help='Also print node, image, location or s
|
||||
parser.add_argument('-port', '--port', help='Port to connect to when using ssh')
|
||||
parser.add_argument('-awsregion', '--awsregion', help='Specify aws region to not have to go through all of them')
|
||||
parser.add_argument('-ssh', '--ssh', help='Connect to an instance using ssh with the option to use -P PROVIDER to choose node from a specific provider', action='store_true')
|
||||
parser.add_argument('-init', '--init', help='Initialize a specific provider\'s values' , choices=['gce', 'azure', 'aws'])
|
||||
args = parser.parse_args()
|
||||
|
||||
# If one or both keys don't exist we create them
|
||||
@@ -113,7 +114,40 @@ if not os.path.exists(ENV_FILE):
|
||||
|
||||
# We then check if the .env file is empty to determine if it's the first run of the script
|
||||
if os.stat(ENV_FILE).st_size == 0:
|
||||
print('You will be asked for each needed value\nIf you want to skip a provider press enter on each of their values because they are all needed for authentication\nIf at some point you delete the provider\'s value entry you will once again be asked to enter it\nIf you pressed enter by mistake or inserted an incorrect value just edit the file directly or delete the corresponding line\nThere is also the choice of using the -v option to have that done interactively')
|
||||
if args.init:
|
||||
match args.init:
|
||||
case "gce":
|
||||
with open(ENV_FILE, 'a') as f:
|
||||
f.write('SECDEP_AZURE_TENANT_ID=\n')
|
||||
f.write('SECDEP_AZURE_SUB_ID=\n')
|
||||
f.write('SECDEP_AZURE_APP_ID=\n')
|
||||
f.write('SECDEP_AZURE_PASSWORD=\n')
|
||||
f.write('SECDEP_AWS_ACCESS_KEY=\n')
|
||||
f.write('SECDEP_AWS_SECRET_KEY=\n')
|
||||
case "azure":
|
||||
with open(ENV_FILE, 'a') as f:
|
||||
f.write('SECDEP_GCE_CLIENT_ID=\n')
|
||||
f.write('SECDEP_GCE_CLIENT_SECRET=\n')
|
||||
f.write('SECDEP_GCE_PROJECT_ID=\n')
|
||||
f.write('SECDEP_AWS_ACCESS_KEY=\n')
|
||||
f.write('SECDEP_AWS_SECRET_KEY=\n')
|
||||
case "aws":
|
||||
with open(ENV_FILE, 'a') as f:
|
||||
f.write('SECDEP_GCE_CLIENT_ID=\n')
|
||||
f.write('SECDEP_GCE_CLIENT_SECRET=\n')
|
||||
f.write('SECDEP_GCE_PROJECT_ID=\n')
|
||||
f.write('SECDEP_AZURE_TENANT_ID=\n')
|
||||
f.write('SECDEP_AZURE_SUB_ID=\n')
|
||||
f.write('SECDEP_AZURE_APP_ID=\n')
|
||||
f.write('SECDEP_AZURE_PASSWORD=\n')
|
||||
case _:
|
||||
print("Invalid provider")
|
||||
else:
|
||||
print('You will be asked for each needed value\nIf you want to skip a provider press enter on each of their values because they are all needed for authentication\nIf at some point you delete the provider\'s value entry you will once again be asked to enter it\nIf you pressed enter by mistake or inserted an incorrect value just edit the file directly or delete the corresponding line\nThere is also the choice of using the -v option to have that done interactively')
|
||||
|
||||
if os.stat(ENV_FILE).st_size != 0 and args.init:
|
||||
print("The init flag was only meant to be run once if you knew you were going to be using only one provider. If you need to change a provider\'s needed values use the --values or -v flag instead")
|
||||
exit(0)
|
||||
|
||||
# We search for these values in the ENV_FILE and for each not found, we prompt the user to enter it
|
||||
# We then write the values to the ENV_FILE
|
||||
@@ -242,6 +276,10 @@ def update_env_file():
|
||||
load_dotenv(ENV_FILE)
|
||||
get_env_vars()
|
||||
|
||||
# If -v or --values is passed, call the update_env_file function
|
||||
if args.values:
|
||||
update_env_file()
|
||||
|
||||
# AWS and AZURE have thousands of image choice so we hardcode the ones we want in order to not wait forever during the input validation
|
||||
AWS_ubuntu22_04_images = {
|
||||
"ap-northeast-1": "ami-0cd7ad8676931d727",
|
||||
@@ -1187,6 +1225,8 @@ def list_all_nodes(provider, filterIn=None, awsRegion=None):
|
||||
for node in gceNodes:
|
||||
nodes.append(node)
|
||||
print("Loading %s%%..." % (int((1/providers_quantity)*100)))
|
||||
else:
|
||||
print("Skipping gce")
|
||||
if SECDEP_AZURE_APP_ID != "":
|
||||
print("Getting AZURE nodes...")
|
||||
driver2 = get_corresponding_driver("azure")
|
||||
@@ -1195,7 +1235,10 @@ def list_all_nodes(provider, filterIn=None, awsRegion=None):
|
||||
for node in azureNodes:
|
||||
nodes.append(node)
|
||||
print("Loading %s%%..." % (int((2/providers_quantity)*100)))
|
||||
else:
|
||||
print("Skipping azure")
|
||||
if SECDEP_AWS_ACCESS_KEY != "":
|
||||
driver3 = get_corresponding_driver("aws")
|
||||
print("Getting AWS nodes...")
|
||||
awsLocations = ["ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "eu-central-1", "eu-north-1", "eu-west-1", "eu-west-2", "eu-west-3", "sa-east-1", "us-east-1", "us-east-2", "us-west-1", "us-west-2"]
|
||||
for region in awsLocations:
|
||||
@@ -1206,6 +1249,8 @@ def list_all_nodes(provider, filterIn=None, awsRegion=None):
|
||||
for node in awsNodes:
|
||||
nodes.append(node)
|
||||
print("Loading %s%%..." % (int((3/providers_quantity)*100)))
|
||||
else:
|
||||
print("Skipping aws")
|
||||
elif provider == "gce":
|
||||
if SECDEP_GCE_CLIENT_ID != "":
|
||||
print("Getting GCE nodes...")
|
||||
@@ -1215,6 +1260,8 @@ def list_all_nodes(provider, filterIn=None, awsRegion=None):
|
||||
for node in gceNodes:
|
||||
nodes.append(node)
|
||||
print("Loading %s%%..." % (int((1/providers_quantity)*100)))
|
||||
else:
|
||||
print("Skipping gce")
|
||||
elif provider == "azure":
|
||||
if SECDEP_AZURE_APP_ID != "":
|
||||
print("Getting AZURE nodes...")
|
||||
@@ -1224,8 +1271,11 @@ def list_all_nodes(provider, filterIn=None, awsRegion=None):
|
||||
for node in azureNodes:
|
||||
nodes.append(node)
|
||||
print("Loading %s%%..." % (int((2/providers_quantity)*100)))
|
||||
else:
|
||||
print("Skipping azure")
|
||||
elif provider == "aws":
|
||||
if SECDEP_AWS_ACCESS_KEY != "":
|
||||
driver3 = get_corresponding_driver("aws")
|
||||
print("Getting AWS nodes...")
|
||||
awsLocations = ["ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "eu-central-1", "eu-north-1", "eu-west-1", "eu-west-2", "eu-west-3", "sa-east-1", "us-east-1", "us-east-2", "us-west-1", "us-west-2"]
|
||||
if awsRegion is None:
|
||||
@@ -1247,6 +1297,8 @@ def list_all_nodes(provider, filterIn=None, awsRegion=None):
|
||||
for node in awsNodes:
|
||||
nodes.append(node)
|
||||
print("Loading %s%%..." % (int((3/providers_quantity)*100)))
|
||||
else:
|
||||
print("Skipping aws")
|
||||
count = 0
|
||||
if len(nodes) == 0:
|
||||
print("No nodes")
|
||||
@@ -1393,9 +1445,6 @@ if args.awsregion and args.provider != "aws":
|
||||
# If -I -S or -G is passed, provider must be passed as well
|
||||
if args.listimages or args.listsizes or args.listlocations:
|
||||
assert args.provider is not None, "Provider must be passed if listing images, sizes or locations"
|
||||
# If -v or --values is passed, call the update_env_file function
|
||||
if args.values:
|
||||
update_env_file()
|
||||
if args.listimages and args.provider:
|
||||
# If -I or --listimages is passed, call the list_provider_images function
|
||||
if args.print:
|
||||
|
||||
Reference in New Issue
Block a user