Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
devlead committed Nov 28, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 1a59b56 + 86b9886 commit 1fc3df5
Showing 16 changed files with 120 additions and 30 deletions.
14 changes: 10 additions & 4 deletions src/ARI.Tests/Fixture/MocksFixture.cs
Original file line number Diff line number Diff line change
@@ -32,18 +32,20 @@ public static class MocksFixture
"AuthorizationSource",
Array.Empty<ManagedByTenant>()
);
public static IDictionary<string, string> Tags { get; } = new Dictionary<string, string>
public static IDictionary<string, string> Tags { get; } = new AzureResourceTags
{
{ "Tag3", "Value4" },
{ "Tag1", "Value1" },
{ "Tag2", "Value2" }
{ "Tag2", "Value2" },
{ "Tag0", "Value3" }
}.AsReadOnly();

public static ResourceGroup ResourceGroup { get; } = new(
"Id",
"Location",
"ManagedBy",
"Name",
new Dictionary<string, string>
new AzureResourceProperties
{
{ "provisioningState", "Succeeded" }
},
@@ -62,7 +64,11 @@ public static class MocksFixture
"Name",
DateTimeOffset.MinValue,
DateTimeOffset.MaxValue,
new Dictionary<string, string>(),
new AzureResourceProperties
{
{"Property1", "Value1" },
{"Property0", "Value2" }
},
"ProvisioningState",
"Type",
new SKU(
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
summary: Summary
modifiedby: ARI
modified: 9999-12-31 23:59
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
summary: Summary
modifiedby: ARI
order: 0
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
modifiedby: ARI
modified: 9999-12-31 23:59
order: 0
---
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
emptyString
Original file line number Diff line number Diff line change
@@ -3,5 +3,7 @@

| Tag | Value |
|-------------------------------------|-------------------------------------------------------------------------------------------------|
| **Tag0** | `Value3` |
| **Tag1** | `Value1` |
| **Tag2** | `Value2` |
| **Tag3** | `Value4` |
24 changes: 21 additions & 3 deletions src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
using ARI.Models.Tenant;
using ARI.Models.Tenant.Subscription;
using ARI.Models.Tenant.Subscription.ResourceGroup;
using Spectre.Console.Cli;

namespace ARI.Tests.Unit.Extensions;

[TestFixture]
public class TextWriterMarkdownExtensionsTests
{
[Test]
public async Task AddFrontmatter()
[TestCase(false, false, false, false)]
[TestCase(true, false, false, false)]
[TestCase(false, true, false, false)]
[TestCase(false, false, true, false)]
[TestCase(false, false, false, true)]
public async Task AddFrontmatter(
bool skipFrontmatter,
bool skipFrontmatterSummary,
bool skipFrontmatterModified,
bool skipFrontmatterOrder
)
{
// Given
var sw = new StringWriter();
var lastUpdateTime = DateTimeOffset.MaxValue;
var summary = "Summary";
var order = 0;

var settings = new ARI.Commands.Settings.InventorySettings
{
SkipFrontmatter = skipFrontmatter,
SkipFrontmatterSummary = skipFrontmatterSummary,
SkipFrontmatterModified = skipFrontmatterModified,
SkipFrontmatterOrder = skipFrontmatterOrder
};
// When
await sw.AddFrontmatter(
lastUpdateTime,
summary,
order
order,
settings
);

// Then
15 changes: 10 additions & 5 deletions src/ARI/Commands/InventoryCommand.cs
Original file line number Diff line number Diff line change
@@ -41,7 +41,8 @@ public override async Task<int> ExecuteAsync(CommandContext context, InventorySe
await writer.AddFrontmatter(
modified,
$"Tenant {tenant.DisplayName} ({tenant.TenantId})",
1
1,
settings
);

await writer.AddTenantOverview(tenant);
@@ -51,7 +52,8 @@ await writer.AddFrontmatter(
await writer.AddFrontmatter(
modified,
"Azure Inventory",
1
1,
settings
);
}

@@ -72,7 +74,8 @@ await ForEachAsync(
await writer.AddFrontmatter(
modified,
$"Subscription {subscription.DisplayName} ({subscription.TenantId})",
subscription.Order
subscription.Order,
settings
);

await writer.AddSubscriptionOverview(subscription);
@@ -97,7 +100,8 @@ await ForEachAsync(
await writer.AddFrontmatter(
modified,
$"Resource Group {resourceGroup.Name} ({subscription.SubscriptionId})",
resourceGroup.Order
resourceGroup.Order,
settings
);

await writer.AddResourceGroupOverview(resourceGroup);
@@ -157,7 +161,8 @@ await ForEachAsync(
await writer.AddFrontmatter(
modified,
$"Resource {resource.Name} ({subscription.SubscriptionId})",
resource.Order
resource.Order,
settings
);

await writer.AddResourceOverview(resource);
12 changes: 12 additions & 0 deletions src/ARI/Commands/Settings/InventorySettings.cs
Original file line number Diff line number Diff line change
@@ -22,4 +22,16 @@ public class InventorySettings : CommandSettings

[CommandOption("--markdown-name")]
public string MarkdownName { get; set; } = "index";

[CommandOption("--skip-frontmatter")]
public bool SkipFrontmatter { get; set; }

[CommandOption("--skip-frontmatter-summary")]
public bool SkipFrontmatterSummary { get; set; }

[CommandOption("--skip-frontmatter-modifed")]
public bool SkipFrontmatterModified { get; set; }

[CommandOption("--skip-frontmatter-order")]
public bool SkipFrontmatterOrder { get; set; }
}
41 changes: 28 additions & 13 deletions src/ARI/Extensions/TextWriterMarkdownExtensions.cs
Original file line number Diff line number Diff line change
@@ -15,20 +15,35 @@ public static async Task AddFrontmatter(
this TextWriter writer,
DateTimeOffset lastUpdateTime,
string summary,
int order)
int order,
InventorySettings settings
)
{
await writer.WriteLineAsync(
FormattableString.Invariant(
$$"""
---
summary: {{summary}}
modifiedby: ARI
modified: {{lastUpdateTime:yyyy-MM-dd HH:mm}}
order: {{order}}
---
"""
)
);
if (settings.SkipFrontmatter)
{
return;
}

await writer.WriteLineAsync("---");

if (!settings.SkipFrontmatterSummary)
{
await writer.WriteLineAsync(FormattableString.Invariant($"summary: {summary}"));
}

await writer.WriteLineAsync(FormattableString.Invariant($"modifiedby: ARI"));

if (!settings.SkipFrontmatterModified)
{
await writer.WriteLineAsync(FormattableString.Invariant($"modified: {lastUpdateTime:yyyy-MM-dd HH:mm}"));
}

if (!settings.SkipFrontmatterOrder)
{
await writer.WriteLineAsync(FormattableString.Invariant($"order: {order}"));
}

await writer.WriteLineAsync("---");
}

public static async Task AddTenantOverview(
4 changes: 1 addition & 3 deletions src/ARI/Models/Tenant/AzureResourceBase.cs
Original file line number Diff line number Diff line change
@@ -5,15 +5,13 @@ namespace ARI.Models.Tenant;

public abstract record AzureResourceBase
{
private static Dictionary<string, string> Empty { get; } = new Dictionary<string, string>();

public abstract string PublicId { get; }
public abstract string Description { get; }

public int Order { get; init; } = 0;

[JsonPropertyName("tags")]
public Dictionary<string, string> Tags { get; init; } = Empty;
public AzureResourceTags Tags { get; init; } = AzureResourceTags.Empty;

public virtual void Deconstruct(out string key, out string value)
{
6 changes: 6 additions & 0 deletions src/ARI/Models/Tenant/AzureResourceProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ARI.Models.Tenant;

public class AzureResourceProperties : AzureResourceTags
{
}

12 changes: 12 additions & 0 deletions src/ARI/Models/Tenant/AzureResourceTags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace ARI.Models.Tenant;

public class AzureResourceTags : SortedDictionary<string, string>
{
public static AzureResourceTags Empty { get; } = new();


public AzureResourceTags() :base(StringComparer.OrdinalIgnoreCase)
{
}
}

Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ public record Resource(
[property: JsonPropertyName("changedTime")]
DateTimeOffset ChangedTime,
[property: JsonPropertyName("properties")]
Dictionary<string,string> Properties,
AzureResourceProperties Properties,
[property: JsonPropertyName("provisioningState")]
string ProvisioningState,
[property: JsonPropertyName("type")]
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ public record ResourceGroup(
[property: JsonPropertyName("name")]
string Name,
[property: JsonPropertyName("properties")]
Dictionary<string,string> Properties,
AzureResourceProperties Properties,
[property: JsonPropertyName("type")]
string Type
) : AzureResourceBase

0 comments on commit 1fc3df5

Please sign in to comment.