-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Return removed staging CA for letsenrypt * Fix missing $ * Remove PAYMENTS_AUTORECHARGE_DEFAULT_MIN_BALANCE * Add helpers scripts
- Loading branch information
1 parent
5248695
commit 72218cb
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import secrets | ||
import string | ||
import sys | ||
|
||
|
||
def generate_password(length=12): | ||
# https://stackoverflow.com/a/39596292 | ||
alphabet = string.ascii_letters + string.digits | ||
password = "".join(secrets.choice(alphabet) for i in range(length)) | ||
return password | ||
|
||
|
||
if len(sys.argv) < 2: | ||
pwd_len = 30 | ||
else: | ||
pwd_len = int(sys.argv[1]) | ||
|
||
new_password = generate_password(pwd_len) | ||
print(new_password) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import sys | ||
from pprint import pprint | ||
|
||
import boto3 | ||
|
||
# Create a session with the specified profile or use the default profile | ||
profile_name = sys.argv[1] if len(sys.argv) > 1 else None | ||
session = boto3.Session(profile_name=profile_name) | ||
|
||
# Use the session to create an EC2 client to get the default region | ||
ec2_client = session.client("ec2") | ||
default_region = ec2_client.meta.region_name | ||
|
||
# Use the session to create an EC2 resource with the default region | ||
ec2 = session.resource("ec2", region_name=default_region) | ||
|
||
unused_keys = {} | ||
|
||
# Iterate over all regions | ||
for region in ec2.meta.client.describe_regions()["Regions"]: | ||
region_name = region["RegionName"] | ||
try: | ||
# Use the session to create an EC2 resource for the specific region | ||
ec2conn = session.resource("ec2", region_name=region_name) | ||
|
||
# Get all key pairs in the region | ||
key_pairs = ec2conn.key_pairs.all() | ||
|
||
# Get the names of key pairs used by instances in the region | ||
used_keys = {instance.key_name for instance in ec2conn.instances.all()} | ||
|
||
# Iterate over key pairs and delete unused ones | ||
for key_pair in key_pairs: | ||
if key_pair.name not in used_keys: | ||
unused_keys[key_pair.name] = region_name | ||
except Exception as e: | ||
print(f"No access to region {region_name}: {e}") | ||
|
||
# Print the results | ||
print(f"Found {len(unused_keys)} unused key pairs across all regions:") | ||
pprint(unused_keys) |