@@ -20,100 +20,24 @@ package client
20
20
import (
21
21
"context"
22
22
"fmt"
23
- "net/url"
24
- "strings"
25
23
26
24
"github.com/bloodhoundad/azurehound/v2/client/query"
27
- "github.com/bloodhoundad/azurehound/v2/client/rest"
28
25
"github.com/bloodhoundad/azurehound/v2/constants"
29
26
"github.com/bloodhoundad/azurehound/v2/models/azure"
30
- "github.com/bloodhoundad/azurehound/v2/panicrecovery"
31
- "github.com/bloodhoundad/azurehound/v2/pipeline"
32
27
)
33
28
34
- func (s * azureClient ) GetAzureADAppRoleAssignments (ctx context.Context , servicePrincipalId string , filter , search , orderBy , expand string , selectCols []string , top int32 , count bool ) (azure.AppRoleAssignmentList , error ) {
29
+ // GetAzureADAppRoleAssignments https://learn.microsoft.com/en-us/graph/api/serviceprincipal-list-approleassignedto?view=graph-rest-1.0
30
+ func (s * azureClient ) ListAzureADAppRoleAssignments (ctx context.Context , servicePrincipalId string , params query.GraphParams ) <- chan AzureResult [azure.AppRoleAssignment ] {
35
31
var (
36
- path = fmt .Sprintf ("/%s/servicePrincipals/%s/appRoleAssignedTo" , constants .GraphApiVersion , servicePrincipalId )
37
- params = query.Params {Filter : filter , Search : search , OrderBy : orderBy , Select : selectCols , Top : top , Count : count , Expand : expand }
38
- headers map [string ]string
39
- response azure.AppRoleAssignmentList
32
+ out = make (chan AzureResult [azure.AppRoleAssignment ])
33
+ path = fmt .Sprintf ("/%s/servicePrincipals/%s/appRoleAssignedTo" , constants .GraphApiVersion , servicePrincipalId )
40
34
)
41
35
42
- count = count || search != "" || (filter != "" && orderBy != "" ) || strings .Contains (filter , "endsWith" )
43
- if count {
44
- headers = make (map [string ]string )
45
- headers ["ConsistencyLevel" ] = "eventual"
36
+ if params .Top == 0 {
37
+ params .Top = 999
46
38
}
47
- if res , err := s .msgraph .Get (ctx , path , params .AsMap (), headers ); err != nil {
48
- return response , err
49
- } else if err := rest .Decode (res .Body , & response ); err != nil {
50
- return response , err
51
- } else {
52
- return response , nil
53
- }
54
- }
55
-
56
- func (s * azureClient ) ListAzureADAppRoleAssignments (ctx context.Context , servicePrincipal , filter , search , orderBy , expand string , selectCols []string ) <- chan azure.AppRoleAssignmentResult {
57
- out := make (chan azure.AppRoleAssignmentResult )
58
-
59
- go func () {
60
- defer panicrecovery .PanicRecovery ()
61
- defer close (out )
62
-
63
- var (
64
- errResult = azure.AppRoleAssignmentResult {}
65
- nextLink string
66
- )
67
39
68
- if list , err := s .GetAzureADAppRoleAssignments (ctx , servicePrincipal , filter , search , orderBy , expand , selectCols , 999 , false ); err != nil {
69
- errResult .Error = err
70
- if ok := pipeline .Send (ctx .Done (), out , errResult ); ! ok {
71
- return
72
- }
73
- } else {
74
- for _ , u := range list .Value {
75
- if ok := pipeline .Send (ctx .Done (), out , azure.AppRoleAssignmentResult {Ok : u }); ! ok {
76
- return
77
- }
78
- }
40
+ go getAzureObjectList [azure.AppRoleAssignment ](s .msgraph , ctx , path , params , out )
79
41
80
- nextLink = list .NextLink
81
- for nextLink != "" {
82
- var list azure.AppRoleAssignmentList
83
- if url , err := url .Parse (nextLink ); err != nil {
84
- errResult .Error = err
85
- if ok := pipeline .Send (ctx .Done (), out , errResult ); ! ok {
86
- return
87
- }
88
- nextLink = ""
89
- } else if req , err := rest .NewRequest (ctx , "GET" , url , nil , nil , nil ); err != nil {
90
- errResult .Error = err
91
- if ok := pipeline .Send (ctx .Done (), out , errResult ); ! ok {
92
- return
93
- }
94
- nextLink = ""
95
- } else if res , err := s .msgraph .Send (req ); err != nil {
96
- errResult .Error = err
97
- if ok := pipeline .Send (ctx .Done (), out , errResult ); ! ok {
98
- return
99
- }
100
- nextLink = ""
101
- } else if err := rest .Decode (res .Body , & list ); err != nil {
102
- errResult .Error = err
103
- if ok := pipeline .Send (ctx .Done (), out , errResult ); ! ok {
104
- return
105
- }
106
- nextLink = ""
107
- } else {
108
- for _ , u := range list .Value {
109
- if ok := pipeline .Send (ctx .Done (), out , azure.AppRoleAssignmentResult {Ok : u }); ! ok {
110
- return
111
- }
112
- }
113
- nextLink = list .NextLink
114
- }
115
- }
116
- }
117
- }()
118
42
return out
119
43
}
0 commit comments