that coulda been bad
This commit is contained in:
28
secdep.py
28
secdep.py
@@ -168,7 +168,7 @@ if os.stat(ENV_FILE).st_size == 0:
|
||||
f.write('SECDEP_AZURE_APP_ID=\n')
|
||||
f.write('SECDEP_AZURE_PASSWORD=\n')
|
||||
case _:
|
||||
console.print("Invalid provider", style="bold red")
|
||||
console.print("[u]Invalid[/u] provider", style="bold red")
|
||||
else:
|
||||
console.print('[bold white]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 [u]-e[/u] option to have that done interactively[/bold white]')
|
||||
|
||||
@@ -284,7 +284,7 @@ def update_env_file():
|
||||
elif choice == 0:
|
||||
return
|
||||
except ValueError:
|
||||
print("Invalid choice")
|
||||
console.print("[u]Invalid[/u] choice", style="bold red")
|
||||
update_env_file()
|
||||
else:
|
||||
entry = file_entries[choice - 1]
|
||||
@@ -642,7 +642,7 @@ def get_corresponding_driver(provider):
|
||||
case "aws":
|
||||
driver = aws_driver
|
||||
case _:
|
||||
console.print("Invalid provider", style="bold red")
|
||||
console.print("[u]Invalid[/u] provider", style="bold red")
|
||||
assert driver is not None, "You need to set all {} environment variables first".format(provider.upper())
|
||||
return driver
|
||||
|
||||
@@ -1005,6 +1005,8 @@ def create_node(provider, name=None, location=None, size=None, image=None, confi
|
||||
# Any input other than yes does not continue the node creation
|
||||
assert confirm, "User did not confirm"
|
||||
if provider == "gce":
|
||||
status = Status("[bold white]Creating instance, please wait...[/bold white]", spinner="dots")
|
||||
status.start()
|
||||
gceNodes = driver.list_nodes()
|
||||
for gceNode in gceNodes:
|
||||
if gceNode.name == name:
|
||||
@@ -1027,6 +1029,8 @@ def create_node(provider, name=None, location=None, size=None, image=None, confi
|
||||
else:
|
||||
node = driver.create_node(name=name, image=image, size=size, location=location, ex_service_accounts=sa_scopes, ex_metadata=metadata)
|
||||
elif provider == "azure":
|
||||
status = Status("[bold white]Creating instance, please wait...[/bold white]", spinner="dots")
|
||||
status.start()
|
||||
console.print("Keep in mind azure node creation may take a while because we need to create all the needed resources first", style="bold white")
|
||||
res_groups = driver.ex_list_resource_groups()
|
||||
for res_group in res_groups:
|
||||
@@ -1082,6 +1086,8 @@ def create_node(provider, name=None, location=None, size=None, image=None, confi
|
||||
else:
|
||||
node = driver.create_node(name=name, size=size, image=image, location=location, auth=auth, ex_user_name="secdep", ex_resource_group=res_group.name, ex_use_managed_disks=True, ex_nic=newnic, ex_os_disk_delete=True)
|
||||
else:
|
||||
status = Status("[bold white]Creating instance, please wait...[/bold white]", spinner="dots")
|
||||
status.start()
|
||||
# If provider was aws
|
||||
# Delete all keys since we are just going to upload the same one for the creation
|
||||
# This doesn't affect already existing nodes because as we said, it it the same one used for the others
|
||||
@@ -1126,6 +1132,8 @@ def create_node(provider, name=None, location=None, size=None, image=None, confi
|
||||
else:
|
||||
# When the -y or --yes parameter is passed we go straight to the node creation
|
||||
if provider == "gce":
|
||||
status = Status("[bold white]Creating instance, please wait...[/bold white]", spinner="dots")
|
||||
status.start()
|
||||
gceNodes = driver.list_nodes()
|
||||
for gceNode in gceNodes:
|
||||
if gceNode.name == name:
|
||||
@@ -1148,6 +1156,8 @@ def create_node(provider, name=None, location=None, size=None, image=None, confi
|
||||
else:
|
||||
node = driver.create_node(name=name, image=image, size=size, location=location, ex_service_accounts=sa_scopes, ex_metadata=metadata)
|
||||
elif provider == "azure":
|
||||
status = Status("[bold white]Creating instance, please wait...[/bold white]", spinner="dots")
|
||||
status.start()
|
||||
console.print("Keep in mind azure node creation may take a while because we need to create all the needed resources first", style="bold white")
|
||||
res_groups = driver.ex_list_resource_groups()
|
||||
for res_group in res_groups:
|
||||
@@ -1203,6 +1213,8 @@ def create_node(provider, name=None, location=None, size=None, image=None, confi
|
||||
else:
|
||||
node = driver.create_node(name=name, size=size, image=image, location=location, auth=auth, ex_user_name="secdep", ex_resource_group=res_group.name, ex_use_managed_disks=True, ex_nic=newnic, ex_os_disk_delete=True)
|
||||
else:
|
||||
status = Status("[bold white]Creating instance, please wait...[/bold white]", spinner="dots")
|
||||
status.start()
|
||||
# If provider was aws
|
||||
# Delete all keys since we are just going to upload the same one for the creation
|
||||
# This doesn't affect already existing nodes because as we said, it it the same one used for the others
|
||||
@@ -1253,6 +1265,7 @@ def create_node(provider, name=None, location=None, size=None, image=None, confi
|
||||
console.print("[bold white]\nssh -p 22100 -i %s secdep@%s\n[/bold white]" % (SECDEP_SSH_PRIVATE_KEY, node.public_ips[0]))
|
||||
else:
|
||||
console.print("[bold white]\nssh -i %s secdep@%s\n[/bold white]" % (SECDEP_SSH_PRIVATE_KEY, node.public_ips[0]))
|
||||
status.stop()
|
||||
return node
|
||||
|
||||
def list_all_nodes(provider, filterIn=None, awsRegion=None):
|
||||
@@ -1335,10 +1348,11 @@ def list_all_nodes(provider, filterIn=None, awsRegion=None):
|
||||
for node in awsNodes:
|
||||
nodes.append(node)
|
||||
else:
|
||||
status.stop()
|
||||
if awsRegion not in awsLocations:
|
||||
print("Invalid region")
|
||||
console.print("[u]Invalid[/u] region", style="bold red")
|
||||
awsRegion = choose_from_list(listAWSregions(awsLocations),"aws_region")
|
||||
assert awsRegion is not None, "You chose an invalid aws region so we can't continue unless you choose a corect one"
|
||||
assert awsRegion is not None, "You chose an invalid aws region so we can't continue unless you choose a correct one"
|
||||
driver3 = get_driver(Provider.EC2)(SECDEP_AWS_ACCESS_KEY, SECDEP_AWS_SECRET_KEY, region=awsRegion)
|
||||
awsNodes = driver3.list_nodes()
|
||||
if len(awsNodes) > 0:
|
||||
@@ -1404,7 +1418,7 @@ def node_action(action, provider, awsRegion=None):
|
||||
case "delete":
|
||||
succeded = driver.destroy_node(node)
|
||||
case _:
|
||||
print("Invalid action command")
|
||||
console.print("[u]Invalid[/u] action command", style="bold red")
|
||||
exit(0)
|
||||
if(succeded):
|
||||
console.print("[bold white]%s node %s -> successful[/bold white]" % (providerName.upper(), action))
|
||||
@@ -1445,7 +1459,7 @@ def node_action_all(action, provider, awsRegion=None):
|
||||
case "deleteall":
|
||||
succeded = driver.destroy_node(node)
|
||||
case _:
|
||||
print("Invalid action command")
|
||||
console.print("[u]Invalid[/u] action command", style="bold red")
|
||||
exit(0)
|
||||
if(succeded):
|
||||
console.print("[bold white]%s node %s -> successful[/bold white]" % (node.name, string))
|
||||
|
||||
Reference in New Issue
Block a user