Skip to content

Commit

Permalink
adding the support for multiple NamedLocation
Browse files Browse the repository at this point in the history
Signed-off-by: Hossein Rouhani <h_rouhani@hotmail.com>
  • Loading branch information
HRouhani committed Sep 5, 2024
1 parent 4339ce3 commit 0912629
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions providers/ms365/resources/conditional-access.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,36 @@ import (
"go.mondoo.com/cnquery/v11/providers/ms365/connection"
)

func (a *mqlMicrosoftConditionalAccess) namedLocations() (string, error) {
func (a *mqlMicrosoftConditionalAccess) namedLocations() ([]interface{}, error) {
conn := a.MqlRuntime.Connection.(*connection.Ms365Connection)
graphClient, err := conn.GraphClient()
if err != nil {
return "", err
return nil, err
}

// Make a request to get named locations
ctx := context.Background()
namedLocations, err := graphClient.Identity().ConditionalAccess().NamedLocations().Get(ctx, nil)
if err != nil {
return "", transformError(err)
return nil, transformError(err)
}

// Check if any of the named locations exist and return the first one
// Collect all named location names
var locationNames []interface{} // Changed to interface{} to match the expected return type
for _, location := range namedLocations.GetValue() {
// Use type assertion to check for IP named locations
if ipLocation, ok := location.(*models.IpNamedLocation); ok {
displayName := ipLocation.GetDisplayName()
if displayName != nil {
return *displayName, nil
locationNames = append(locationNames, *displayName)
}
}
}

log.Println("No named locations are defined.")
return "", nil
if len(locationNames) == 0 {
log.Println("No named locations are defined.")
return nil, nil
}

return locationNames, nil
}
2 changes: 1 addition & 1 deletion providers/ms365/resources/ms365.lr
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ microsoft.tenant @defaults("name") {
// Microsoft Conditional Access Policies
private microsoft.conditionalAccess {
// Return the name of the first named location
namedLocations() string
namedLocations() []string
}

// Microsoft Entra ID user
Expand Down

0 comments on commit 0912629

Please sign in to comment.