Skip to content

Commit

Permalink
Merge pull request #172 from Azure/issue-171
Browse files Browse the repository at this point in the history
Fixing 171
  • Loading branch information
cmendible authored Dec 6, 2023
2 parents 00f9505 + 8e540da commit 4d82776
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 151 deletions.
4 changes: 2 additions & 2 deletions cmd/azqr/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package azqr

import (
"github.com/Azure/azqr/internal/scanners"
"github.com/Azure/azqr/internal/scanners/plan"
"github.com/Azure/azqr/internal/scanners/asp"
"github.com/spf13/cobra"
)

Expand All @@ -20,7 +20,7 @@ var planCmd = &cobra.Command{
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
serviceScanners := []scanners.IAzureScanner{
&plan.AppServiceScanner{},
&asp.AppServiceScanner{},
}

scan(cmd, serviceScanners)
Expand Down
4 changes: 2 additions & 2 deletions cmd/azqr/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import (
"github.com/Azure/azqr/internal/scanners/logic"
"github.com/Azure/azqr/internal/scanners/maria"
"github.com/Azure/azqr/internal/scanners/mysql"
"github.com/Azure/azqr/internal/scanners/plan"
"github.com/Azure/azqr/internal/scanners/asp"
"github.com/Azure/azqr/internal/scanners/psql"
"github.com/Azure/azqr/internal/scanners/redis"
"github.com/Azure/azqr/internal/scanners/sb"
Expand Down Expand Up @@ -459,7 +459,7 @@ func GetScanners() []scanners.IAzureScanner {
&maria.MariaScanner{},
&mysql.MySQLFlexibleScanner{},
&mysql.MySQLScanner{},
&plan.AppServiceScanner{},
&asp.AppServiceScanner{},
&psql.PostgreFlexibleScanner{},
&psql.PostgreScanner{},
&redis.RedisScanner{},
Expand Down
247 changes: 124 additions & 123 deletions docs/content/en/docs/Rules/_index.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/scanners/aks/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (a *AKSScanner) GetRules() map[string]scanners.AzureRule {
c := target.(*armcontainerservice.ManagedCluster)
defaultMaxSurge := false
for _, profile := range c.Properties.AgentPoolProfiles {
if profile.UpgradeSettings.MaxSurge == nil || (profile.UpgradeSettings.MaxSurge == ref.Of("1")) {
if profile.UpgradeSettings == nil || profile.UpgradeSettings.MaxSurge == nil || (profile.UpgradeSettings.MaxSurge == ref.Of("1")) {
defaultMaxSurge = true
break
}
Expand Down
21 changes: 21 additions & 0 deletions internal/scanners/aks/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,27 @@ func TestAKSScanner_Rules(t *testing.T) {
result: "",
},
},
{
name: "AKSScanner Max Surge with nil UpgradeSettings",
fields: fields{
rule: "aks-016",
target: &armcontainerservice.ManagedCluster{
SKU: &armcontainerservice.ManagedClusterSKU{
Tier: getSKUTierPaid(),
},
Properties: &armcontainerservice.ManagedClusterProperties{
AgentPoolProfiles: []*armcontainerservice.ManagedClusterAgentPoolProfile{
{},
},
},
},
scanContext: &scanners.ScanContext{},
},
want: want{
broken: true,
result: "",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package plan
package asp

import (
"strings"
Expand Down Expand Up @@ -71,7 +71,7 @@ func (a *AppServiceScanner) Scan(resourceGroupName string, scanContext *scanners
// https://learn.microsoft.com/en-us/azure/azure-functions/functions-app-settings
kind := strings.ToLower(*s.Kind)
switch kind {
case "functionapp":
case "functionapp,linux", "functionapp":
rr := engine.EvaluateRules(functionRules, s, scanContext)

result = scanners.AzureServiceResult{
Expand Down
26 changes: 13 additions & 13 deletions internal/scanners/plan/rules.go → internal/scanners/asp/rules.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package plan
package asp

import (
"strings"
Expand All @@ -27,8 +27,8 @@ func (a *AppServiceScanner) GetRules() map[string]scanners.AzureRule {

func (a *AppServiceScanner) getPlanRules() map[string]scanners.AzureRule {
return map[string]scanners.AzureRule{
"plan-001": {
Id: "plan-001",
"asp-001": {
Id: "asp-001",
Category: scanners.RulesCategoryReliability,
Subcategory: scanners.RulesSubcategoryReliabilityDiagnosticLogs,
Description: "Plan should have diagnostic settings enabled",
Expand All @@ -40,8 +40,8 @@ func (a *AppServiceScanner) getPlanRules() map[string]scanners.AzureRule {
},
Field: scanners.OverviewFieldDiagnostics,
},
"plan-002": {
Id: "plan-002",
"asp-002": {
Id: "asp-002",
Category: scanners.RulesCategoryReliability,
Subcategory: scanners.RulesSubcategoryReliabilityAvailabilityZones,
Description: "Plan should have availability zones enabled",
Expand All @@ -54,8 +54,8 @@ func (a *AppServiceScanner) getPlanRules() map[string]scanners.AzureRule {
Url: "https://learn.microsoft.com/en-us/azure/reliability/migrate-app-service",
Field: scanners.OverviewFieldAZ,
},
"plan-003": {
Id: "plan-003",
"asp-003": {
Id: "asp-003",
Category: scanners.RulesCategoryReliability,
Subcategory: scanners.RulesSubcategoryReliabilitySLA,
Description: "Plan should have a SLA",
Expand All @@ -72,8 +72,8 @@ func (a *AppServiceScanner) getPlanRules() map[string]scanners.AzureRule {
Url: "https://www.azure.cn/en-us/support/sla/app-service/",
Field: scanners.OverviewFieldSLA,
},
"plan-005": {
Id: "plan-005",
"asp-005": {
Id: "asp-005",
Category: scanners.RulesCategoryReliability,
Subcategory: scanners.RulesSubcategoryReliabilitySKU,
Description: "Plan SKU",
Expand All @@ -85,8 +85,8 @@ func (a *AppServiceScanner) getPlanRules() map[string]scanners.AzureRule {
Url: "https://learn.microsoft.com/en-us/azure/app-service/overview-hosting-plans",
Field: scanners.OverviewFieldSKU,
},
"plan-006": {
Id: "plan-006",
"asp-006": {
Id: "asp-006",
Category: scanners.RulesCategoryOperationalExcellence,
Subcategory: scanners.RulesSubcategoryOperationalExcellenceCAF,
Description: "Plan Name should comply with naming conventions",
Expand All @@ -99,8 +99,8 @@ func (a *AppServiceScanner) getPlanRules() map[string]scanners.AzureRule {
Url: "https://learn.microsoft.com/en-us/azure/cloud-adoption-framework/ready/azure-best-practices/resource-abbreviations",
Field: scanners.OverviewFieldCAF,
},
"plan-007": {
Id: "plan-007",
"asp-007": {
Id: "asp-007",
Category: scanners.RulesCategoryOperationalExcellence,
Subcategory: scanners.RulesSubcategoryOperationalExcellenceTags,
Description: "Plan should have tags",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package plan
package asp

import (
"reflect"
Expand Down Expand Up @@ -30,7 +30,7 @@ func TestAppServiceScanner_Rules(t *testing.T) {
{
name: "AppServiceScanner DiagnosticSettings",
fields: fields{
rule: "plan-001",
rule: "asp-001",
target: &armappservice.Plan{
ID: ref.Of("test"),
},
Expand All @@ -48,7 +48,7 @@ func TestAppServiceScanner_Rules(t *testing.T) {
{
name: "AppServiceScanner Availability Zones",
fields: fields{
rule: "plan-002",
rule: "asp-002",
target: &armappservice.Plan{
Properties: &armappservice.PlanProperties{
ZoneRedundant: ref.Of(true),
Expand All @@ -64,7 +64,7 @@ func TestAppServiceScanner_Rules(t *testing.T) {
{
name: "AppServiceScanner SLA None",
fields: fields{
rule: "plan-003",
rule: "asp-003",
target: &armappservice.Plan{
SKU: &armappservice.SKUDescription{
Tier: ref.Of("Free"),
Expand All @@ -80,7 +80,7 @@ func TestAppServiceScanner_Rules(t *testing.T) {
{
name: "AppServiceScanner SLA 99.95%",
fields: fields{
rule: "plan-003",
rule: "asp-003",
target: &armappservice.Plan{
SKU: &armappservice.SKUDescription{
Tier: ref.Of("ElasticPremium"),
Expand All @@ -96,7 +96,7 @@ func TestAppServiceScanner_Rules(t *testing.T) {
{
name: "AppServiceScanner SKU",
fields: fields{
rule: "plan-005",
rule: "asp-005",
target: &armappservice.Plan{
SKU: &armappservice.SKUDescription{
Name: ref.Of("EP1"),
Expand All @@ -112,7 +112,7 @@ func TestAppServiceScanner_Rules(t *testing.T) {
{
name: "AppServiceScanner CAF",
fields: fields{
rule: "plan-006",
rule: "asp-006",
target: &armappservice.Plan{
Name: ref.Of("asp-test"),
},
Expand Down
2 changes: 1 addition & 1 deletion internal/scanners/sql/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (a *SQLScanner) getDatabaseRules() map[string]scanners.AzureRule {
Severity: scanners.SeverityLow,
Eval: func(target interface{}, scanContext *scanners.ScanContext) (bool, string) {
c := target.(*armsql.Database)
caf := strings.HasPrefix(*c.Name, "sqldb")
caf := *c.Name == "master" || strings.HasPrefix(*c.Name, "sqldb")
return !caf, ""
},
Url: "https://learn.microsoft.com/en-us/azure/cloud-adoption-framework/ready/azure-best-practices/resource-abbreviations",
Expand Down
File renamed without changes.

0 comments on commit 4d82776

Please sign in to comment.