Skip to content

Commit

Permalink
✨ add resource for azure functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeffrey committed Sep 21, 2024
1 parent 331a6c4 commit 1d8759b
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 0 deletions.
16 changes: 16 additions & 0 deletions providers/azure/resources/azure.lr
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ azure.subscription @defaults ("name") {
iot() azure.subscription.iotService
}

// Azure function
private azure.subscription.webService.function @defaults("name") {
// ID of the function
id string
// Name of the function
name string
// Type of function
type string
// Kind of function
kind string
// Properties for the function
properties dict
}

// Azure resource group
private azure.subscription.resourcegroup @defaults("name location") {
// Resource group ID
Expand Down Expand Up @@ -1031,6 +1045,8 @@ private azure.subscription.webService.appsite @defaults("id name location") {
stack() dict
// Diagnostic settings for the web app site
diagnosticSettings() []azure.subscription.monitorService.diagnosticsetting
// List of functions for the web app site
functions []azure.subscription.webService.function
}

// Azure AppSite authentication settings
Expand Down
124 changes: 124 additions & 0 deletions providers/azure/resources/azure.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions providers/azure/resources/azure.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ resources:
cloudDefender: {}
compute: {}
cosmosDb: {}
functions:
min_mondoo_version: 9.0.0
iam:
min_mondoo_version: 9.0.0
id: {}
Expand Down Expand Up @@ -604,6 +606,17 @@ resources:
refs:
- title: Azure Cosmos DB documentation
url: https://learn.microsoft.com/en-us/azure/cosmos-db/
azure.subscription.function:
fields:
id: {}
kind: {}
name: {}
properties: {}
type: {}
min_mondoo_version: 9.0.0
platform:
name:
- azure
azure.subscription.iotService:
fields:
hubs: {}
Expand Down Expand Up @@ -2853,6 +2866,8 @@ resources:
connectionSettings: {}
diagnosticSettings:
min_mondoo_version: 9.0.0
functions:
min_mondoo_version: 9.0.0
id: {}
identity: {}
kind: {}
Expand Down Expand Up @@ -2901,3 +2916,15 @@ resources:
refs:
- title: Azure Web documentation
url: https://learn.microsoft.com/en-us/azure/?product=web
azure.subscription.webService.function:
fields:
id: {}
kind: {}
name: {}
properties: {}
type: {}
is_private: true
min_mondoo_version: 9.0.0
platform:
name:
- azure
54 changes: 54 additions & 0 deletions providers/azure/resources/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,60 @@ func (a *mqlAzureSubscriptionWebServiceAppsite) metadata() (interface{}, error)
return res, nil
}

func (a *mqlAzureSubscriptionWebServiceAppsite) functions() ([]interface{}, error) {
conn := a.MqlRuntime.Connection.(*connection.AzureConnection)
ctx := context.Background()
token := conn.Token()
id := a.Id.Data
resourceID, err := ParseResourceID(id)
if err != nil {
return nil, err
}
client, err := web.NewWebAppsClient(resourceID.SubscriptionID, token, &arm.ClientOptions{
ClientOptions: conn.ClientOptions(),
})
if err != nil {
return nil, err
}

site, err := resourceID.Component("sites")
if err != nil {
return nil, err
}
pager := client.NewListFunctionsPager(resourceID.ResourceGroup, site, &web.WebAppsClientListFunctionsOptions{})
res := []interface{}{}

for pager.More() {
page, err := pager.NextPage(ctx)
if err != nil {
return nil, err
}
for _, entry := range page.Value {
props, err := convert.JsonToDict(entry.Properties)
if err != nil {
return nil, err
}
mqlAzure, err := CreateResource(a.MqlRuntime, "azure.subscription.webService.function",
map[string]*llx.RawData{
"id": llx.StringDataPtr(entry.ID),
"name": llx.StringDataPtr(entry.Name),
"type": llx.StringDataPtr(entry.Type),
"kind": llx.StringDataPtr(entry.Kind),
"properties": llx.AnyData(props),
})
if err != nil {
return nil, err
}
res = append(res, mqlAzure)
}
}
return res, nil
}

func (a *mqlAzureSubscriptionWebServiceFunction) id() (string, error) {
return a.id()
}

func (a *mqlAzureSubscriptionWebServiceAppsite) connectionSettings() (interface{}, error) {
conn := a.MqlRuntime.Connection.(*connection.AzureConnection)
ctx := context.Background()
Expand Down

0 comments on commit 1d8759b

Please sign in to comment.