為標註的雲端原生應用程式產生合規性報告

已完成

合規性部門必須能夠檢閱程式碼和合規性報告以確保應用程式符合公司的原則。 .NET 合規性架構提供了一種產生顯示應用程式合規性狀態的報告的方法。

什麼是合規性報告?

合規性報告可以在編譯時間產生。 .NET 合規性架構會產生一個 JSON 檔案,其中包含有關應用程式中所使用的資料分類和修訂方法的詳細資料。

{
    "Name": "DataEntities",
    "Types": [
        {
            "Name": "DataEntities.Order",
            "Members": [
                {
                    "Name": "CustomerAddress",
                    "Type": "string",
                    "File": "C:\\Developer\\mslearn-dotnet-cloudnative\\dotnet-compliance\\eShopLite\\DataEntities\\Order.cs",
                    "Line": "25",
                    "Classifications": [
                        {
                            "Name": "EUIIData"
                        }
                    ]
                },
                {
                    "Name": "CustomerName",
                    "Type": "string",
                    "File": "C:\\Developer\\mslearn-dotnet-cloudnative\\dotnet-compliance\\eShopLite\\DataEntities\\Order.cs",
                    "Line": "21",
                    "Classifications": [
                        {
                            "Name": "EUIIData"
                        }
                    ]
                },
    ...

上面的報告是來自 eShopLite.DataEntities 專案的範例。 它會顯示 Order 類別有兩個分類為 EUIIData 的屬性。

{
    "Name": "Store",
    "Types": [
        {
            "Name": "Store.Services.Log",
            "Logging Methods": [
                {
                    "Name": "LogOrders",
                    "Parameters": [
                        {
                            "Name": "logger",
                            "Type": "Microsoft.Extensions.Logging.ILogger",
                            "File": "C:\\Developer\\mslearn-dotnet-cloudnative\\dotnet-compliance\\eShopLite\\Store\\Services\\ProductService.cs",
                            "Line": "103"
                        },
                        {
                            "Name": "order",
                            "Type": "DataEntities.Order",
                            "File": "C:\\Developer\\mslearn-dotnet-cloudnative\\dotnet-compliance\\eShopLite\\Store\\Services\\ProductService.cs",
                            "Line": "103"
                        }
                    ]
                }
            ]
        }
    ]
}

上面的報告是來自 eShopLite.Store 專案的範例。 它會顯示 ProductService 類別中的 LogOrders 方法採用 Order 物件作為記錄的參數。

如何產生合規性報告

對於您要為其產生報告的每個專案,您需要執行兩個步驟:

  1. Microsoft.Extensions.AuditReports NuGet 套件新增至每個專案。

  2. 將兩個項目新增至 csproj 專案檔的 PropertyGroup 區段:

    <GenerateComplianceReport>true</GenerateComplianceReport>
    <ComplianceReportOutputPath>$(MSBuildThisFileDirectory)\path to folder location</ComplianceReportOutputPath>
    

    第一個會開啟相容性報告產生。 第二個會指定將產生報告的資料夾路徑。 檔名為 ComplianceReport.json

透過這些更新,在解決方案資料夾中執行 dotnet build 會為 GenerateComplianceReport 屬性設定為 true 的每個專案產生合規性報告。