diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a92cc4d9..63d3443f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -79,7 +79,7 @@ jobs: run: | go install gotest.tools/gotestsum@latest CGO_ENABLED=0 gotestsum --jsonfile ./test_report_unit.json --format standard-quiet -- ./internal/... $COVERAGE_OPTS --tags=unit - go test ./internal/analyzers/ + go test ./internal/scanners/ - name: Codecov if: matrix.target_os == 'linux' diff --git a/cmd/azqr/main.go b/cmd/azqr/main.go index 26ca77b3..aad1e851 100644 --- a/cmd/azqr/main.go +++ b/cmd/azqr/main.go @@ -6,15 +6,13 @@ import ( "fmt" "log" "os" - "strings" "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" - "github.com/cmendible/azqr/internal/analyzers" - "github.com/cmendible/azqr/internal/report/templates" - "github.com/fbiville/markdown-table-formatter/pkg/markdown" + "github.com/cmendible/azqr/internal/scanners" + "github.com/cmendible/azqr/internal/renderers" "golang.org/x/sync/semaphore" ) @@ -29,8 +27,8 @@ var ( func main() { subscriptionPtr := flag.String("s", "", "Azure Subscription Id (Required)") resourceGroupPtr := flag.String("g", "", "Azure Resource Group") - outputPtr := flag.String("o", "report.md", "Output file") - customerPtr := flag.String("c", "", "Customer Name") + outputPtr := flag.String("o", "azqr_report", "Output file prefix") + customerPtr := flag.String("c", "Replace_With_Customer_Name", "Customer Name") detail := flag.Bool("d", false, "Enable more details in the report") concurrency := flag.Int("p", defaultConcurrency, fmt.Sprintf("Parallel processes. Default to %d. A < 0 value will use the maxmimum concurrency.", defaultConcurrency)) ver := flag.Bool("v", false, "Print version and exit") @@ -39,9 +37,16 @@ func main() { subscriptionID := *subscriptionPtr resourceGroupName := *resourceGroupPtr - outputFile := *outputPtr + outputFilePrefix := *outputPtr customer := *customerPtr + current_time := time.Now() + outputFileStamp := fmt.Sprintf("%d_%02d_%02d_T%02d%02d%02d", + current_time.Year(), current_time.Month(), current_time.Day(), + current_time.Hour(), current_time.Minute(), current_time.Second()) + + outputFile := fmt.Sprintf("%s_%s", outputFilePrefix, outputFileStamp) + if *ver { fmt.Printf("azqr version: %s", version) os.Exit(0) @@ -79,53 +84,53 @@ func main() { } } - svcanalyzers := []analyzers.IAzureServiceAnalyzer{ - &analyzers.AKSAnalyzer{}, - &analyzers.APIManagementAnalyzer{}, - &analyzers.ApplicationGatewayAnalyzer{}, - &analyzers.ContainerAppsAnalyzer{}, - &analyzers.ContainerInstanceAnalyzer{}, - &analyzers.CosmosDBAnalyzer{}, - &analyzers.ContainerRegistryAnalyzer{}, - &analyzers.EventHubAnalyzer{}, - &analyzers.EventGridAnalyzer{}, - &analyzers.KeyVaultAnalyzer{}, - &analyzers.AppServiceAnalyzer{}, - &analyzers.RedisAnalyzer{}, - &analyzers.ServiceBusAnalyzer{}, - &analyzers.SignalRAnalyzer{}, - &analyzers.StorageAnalyzer{}, - &analyzers.PostgreAnalyzer{}, - &analyzers.SQLAnalyzer{}, + svcScanners := []scanners.IAzureScanner{ + &scanners.AKSScanner{}, + &scanners.APIManagementScanner{}, + &scanners.ApplicationGatewayScanner{}, + &scanners.ContainerAppsScanner{}, + &scanners.ContainerInstanceScanner{}, + &scanners.CosmosDBScanner{}, + &scanners.ContainerRegistryScanner{}, + &scanners.EventHubScanner{}, + &scanners.EventGridScanner{}, + &scanners.KeyVaultScanner{}, + &scanners.AppServiceScanner{}, + &scanners.RedisScanner{}, + &scanners.ServiceBusScanner{}, + &scanners.SignalRScanner{}, + &scanners.StorageScanner{}, + &scanners.PostgreScanner{}, + &scanners.SQLScanner{}, } ctx, cancel := context.WithCancel(ctx) defer cancel() - config := analyzers.ServiceAnalizerConfig{ + config := scanners.ScannerConfig{ Ctx: ctx, SubscriptionID: subscriptionID, Cred: cred, EnableDetailedScan: *detail, } - for _, a := range svcanalyzers { + for _, a := range svcScanners { err := a.Init(config) if err != nil { log.Fatal(err) } } - var all []analyzers.IAzureServiceResult + var all []scanners.IAzureServiceResult rc := ReviewContext{ Ctx: ctx, - ResCh: make(chan []analyzers.IAzureServiceResult), + ResCh: make(chan []scanners.IAzureServiceResult), ErrCh: make(chan error), } for _, r := range resourceGroups { log.Printf("Analyzing Resource Group %s", r) - go reviewRunner(&rc, r, &svcanalyzers, *concurrency) - res, err := waitForReviews(&rc, len(svcanalyzers)) + go reviewRunner(&rc, r, &svcScanners, *concurrency) + res, err := waitForReviews(&rc, len(svcScanners)) // As soon as any error happen, we cancel every still running analysis if err != nil { cancel() @@ -133,44 +138,9 @@ func main() { } all = append(all, *res...) } - resultsTable := renderTable(all) - - var allFunctions []analyzers.IAzureServiceResult - for _, r := range all { - v, ok := r.(analyzers.AzureFunctionAppResult) - if ok { - allFunctions = append(allFunctions, v) - } - } - - reportTemplate := templates.GetTemplates("Report.md") - reportTemplate = strings.Replace(reportTemplate, "{{results}}", resultsTable, 1) - reportTemplate = strings.Replace(reportTemplate, "{{date}}", time.Now().Format("2006-01-02"), 1) - reportTemplate = strings.Replace(reportTemplate, "{{customer}}", customer, -1) - - recommendations := "" - dict := map[string]bool{} - for _, r := range all { - parsedType := strings.Replace(r.GetResourceType(), "/", ".", -1) - if _, ok := dict[r.GetResourceType()]; !ok { - dict[r.GetResourceType()] = true - recommendations += "\n\n" - recommendations += templates.GetTemplates(fmt.Sprintf("%s.md", parsedType)) - - if r.GetResourceType() == "Microsoft.Web/serverfarms/sites" && len(allFunctions) > 0 && config.EnableDetailedScan { - recommendations = strings.Replace(recommendations, "{{functions}}", renderDetailsTable(allFunctions), 1) - } else { - recommendations = strings.Replace(recommendations, "{{functions}}", "", 1) - } - } - } - reportTemplate = strings.Replace(reportTemplate, "{{recommendations}}", recommendations, 1) - - err = os.WriteFile(outputFile, []byte(reportTemplate), 0644) - if err != nil { - log.Fatal(err) - } + renderers.CreateMarkdownReport(all, customer, outputFile, config.EnableDetailedScan) + renderers.CreateExcelReport(all, outputFile) } // ReviewContext A running resource group analysis support context @@ -178,13 +148,13 @@ type ReviewContext struct { // Review context, will be passed to every created goroutines Ctx context.Context // Communication interface for each review results - ResCh chan []analyzers.IAzureServiceResult + ResCh chan []scanners.IAzureServiceResult // Communication interface for errors ErrCh chan error } // Run a review on a peculiar resource group "r" with the appropriates analysers using "concurrency" goroutines -func reviewRunner(rc *ReviewContext, r string, svcAnalysers *[]analyzers.IAzureServiceAnalyzer, concurrency int) { +func reviewRunner(rc *ReviewContext, r string, svcAnalysers *[]scanners.IAzureScanner, concurrency int) { if concurrency <= 0 { concurrency = len(*svcAnalysers) } @@ -198,7 +168,7 @@ func reviewRunner(rc *ReviewContext, r string, svcAnalysers *[]analyzers.IAzureS // the iteration variable, as only the last element of the loop will // be processed analyserPtr := &(*svcAnalysers)[i] - go func(a *analyzers.IAzureServiceAnalyzer, r string) { + go func(a *scanners.IAzureScanner, r string) { defer sem.Release(1) // In case the analysis was cancelled, we don't need to execute the review if context.Canceled == rc.Ctx.Err() { @@ -214,9 +184,9 @@ func reviewRunner(rc *ReviewContext, r string, svcAnalysers *[]analyzers.IAzureS } // Wait for at least "nb" goroutines to hands their result and return them -func waitForReviews(rc *ReviewContext, nb int) (*[]analyzers.IAzureServiceResult, error) { +func waitForReviews(rc *ReviewContext, nb int) (*[]scanners.IAzureServiceResult, error) { received := 0 - reviews := make([]analyzers.IAzureServiceResult, 0) + reviews := make([]scanners.IAzureServiceResult, 0) for { select { // In case a timeout is set @@ -265,58 +235,3 @@ func listResourceGroup(ctx context.Context, subscriptionID string, cred azcore.T } return resourceGroups, nil } - -func renderTable(results []analyzers.IAzureServiceResult) string { - if len(results) == 0 { - return "No results found." - } - - heathers := results[0].GetProperties() - - rows := [][]string{} - for _, r := range results { - rows = append(mapToRow(heathers, r.ToMap()), rows...) - } - - prettyPrintedTable, err := markdown.NewTableFormatterBuilder(). - WithPrettyPrint(). - Build(heathers...). - Format(rows) - - if err != nil { - log.Fatal(err) - } - fmt.Println("") - fmt.Println(prettyPrintedTable) - return prettyPrintedTable -} - -func renderDetailsTable(results []analyzers.IAzureServiceResult) string { - heathers := results[0].GetDetailProperties() - - rows := [][]string{} - for _, r := range results { - rows = append(mapToRow(heathers, r.ToDetail()), rows...) - } - - prettyPrintedTable, err := markdown.NewTableFormatterBuilder(). - WithPrettyPrint(). - Build(heathers...). - Format(rows) - - if err != nil { - log.Fatal(err) - } - - return prettyPrintedTable -} - -func mapToRow(heathers []string, m map[string]string) [][]string { - v := make([]string, 0, len(m)) - - for _, k := range heathers { - v = append(v, m[k]) - } - - return [][]string{v} -} diff --git a/go.mod b/go.mod index 8fc706c8..ac4af516 100644 --- a/go.mod +++ b/go.mod @@ -27,6 +27,8 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.1.0 github.com/Azure/go-autorest/autorest/to v0.4.0 github.com/fbiville/markdown-table-formatter v0.3.0 + github.com/gomarkdown/markdown v0.0.0-20221013030248-663e2500819c + github.com/xuri/excelize/v2 v2.7.0 golang.org/x/sync v0.1.0 ) @@ -37,9 +39,14 @@ require ( github.com/golang-jwt/jwt v3.2.1+incompatible // indirect github.com/google/uuid v1.1.1 // indirect github.com/kylelemons/godebug v1.1.0 // indirect + github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect - golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88 // indirect - golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect - golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect - golang.org/x/text v0.3.7 // indirect + github.com/richardlehane/mscfb v1.0.4 // indirect + github.com/richardlehane/msoleps v1.0.3 // indirect + github.com/xuri/efp v0.0.0-20220603152613-6918739fd470 // indirect + github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22 // indirect + golang.org/x/crypto v0.5.0 // indirect + golang.org/x/net v0.5.0 // indirect + golang.org/x/sys v0.4.0 // indirect + golang.org/x/text v0.6.0 // indirect ) diff --git a/go.sum b/go.sum index 7fc97222..fb2e87c8 100644 --- a/go.sum +++ b/go.sum @@ -51,32 +51,83 @@ github.com/Azure/go-autorest/autorest/to v0.4.0 h1:oXVqrxakqqV1UZdSazDOPOLvOIz+X github.com/Azure/go-autorest/autorest/to v0.4.0/go.mod h1:fE8iZBn7LQR7zH/9XU2NcPR4o9jEImooCeWJcYV/zLE= github.com/AzureAD/microsoft-authentication-library-for-go v0.5.1 h1:BWe8a+f/t+7KY7zH2mqygeUD0t8hNFXe08p1Pb3/jKE= github.com/AzureAD/microsoft-authentication-library-for-go v0.5.1/go.mod h1:Vt9sXTKwMyGcOxSmLDMnGPgqsUg7m8pe215qMLrDXw4= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c= github.com/fbiville/markdown-table-formatter v0.3.0 h1:PIm1UNgJrFs8q1htGTw+wnnNYvwXQMMMIKNZop2SSho= github.com/fbiville/markdown-table-formatter v0.3.0/go.mod h1:q89TDtSEVDdTaufgSbfHpNVdPU/bmfvqNkrC5HagmLY= github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfEP4Q1lOd9Z/+c= github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= github.com/golang-jwt/jwt/v4 v4.2.0 h1:besgBTC8w8HjP6NzQdxwKH9Z5oQMZ24ThTrHp3cZ8eU= +github.com/gomarkdown/markdown v0.0.0-20221013030248-663e2500819c h1:iyaGYbCmcYK0Ja9a3OUa2Fo+EaN0cbLu0eKpBwPFzc8= +github.com/gomarkdown/markdown v0.0.0-20221013030248-663e2500819c/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/montanaflynn/stats v0.6.6/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 h1:Qj1ukM4GlMWXNdMBuXcXfz/Kw9s1qm0CLY32QxuSImI= github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4/go.mod h1:N6UoU20jOqggOuDwUaBQpluzLNDqif3kq9z2wpdYEfQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88 h1:Tgea0cVUD0ivh5ADBX4WwuI12DUd2to3nCYe2eayMIw= -golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA= -golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/richardlehane/mscfb v1.0.4 h1:WULscsljNPConisD5hR0+OyZjwK46Pfyr6mPu5ZawpM= +github.com/richardlehane/mscfb v1.0.4/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk= +github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg= +github.com/richardlehane/msoleps v1.0.3 h1:aznSZzrwYRl3rLKRT3gUk9am7T/mLNSnJINvN0AQoVM= +github.com/richardlehane/msoleps v1.0.3/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/xuri/efp v0.0.0-20220603152613-6918739fd470 h1:6932x8ltq1w4utjmfMPVj09jdMlkY0aiA6+Skbtl3/c= +github.com/xuri/efp v0.0.0-20220603152613-6918739fd470/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI= +github.com/xuri/excelize/v2 v2.7.0 h1:Hri/czwyRCW6f6zrCDWXcXKshlq4xAZNpNOpdfnFhEw= +github.com/xuri/excelize/v2 v2.7.0/go.mod h1:ebKlRoS+rGyLMyUx3ErBECXs/HNYqyj+PbkkKRK5vSI= +github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22 h1:OAmKAfT06//esDdpi/DZ8Qsdt4+M5+ltca05dA5bG2M= +github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= +golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= +golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 h1:Lj6HJGCSn5AjxRAH2+r35Mir4icalbqku+CLUtjnvXY= +golang.org/x/image v0.0.0-20220902085622-e7cb96979f69/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= +golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= +golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= +golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/renderers/excel.go b/internal/renderers/excel.go new file mode 100644 index 00000000..c7e3577a --- /dev/null +++ b/internal/renderers/excel.go @@ -0,0 +1,69 @@ +package renderers + +import ( + "fmt" + "log" + + "github.com/cmendible/azqr/internal/scanners" + "github.com/xuri/excelize/v2" +) + +func CreateExcelReport(all []scanners.IAzureServiceResult, outputFile string) { + if len(all) > 0 { + f := excelize.NewFile() + defer func() { + if err := f.Close(); err != nil { + log.Fatal(err) + } + }() + + err := f.SetSheetName("Sheet1", "Overview") + if err != nil { + log.Fatal(err) + return + } + + heathers := all[0].GetProperties() + + rows := [][]string{} + for _, r := range all { + rows = append(mapToRow(heathers, r.ToMap()), rows...) + } + + for idx, row := range rows { + cell, err := excelize.CoordinatesToCellName(1, idx+1) + if err != nil { + log.Fatal(err) + return + } + if idx > 0 { + err := f.SetSheetRow("Overview", cell, &row) + if err != nil { + log.Fatal(err) + return + } + } else { + err := f.SetSheetRow("Overview", cell, &heathers) + if err != nil { + log.Fatal(err) + return + } + font := excelize.Font{Bold: true} + style, err := f.NewStyle(&excelize.Style{Font: &font}) + if err != nil { + fmt.Println(err) + return + } + err = f.SetRowStyle("Overview", 1, 1, style) + if err != nil { + log.Fatal(err) + return + } + } + } + + if err := f.SaveAs(fmt.Sprintf("%s.xlsx", outputFile)); err != nil { + log.Fatal(err) + } + } +} diff --git a/internal/renderers/markdown.go b/internal/renderers/markdown.go new file mode 100644 index 00000000..0243c0b6 --- /dev/null +++ b/internal/renderers/markdown.go @@ -0,0 +1,117 @@ +package renderers + +import ( + "fmt" + "log" + "os" + "strings" + "time" + + "github.com/cmendible/azqr/internal/scanners" + "github.com/cmendible/azqr/internal/report/templates" + "github.com/fbiville/markdown-table-formatter/pkg/markdown" + mdparser "github.com/gomarkdown/markdown" +) + +func CreateMarkdownReport(all []scanners.IAzureServiceResult, customer, outputFile string, detailedScan bool) { + resultsTable := renderTable(all) + + var allFunctions []scanners.IAzureServiceResult + for _, r := range all { + v, ok := r.(scanners.AzureFunctionAppResult) + if ok { + allFunctions = append(allFunctions, v) + } + } + + reportTemplate := templates.GetTemplates("Report.md") + reportTemplate = strings.Replace(reportTemplate, "{{results}}", resultsTable, 1) + reportTemplate = strings.Replace(reportTemplate, "{{date}}", time.Now().Format("2006-01-02"), 1) + reportTemplate = strings.Replace(reportTemplate, "{{customer}}", customer, -1) + + recommendations := "" + dict := map[string]bool{} + for _, r := range all { + parsedType := strings.Replace(r.GetResourceType(), "/", ".", -1) + if _, ok := dict[r.GetResourceType()]; !ok { + dict[r.GetResourceType()] = true + recommendations += "\n\n" + recommendations += templates.GetTemplates(fmt.Sprintf("%s.md", parsedType)) + + if r.GetResourceType() == "Microsoft.Web/serverfarms/sites" && len(allFunctions) > 0 && detailedScan { + recommendations = strings.Replace(recommendations, "{{functions}}", renderDetailsTable(allFunctions), 1) + } else { + recommendations = strings.Replace(recommendations, "{{functions}}", "", 1) + } + } + } + + reportTemplate = strings.Replace(reportTemplate, "{{recommendations}}", recommendations, 1) + + err := os.WriteFile(fmt.Sprintf("%s.md", outputFile), []byte(reportTemplate), 0644) + if err != nil { + log.Fatal(err) + } + + md := []byte(reportTemplate) + output := mdparser.ToHTML(md, nil, nil) + err = os.WriteFile(fmt.Sprintf("%s.html", outputFile), output, 0644) + if err != nil { + log.Fatal(err) + } +} + +func renderTable(results []scanners.IAzureServiceResult) string { + if len(results) == 0 { + return "No results found." + } + + heathers := results[0].GetProperties() + + rows := [][]string{} + for _, r := range results { + rows = append(mapToRow(heathers, r.ToMap()), rows...) + } + + prettyPrintedTable, err := markdown.NewTableFormatterBuilder(). + WithPrettyPrint(). + Build(heathers...). + Format(rows) + + if err != nil { + log.Fatal(err) + } + fmt.Println("") + fmt.Println(prettyPrintedTable) + return prettyPrintedTable +} + +func renderDetailsTable(results []scanners.IAzureServiceResult) string { + heathers := results[0].GetDetailProperties() + + rows := [][]string{} + for _, r := range results { + rows = append(mapToRow(heathers, r.ToDetail()), rows...) + } + + prettyPrintedTable, err := markdown.NewTableFormatterBuilder(). + WithPrettyPrint(). + Build(heathers...). + Format(rows) + + if err != nil { + log.Fatal(err) + } + + return prettyPrintedTable +} + +func mapToRow(heathers []string, m map[string]string) [][]string { + v := make([]string, 0, len(m)) + + for _, k := range heathers { + v = append(v, m[k]) + } + + return [][]string{v} +} diff --git a/internal/analyzers/agw_anayzer.go b/internal/scanners/agw.go similarity index 83% rename from internal/analyzers/agw_anayzer.go rename to internal/scanners/agw.go index 8a0ed9d8..afc3659f 100644 --- a/internal/analyzers/agw_anayzer.go +++ b/internal/scanners/agw.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -9,8 +9,8 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork" ) -// ApplicationGatewayAnalyzer - Analyzer for Application Gateways -type ApplicationGatewayAnalyzer struct { +// ApplicationGatewayScanner - Analyzer for Application Gateways +type ApplicationGatewayScanner struct { diagnosticsSettings DiagnosticsSettings subscriptionID string ctx context.Context @@ -20,11 +20,11 @@ type ApplicationGatewayAnalyzer struct { } // Init - Initializes the ApplicationGatewayAnalyzer -func (a *ApplicationGatewayAnalyzer) Init(config ServiceAnalizerConfig) error { +func (a *ApplicationGatewayScanner) Init(config ScannerConfig) error { a.subscriptionID = config.SubscriptionID a.ctx = config.Ctx a.cred = config.Cred - var err error + var err error a.gatewaysClient, err = armnetwork.NewApplicationGatewaysClient(config.SubscriptionID, config.Cred, nil) if err != nil { return err @@ -38,7 +38,7 @@ func (a *ApplicationGatewayAnalyzer) Init(config ServiceAnalizerConfig) error { } // Review - Analyzes all Application Gateways in a Resource Group -func (a *ApplicationGatewayAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, error) { +func (a *ApplicationGatewayScanner) Review(resourceGroupName string) ([]IAzureServiceResult, error) { log.Printf("Analyzing Application Gateways in Resource Group %s", resourceGroupName) gateways, err := a.listGateways(resourceGroupName) @@ -69,7 +69,7 @@ func (a *ApplicationGatewayAnalyzer) Review(resourceGroupName string) ([]IAzureS return results, nil } -func (a *ApplicationGatewayAnalyzer) listGateways(resourceGroupName string) ([]*armnetwork.ApplicationGateway, error) { +func (a *ApplicationGatewayScanner) listGateways(resourceGroupName string) ([]*armnetwork.ApplicationGateway, error) { if a.listGatewaysFunc == nil { pager := a.gatewaysClient.NewListPager(resourceGroupName, nil) results := []*armnetwork.ApplicationGateway{} diff --git a/internal/analyzers/agw_anayzer_test.go b/internal/scanners/agw_test.go similarity index 92% rename from internal/analyzers/agw_anayzer_test.go rename to internal/scanners/agw_test.go index 866f8ccc..71ea2d77 100644 --- a/internal/analyzers/agw_anayzer_test.go +++ b/internal/scanners/agw_test.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -74,14 +74,14 @@ func TestApplicationGatewayAnalyzer_Review(t *testing.T) { } tests := []struct { name string - a ApplicationGatewayAnalyzer + a ApplicationGatewayScanner args args want []IAzureServiceResult wantErr bool }{ { name: "Test Review", - a: ApplicationGatewayAnalyzer{ + a: ApplicationGatewayScanner{ diagnosticsSettings: DiagnosticsSettings{ diagnosticsSettingsClient: nil, ctx: context.TODO(), @@ -117,11 +117,11 @@ func TestApplicationGatewayAnalyzer_Review(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := tt.a.Review(tt.args.resourceGroupName) if (err != nil) != tt.wantErr { - t.Errorf("ApplicationGatewayAnalyzer.Review() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ApplicationGatewayScanner.Review() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ApplicationGatewayAnalyzer.Review() = %v, want %v", got, tt.want) + t.Errorf("ApplicationGatewaScanner.Review() = %v, want %v", got, tt.want) } }) } diff --git a/internal/analyzers/aks_analyzer.go b/internal/scanners/aks.go similarity index 86% rename from internal/analyzers/aks_analyzer.go rename to internal/scanners/aks.go index b51712c1..1cf61659 100644 --- a/internal/analyzers/aks_analyzer.go +++ b/internal/scanners/aks.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -9,8 +9,8 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice" ) -// AKSAnalyzer - Analyzer for AKS Clusters -type AKSAnalyzer struct { +// AKSScanner - Analyzer for AKS Clusters +type AKSScanner struct { diagnosticsSettings DiagnosticsSettings subscriptionID string ctx context.Context @@ -19,12 +19,12 @@ type AKSAnalyzer struct { listClustersFunc func(resourceGroupName string) ([]*armcontainerservice.ManagedCluster, error) } -// Init - Initializes the AKSAnalyzer -func (a *AKSAnalyzer) Init(config ServiceAnalizerConfig) error { +// Init - Initializes the AKSScanner +func (a *AKSScanner) Init(config ScannerConfig) error { a.subscriptionID = config.SubscriptionID a.ctx = config.Ctx a.cred = config.Cred - var err error + var err error a.clustersClient, err = armcontainerservice.NewManagedClustersClient(config.SubscriptionID, config.Cred, nil) if err != nil { return err @@ -38,7 +38,7 @@ func (a *AKSAnalyzer) Init(config ServiceAnalizerConfig) error { } // Review - Analyzes all AKS Clusters in a Resource Group -func (a *AKSAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, error) { +func (a *AKSScanner) Review(resourceGroupName string) ([]IAzureServiceResult, error) { log.Printf("Analyzing AKS Clusters in Resource Group %s", resourceGroupName) clusters, err := a.listClusters(resourceGroupName) @@ -90,7 +90,7 @@ func (a *AKSAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, e return results, nil } -func (a *AKSAnalyzer) listClusters(resourceGroupName string) ([]*armcontainerservice.ManagedCluster, error) { +func (a *AKSScanner) listClusters(resourceGroupName string) ([]*armcontainerservice.ManagedCluster, error) { if a.listClustersFunc == nil { pager := a.clustersClient.NewListByResourceGroupPager(resourceGroupName, nil) diff --git a/internal/analyzers/aks_analyzer_test.go b/internal/scanners/aks_test.go similarity index 93% rename from internal/analyzers/aks_analyzer_test.go rename to internal/scanners/aks_test.go index 904a3b85..27c8e585 100644 --- a/internal/analyzers/aks_analyzer_test.go +++ b/internal/scanners/aks_test.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -78,20 +78,20 @@ func newAKSPrivateEndpointResult(t *testing.T) AzureServiceResult { return svc } -func TestAKSAnalyzer_Review(t *testing.T) { +func TestAKSScanner_Review(t *testing.T) { type args struct { resourceGroupName string } tests := []struct { name string - a AKSAnalyzer + a AKSScanner args args want []IAzureServiceResult wantErr bool }{ { name: "Test Review", - a: AKSAnalyzer{ + a: AKSScanner{ diagnosticsSettings: DiagnosticsSettings{ diagnosticsSettingsClient: nil, ctx: context.TODO(), @@ -127,11 +127,11 @@ func TestAKSAnalyzer_Review(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := tt.a.Review(tt.args.resourceGroupName) if (err != nil) != tt.wantErr { - t.Errorf("AKSAnalyzer.Review() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("AKSScanner.Review() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("AKSAnalyzer.Review() = %v, want %v", got, tt.want) + t.Errorf("AKSScanner.Review() = %v, want %v", got, tt.want) } }) } diff --git a/internal/analyzers/apim_analyzer.go b/internal/scanners/apim.go similarity index 83% rename from internal/analyzers/apim_analyzer.go rename to internal/scanners/apim.go index 94dfea5b..8ec8e242 100644 --- a/internal/analyzers/apim_analyzer.go +++ b/internal/scanners/apim.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -9,8 +9,8 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/apimanagement/armapimanagement" ) -// APIManagementAnalyzer - Analyzer for API Management Services -type APIManagementAnalyzer struct { +// APIManagementScanner - Analyzer for API Management Services +type APIManagementScanner struct { diagnosticsSettings DiagnosticsSettings subscriptionID string ctx context.Context @@ -19,12 +19,12 @@ type APIManagementAnalyzer struct { listServicesFunc func(resourceGroupName string) ([]*armapimanagement.ServiceResource, error) } -// Init - Initializes the APIManagementAnalyzer -func (a *APIManagementAnalyzer) Init(config ServiceAnalizerConfig) error { +// Init - Initializes the APIManagementScanner +func (a *APIManagementScanner) Init(config ScannerConfig) error { a.subscriptionID = config.SubscriptionID a.ctx = config.Ctx a.cred = config.Cred - var err error + var err error a.serviceClient, err = armapimanagement.NewServiceClient(config.SubscriptionID, config.Cred, nil) if err != nil { return err @@ -38,7 +38,7 @@ func (a *APIManagementAnalyzer) Init(config ServiceAnalizerConfig) error { } // Review -Analyzes all API Management Services in a Resource Group -func (a *APIManagementAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, error) { +func (a *APIManagementScanner) Review(resourceGroupName string) ([]IAzureServiceResult, error) { log.Printf("Analyzing API Management Services in Resource Group %s", resourceGroupName) services, err := a.listServices(resourceGroupName) @@ -77,7 +77,7 @@ func (a *APIManagementAnalyzer) Review(resourceGroupName string) ([]IAzureServic return results, nil } -func (a *APIManagementAnalyzer) listServices(resourceGroupName string) ([]*armapimanagement.ServiceResource, error) { +func (a *APIManagementScanner) listServices(resourceGroupName string) ([]*armapimanagement.ServiceResource, error) { if a.listServicesFunc == nil { pager := a.serviceClient.NewListByResourceGroupPager(resourceGroupName, nil) diff --git a/internal/analyzers/apim_analyzer_test.go b/internal/scanners/apim_test.go similarity index 93% rename from internal/analyzers/apim_analyzer_test.go rename to internal/scanners/apim_test.go index 7a4d1d71..21e70b68 100644 --- a/internal/analyzers/apim_analyzer_test.go +++ b/internal/scanners/apim_test.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -76,14 +76,14 @@ func TestAPIMAnalyzer_Review(t *testing.T) { } tests := []struct { name string - a APIManagementAnalyzer + a APIManagementScanner args args want []IAzureServiceResult wantErr bool }{ { name: "Test Review", - a: APIManagementAnalyzer{ + a: APIManagementScanner{ diagnosticsSettings: DiagnosticsSettings{ diagnosticsSettingsClient: nil, ctx: context.TODO(), @@ -119,11 +119,11 @@ func TestAPIMAnalyzer_Review(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := tt.a.Review(tt.args.resourceGroupName) if (err != nil) != tt.wantErr { - t.Errorf("ApiManagementAnalyzer.Review() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("APIManagementScanner.Review() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ApiManagementAnalyzer.Review() = %v, want %v", got, tt.want) + t.Errorf("APIManagementScanner.Review() = %v, want %v", got, tt.want) } }) } diff --git a/internal/analyzers/cae_analyzer.go b/internal/scanners/cae.go similarity index 82% rename from internal/analyzers/cae_analyzer.go rename to internal/scanners/cae.go index a8a6fbb6..82b007a5 100644 --- a/internal/analyzers/cae_analyzer.go +++ b/internal/scanners/cae.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -9,8 +9,8 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appcontainers/armappcontainers" ) -// ContainerAppsAnalyzer - Analyzer for Container Apps -type ContainerAppsAnalyzer struct { +// ContainerAppsScanner - Analyzer for Container Apps +type ContainerAppsScanner struct { diagnosticsSettings DiagnosticsSettings subscriptionID string ctx context.Context @@ -19,12 +19,12 @@ type ContainerAppsAnalyzer struct { listAppsFunc func(resourceGroupName string) ([]*armappcontainers.ManagedEnvironment, error) } -// Init - Initializes the ContainerAppsAnalyzer -func (a *ContainerAppsAnalyzer) Init(config ServiceAnalizerConfig) error { +// Init - Initializes the ContainerAppsScanner +func (a *ContainerAppsScanner) Init(config ScannerConfig) error { a.subscriptionID = config.SubscriptionID a.ctx = config.Ctx a.cred = config.Cred - var err error + var err error a.appsClient, err = armappcontainers.NewManagedEnvironmentsClient(config.SubscriptionID, config.Cred, nil) if err != nil { return err @@ -38,7 +38,7 @@ func (a *ContainerAppsAnalyzer) Init(config ServiceAnalizerConfig) error { } // Review - Analyzes all Container Apps in a Resource Group -func (a *ContainerAppsAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, error) { +func (a *ContainerAppsScanner) Review(resourceGroupName string) ([]IAzureServiceResult, error) { log.Printf("Analyzing Container Apps in Resource Group %s", resourceGroupName) apps, err := a.listApps(resourceGroupName) @@ -69,7 +69,7 @@ func (a *ContainerAppsAnalyzer) Review(resourceGroupName string) ([]IAzureServic return results, nil } -func (a *ContainerAppsAnalyzer) listApps(resourceGroupName string) ([]*armappcontainers.ManagedEnvironment, error) { +func (a *ContainerAppsScanner) listApps(resourceGroupName string) ([]*armappcontainers.ManagedEnvironment, error) { if a.listAppsFunc == nil { pager := a.appsClient.NewListByResourceGroupPager(resourceGroupName, nil) apps := make([]*armappcontainers.ManagedEnvironment, 0) diff --git a/internal/analyzers/cae_analyzer_test.go b/internal/scanners/cae_test.go similarity index 91% rename from internal/analyzers/cae_analyzer_test.go rename to internal/scanners/cae_test.go index 79bdebe2..8530753e 100644 --- a/internal/analyzers/cae_analyzer_test.go +++ b/internal/scanners/cae_test.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -64,20 +64,20 @@ func newContainerAppsPrivateEndpointResult(t *testing.T) AzureServiceResult { return svc } -func TestContainerAppsAnalyzer_Review(t *testing.T) { +func TestContainerAppsScanner_Review(t *testing.T) { type args struct { resourceGroupName string } tests := []struct { name string - c ContainerAppsAnalyzer + c ContainerAppsScanner args args want []IAzureServiceResult wantErr bool }{ { name: "Test Review", - c: ContainerAppsAnalyzer{ + c: ContainerAppsScanner{ diagnosticsSettings: DiagnosticsSettings{ diagnosticsSettingsClient: nil, ctx: context.TODO(), @@ -113,11 +113,11 @@ func TestContainerAppsAnalyzer_Review(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := tt.c.Review(tt.args.resourceGroupName) if (err != nil) != tt.wantErr { - t.Errorf("ContainerAppsAnalyzer.Review() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ContainerAppsScanner.Review() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ContainerAppsAnalyzer.Review() = %v, want %v", got, tt.want) + t.Errorf("ContainerAppsScanner.Review() = %v, want %v", got, tt.want) } }) } diff --git a/internal/analyzers/ci_analyzer.go b/internal/scanners/ci.go similarity index 83% rename from internal/analyzers/ci_analyzer.go rename to internal/scanners/ci.go index 13d9c66c..506a3b4d 100644 --- a/internal/analyzers/ci_analyzer.go +++ b/internal/scanners/ci.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -9,8 +9,8 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerinstance/armcontainerinstance" ) -// ContainerInstanceAnalyzer - Analyzer for Container Instances -type ContainerInstanceAnalyzer struct { +// ContainerInstanceScanner - Analyzer for Container Instances +type ContainerInstanceScanner struct { diagnosticsSettings DiagnosticsSettings subscriptionID string ctx context.Context @@ -19,8 +19,8 @@ type ContainerInstanceAnalyzer struct { listInstancesFunc func(resourceGroupName string) ([]*armcontainerinstance.ContainerGroup, error) } -// Init - Initializes the ContainerInstanceAnalyzer -func (c *ContainerInstanceAnalyzer) Init(config ServiceAnalizerConfig) error { +// Init - Initializes the ContainerInstanceScanner +func (c *ContainerInstanceScanner) Init(config ScannerConfig) error { c.subscriptionID = config.SubscriptionID c.ctx = config.Ctx c.cred = config.Cred @@ -38,7 +38,7 @@ func (c *ContainerInstanceAnalyzer) Init(config ServiceAnalizerConfig) error { } // Review - Analyzes all Container Instances in a Resource Group -func (c *ContainerInstanceAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, error) { +func (c *ContainerInstanceScanner) Review(resourceGroupName string) ([]IAzureServiceResult, error) { log.Printf("Analyzing Container Instances in Resource Group %s", resourceGroupName) instances, err := c.listInstances(resourceGroupName) @@ -69,7 +69,7 @@ func (c *ContainerInstanceAnalyzer) Review(resourceGroupName string) ([]IAzureSe return results, nil } -func (c *ContainerInstanceAnalyzer) listInstances(resourceGroupName string) ([]*armcontainerinstance.ContainerGroup, error) { +func (c *ContainerInstanceScanner) listInstances(resourceGroupName string) ([]*armcontainerinstance.ContainerGroup, error) { if c.listInstancesFunc == nil { pager := c.instancesClient.NewListByResourceGroupPager(resourceGroupName, nil) apps := make([]*armcontainerinstance.ContainerGroup, 0) diff --git a/internal/analyzers/ci_analyzer_test.go b/internal/scanners/ci_test.go similarity index 91% rename from internal/analyzers/ci_analyzer_test.go rename to internal/scanners/ci_test.go index 94d44ff5..0e151bec 100644 --- a/internal/analyzers/ci_analyzer_test.go +++ b/internal/scanners/ci_test.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -68,20 +68,20 @@ func newContainerInstancePrivateEndpointResult(t *testing.T) AzureServiceResult return svc } -func TestContainerInstanceAnalyzer_Review(t *testing.T) { +func TestContainerInstanceScanner_Review(t *testing.T) { type args struct { resourceGroupName string } tests := []struct { name string - c ContainerInstanceAnalyzer + c ContainerInstanceScanner args args want []IAzureServiceResult wantErr bool }{ { name: "Test Review", - c: ContainerInstanceAnalyzer{ + c: ContainerInstanceScanner{ diagnosticsSettings: DiagnosticsSettings{ diagnosticsSettingsClient: nil, ctx: context.TODO(), @@ -117,11 +117,11 @@ func TestContainerInstanceAnalyzer_Review(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := tt.c.Review(tt.args.resourceGroupName) if (err != nil) != tt.wantErr { - t.Errorf("ContainerInstanceAnalyzer.Review() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ContainerInstanceScanner.Review() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ContainerInstanceAnalyzer.Review() = %v, want %v", got, tt.want) + t.Errorf("ContainerInstanceScanner.Review() = %v, want %v", got, tt.want) } }) } diff --git a/internal/analyzers/cosmosdb_analyzer.go b/internal/scanners/cosmosdb.go similarity index 86% rename from internal/analyzers/cosmosdb_analyzer.go rename to internal/scanners/cosmosdb.go index e28dca78..d4b390bb 100644 --- a/internal/analyzers/cosmosdb_analyzer.go +++ b/internal/scanners/cosmosdb.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -9,8 +9,8 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmos/armcosmos" ) -// CosmosDBAnalyzer - Analyzer for CosmosDB Databases -type CosmosDBAnalyzer struct { +// CosmosDBScanner - Analyzer for CosmosDB Databases +type CosmosDBScanner struct { diagnosticsSettings DiagnosticsSettings subscriptionID string ctx context.Context @@ -19,12 +19,12 @@ type CosmosDBAnalyzer struct { listDatabasesFunc func(resourceGroupName string) ([]*armcosmos.DatabaseAccountGetResults, error) } -// Init - Initializes the CosmosDBAnalyzer -func (a *CosmosDBAnalyzer) Init(config ServiceAnalizerConfig) error { +// Init - Initializes the CosmosDBScanner +func (a *CosmosDBScanner) Init(config ScannerConfig) error { a.subscriptionID = config.SubscriptionID a.ctx = config.Ctx a.cred = config.Cred - var err error + var err error a.databasesClient, err = armcosmos.NewDatabaseAccountsClient(config.SubscriptionID, config.Cred, nil) if err != nil { return err @@ -38,7 +38,7 @@ func (a *CosmosDBAnalyzer) Init(config ServiceAnalizerConfig) error { } // Review - Analyzes all CosmosDB Databases in a Resource Group -func (c *CosmosDBAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, error) { +func (c *CosmosDBScanner) Review(resourceGroupName string) ([]IAzureServiceResult, error) { log.Printf("Analyzing CosmosDB Databases in Resource Group %s", resourceGroupName) databases, err := c.listDatabases(resourceGroupName) @@ -87,7 +87,7 @@ func (c *CosmosDBAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResu return results, nil } -func (c *CosmosDBAnalyzer) listDatabases(resourceGroupName string) ([]*armcosmos.DatabaseAccountGetResults, error) { +func (c *CosmosDBScanner) listDatabases(resourceGroupName string) ([]*armcosmos.DatabaseAccountGetResults, error) { if c.listDatabasesFunc == nil { pager := c.databasesClient.NewListByResourceGroupPager(resourceGroupName, nil) diff --git a/internal/analyzers/cosmosdb_analyzer_test.go b/internal/scanners/cosmosdb_test.go similarity index 92% rename from internal/analyzers/cosmosdb_analyzer_test.go rename to internal/scanners/cosmosdb_test.go index ddb47ee9..0a32ccda 100644 --- a/internal/analyzers/cosmosdb_analyzer_test.go +++ b/internal/scanners/cosmosdb_test.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -78,20 +78,20 @@ func newCosmosDBPrivateEndpointResult(t *testing.T) AzureServiceResult { return svc } -func TestCosmosDBAnalyzer_Review(t *testing.T) { +func TestCosmosDBScanner_Review(t *testing.T) { type args struct { resourceGroupName string } tests := []struct { name string - c CosmosDBAnalyzer + c CosmosDBScanner args args want []IAzureServiceResult wantErr bool }{ { name: "Test Review", - c: CosmosDBAnalyzer{ + c: CosmosDBScanner{ diagnosticsSettings: DiagnosticsSettings{ diagnosticsSettingsClient: nil, ctx: context.TODO(), @@ -127,11 +127,11 @@ func TestCosmosDBAnalyzer_Review(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := tt.c.Review(tt.args.resourceGroupName) if (err != nil) != tt.wantErr { - t.Errorf("CosmosDBAnalyzer.Review() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("CosmosDBScanner.Review() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("CosmosDBAnalyzer.Review() = %v, want %v", got, tt.want) + t.Errorf("CosmosDBScanner.Review() = %v, want %v", got, tt.want) } }) } diff --git a/internal/analyzers/cr_analyzer.go b/internal/scanners/cr.go similarity index 83% rename from internal/analyzers/cr_analyzer.go rename to internal/scanners/cr.go index 6116a46c..f388bfc8 100644 --- a/internal/analyzers/cr_analyzer.go +++ b/internal/scanners/cr.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -9,8 +9,8 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerregistry/armcontainerregistry" ) -// ContainerRegistryAnalyzer - Analyzer for Container Registries -type ContainerRegistryAnalyzer struct { +// ContainerRegistryScanner - Analyzer for Container Registries +type ContainerRegistryScanner struct { diagnosticsSettings DiagnosticsSettings subscriptionID string ctx context.Context @@ -19,8 +19,8 @@ type ContainerRegistryAnalyzer struct { listRegistriesFunc func(resourceGroupName string) ([]*armcontainerregistry.Registry, error) } -// Init - Initializes the ContainerRegistryAnalyzer -func (c *ContainerRegistryAnalyzer) Init(config ServiceAnalizerConfig) error { +// Init - Initializes the ContainerRegistryScanner +func (c *ContainerRegistryScanner) Init(config ScannerConfig) error { c.subscriptionID = config.SubscriptionID c.ctx = config.Ctx c.cred = config.Cred @@ -38,7 +38,7 @@ func (c *ContainerRegistryAnalyzer) Init(config ServiceAnalizerConfig) error { } // Review - Analyzes all Container Registries in a Resource Group -func (c *ContainerRegistryAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, error) { +func (c *ContainerRegistryScanner) Review(resourceGroupName string) ([]IAzureServiceResult, error) { log.Printf("Analyzing Container Registries in Resource Group %s", resourceGroupName) regsitries, err := c.listRegistries(resourceGroupName) @@ -69,7 +69,7 @@ func (c *ContainerRegistryAnalyzer) Review(resourceGroupName string) ([]IAzureSe return results, nil } -func (c *ContainerRegistryAnalyzer) listRegistries(resourceGroupName string) ([]*armcontainerregistry.Registry, error) { +func (c *ContainerRegistryScanner) listRegistries(resourceGroupName string) ([]*armcontainerregistry.Registry, error) { if c.listRegistriesFunc == nil { pager := c.registriesClient.NewListByResourceGroupPager(resourceGroupName, nil) diff --git a/internal/analyzers/cr_analyzer_test.go b/internal/scanners/cr_test.go similarity index 91% rename from internal/analyzers/cr_analyzer_test.go rename to internal/scanners/cr_test.go index d57859d6..83e20d1f 100644 --- a/internal/analyzers/cr_analyzer_test.go +++ b/internal/scanners/cr_test.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -72,20 +72,20 @@ func newContainerRegistryPrivateEndpointResult(t *testing.T) AzureServiceResult return svc } -func TestContainerRegistryAnalyzer_Review(t *testing.T) { +func TestContainerRegistryScanner_Review(t *testing.T) { type args struct { resourceGroupName string } tests := []struct { name string - c ContainerRegistryAnalyzer + c ContainerRegistryScanner args args want []IAzureServiceResult wantErr bool }{ { name: "Test Review", - c: ContainerRegistryAnalyzer{ + c: ContainerRegistryScanner{ diagnosticsSettings: DiagnosticsSettings{ diagnosticsSettingsClient: nil, ctx: context.TODO(), @@ -121,11 +121,11 @@ func TestContainerRegistryAnalyzer_Review(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := tt.c.Review(tt.args.resourceGroupName) if (err != nil) != tt.wantErr { - t.Errorf("ContainerRegistryAnalyzer.Review() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ContainerRegistryScanner.Review() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ContainerRegistryAnalyzer.Review() = %v, want %v", got, tt.want) + t.Errorf("ContainerRegistryScanner.Review() = %v, want %v", got, tt.want) } }) } diff --git a/internal/analyzers/diagnostics_settings.go b/internal/scanners/diagnostics_settings.go similarity index 98% rename from internal/analyzers/diagnostics_settings.go rename to internal/scanners/diagnostics_settings.go index 16480ecb..a58e03c9 100644 --- a/internal/analyzers/diagnostics_settings.go +++ b/internal/scanners/diagnostics_settings.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" diff --git a/internal/analyzers/eventhub_analyzer.go b/internal/scanners/eventhub.go similarity index 84% rename from internal/analyzers/eventhub_analyzer.go rename to internal/scanners/eventhub.go index cff08d96..6ae27d5e 100644 --- a/internal/analyzers/eventhub_analyzer.go +++ b/internal/scanners/eventhub.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -9,8 +9,8 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/eventhub/armeventhub" ) -// EventHubAnalyzer - Analyzer for Event Hubs -type EventHubAnalyzer struct { +// EventHubScanner - Analyzer for Event Hubs +type EventHubScanner struct { diagnosticsSettings DiagnosticsSettings subscriptionID string ctx context.Context @@ -19,12 +19,12 @@ type EventHubAnalyzer struct { listEventHubsFunc func(resourceGroupName string) ([]*armeventhub.EHNamespace, error) } -// Init - Initializes the EventHubAnalyzer -func (a *EventHubAnalyzer) Init(config ServiceAnalizerConfig) error { +// Init - Initializes the EventHubScanner +func (a *EventHubScanner) Init(config ScannerConfig) error { a.subscriptionID = config.SubscriptionID a.ctx = config.Ctx a.cred = config.Cred - var err error + var err error a.client, err = armeventhub.NewNamespacesClient(config.SubscriptionID, config.Cred, nil) if err != nil { return err @@ -38,7 +38,7 @@ func (a *EventHubAnalyzer) Init(config ServiceAnalizerConfig) error { } // Review - Analyzes all Event Hubs in a Resource Group -func (c *EventHubAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, error) { +func (c *EventHubScanner) Review(resourceGroupName string) ([]IAzureServiceResult, error) { log.Printf("Analyzing Event Hubs in Resource Group %s", resourceGroupName) eventHubs, err := c.listEventHubs(resourceGroupName) @@ -75,7 +75,7 @@ func (c *EventHubAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResu return results, nil } -func (c *EventHubAnalyzer) listEventHubs(resourceGroupName string) ([]*armeventhub.EHNamespace, error) { +func (c *EventHubScanner) listEventHubs(resourceGroupName string) ([]*armeventhub.EHNamespace, error) { if c.listEventHubsFunc == nil { pager := c.client.NewListByResourceGroupPager(resourceGroupName, nil) diff --git a/internal/analyzers/eventhub_analyzer_test.go b/internal/scanners/eventhub_test.go similarity index 92% rename from internal/analyzers/eventhub_analyzer_test.go rename to internal/scanners/eventhub_test.go index 849405db..5b184b66 100644 --- a/internal/analyzers/eventhub_analyzer_test.go +++ b/internal/scanners/eventhub_test.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -70,20 +70,20 @@ func newEventHubPrivateEndpointResult(t *testing.T) AzureServiceResult { return svc } -func TestEventHubAnalyzer_Review(t *testing.T) { +func TestEventHubScanner_Review(t *testing.T) { type args struct { resourceGroupName string } tests := []struct { name string - c EventHubAnalyzer + c EventHubScanner args args want []IAzureServiceResult wantErr bool }{ { name: "Test Review", - c: EventHubAnalyzer{ + c: EventHubScanner{ diagnosticsSettings: DiagnosticsSettings{ diagnosticsSettingsClient: nil, ctx: context.TODO(), @@ -119,11 +119,11 @@ func TestEventHubAnalyzer_Review(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := tt.c.Review(tt.args.resourceGroupName) if (err != nil) != tt.wantErr { - t.Errorf("EventHubAnalyzer.Review() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("EventHubScanner.Review() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("EventHubAnalyzer.Review() = %v, want %v", got, tt.want) + t.Errorf("EventHubScanner.Review() = %v, want %v", got, tt.want) } }) } diff --git a/internal/analyzers/evgd_analyzer.go b/internal/scanners/evgd.go similarity index 83% rename from internal/analyzers/evgd_analyzer.go rename to internal/scanners/evgd.go index 53d1cf4f..84127a3a 100644 --- a/internal/analyzers/evgd_analyzer.go +++ b/internal/scanners/evgd.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -9,8 +9,8 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/eventgrid/armeventgrid" ) -// EventGridAnalyzer - Analyzer for EventGrid Domains -type EventGridAnalyzer struct { +// EventGridScanner - Analyzer for EventGrid Domains +type EventGridScanner struct { diagnosticsSettings DiagnosticsSettings subscriptionID string ctx context.Context @@ -19,12 +19,12 @@ type EventGridAnalyzer struct { listDomainFunc func(resourceGroupName string) ([]*armeventgrid.Domain, error) } -// Init - Initializes the EventGridAnalyzer -func (a *EventGridAnalyzer) Init(config ServiceAnalizerConfig) error { +// Init - Initializes the EventGridScanner +func (a *EventGridScanner) Init(config ScannerConfig) error { a.subscriptionID = config.SubscriptionID a.ctx = config.Ctx a.cred = config.Cred - var err error + var err error a.domainsClient, err = armeventgrid.NewDomainsClient(config.SubscriptionID, config.Cred, nil) if err != nil { return err @@ -38,7 +38,7 @@ func (a *EventGridAnalyzer) Init(config ServiceAnalizerConfig) error { } // Review - Analyzes all EventGrid Domains in a Resource Group -func (a *EventGridAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, error) { +func (a *EventGridScanner) Review(resourceGroupName string) ([]IAzureServiceResult, error) { log.Printf("Analyzing EventGrid Domains in Resource Group %s", resourceGroupName) domains, err := a.listDomain(resourceGroupName) @@ -69,7 +69,7 @@ func (a *EventGridAnalyzer) Review(resourceGroupName string) ([]IAzureServiceRes return results, nil } -func (a *EventGridAnalyzer) listDomain(resourceGroupName string) ([]*armeventgrid.Domain, error) { +func (a *EventGridScanner) listDomain(resourceGroupName string) ([]*armeventgrid.Domain, error) { if a.listDomainFunc == nil { pager := a.domainsClient.NewListByResourceGroupPager(resourceGroupName, nil) diff --git a/internal/analyzers/evgd_analyzer_test.go b/internal/scanners/evgd_test.go similarity index 90% rename from internal/analyzers/evgd_analyzer_test.go rename to internal/scanners/evgd_test.go index 230efe94..0ec3de60 100644 --- a/internal/analyzers/evgd_analyzer_test.go +++ b/internal/scanners/evgd_test.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -53,20 +53,20 @@ func newEventGridPrivateEndpointResult(t *testing.T) AzureServiceResult { return svc } -func TestEventGridAnalyzer_Review(t *testing.T) { +func TestEventGridScanner_Review(t *testing.T) { type args struct { resourceGroupName string } tests := []struct { name string - a EventGridAnalyzer + a EventGridScanner args args want []IAzureServiceResult wantErr bool }{ { name: "Test Review", - a: EventGridAnalyzer{ + a: EventGridScanner{ diagnosticsSettings: DiagnosticsSettings{ diagnosticsSettingsClient: nil, ctx: context.TODO(), @@ -100,11 +100,11 @@ func TestEventGridAnalyzer_Review(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := tt.a.Review(tt.args.resourceGroupName) if (err != nil) != tt.wantErr { - t.Errorf("EventGridAnalyzer.Review() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("EventGridScanner.Review() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("EventGridAnalyzer.Review() = %v, want %v", got, tt.want) + t.Errorf("EventGridScanner.Review() = %v, want %v", got, tt.want) } }) } diff --git a/internal/analyzers/kv_analyzer.go b/internal/scanners/kv.go similarity index 84% rename from internal/analyzers/kv_analyzer.go rename to internal/scanners/kv.go index ac28ca36..76aefd11 100644 --- a/internal/analyzers/kv_analyzer.go +++ b/internal/scanners/kv.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -9,8 +9,8 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/keyvault/armkeyvault" ) -// KeyVaultAnalyzer - Analyzer for Key Vaults -type KeyVaultAnalyzer struct { +// KeyVaultScanner - Analyzer for Key Vaults +type KeyVaultScanner struct { diagnosticsSettings DiagnosticsSettings subscriptionID string ctx context.Context @@ -19,8 +19,8 @@ type KeyVaultAnalyzer struct { listVaultsFunc func(resourceGroupName string) ([]*armkeyvault.Vault, error) } -// Init - Initializes the KeyVaultAnalyzer -func (c *KeyVaultAnalyzer) Init(config ServiceAnalizerConfig) error { +// Init - Initializes the KeyVaultScanner +func (c *KeyVaultScanner) Init(config ScannerConfig) error { c.subscriptionID = config.SubscriptionID c.ctx = config.Ctx c.cred = config.Cred @@ -38,7 +38,7 @@ func (c *KeyVaultAnalyzer) Init(config ServiceAnalizerConfig) error { } // Review - Analyzes all Key Vaults in a Resource Group -func (c *KeyVaultAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, error) { +func (c *KeyVaultScanner) Review(resourceGroupName string) ([]IAzureServiceResult, error) { log.Printf("Analyzing Key Vaults in Resource Group %s", resourceGroupName) vaults, err := c.listVaults(resourceGroupName) @@ -69,7 +69,7 @@ func (c *KeyVaultAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResu return results, nil } -func (c *KeyVaultAnalyzer) listVaults(resourceGroupName string) ([]*armkeyvault.Vault, error) { +func (c *KeyVaultScanner) listVaults(resourceGroupName string) ([]*armkeyvault.Vault, error) { if c.listVaultsFunc == nil { pager := c.vaultsClient.NewListByResourceGroupPager(resourceGroupName, nil) diff --git a/internal/analyzers/kv_analyzer_test.go b/internal/scanners/kv_test.go similarity index 90% rename from internal/analyzers/kv_analyzer_test.go rename to internal/scanners/kv_test.go index 1280b947..46e8e355 100644 --- a/internal/analyzers/kv_analyzer_test.go +++ b/internal/scanners/kv_test.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -57,20 +57,20 @@ func newKeyVaultPrivateEndpointResult(t *testing.T) AzureServiceResult { return svc } -func TestKeyVaultAnalyzer_Review(t *testing.T) { +func TestKeyVaultScanner_Review(t *testing.T) { type args struct { resourceGroupName string } tests := []struct { name string - c KeyVaultAnalyzer + c KeyVaultScanner args args want []IAzureServiceResult wantErr bool }{ { name: "Test Review", - c: KeyVaultAnalyzer{ + c: KeyVaultScanner{ diagnosticsSettings: DiagnosticsSettings{ diagnosticsSettingsClient: nil, ctx: context.TODO(), @@ -104,11 +104,11 @@ func TestKeyVaultAnalyzer_Review(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := tt.c.Review(tt.args.resourceGroupName) if (err != nil) != tt.wantErr { - t.Errorf("KeyVaultAnalyzer.Review() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("KeyVaultScanner.Review() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("KeyVaultAnalyzer.Review() = %v, want %v", got, tt.want) + t.Errorf("KeyVaultScanner.Review() = %v, want %v", got, tt.want) } }) } diff --git a/internal/analyzers/plan_analyzer.go b/internal/scanners/plan.go similarity index 91% rename from internal/analyzers/plan_analyzer.go rename to internal/scanners/plan.go index 04ab5205..19cf091a 100644 --- a/internal/analyzers/plan_analyzer.go +++ b/internal/scanners/plan.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -9,8 +9,8 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice/v2" ) -// AppServiceAnalyzer - Analyzer for App Service Plans -type AppServiceAnalyzer struct { +// AppServiceScanner - Analyzer for App Service Plans +type AppServiceScanner struct { diagnosticsSettings DiagnosticsSettings subscriptionID string ctx context.Context @@ -22,8 +22,8 @@ type AppServiceAnalyzer struct { listSitesFunc func(resourceGroupName string, planName string) ([]*armappservice.Site, error) } -// Init - Initializes the AppServiceAnalyzer -func (a *AppServiceAnalyzer) Init(config ServiceAnalizerConfig) error { +// Init - Initializes the AppServiceScanner +func (a *AppServiceScanner) Init(config ScannerConfig) error { a.subscriptionID = config.SubscriptionID a.ctx = config.Ctx a.cred = config.Cred @@ -45,7 +45,7 @@ func (a *AppServiceAnalyzer) Init(config ServiceAnalizerConfig) error { } // Review - Analyzes all App Service Plans in a Resource Group -func (a *AppServiceAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, error) { +func (a *AppServiceScanner) Review(resourceGroupName string) ([]IAzureServiceResult, error) { log.Printf("Analyzing App Service Plans in Resource Group %s", resourceGroupName) sites, err := a.listPlans(resourceGroupName) @@ -174,7 +174,7 @@ func (a *AppServiceAnalyzer) Review(resourceGroupName string) ([]IAzureServiceRe return results, nil } -func (a *AppServiceAnalyzer) listPlans(resourceGroupName string) ([]*armappservice.Plan, error) { +func (a *AppServiceScanner) listPlans(resourceGroupName string) ([]*armappservice.Plan, error) { if a.listPlansFunc == nil { pager := a.plansClient.NewListByResourceGroupPager(resourceGroupName, nil) results := []*armappservice.Plan{} @@ -192,7 +192,7 @@ func (a *AppServiceAnalyzer) listPlans(resourceGroupName string) ([]*armappservi return a.listPlansFunc(resourceGroupName) } -func (a *AppServiceAnalyzer) listSites(resourceGroupName string, plan string) ([]*armappservice.Site, error) { +func (a *AppServiceScanner) listSites(resourceGroupName string, plan string) ([]*armappservice.Site, error) { if a.listSitesFunc == nil { pager := a.plansClient.NewListWebAppsPager(resourceGroupName, plan, nil) results := []*armappservice.Site{} diff --git a/internal/analyzers/psql_analyzer.go b/internal/scanners/psql.go similarity index 89% rename from internal/analyzers/psql_analyzer.go rename to internal/scanners/psql.go index c779140d..19003e9a 100644 --- a/internal/analyzers/psql_analyzer.go +++ b/internal/scanners/psql.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -10,8 +10,8 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/postgresql/armpostgresqlflexibleservers" ) -// PostgreAnalyzer - Analyzer for PostgreSQL -type PostgreAnalyzer struct { +// PostgreScanner - Analyzer for PostgreSQL +type PostgreScanner struct { diagnosticsSettings DiagnosticsSettings subscriptionID string ctx context.Context @@ -22,8 +22,8 @@ type PostgreAnalyzer struct { listFlexibleFunc func(resourceGroupName string) ([]*armpostgresqlflexibleservers.Server, error) } -// Init - Initializes the PostgreAnalyzer -func (c *PostgreAnalyzer) Init(config ServiceAnalizerConfig) error { +// Init - Initializes the PostgreScanner +func (c *PostgreScanner) Init(config ScannerConfig) error { c.subscriptionID = config.SubscriptionID c.ctx = config.Ctx c.cred = config.Cred @@ -45,7 +45,7 @@ func (c *PostgreAnalyzer) Init(config ServiceAnalizerConfig) error { } // Review - Analyzes all PostgreSQL in a Resource Group -func (c *PostgreAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, error) { +func (c *PostgreScanner) Review(resourceGroupName string) ([]IAzureServiceResult, error) { log.Printf("Analyzing Postgre in Resource Group %s", resourceGroupName) postgre, err := c.listPostgre(resourceGroupName) @@ -111,7 +111,7 @@ func (c *PostgreAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResul return results, nil } -func (c *PostgreAnalyzer) listPostgre(resourceGroupName string) ([]*armpostgresql.Server, error) { +func (c *PostgreScanner) listPostgre(resourceGroupName string) ([]*armpostgresql.Server, error) { if c.listPostgreFunc == nil { pager := c.postgreClient.NewListByResourceGroupPager(resourceGroupName, nil) @@ -129,7 +129,7 @@ func (c *PostgreAnalyzer) listPostgre(resourceGroupName string) ([]*armpostgresq return c.listPostgreFunc(resourceGroupName) } -func (c *PostgreAnalyzer) listFlexiblePostgre(resourceGroupName string) ([]*armpostgresqlflexibleservers.Server, error) { +func (c *PostgreScanner) listFlexiblePostgre(resourceGroupName string) ([]*armpostgresqlflexibleservers.Server, error) { if c.listFlexibleFunc == nil { pager := c.flexibleClient.NewListByResourceGroupPager(resourceGroupName, nil) diff --git a/internal/analyzers/redis_analyzer.go b/internal/scanners/redis.go similarity index 85% rename from internal/analyzers/redis_analyzer.go rename to internal/scanners/redis.go index df85b8ed..51dee5a9 100644 --- a/internal/analyzers/redis_analyzer.go +++ b/internal/scanners/redis.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -9,8 +9,8 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/redis/armredis" ) -// RedisAnalyzer - Analyzer for Redis -type RedisAnalyzer struct { +// RedisScanner - Analyzer for Redis +type RedisScanner struct { diagnosticsSettings DiagnosticsSettings subscriptionID string ctx context.Context @@ -19,8 +19,8 @@ type RedisAnalyzer struct { listRedisFunc func(resourceGroupName string) ([]*armredis.ResourceInfo, error) } -// Init - Initializes the RedisAnalyzer -func (c *RedisAnalyzer) Init(config ServiceAnalizerConfig) error { +// Init - Initializes the RedisScanner +func (c *RedisScanner) Init(config ScannerConfig) error { c.subscriptionID = config.SubscriptionID c.ctx = config.Ctx c.cred = config.Cred @@ -38,7 +38,7 @@ func (c *RedisAnalyzer) Init(config ServiceAnalizerConfig) error { } // Review - Analyzes all Redis in a Resource Group -func (c *RedisAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, error) { +func (c *RedisScanner) Review(resourceGroupName string) ([]IAzureServiceResult, error) { log.Printf("Analyzing Redis in Resource Group %s", resourceGroupName) redis, err := c.listRedis(resourceGroupName) @@ -69,7 +69,7 @@ func (c *RedisAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, return results, nil } -func (c *RedisAnalyzer) listRedis(resourceGroupName string) ([]*armredis.ResourceInfo, error) { +func (c *RedisScanner) listRedis(resourceGroupName string) ([]*armredis.ResourceInfo, error) { if c.listRedisFunc == nil { pager := c.redisClient.NewListByResourceGroupPager(resourceGroupName, nil) diff --git a/internal/analyzers/redis_analyzer_test.go b/internal/scanners/redis_test.go similarity index 92% rename from internal/analyzers/redis_analyzer_test.go rename to internal/scanners/redis_test.go index 3ac60cd3..2a47c5e7 100644 --- a/internal/analyzers/redis_analyzer_test.go +++ b/internal/scanners/redis_test.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -70,20 +70,20 @@ func newRedisPrivateEndpointResult(t *testing.T) AzureServiceResult { return svc } -func TestRedisAnalyzer_Review(t *testing.T) { +func TestRedisScanner_Review(t *testing.T) { type args struct { resourceGroupName string } tests := []struct { name string - c RedisAnalyzer + c RedisScanner args args want []IAzureServiceResult wantErr bool }{ { name: "Test Review", - c: RedisAnalyzer{ + c: RedisScanner{ diagnosticsSettings: DiagnosticsSettings{ diagnosticsSettingsClient: nil, ctx: context.TODO(), @@ -119,11 +119,11 @@ func TestRedisAnalyzer_Review(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := tt.c.Review(tt.args.resourceGroupName) if (err != nil) != tt.wantErr { - t.Errorf("RedisAnalyzer.Review() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("RedisScanner.Review() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("RedisAnalyzer.Review() = %v, want %v", got, tt.want) + t.Errorf("RedisScanner.Review() = %v, want %v", got, tt.want) } }) } diff --git a/internal/analyzers/sb_analyzer.go b/internal/scanners/sb.go similarity index 84% rename from internal/analyzers/sb_analyzer.go rename to internal/scanners/sb.go index eb865f4b..36e34949 100644 --- a/internal/analyzers/sb_analyzer.go +++ b/internal/scanners/sb.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -9,8 +9,8 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/servicebus/armservicebus" ) -// ServiceBusAnalyzer - Analyzer for Service Bus -type ServiceBusAnalyzer struct { +// ServiceBusScanner - Analyzer for Service Bus +type ServiceBusScanner struct { diagnosticsSettings DiagnosticsSettings subscriptionID string ctx context.Context @@ -19,8 +19,8 @@ type ServiceBusAnalyzer struct { listServiceBusFunc func(resourceGroupName string) ([]*armservicebus.SBNamespace, error) } -// Init - Initializes the ServiceBusAnalyzer -func (a *ServiceBusAnalyzer) Init(config ServiceAnalizerConfig) error { +// Init - Initializes the ServiceBusScanner +func (a *ServiceBusScanner) Init(config ScannerConfig) error { a.subscriptionID = config.SubscriptionID a.ctx = config.Ctx a.cred = config.Cred @@ -38,7 +38,7 @@ func (a *ServiceBusAnalyzer) Init(config ServiceAnalizerConfig) error { } // Review - Analyzes all Service Bus in a Resource Group -func (c *ServiceBusAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, error) { +func (c *ServiceBusScanner) Review(resourceGroupName string) ([]IAzureServiceResult, error) { log.Printf("Analyzing Service Bus in Resource Group %s", resourceGroupName) servicebus, err := c.listServiceBus(resourceGroupName) @@ -75,7 +75,7 @@ func (c *ServiceBusAnalyzer) Review(resourceGroupName string) ([]IAzureServiceRe return results, nil } -func (c *ServiceBusAnalyzer) listServiceBus(resourceGroupName string) ([]*armservicebus.SBNamespace, error) { +func (c *ServiceBusScanner) listServiceBus(resourceGroupName string) ([]*armservicebus.SBNamespace, error) { if c.listServiceBusFunc == nil { pager := c.servicebusClient.NewListByResourceGroupPager(resourceGroupName, nil) diff --git a/internal/analyzers/sb_analyzer_test.go b/internal/scanners/sb_test.go similarity index 90% rename from internal/analyzers/sb_analyzer_test.go rename to internal/scanners/sb_test.go index 6ce9896c..200548b0 100644 --- a/internal/analyzers/sb_analyzer_test.go +++ b/internal/scanners/sb_test.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -57,20 +57,20 @@ func newServiceBusPrivateEndpointResult(t *testing.T) AzureServiceResult { return svc } -func TestServiceBusAnalyzer_Review(t *testing.T) { +func TestServiceBusScanner_Review(t *testing.T) { type args struct { resourceGroupName string } tests := []struct { name string - c ServiceBusAnalyzer + c ServiceBusScanner args args want []IAzureServiceResult wantErr bool }{ { name: "Test Review", - c: ServiceBusAnalyzer{ + c: ServiceBusScanner{ diagnosticsSettings: DiagnosticsSettings{ diagnosticsSettingsClient: nil, ctx: context.TODO(), @@ -104,11 +104,11 @@ func TestServiceBusAnalyzer_Review(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := tt.c.Review(tt.args.resourceGroupName) if (err != nil) != tt.wantErr { - t.Errorf("ServiceBusAnalyzer.Review() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ServiceBusScanner.Review() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ServiceBusAnalyzer.Review() = %v, want %v", got, tt.want) + t.Errorf("ServiceBusScanner.Review() = %v, want %v", got, tt.want) } }) } diff --git a/internal/analyzers/analyzer.go b/internal/scanners/scanner.go similarity index 95% rename from internal/analyzers/analyzer.go rename to internal/scanners/scanner.go index d4b54ca0..d37aded7 100644 --- a/internal/analyzers/analyzer.go +++ b/internal/scanners/scanner.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -19,8 +19,8 @@ type ( Value() AzureServiceResult } - // ServiceAnalizerConfig - Struct for all Service Analyzers Config - ServiceAnalizerConfig struct { + // ScannerConfig - Struct for all Service Analyzers Config + ScannerConfig struct { Ctx context.Context Cred azcore.TokenCredential SubscriptionID string @@ -29,8 +29,8 @@ type ( } // AzureServiceAnalyzer - Interface for all Azure Service Analyzers - IAzureServiceAnalyzer interface { - Init(config ServiceAnalizerConfig) error + IAzureScanner interface { + Init(config ScannerConfig) error Review(resourceGroupName string) ([]IAzureServiceResult, error) } diff --git a/internal/analyzers/sigr_analyzer.go b/internal/scanners/sigr.go similarity index 85% rename from internal/analyzers/sigr_analyzer.go rename to internal/scanners/sigr.go index 7df00906..043dbb3a 100644 --- a/internal/analyzers/sigr_analyzer.go +++ b/internal/scanners/sigr.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -9,8 +9,8 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/signalr/armsignalr" ) -// SignalRAnalyzer - Analyzer for SignalR -type SignalRAnalyzer struct { +// SignalRScanner - Analyzer for SignalR +type SignalRScanner struct { diagnosticsSettings DiagnosticsSettings subscriptionID string ctx context.Context @@ -19,8 +19,8 @@ type SignalRAnalyzer struct { listSignalRFunc func(resourceGroupName string) ([]*armsignalr.ResourceInfo, error) } -// Init - Initializes the SignalRAnalyzer -func (c *SignalRAnalyzer) Init(config ServiceAnalizerConfig) error { +// Init - Initializes the SignalRScanner +func (c *SignalRScanner) Init(config ScannerConfig) error { c.subscriptionID = config.SubscriptionID c.ctx = config.Ctx c.cred = config.Cred @@ -38,7 +38,7 @@ func (c *SignalRAnalyzer) Init(config ServiceAnalizerConfig) error { } // Review - Analyzes all SignalR in a Resource Group -func (c *SignalRAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, error) { +func (c *SignalRScanner) Review(resourceGroupName string) ([]IAzureServiceResult, error) { log.Printf("Analyzing SignalR in Resource Group %s", resourceGroupName) signalr, err := c.listSignalR(resourceGroupName) @@ -75,7 +75,7 @@ func (c *SignalRAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResul return results, nil } -func (c *SignalRAnalyzer) listSignalR(resourceGroupName string) ([]*armsignalr.ResourceInfo, error) { +func (c *SignalRScanner) listSignalR(resourceGroupName string) ([]*armsignalr.ResourceInfo, error) { if c.listSignalRFunc == nil { pager := c.signalrClient.NewListByResourceGroupPager(resourceGroupName, nil) diff --git a/internal/analyzers/sigr_analyzer_test.go b/internal/scanners/sigr_test.go similarity index 92% rename from internal/analyzers/sigr_analyzer_test.go rename to internal/scanners/sigr_test.go index dede09bc..802b301a 100644 --- a/internal/analyzers/sigr_analyzer_test.go +++ b/internal/scanners/sigr_test.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -71,20 +71,20 @@ func newSignalRPrivateEndpointResult(t *testing.T) AzureServiceResult { return svc } -func TestSignalRAnalyzer_Review(t *testing.T) { +func TestSignalRScanner_Review(t *testing.T) { type args struct { resourceGroupName string } tests := []struct { name string - c SignalRAnalyzer + c SignalRScanner args args want []IAzureServiceResult wantErr bool }{ { name: "Test Review", - c: SignalRAnalyzer{ + c: SignalRScanner{ diagnosticsSettings: DiagnosticsSettings{ diagnosticsSettingsClient: nil, ctx: context.TODO(), @@ -120,11 +120,11 @@ func TestSignalRAnalyzer_Review(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := tt.c.Review(tt.args.resourceGroupName) if (err != nil) != tt.wantErr { - t.Errorf("SignalRAnalyzer.Review() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("SignalRScanner.Review() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("SignalRAnalyzer.Review() = %v, want %v", got, tt.want) + t.Errorf("SignalRScanner.Review() = %v, want %v", got, tt.want) } }) } diff --git a/internal/analyzers/sql_analyzer.go b/internal/scanners/sql.go similarity index 87% rename from internal/analyzers/sql_analyzer.go rename to internal/scanners/sql.go index 48600227..80d877a7 100644 --- a/internal/analyzers/sql_analyzer.go +++ b/internal/scanners/sql.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -9,8 +9,8 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/sql/armsql" ) -// SQLAnalyzer - Analyzer for SQL -type SQLAnalyzer struct { +// SQLScanner - Analyzer for SQL +type SQLScanner struct { diagnosticsSettings DiagnosticsSettings subscriptionID string ctx context.Context @@ -21,8 +21,8 @@ type SQLAnalyzer struct { listDatabasesFunc func(resourceGroupName, serverName string) ([]*armsql.Database, error) } -// Init - Initializes the SQLAnalyzer -func (c *SQLAnalyzer) Init(config ServiceAnalizerConfig) error { +// Init - Initializes the SQLScanner +func (c *SQLScanner) Init(config ScannerConfig) error { c.subscriptionID = config.SubscriptionID c.ctx = config.Ctx c.cred = config.Cred @@ -44,7 +44,7 @@ func (c *SQLAnalyzer) Init(config ServiceAnalizerConfig) error { } // Review - Analyzes all SQL in a Resource Group -func (c *SQLAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, error) { +func (c *SQLScanner) Review(resourceGroupName string) ([]IAzureServiceResult, error) { log.Printf("Analyzing SQL in Resource Group %s", resourceGroupName) sql, err := c.listSQL(resourceGroupName) @@ -85,7 +85,7 @@ func (c *SQLAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, e sla := "99.99%" availabilityZones := *database.Properties.ZoneRedundant - if availabilityZones && *database.SKU.Tier == "Premium" { + if availabilityZones && *database.SKU.Tier == "Premium" { sla = "99.995%" } @@ -108,7 +108,7 @@ func (c *SQLAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, e return results, nil } -func (c *SQLAnalyzer) listSQL(resourceGroupName string) ([]*armsql.Server, error) { +func (c *SQLScanner) listSQL(resourceGroupName string) ([]*armsql.Server, error) { if c.listServersFunc == nil { pager := c.sqlClient.NewListByResourceGroupPager(resourceGroupName, nil) @@ -126,7 +126,7 @@ func (c *SQLAnalyzer) listSQL(resourceGroupName string) ([]*armsql.Server, error return c.listServersFunc(resourceGroupName) } -func (c *SQLAnalyzer) listDatabases(resourceGroupName, serverName string) ([]*armsql.Database, error) { +func (c *SQLScanner) listDatabases(resourceGroupName, serverName string) ([]*armsql.Database, error) { if c.listDatabasesFunc == nil { pager := c.sqlDatabasedClient.NewListByServerPager(resourceGroupName, serverName, nil) diff --git a/internal/analyzers/sql_analyzer_test.go b/internal/scanners/sql_test.go similarity index 91% rename from internal/analyzers/sql_analyzer_test.go rename to internal/scanners/sql_test.go index 2ef79e33..bb5595f4 100644 --- a/internal/analyzers/sql_analyzer_test.go +++ b/internal/scanners/sql_test.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -53,20 +53,20 @@ func newSQLServerPrivateEndpointResult(t *testing.T) AzureServiceResult { return svc } -func TestSQLAnalyzer_Review(t *testing.T) { +func TestSQLScanner_Review(t *testing.T) { type args struct { resourceGroupName string } tests := []struct { name string - c SQLAnalyzer + c SQLScanner args args want []IAzureServiceResult wantErr bool }{ { name: "Test Review", - c: SQLAnalyzer{ + c: SQLScanner{ diagnosticsSettings: DiagnosticsSettings{ diagnosticsSettingsClient: nil, ctx: context.TODO(), @@ -104,11 +104,11 @@ func TestSQLAnalyzer_Review(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := tt.c.Review(tt.args.resourceGroupName) if (err != nil) != tt.wantErr { - t.Errorf("SQLAnalyzer.Review() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("SQLScanner.Review() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("SQLAnalyzer.Review() = %v, want %v", got, tt.want) + t.Errorf("SQLScanner.Review() = %v, want %v", got, tt.want) } }) } diff --git a/internal/analyzers/st_analyzer.go b/internal/scanners/st.go similarity index 86% rename from internal/analyzers/st_analyzer.go rename to internal/scanners/st.go index 8338f3a5..006e4d1f 100644 --- a/internal/analyzers/st_analyzer.go +++ b/internal/scanners/st.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -9,8 +9,8 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage" ) -// StorageAnalyzer - Analyzer for Storage -type StorageAnalyzer struct { +// StorageScanner - Analyzer for Storage +type StorageScanner struct { diagnosticsSettings DiagnosticsSettings subscriptionID string ctx context.Context @@ -19,8 +19,8 @@ type StorageAnalyzer struct { listStorageFunc func(resourceGroupName string) ([]*armstorage.Account, error) } -// Init - Initializes the StorageAnalyzer -func (c *StorageAnalyzer) Init(config ServiceAnalizerConfig) error { +// Init - Initializes the StorageScanner +func (c *StorageScanner) Init(config ScannerConfig) error { c.subscriptionID = config.SubscriptionID c.ctx = config.Ctx c.cred = config.Cred @@ -38,7 +38,7 @@ func (c *StorageAnalyzer) Init(config ServiceAnalizerConfig) error { } // Review - Analyzes all Storage in a Resource Group -func (c *StorageAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResult, error) { +func (c *StorageScanner) Review(resourceGroupName string) ([]IAzureServiceResult, error) { log.Printf("Analyzing Storage in Resource Group %s", resourceGroupName) storage, err := c.listStorage(resourceGroupName) @@ -80,7 +80,7 @@ func (c *StorageAnalyzer) Review(resourceGroupName string) ([]IAzureServiceResul return results, nil } -func (c *StorageAnalyzer) listStorage(resourceGroupName string) ([]*armstorage.Account, error) { +func (c *StorageScanner) listStorage(resourceGroupName string) ([]*armstorage.Account, error) { if c.listStorageFunc == nil { pager := c.storageClient.NewListByResourceGroupPager(resourceGroupName, nil) diff --git a/internal/analyzers/st_analyzer_test.go b/internal/scanners/st_test.go similarity index 92% rename from internal/analyzers/st_analyzer_test.go rename to internal/scanners/st_test.go index fccd2964..b4dae4c3 100644 --- a/internal/analyzers/st_analyzer_test.go +++ b/internal/scanners/st_test.go @@ -1,4 +1,4 @@ -package analyzers +package scanners import ( "context" @@ -73,20 +73,20 @@ func newStoragePrivateEndpointResult(t *testing.T) AzureServiceResult { return svc } -func TestStorageAnalyzer_Review(t *testing.T) { +func TestStorageScanner_Review(t *testing.T) { type args struct { resourceGroupName string } tests := []struct { name string - c StorageAnalyzer + c StorageScanner args args want []IAzureServiceResult wantErr bool }{ { name: "Test Review", - c: StorageAnalyzer{ + c: StorageScanner{ diagnosticsSettings: DiagnosticsSettings{ diagnosticsSettingsClient: nil, ctx: context.TODO(), @@ -122,11 +122,11 @@ func TestStorageAnalyzer_Review(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := tt.c.Review(tt.args.resourceGroupName) if (err != nil) != tt.wantErr { - t.Errorf("StorageAnalyzer.Review() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("StorageScanner.Review() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("StorageAnalyzer.Review() = %v, want %v", got, tt.want) + t.Errorf("StorageScanner.Review() = %v, want %v", got, tt.want) } }) }