Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dseichter/issue14 #28

Merged
merged 5 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added icons/Delete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/Download_from_the_Cloud.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,474 changes: 1,171 additions & 303 deletions src/AWSManager.fbp

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions src/aws_cloudfront.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import boto3
import aws_session_handler
import json


# get all cloudfront distributions and return a list of distributions
def get_cloudfront_distributions():
cloudfront = boto3.client('cloudfront')
session = aws_session_handler.get_session()
cloudfront = session.client('cloudfront')
distributions = cloudfront.list_distributions()
distributions_list = []
for distribution in distributions['DistributionList']['Items']:
Expand All @@ -14,20 +16,23 @@ def get_cloudfront_distributions():

# get information about a cloudfront distribution
def get_cloudfront_distribution(distribution_id):
cloudfront = boto3.client('cloudfront')
session = aws_session_handler.get_session()
cloudfront = session.client('cloudfront')
distribution = cloudfront.get_distribution(Id=distribution_id)
return distribution


# invalidate a cloudfront distribution
def invalidate_cloudfront_distribution(distribution_id, paths):
cloudfront = boto3.client('cloudfront')
session = aws_session_handler.get_session()
cloudfront = session.client('cloudfront')
response = cloudfront.create_invalidation(DistributionId=distribution_id, InvalidationBatch={'Paths': {'Quantity': len(paths), 'Items': paths}, 'CallerReference': 'awsmanager'})
return json.dumps(response, indent=2, default=str)


# load tags of a cloudfront distribution
def get_cloudfront_distribution_tags(distribution_id):
cloudfront = boto3.client('cloudfront')
session = aws_session_handler.get_session()
cloudfront = session.client('cloudfront')
tags = cloudfront.list_tags_for_resource(Resource=distribution_id)
return tags
22 changes: 15 additions & 7 deletions src/aws_ec2.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import boto3
import aws_session_handler


# get information about an ec2 instance
def get_ec2_instance(region, instance_id):
ec2 = boto3.client('ec2', region_name=region)
session = aws_session_handler.get_session()
ec2 = session.client('ec2', region_name=region)
instance = ec2.describe_instances(InstanceIds=[instance_id])
return instance['Reservations'][0]['Instances'][0]


# get all information about a volumeid
def get_ec2_volume(region, volume_id):
ec2 = boto3.client('ec2', region_name=region)
session = aws_session_handler.get_session()
ec2 = session.client('ec2', region_name=region)
volume = ec2.describe_volumes(VolumeIds=[volume_id])
return volume['Volumes'][0]


# get all ec2 instances of a region and return a list of instances
def get_ec2_instances(region):
ec2 = boto3.client('ec2', region_name=region)
session = aws_session_handler.get_session()
ec2 = session.client('ec2', region_name=region)
instances = ec2.describe_instances()
instances_list = []
for reservation in instances['Reservations']:
Expand All @@ -28,23 +32,27 @@ def get_ec2_instances(region):

# start a given instance
def start_ec2_instance(region, instance_id):
ec2 = boto3.client('ec2', region_name=region)
session = aws_session_handler.get_session()
ec2 = session.client('ec2', region_name=region)
ec2.start_instances(InstanceIds=[instance_id])


# stop a given instance
def stop_ec2_instance(region, instance_id):
ec2 = boto3.client('ec2', region_name=region)
session = aws_session_handler.get_session()
ec2 = session.client('ec2', region_name=region)
ec2.stop_instances(InstanceIds=[instance_id])


# reboot a given instance
def reboot_ec2_instance(region, instance_id):
ec2 = boto3.client('ec2', region_name=region)
session = aws_session_handler.get_session()
ec2 = session.client('ec2', region_name=region)
ec2.reboot_instances(InstanceIds=[instance_id])


# terminate a given instance
def terminate_ec2_instance(region, instance_id):
ec2 = boto3.client('ec2', region_name=region)
session = aws_session_handler.get_session()
ec2 = session.client('ec2', region_name=region)
ec2.terminate_instances(InstanceIds=[instance_id])
10 changes: 7 additions & 3 deletions src/aws_lambda.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import boto3
import aws_session_handler
import json


