-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
488 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
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
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,85 @@ | ||
using Amazon.RDS; | ||
using Amazon.RDS.Model; | ||
|
||
using static MountAws.PagingHelper; | ||
|
||
namespace MountAws.Services.Rds; | ||
|
||
public static class ApiExtensions | ||
{ | ||
public static IEnumerable<DBInstance> DescribeDBInstances(this IAmazonRDS rds, Filter filter) | ||
{ | ||
return rds.DescribeDBInstances(new[] { filter }); | ||
} | ||
|
||
public static IEnumerable<DBInstance> DescribeDBInstances(this IAmazonRDS rds, IEnumerable<Filter>? filters = null) | ||
{ | ||
return Paginate(nextToken => | ||
{ | ||
var response = rds.DescribeDBInstancesAsync(new DescribeDBInstancesRequest | ||
{ | ||
Filters = filters?.ToList(), | ||
Marker = nextToken | ||
}) | ||
.GetAwaiter() | ||
.GetResult(); | ||
|
||
return (response.DBInstances, response.Marker); | ||
}); | ||
} | ||
|
||
public static DBInstance? DescribeDBInstance(this IAmazonRDS rds, string dbInstanceIdentifier) | ||
{ | ||
try | ||
{ | ||
return rds.DescribeDBInstancesAsync(new DescribeDBInstancesRequest | ||
{ | ||
DBInstanceIdentifier = dbInstanceIdentifier | ||
}) | ||
.GetAwaiter() | ||
.GetResult() | ||
.DBInstances | ||
.Single(); | ||
} | ||
catch (DBInstanceNotFoundException) | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
public static IEnumerable<DBCluster> DescribeDBClusters(this IAmazonRDS rds, IEnumerable<Filter>? filters = null) | ||
{ | ||
return Paginate(nextToken => | ||
{ | ||
var response = rds.DescribeDBClustersAsync(new DescribeDBClustersRequest | ||
{ | ||
Filters = filters?.ToList(), | ||
Marker = nextToken, | ||
IncludeShared = true | ||
}) | ||
.GetAwaiter() | ||
.GetResult(); | ||
|
||
return (response.DBClusters, response.Marker); | ||
}); | ||
} | ||
|
||
public static DBCluster? DescribeDBCluster(this IAmazonRDS rds, string dbClusterIdentifier) | ||
{ | ||
try | ||
{ | ||
return rds.DescribeDBClustersAsync(new DescribeDBClustersRequest | ||
{ | ||
DBClusterIdentifier = dbClusterIdentifier | ||
}) | ||
.GetAwaiter() | ||
.GetResult() | ||
.DBClusters | ||
.Single(); | ||
} | ||
catch (DBClusterNotFoundException) | ||
{ | ||
return null; | ||
} | ||
} | ||
} |
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,35 @@ | ||
using Amazon.RDS; | ||
using Amazon.RDS.Model; | ||
using MountAnything; | ||
|
||
namespace MountAws.Services.Rds; | ||
|
||
public class ClusterHandler : PathHandler | ||
{ | ||
private readonly IAmazonRDS _rds; | ||
|
||
public ClusterHandler(ItemPath path, IPathHandlerContext context, IAmazonRDS rds) : base(path, context) | ||
{ | ||
_rds = rds; | ||
} | ||
|
||
protected override IItem? GetItemImpl() | ||
{ | ||
var cluster = _rds.DescribeDBCluster(ItemName); | ||
|
||
return cluster != null ? new ClusterItem(ParentPath, cluster) : null; | ||
} | ||
|
||
protected override IEnumerable<IItem> GetChildItemsImpl() | ||
{ | ||
var clusterItem = GetItem() as ClusterItem; | ||
if (clusterItem == null) | ||
return Enumerable.Empty<IItem>(); | ||
|
||
return _rds.DescribeDBInstances(new Filter | ||
{ | ||
Name = "db-cluster-id", | ||
Values = new List<string>{clusterItem.ItemName} | ||
}).Select(db => new InstanceItem(Path, db)); | ||
} | ||
} |
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,26 @@ | ||
using Amazon.RDS; | ||
using MountAnything; | ||
|
||
namespace MountAws.Services.Rds; | ||
|
||
public class ClusterInstanceHandler : PathHandler | ||
{ | ||
private readonly IAmazonRDS _rds; | ||
|
||
public ClusterInstanceHandler(ItemPath path, IPathHandlerContext context, IAmazonRDS rds) : base(path, context) | ||
{ | ||
_rds = rds; | ||
} | ||
|
||
protected override IItem? GetItemImpl() | ||
{ | ||
var instance = _rds.DescribeDBInstance(ItemName); | ||
|
||
return instance != null ? new InstanceItem(ParentPath, instance) : null; | ||
} | ||
|
||
protected override IEnumerable<IItem> GetChildItemsImpl() | ||
{ | ||
yield break; | ||
} | ||
} |
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,22 @@ | ||
using Amazon.RDS.Model; | ||
using MountAnything; | ||
|
||
namespace MountAws.Services.Rds; | ||
|
||
public class ClusterItem : AwsItem<DBCluster> | ||
{ | ||
public ClusterItem(ItemPath parentPath, DBCluster cluster) : base(parentPath, cluster) | ||
{ | ||
ItemName = cluster.DBClusterIdentifier; | ||
} | ||
|
||
[ItemProperty] | ||
public int MemberCount => UnderlyingObject.DBClusterMembers.Count; | ||
|
||
public override string ItemName { get; } | ||
|
||
public override bool IsContainer => true; | ||
|
||
public override string? WebUrl => | ||
UrlBuilder.CombineWith($"rds/home#database:id={UnderlyingObject.DBClusterIdentifier};is-cluster=true"); | ||
} |
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,32 @@ | ||
using Amazon.RDS; | ||
using MountAnything; | ||
using MountAws.Services.Core; | ||
|
||
namespace MountAws.Services.Rds; | ||
|
||
public class ClustersHandler : PathHandler | ||
{ | ||
public static IItem CreateItem(ItemPath parentPath) | ||
{ | ||
return new GenericContainerItem(parentPath, "clusters", | ||
"Navigate RDS DB Clusters (i.e. Aurora) in the current account and region"); | ||
} | ||
|
||
private readonly IAmazonRDS _rds; | ||
|
||
public ClustersHandler(ItemPath path, IPathHandlerContext context, IAmazonRDS rds) : base(path, context) | ||
{ | ||
_rds = rds; | ||
} | ||
|
||
protected override IItem GetItemImpl() | ||
{ | ||
return CreateItem(ParentPath); | ||
} | ||
|
||
protected override IEnumerable<IItem> GetChildItemsImpl() | ||
{ | ||
return _rds.DescribeDBClusters() | ||
.Select(cluster => new ClusterItem(Path, cluster)); | ||
} | ||
} |
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,76 @@ | ||
<Configuration> | ||
<ViewDefinitions> | ||
<View> | ||
<Name>RdsDbInstance</Name> | ||
<ViewSelectedBy> | ||
<TypeName>MountAws.Services.Rds.InstanceItem</TypeName> | ||
</ViewSelectedBy> | ||
<TableControl> | ||
<TableHeaders> | ||
<TableColumnHeader> | ||
</TableColumnHeader> | ||
<TableColumnHeader> | ||
</TableColumnHeader> | ||
<TableColumnHeader> | ||
</TableColumnHeader> | ||
<TableColumnHeader> | ||
</TableColumnHeader> | ||
</TableHeaders> | ||
<TableRowEntries> | ||
<TableRowEntry> | ||
<TableColumnItems> | ||
<TableColumnItem> | ||
<PropertyName>Name</PropertyName> | ||
</TableColumnItem> | ||
<TableColumnItem> | ||
<PropertyName>Engine</PropertyName> | ||
</TableColumnItem> | ||
<TableColumnItem> | ||
<PropertyName>EngineVersion</PropertyName> | ||
</TableColumnItem> | ||
<TableColumnItem> | ||
<PropertyName>DBInstanceClass</PropertyName> | ||
</TableColumnItem> | ||
</TableColumnItems> | ||
</TableRowEntry> | ||
</TableRowEntries> | ||
</TableControl> | ||
</View> | ||
<View> | ||
<Name>RdsDbCluster</Name> | ||
<ViewSelectedBy> | ||
<TypeName>MountAws.Services.Rds.ClusterItem</TypeName> | ||
</ViewSelectedBy> | ||
<TableControl> | ||
<TableHeaders> | ||
<TableColumnHeader> | ||
</TableColumnHeader> | ||
<TableColumnHeader> | ||
</TableColumnHeader> | ||
<TableColumnHeader> | ||
</TableColumnHeader> | ||
<TableColumnHeader> | ||
</TableColumnHeader> | ||
</TableHeaders> | ||
<TableRowEntries> | ||
<TableRowEntry> | ||
<TableColumnItems> | ||
<TableColumnItem> | ||
<PropertyName>Name</PropertyName> | ||
</TableColumnItem> | ||
<TableColumnItem> | ||
<PropertyName>Engine</PropertyName> | ||
</TableColumnItem> | ||
<TableColumnItem> | ||
<PropertyName>EngineVersion</PropertyName> | ||
</TableColumnItem> | ||
<TableColumnItem> | ||
<PropertyName>MemberCount</PropertyName> | ||
</TableColumnItem> | ||
</TableColumnItems> | ||
</TableRowEntry> | ||
</TableRowEntries> | ||
</TableControl> | ||
</View> | ||
</ViewDefinitions> | ||
</Configuration> |
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,26 @@ | ||
using Amazon.RDS; | ||
using MountAnything; | ||
|
||
namespace MountAws.Services.Rds; | ||
|
||
public class InstanceHandler : PathHandler | ||
{ | ||
private readonly IAmazonRDS _rds; | ||
|
||
public InstanceHandler(ItemPath path, IPathHandlerContext context, IAmazonRDS rds) : base(path, context) | ||
{ | ||
_rds = rds; | ||
} | ||
|
||
protected override IItem? GetItemImpl() | ||
{ | ||
var dbInstance = _rds.DescribeDBInstance(ItemName); | ||
|
||
return dbInstance != null ? new InstanceItem(ParentPath, dbInstance) : null; | ||
} | ||
|
||
protected override IEnumerable<IItem> GetChildItemsImpl() | ||
{ | ||
yield break; | ||
} | ||
} |
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,17 @@ | ||
using Amazon.RDS.Model; | ||
using MountAnything; | ||
|
||
namespace MountAws.Services.Rds; | ||
|
||
public class InstanceItem : AwsItem<DBInstance> | ||
{ | ||
public InstanceItem(ItemPath parentPath, DBInstance dbInstance) : base(parentPath, dbInstance) | ||
{ | ||
ItemName = dbInstance.DBInstanceIdentifier; | ||
} | ||
|
||
public override string ItemName { get; } | ||
public override bool IsContainer => false; | ||
public override string? WebUrl => | ||
UrlBuilder.CombineWith($"rds/home#database:id={UnderlyingObject.DBInstanceIdentifier};is-cluster=false"); | ||
} |
Oops, something went wrong.