Skip to content

Commit

Permalink
Merge pull request #25 from dseichter/dseichter/issue16
Browse files Browse the repository at this point in the history
#16 Add details of cloudfront
  • Loading branch information
Daniel Seichter authored Jul 3, 2024
2 parents ee01c2d + ea5421b commit 8119bf7
Show file tree
Hide file tree
Showing 7 changed files with 1,412 additions and 30 deletions.
1,224 changes: 1,200 additions & 24 deletions src/AWSManager.fbp

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions src/aws_cloudfront.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import boto3
import json


# get all cloudfront distributions and return a list of distributions
Expand All @@ -9,3 +10,24 @@ def get_cloudfront_distributions():
for distribution in distributions['DistributionList']['Items']:
distributions_list.append(distribution)
return distributions_list


# get information about a cloudfront distribution
def get_cloudfront_distribution(distribution_id):
cloudfront = boto3.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')
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')
tags = cloudfront.list_tags_for_resource(Resource=distribution_id)
return tags
12 changes: 12 additions & 0 deletions src/awsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,21 @@ def aws_s3_reload(self, event):
def aws_rds_reload(self, event):
ui_aws_rds.aws_rds_reload(self, event)

def aws_cloudfront_load_details(self, event):
ui_aws_cloudfront.aws_cloudfront_load_details(self, event)

def aws_cloudfront_reload(self, event):
ui_aws_cloudfront.aws_cloudfront_reload(self, event)

def aws_cloudfront_refresh_distribution(self, event):
ui_aws_cloudfront.aws_cloudfront_refresh_distribution(self, event)

def aws_cloudfront_open_mgmt_console(self, event):
ui_aws_cloudfront.aws_cloudfront_open_mgmt_console(self, event)

def aws_cloudfront_invalidate(self, event):
ui_aws_cloudfront.aws_cloudfront_invalidate(self, event)


# mandatory in wx, create an app, False stands for not deteriction stdin/stdout
# refer manual for details
Expand Down
115 changes: 111 additions & 4 deletions src/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ def __init__( self, parent ):

fgSizerEC2Details.Add( self.staticTextEC2_Tags, 0, wx.ALL, 5 )

self.propertyGridEC2_tags = wx.propgrid.PropertyGrid(self.panelEC2Details, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.propgrid.PG_AUTO_SORT|wx.propgrid.PG_DEFAULT_STYLE|wx.propgrid.PG_LIMITED_EDITING)
fgSizerEC2Details.Add( self.propertyGridEC2_tags, 1, wx.ALL|wx.EXPAND, 5 )
self.propertyGridEC2_Tags = wx.propgrid.PropertyGrid(self.panelEC2Details, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.propgrid.PG_AUTO_SORT|wx.propgrid.PG_DEFAULT_STYLE|wx.propgrid.PG_LIMITED_EDITING)
fgSizerEC2Details.Add( self.propertyGridEC2_Tags, 1, wx.ALL|wx.EXPAND, 5 )


