@@ -16,6 +16,7 @@ public class MarkdownReporter : BaseReporter
16
16
17
17
private readonly Dictionary < Type , Func < object , string ? > > _transformers = new ( )
18
18
{
19
+ { typeof ( ApiCenterMinimalPermissionsPluginReport ) , TransformApiCenterMinimalPermissionsReport } ,
19
20
{ typeof ( ApiCenterOnboardingPluginReport ) , TransformApiCenterOnboardingReport } ,
20
21
{ typeof ( ApiCenterProductionVersionPluginReport ) , TransformApiCenterProductionVersionReport } ,
21
22
{ typeof ( ExecutionSummaryPluginReportByUrl ) , TransformExecutionSummaryByUrl } ,
@@ -103,6 +104,92 @@ public MarkdownReporter(IPluginEvents pluginEvents, IProxyContext context, ILogg
103
104
return sb . ToString ( ) ;
104
105
}
105
106
107
+ private static string ? TransformApiCenterMinimalPermissionsReport ( object report )
108
+ {
109
+ var apiCenterMinimalPermissionsReport = ( ApiCenterMinimalPermissionsPluginReport ) report ;
110
+
111
+ var sb = new StringBuilder ( ) ;
112
+ sb . AppendLine ( "# Azure API Center minimal permissions report" )
113
+ . AppendLine ( ) ;
114
+
115
+ sb . AppendLine ( "## ℹ️ Summary" )
116
+ . AppendLine ( )
117
+ . AppendLine ( "<table>" )
118
+ . AppendFormat ( "<tr><td>🔎 APIs inspected</td><td align=\" right\" >{0}</td></tr>{1}" , apiCenterMinimalPermissionsReport . Results . Length , Environment . NewLine )
119
+ . AppendFormat ( "<tr><td>🔎 Requests inspected</td><td align=\" right\" >{0}</td></tr>{1}" , apiCenterMinimalPermissionsReport . Results . Sum ( r => r . Requests . Length ) , Environment . NewLine )
120
+ . AppendFormat ( "<tr><td>✅ APIs called using minimal permissions</td><td align=\" right\" >{0}</td></tr>{1}" , apiCenterMinimalPermissionsReport . Results . Count ( r => r . UsesMinimalPermissions ) , Environment . NewLine )
121
+ . AppendFormat ( "<tr><td>🛑 APIs called using excessive permissions</td><td align=\" right\" >{0}</td></tr>{1}" , apiCenterMinimalPermissionsReport . Results . Count ( r => ! r . UsesMinimalPermissions ) , Environment . NewLine )
122
+ . AppendFormat ( "<tr><td>⚠️ Unmatched requests</td><td align=\" right\" >{0}</td></tr>{1}" , apiCenterMinimalPermissionsReport . UnmatchedRequests . Length , Environment . NewLine )
123
+ . AppendFormat ( "<tr><td>🛑 Errors</td><td align=\" right\" >{0}</td></tr>{1}" , apiCenterMinimalPermissionsReport . Errors . Length , Environment . NewLine )
124
+ . AppendLine ( "</table>" )
125
+ . AppendLine ( ) ;
126
+
127
+ sb . AppendLine ( "## 🔌 APIs" )
128
+ . AppendLine ( ) ;
129
+
130
+ if ( apiCenterMinimalPermissionsReport . Results . Any ( ) )
131
+ {
132
+ foreach ( var apiResult in apiCenterMinimalPermissionsReport . Results )
133
+ {
134
+ sb . AppendFormat ( "### {0}{1}" , apiResult . ApiName , Environment . NewLine )
135
+ . AppendLine ( )
136
+ . AppendFormat ( apiResult . UsesMinimalPermissions ? "✅ Called using minimal permissions{0}" : "🛑 Called using excessive permissions{0}" , Environment . NewLine )
137
+ . AppendLine ( )
138
+ . AppendLine ( "#### Permissions" )
139
+ . AppendLine ( )
140
+ . AppendFormat ( "- Minimal permissions: {0}{1}" , string . Join ( ", " , apiResult . MinimalPermissions . Order ( ) . Select ( p => $ "`{ p } `") ) , Environment . NewLine )
141
+ . AppendFormat ( "- Permissions on the token: {0}{1}" , string . Join ( ", " , apiResult . TokenPermissions . Order ( ) . Select ( p => $ "`{ p } `") ) , Environment . NewLine )
142
+ . AppendFormat ( "- Excessive permissions: {0}{1}" , apiResult . ExcessivePermissions . Any ( ) ? string . Join ( ", " , apiResult . ExcessivePermissions . Order ( ) . Select ( p => $ "`{ p } `") ) : "none" , Environment . NewLine )
143
+ . AppendLine ( )
144
+ . AppendLine ( "#### Requests" )
145
+ . AppendLine ( )
146
+ . AppendJoin ( Environment . NewLine , apiResult . Requests . Select ( r => $ "- { r } ") ) . AppendLine ( )
147
+ . AppendLine ( ) ;
148
+ }
149
+ }
150
+ else
151
+ {
152
+ sb . AppendLine ( "No APIs found." )
153
+ . AppendLine ( ) ;
154
+ }
155
+
156
+ sb . AppendLine ( "## ⚠️ Unmatched requests" )
157
+ . AppendLine ( ) ;
158
+
159
+ if ( apiCenterMinimalPermissionsReport . UnmatchedRequests . Any ( ) )
160
+ {
161
+ sb . AppendLine ( "The following requests were not matched to any API in API Center:" )
162
+ . AppendLine ( )
163
+ . AppendJoin ( Environment . NewLine , apiCenterMinimalPermissionsReport . UnmatchedRequests
164
+ . Select ( r => $ "- { r } ") . Order ( ) ) . AppendLine ( )
165
+ . AppendLine ( ) ;
166
+ }
167
+ else
168
+ {
169
+ sb . AppendLine ( "No unmatched requests found." )
170
+ . AppendLine ( ) ;
171
+ }
172
+
173
+ sb . AppendLine ( "## 🛑 Errors" )
174
+ . AppendLine ( ) ;
175
+
176
+ if ( apiCenterMinimalPermissionsReport . Errors . Any ( ) )
177
+ {
178
+ sb . AppendLine ( "The following errors occurred while determining minimal permissions:" )
179
+ . AppendLine ( )
180
+ . AppendJoin ( Environment . NewLine , apiCenterMinimalPermissionsReport . Errors
181
+ . OrderBy ( o => o . Request )
182
+ . Select ( e => $ "- `{ e . Request } `: { e . Error } ") ) . AppendLine ( )
183
+ . AppendLine ( ) ;
184
+ }
185
+ else
186
+ {
187
+ sb . AppendLine ( "No errors occurred." ) ;
188
+ }
189
+
190
+ return sb . ToString ( ) ;
191
+ }
192
+
106
193
private static string ? TransformApiCenterProductionVersionReport ( object report )
107
194
{
108
195
var getReadableApiStatus = ( ApiCenterProductionVersionPluginReportItemStatus status ) => status switch
@@ -369,7 +456,7 @@ private static void AddExecutionSummaryReportSummary(IEnumerable<RequestLog> req
369
456
}
370
457
371
458
sb . AppendLine ( ) ;
372
-
459
+
373
460
return sb . ToString ( ) ;
374
461
}
375
462
0 commit comments