# get all lambda functions of a region and return a list of functions
def get_lambda_functions(region):
lambda_client = boto3.client('lambda', region_name=region)
session = aws_session_handler.get_session()
lambda_client = session.client('lambda', region_name=region)
functions = lambda_client.list_functions()
functions_list = []
for lambdafunction in functions['Functions']:
Expand All @@ -14,13 +16,15 @@ def get_lambda_functions(region):

# get information about a lambda function
def get_lambda_function(region, function_name):
lambda_client = boto3.client('lambda', region_name=region)
session = aws_session_handler.get_session()
lambda_client = session.client('lambda', region_name=region)
lambdafunction = lambda_client.get_function(FunctionName=function_name)
return lambdafunction


# invoke a lambda function
def invoke_lambda_function(region, function_name, payload):
lambda_client = boto3.client('lambda', region_name=region)
session = aws_session_handler.get_session()
lambda_client = session.client('lambda', region_name=region)
response = lambda_client.invoke(FunctionName=function_name, Payload=payload)
return json.dumps(response, indent=2, default=str)
4 changes: 3 additions & 1 deletion src/aws_rds.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import boto3
import aws_session_handler


# get all rds databases of a region and return a list of rds databases
def get_rds_databases(region):
rds = boto3.client('rds', region_name=region)
session = aws_session_handler.get_session()
rds = session.client('rds', region_name=region)
databases = rds.describe_db_instances()
databases_list = []
for database in databases['DBInstances']:
Expand Down
35 changes: 34 additions & 1 deletion src/aws_s3.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
import boto3
import aws_session_handler


# get all s3 buckets of a region and return a list of buckets
def get_s3_buckets(region):
s3 = boto3.client('s3', region_name=region)
session = aws_session_handler.get_session()
s3 = session.client('s3', region_name=region)
buckets = s3.list_buckets()
buckets_list = []
for bucket in buckets['Buckets']:
buckets_list.append(bucket)
return buckets_list


# get all objects of a bucket
def get_s3_bucket_objects(region, bucket_name):
s3 = boto3.client('s3', region_name=region)
objects = s3.list_objects_v2(Bucket=bucket_name)
objects_list = []
for obj in objects['Contents']:
objects_list.append(obj)
return objects_list


# download an object from a bucket into given file
def download_object(region, bucket_name, object_name, file_name):
session = aws_session_handler.get_session()
s3 = session.client('s3', region_name=region)
s3.download_file(bucket_name, object_name, file_name)


# upload a file to a bucket
def upload_file(region, bucket_name, file_name, object_name):
session = aws_session_handler.get_session()
s3 = session.client('s3', region_name=region)
s3.upload_file(file_name, bucket_name, object_name)


# delete an object from a bucket
def delete_object(region, bucket_name, object_name):
session = aws_session_handler.get_session()
s3 = session.client('s3', region_name=region)
s3.delete_object(Bucket=bucket_name, Key=object_name)
20 changes: 20 additions & 0 deletions src/aws_session_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import boto3
import settings


# use the selected profile, if no profile is given, use the default profile or the provided credentials
def get_session():
awslogin = settings.read_config()
aws_access_key_id = awslogin.get("aws_access_key_id", None)
aws_secret_access_key = awslogin.get("aws_secret_access_key", None)
aws_session_token = awslogin.get("aws_session_token", None)
aws_profile = awslogin.get("aws_profile", None)
if aws_access_key_id and aws_secret_access_key:
session = boto3.Session(
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
aws_session_token=aws_session_token,
)
elif aws_profile:
session = boto3.Session(profile_name=aws_profile)
return session
28 changes: 28 additions & 0 deletions src/awsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def __init__(self, parent):
self.m_auinotebook1.SetPageBitmap(self.m_auinotebook1.FindPage(self.panelS3), iconsaws.arch_amazon_simple_storage_service_48.GetBitmap().ConvertToImage().Rescale(16, 16).ConvertToBitmap())
self.m_auinotebook1.SetPageBitmap(self.m_auinotebook1.FindPage(self.panelCloudfront), iconsaws.arch_amazon_cloudfront_48.GetBitmap().ConvertToImage().Rescale(16, 16).ConvertToBitmap())

# add the icons to the menu items of S3
self.menuItemS3_DownloadObject.SetBitmap(icons.download_from_the_cloud.GetBitmap().ConvertToImage().Rescale(16, 16).ConvertToBitmap())
self.menuItemS3_DeleteObject.SetBitmap(icons.delete.GetBitmap().ConvertToImage().Rescale(16, 16).ConvertToBitmap())