fgSizerEC2Details.Add( ( 0, 0), 1, wx.EXPAND, 5 )
Expand Down Expand Up @@ -401,7 +401,7 @@ def __init__( self, parent ):
self.panelLambda.SetSizer( bSizer3 )
self.panelLambda.Layout()
bSizer3.Fit( self.panelLambda )
self.m_auinotebook1.AddPage( self.panelLambda, u"Lambda", True, wx.NullBitmap )
self.m_auinotebook1.AddPage( self.panelLambda, u"Lambda", False, wx.NullBitmap )
self.panelS3 = wx.Panel( self.m_auinotebook1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
bSizer81 = wx.BoxSizer( wx.VERTICAL )

Expand Down Expand Up @@ -478,14 +478,105 @@ def __init__( self, parent ):
self.panelCloudfrontTree.Layout()
bSizer43.Fit( self.panelCloudfrontTree )
self.panelCloudfrontDetails = wx.Panel( self.m_splitter13, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
bSizer132 = wx.BoxSizer( wx.VERTICAL )

fgSizerCloudfrontDetails = wx.FlexGridSizer( 0, 3, 0, 0 )
fgSizerCloudfrontDetails.AddGrowableCol( 1 )
fgSizerCloudfrontDetails.SetFlexibleDirection( wx.BOTH )
fgSizerCloudfrontDetails.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )

self.staticTextCloudfront_Id = wx.StaticText( self.panelCloudfrontDetails, wx.ID_ANY, u"ID", wx.DefaultPosition, wx.DefaultSize, 0 )
self.staticTextCloudfront_Id.Wrap( -1 )

fgSizerCloudfrontDetails.Add( self.staticTextCloudfront_Id, 0, wx.ALL, 5 )

self.textCtrlCloudfront_Id = wx.TextCtrl( self.panelCloudfrontDetails, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
fgSizerCloudfrontDetails.Add( self.textCtrlCloudfront_Id, 1, wx.ALL|wx.EXPAND, 5 )

self.buttonCloudfront_RefreshDistribution = wx.Button( self.panelCloudfrontDetails, wx.ID_ANY, u"Refresh", wx.DefaultPosition, wx.DefaultSize, 0 )
fgSizerCloudfrontDetails.Add( self.buttonCloudfront_RefreshDistribution, 0, wx.ALL, 5 )

self.staticTextCloudfront_Status = wx.StaticText( self.panelCloudfrontDetails, wx.ID_ANY, u"Status", wx.DefaultPosition, wx.DefaultSize, 0 )
self.staticTextCloudfront_Status.Wrap( -1 )

fgSizerCloudfrontDetails.Add( self.staticTextCloudfront_Status, 0, wx.ALL, 5 )

self.textCtrlCloudfront_Status = wx.TextCtrl( self.panelCloudfrontDetails, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
fgSizerCloudfrontDetails.Add( self.textCtrlCloudfront_Status, 1, wx.ALL|wx.EXPAND, 5 )

self.buttonCloudfront_OpenMgmtConsole = wx.Button( self.panelCloudfrontDetails, wx.ID_ANY, u"Open in AWS", wx.DefaultPosition, wx.DefaultSize, 0 )
fgSizerCloudfrontDetails.Add( self.buttonCloudfront_OpenMgmtConsole, 0, wx.ALL, 5 )

self.staticTextCloudfront_Description = wx.StaticText( self.panelCloudfrontDetails, wx.ID_ANY, u"Description", wx.DefaultPosition, wx.DefaultSize, 0 )
self.staticTextCloudfront_Description.Wrap( -1 )

fgSizerCloudfrontDetails.Add( self.staticTextCloudfront_Description, 0, wx.ALL, 5 )

self.textCtrlCloudfront_Description = wx.TextCtrl( self.panelCloudfrontDetails, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
fgSizerCloudfrontDetails.Add( self.textCtrlCloudfront_Description, 1, wx.ALL|wx.EXPAND, 5 )


fgSizerCloudfrontDetails.Add( ( 0, 0), 1, wx.EXPAND, 5 )

self.staticTextECloudfront_DomainName = wx.StaticText( self.panelCloudfrontDetails, wx.ID_ANY, u"DomainName", wx.DefaultPosition, wx.DefaultSize, 0 )
self.staticTextECloudfront_DomainName.Wrap( -1 )

fgSizerCloudfrontDetails.Add( self.staticTextECloudfront_DomainName, 0, wx.ALL, 5 )

self.textCtrlCloudfront_DomainName = wx.TextCtrl( self.panelCloudfrontDetails, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
fgSizerCloudfrontDetails.Add( self.textCtrlCloudfront_DomainName, 1, wx.ALL|wx.EXPAND, 5 )

self.buttonCloudfront_InvalidateCache = wx.Button( self.panelCloudfrontDetails, wx.ID_ANY, u"Invalidate", wx.DefaultPosition, wx.DefaultSize, 0 )
fgSizerCloudfrontDetails.Add( self.buttonCloudfront_InvalidateCache, 0, wx.ALL, 5 )

self.staticText_AltDomainName = wx.StaticText( self.panelCloudfrontDetails, wx.ID_ANY, u"Alternative Domains", wx.DefaultPosition, wx.DefaultSize, 0 )
self.staticText_AltDomainName.Wrap( -1 )

fgSizerCloudfrontDetails.Add( self.staticText_AltDomainName, 0, wx.ALL, 5 )

self.textCtrlCloudfront_AltDomainName = wx.TextCtrl( self.panelCloudfrontDetails, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
fgSizerCloudfrontDetails.Add( self.textCtrlCloudfront_AltDomainName, 1, wx.ALL|wx.EXPAND, 5 )


fgSizerCloudfrontDetails.Add( ( 0, 0), 1, wx.EXPAND, 5 )

self.staticTextCloudfront_Origins = wx.StaticText( self.panelCloudfrontDetails, wx.ID_ANY, u"Origins", wx.DefaultPosition, wx.DefaultSize, 0 )
self.staticTextCloudfront_Origins.Wrap( -1 )

fgSizerCloudfrontDetails.Add( self.staticTextCloudfront_Origins, 0, wx.ALL, 5 )

self.textCtrlCloudfront_Origins = wx.TextCtrl( self.panelCloudfrontDetails, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
fgSizerCloudfrontDetails.Add( self.textCtrlCloudfront_Origins, 1, wx.ALL|wx.EXPAND, 5 )


fgSizerCloudfrontDetails.Add( ( 0, 0), 1, wx.EXPAND, 5 )

self.staticTextEC2_Tags1 = wx.StaticText( self.panelCloudfrontDetails, wx.ID_ANY, u"Tags", wx.DefaultPosition, wx.DefaultSize, 0 )
self.staticTextEC2_Tags1.Wrap( -1 )

fgSizerCloudfrontDetails.Add( self.staticTextEC2_Tags1, 0, wx.ALL, 5 )

self.propertyGridCloudfront_Tags = wx.propgrid.PropertyGrid(self.panelCloudfrontDetails, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.propgrid.PG_AUTO_SORT|wx.propgrid.PG_DEFAULT_STYLE|wx.propgrid.PG_LIMITED_EDITING)
fgSizerCloudfrontDetails.Add( self.propertyGridCloudfront_Tags, 1, wx.ALL|wx.EXPAND, 5 )


fgSizerCloudfrontDetails.Add( ( 0, 0), 1, wx.EXPAND, 5 )


bSizer132.Add( fgSizerCloudfrontDetails, 1, wx.EXPAND, 5 )


self.panelCloudfrontDetails.SetSizer( bSizer132 )
self.panelCloudfrontDetails.Layout()
bSizer132.Fit( self.panelCloudfrontDetails )
self.m_splitter13.SplitVertically( self.panelCloudfrontTree, self.panelCloudfrontDetails, 0 )
bSizer83.Add( self.m_splitter13, 1, wx.EXPAND, 5 )


self.panelCloudfront.SetSizer( bSizer83 )
self.panelCloudfront.Layout()
bSizer83.Fit( self.panelCloudfront )
self.m_auinotebook1.AddPage( self.panelCloudfront, u"Cloudfront", False, wx.NullBitmap )
self.m_auinotebook1.AddPage( self.panelCloudfront, u"Cloudfront", True, wx.NullBitmap )

gSizer1.Add( self.m_auinotebook1, 1, wx.EXPAND |wx.ALL, 5 )

Expand Down Expand Up @@ -515,7 +606,11 @@ def __init__( self, parent ):
self.buttonLambda_Invoke.Bind( wx.EVT_BUTTON, self.aws_lambda_invoke )
self.buttonReloadS3.Bind( wx.EVT_BUTTON, self.aws_s3_reload )
self.buttonReloadRDS.Bind( wx.EVT_BUTTON, self.aws_rds_reload )
self.treeCloudfront.Bind( wx.EVT_TREE_ITEM_ACTIVATED, self.aws_cloudfront_load_details )
self.buttonReloadCloudfront.Bind( wx.EVT_BUTTON, self.aws_cloudfront_reload )
self.buttonCloudfront_RefreshDistribution.Bind( wx.EVT_BUTTON, self.aws_cloudfront_refresh_distribution )
self.buttonCloudfront_OpenMgmtConsole.Bind( wx.EVT_BUTTON, self.aws_cloudfront_open_mgmt_console )
self.buttonCloudfront_InvalidateCache.Bind( wx.EVT_BUTTON, self.aws_cloudfront_invalidate )

def __del__( self ):
pass
Expand Down Expand Up @@ -579,9 +674,21 @@ def aws_s3_reload( self, event ):
def aws_rds_reload( self, event ):
event.Skip()

def aws_cloudfront_load_details( self, event ):
event.Skip()

def aws_cloudfront_reload( self, event ):
event.Skip()

def aws_cloudfront_refresh_distribution( self, event ):
event.Skip()

def aws_cloudfront_open_mgmt_console( self, event ):
event.Skip()

def aws_cloudfront_invalidate( self, event ):
event.Skip()

def m_splitter1OnIdle( self, event ):
self.m_splitter1.SetSashPosition( 0 )
self.m_splitter1.Unbind( wx.EVT_IDLE )
Expand Down
65 changes: 65 additions & 0 deletions src/ui_aws_cloudfront.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# import the newly created GUI file
import wx
import wx.propgrid

import aws_cloudfront
import settings
import iconsaws
import webbrowser


def aws_cloudfront_reload(self, event):
Expand All @@ -22,3 +24,66 @@ def aws_cloudfront_reload(self, event):
item = self.treeCloudfront.AppendItem(root, distribution_id + ' (' + distribution_status + ') - ' + distribution_domain_name)
self.treeCloudfront.SetItemImage(item, cloudfront_distribution, wx.TreeItemIcon_Normal)
self.treeCloudfront.ExpandAll()


def aws_cloudfront_load_details(self, event):
# get the selected item
item = self.treeCloudfront.GetSelection()
if item:
# get the text of the selected item
text = self.treeCloudfront.GetItemText(item)
# get the distribution id
distribution_id = text.split(' ')[0]
# get the distribution details
distribution = aws_cloudfront.get_cloudfront_distribution(distribution_id)
# set the details in the text control
self.textCtrlCloudfront_Id.SetValue(distribution_id)
self.textCtrlCloudfront_Status.SetValue(distribution['Distribution']['Status'])
self.textCtrlCloudfront_Description.SetValue(distribution['Distribution']['DistributionConfig']['Comment'])
self.textCtrlCloudfront_DomainName.SetValue(distribution['Distribution']['DomainName'])
self.textCtrlCloudfront_AltDomainName.SetValue(', '.join(distribution['Distribution']['DistributionConfig']['Aliases']['Items']))
self.textCtrlCloudfront_Origins.SetValue(', '.join([origin['DomainName'] for origin in distribution['Distribution']['DistributionConfig']['Origins']['Items']]))
# get the tags
self.propertyGridCloudfront_Tags.Clear()
tags = aws_cloudfront.get_cloudfront_distribution_tags(distribution['Distribution']['ARN'])
# add the tags to the property grid
for tag in tags['Tags']['Items']:
self.propertyGridCloudfront_Tags.Append(wx.propgrid.StringProperty(tag['Key'], tag['Key'], tag['Value']))
self.propertyGridCloudfront_Tags.Refresh()


def aws_cloudfront_refresh_distribution(self, event):
aws_cloudfront_load_details(self, event)


def aws_cloudfront_open_mgmt_console(self, event):
# get the selected item
item = self.treeCloudfront.GetSelection()
if item:
# get the text of the selected item
text = self.treeCloudfront.GetItemText(item)
# get the distribution id
distribution_id = text.split(' ')[0]
# open the management console
webbrowser.open_new_tab(f"https://us-east-1.console.aws.amazon.com/cloudfront/v4/home?region=us-east-1#/distributions/{distribution_id}")


def aws_cloudfront_invalidate(self, event):
# create a small dialog to ask the user for the paths to invalidate
dlg = wx.TextEntryDialog(self, 'Enter the paths to invalidate separated by a comma:', 'Invalidate paths', '/*', style=wx.TextEntryDialogStyle | wx.TE_MULTILINE)
if dlg.ShowModal() == wx.ID_OK:
paths = dlg.GetValue().split(',')
# get the selected item
item = self.treeCloudfront.GetSelection()
if item:
# get the text of the selected item
text = self.treeCloudfront.GetItemText(item)
# get the distribution id
distribution_id = text.split(' ')[0]
# invalidate the distribution
response = aws_cloudfront.invalidate_cloudfront_distribution(distribution_id, paths)
# show the response in a new dialog
dlg_response = wx.TextEntryDialog(self, 'Invalidation response:', 'Response of Invalidation', response, style=wx.TextEntryDialogStyle | wx.TE_MULTILINE | wx.TE_DONTWRAP)
dlg_response.ShowModal()
dlg_response.Destroy()
dlg.Destroy()
2 changes: 1 addition & 1 deletion src/ui_aws_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def aws_ec2_load_details(self, event):
self.propertyGridEC2_tags.Clear()
# add the tags to the property grid
for tag in ec2_instance['Tags']:
self.propertyGridEC2_tags.Append(wx.propgrid.StringProperty(tag['Key'], tag['Key'], tag['Value']))
self.propertyGridEC2_Tags.Append(wx.propgrid.StringProperty(tag['Key'], tag['Key'], tag['Value']))
self.propertyGridEC2_tags.Refresh()
# get volume information and add it to the grid
self.gridEC2_Volumes.ClearGrid()
Expand Down
2 changes: 1 addition & 1 deletion src/ui_aws_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def aws_lambda_invoke(self, event):
# invoke the function
response = aws_lambda.invoke_lambda_function(settings.read_config()['region'], function_name, payload)
# show the response in a new dialog
dlg_response = wx.TextEntryDialog(self, 'Enter the payload for the function:', 'Response of Invocation', response, style=wx.TextEntryDialogStyle | wx.TE_MULTILINE | wx.TE_DONTWRAP)
dlg_response = wx.TextEntryDialog(self, 'Invocation Response:', 'Response of Invocation', response, style=wx.TextEntryDialogStyle | wx.TE_MULTILINE | wx.TE_DONTWRAP)
dlg_response.ShowModal()
dlg_response.Destroy()
dlg.Destroy()

0 comments on commit 8119bf7

Please sign in to comment.