def awsmanagerClose(self, event):
self.Close()

Expand Down Expand Up @@ -107,9 +111,33 @@ def aws_lambda_invoke(self, event):
def aws_lambda_open_mgmt_console(self, event):
ui_aws_lambda.aws_lambda_open_mgmt_console(self, event)

def aws_s3_load_details(self, event):
ui_aws_s3.aws_s3_load_details(self, event)

def aws_s3_reload(self, event):
ui_aws_s3.aws_s3_reload(self, event)

def aws_s3_refresh_bucket(self, event):
ui_aws_s3.aws_s3_refresh_bucket(self, event)

def aws_s3_open_mgmt_console(self, event):
ui_aws_s3.aws_s3_open_mgmt_console(self, event)

def aws_s3_selected_key(self, event):
ui_aws_s3.aws_s3_selected_key(self, event)

def aws_s3_upload_file(self, event):
ui_aws_s3.aws_s3_upload_file(self, event)

def aws_s3_drop_file(self, event):
ui_aws_s3.aws_s3_drop_file(self, event)

def aws_s3_menu_download_object(self, event):
ui_aws_s3.aws_s3_menu_download_object(self, event)

def aws_s3_menu_delete_object(self, event):
ui_aws_s3.aws_s3_menu_delete_object(self, event)

def aws_rds_reload(self, event):
ui_aws_rds.aws_rds_reload(self, event)

Expand Down
42 changes: 32 additions & 10 deletions src/configuration_ui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# importing wx files
import wx

# import the newly created GUI file
import gui

Expand All @@ -18,27 +19,48 @@ def __init__(self, parent):
gui.dialogAbout.SetIcon(self, icons.settings.GetIcon())

def showConfig(self, event):
# read all available profiles
profiles = settings.get_profiles()
# set the values
self.comboBoxAwsProfile.Clear()
self.comboBoxAwsProfile.Append(profiles)
# read all available regions
regions = settings.get_regions()
print(regions)
# set the values
self.comboBoxAwsDefaultRegion.Clear()
self.comboBoxAwsDefaultRegion.Append(regions)

# get the config
config = settings.read_config()
# set the values
self.textAwsAccessKeyId.SetValue(config['aws_access_key_id'])
self.textAwsSecretAccessKey.SetValue(config['aws_secret_access_key'])
self.textAwsSessionToken.SetValue(config['aws_session_token'])
self.comboBoxAwsProfile.SetValue(config['aws_profile'])
self.comboBoxAwsRegion.SetValue(config['region'])
self.textAwsAccessKeyId.SetValue(config["aws_access_key_id"])
self.textAwsSecretAccessKey.SetValue(config["aws_secret_access_key"])
self.textAwsSessionToken.SetValue(config["aws_session_token"])
self.comboBoxAwsProfile.SetValue(config["aws_profile"])
self.comboBoxAwsDefaultRegion.SetValue(config["region"])

self.Layout()
self.Fit()

def saveConfig(self, event):
# save the config
settings.save_config('aws_access_key_id', self.textAwsAccessKeyId.GetValue())
settings.save_config('aws_secret_access_key', self.textAwsSecretAccessKey.GetValue())
settings.save_config('aws_session_token', self.textAwsSessionToken.GetValue())
settings.save_config('aws_profile', self.comboBoxAwsProfile.GetValue())
settings.save_config('region', self.comboBoxAwsRegion.GetValue())
settings.save_config("aws_access_key_id", self.textAwsAccessKeyId.GetValue())
settings.save_config(
"aws_secret_access_key", self.textAwsSecretAccessKey.GetValue()
)
settings.save_config("aws_session_token", self.textAwsSessionToken.GetValue())
settings.save_config("aws_profile", self.comboBoxAwsProfile.GetValue())
settings.save_config("region", self.comboBoxAwsDefaultRegion.GetValue())
# close the dialog
self.Close()

def closeConfig(self, event):
self.Close()

def reloadAwsProfiles(self, event):
# read all available profiles
profiles = settings.get_profiles()
# set the values
self.comboBoxAwsProfile.Clear()
self.comboBoxAwsProfile.Append(profiles)
Loading
Loading