diff --git a/client/client.go b/client/client.go index 4e98b1a..03e5a76 100644 --- a/client/client.go +++ b/client/client.go @@ -17,13 +17,12 @@ package client -//go:generate go run github.com/golang/mock/mockgen -destination=./mocks/client.go -package=mocks . AzureClient +//go:generate go run go.uber.org/mock/mockgen -destination=./mocks/client.go -package=mocks . AzureClient import ( "context" - "fmt" - "encoding/json" + "fmt" "github.com/bloodhoundad/azurehound/v2/client/config" "github.com/bloodhoundad/azurehound/v2/client/rest" @@ -36,7 +35,6 @@ func NewClient(config config.Config) (AzureClient, error) { } else if resourceManager, err := rest.NewRestClient(config.ResourceManagerUrl(), config); err != nil { return nil, err } else { - if config.JWT != "" { if aud, err := rest.ParseAud(config.JWT); err != nil { return nil, err @@ -98,6 +96,11 @@ func (s azureClient) TenantInfo() azure.Tenant { return s.tenant } +func (s azureClient) CloseIdleConnections() { + s.msgraph.CloseIdleConnections() + s.resourceManager.CloseIdleConnections() +} + type AzureClient interface { GetAzureADApp(ctx context.Context, objectId string, selectCols []string) (*azure.Application, error) GetAzureADApps(ctx context.Context, filter, search, orderBy, expand string, selectCols []string, top int32, count bool) (azure.ApplicationList, error) @@ -165,4 +168,5 @@ type AzureClient interface { ListRoleAssignmentsForResource(ctx context.Context, resourceId string, filter string) <-chan azure.RoleAssignmentResult ListAzureADAppRoleAssignments(ctx context.Context, servicePrincipal, filter, search, orderBy, expand string, selectCols []string) <-chan azure.AppRoleAssignmentResult TenantInfo() azure.Tenant + CloseIdleConnections() } diff --git a/client/mocks/client.go b/client/mocks/client.go index 63bb9b0..fa2ca60 100644 --- a/client/mocks/client.go +++ b/client/mocks/client.go @@ -10,7 +10,7 @@ import ( reflect "reflect" azure "github.com/bloodhoundad/azurehound/v2/models/azure" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockAzureClient is a mock of AzureClient interface. @@ -36,6 +36,18 @@ func (m *MockAzureClient) EXPECT() *MockAzureClientMockRecorder { return m.recorder } +// CloseIdleConnections mocks base method. +func (m *MockAzureClient) CloseIdleConnections() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "CloseIdleConnections") +} + +// CloseIdleConnections indicates an expected call of CloseIdleConnections. +func (mr *MockAzureClientMockRecorder) CloseIdleConnections() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CloseIdleConnections", reflect.TypeOf((*MockAzureClient)(nil).CloseIdleConnections)) +} + // GetAzureADApp mocks base method. func (m *MockAzureClient) GetAzureADApp(arg0 context.Context, arg1 string, arg2 []string) (*azure.Application, error) { m.ctrl.T.Helper() diff --git a/client/rest/client.go b/client/rest/client.go index 8076755..77b637f 100644 --- a/client/rest/client.go +++ b/client/rest/client.go @@ -17,7 +17,7 @@ package rest -//go:generate go run github.com/golang/mock/mockgen -destination=./mocks/client.go -package=mocks . RestClient +//go:generate go run go.uber.org/mock/mockgen -destination=./mocks/client.go -package=mocks . RestClient import ( "bytes" @@ -44,6 +44,7 @@ type RestClient interface { Post(ctx context.Context, path string, body interface{}, params, headers map[string]string) (*http.Response, error) Put(ctx context.Context, path string, body interface{}, params, headers map[string]string) (*http.Response, error) Send(req *http.Request) (*http.Response, error) + CloseIdleConnections() } func NewRestClient(apiUrl string, config config.Config) (RestClient, error) { @@ -289,3 +290,7 @@ func (s *restClient) send(req *http.Request) (*http.Response, error) { return nil, fmt.Errorf("unable to complete the request after %d attempts: %w", maxRetries, err) } } + +func (s *restClient) CloseIdleConnections() { + s.http.CloseIdleConnections() +} diff --git a/client/rest/mocks/client.go b/client/rest/mocks/client.go index e2738f5..b9df20b 100644 --- a/client/rest/mocks/client.go +++ b/client/rest/mocks/client.go @@ -9,7 +9,7 @@ import ( http "net/http" reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockRestClient is a mock of RestClient interface. @@ -49,6 +49,18 @@ func (mr *MockRestClientMockRecorder) Authenticate() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Authenticate", reflect.TypeOf((*MockRestClient)(nil).Authenticate)) } +// CloseIdleConnections mocks base method. +func (m *MockRestClient) CloseIdleConnections() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "CloseIdleConnections") +} + +// CloseIdleConnections indicates an expected call of CloseIdleConnections. +func (mr *MockRestClientMockRecorder) CloseIdleConnections() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CloseIdleConnections", reflect.TypeOf((*MockRestClient)(nil).CloseIdleConnections)) +} + // Delete mocks base method. func (m *MockRestClient) Delete(arg0 context.Context, arg1 string, arg2 interface{}, arg3, arg4 map[string]string) (*http.Response, error) { m.ctrl.T.Helper() diff --git a/cmd/list-app-owners_test.go b/cmd/list-app-owners_test.go index 74071a1..666d8f1 100644 --- a/cmd/list-app-owners_test.go +++ b/cmd/list-app-owners_test.go @@ -27,7 +27,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/enums" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-apps_test.go b/cmd/list-apps_test.go index f261bb8..136656a 100644 --- a/cmd/list-apps_test.go +++ b/cmd/list-apps_test.go @@ -24,7 +24,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/client/mocks" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-device-owners_test.go b/cmd/list-device-owners_test.go index a6b8de0..5f0dc3e 100644 --- a/cmd/list-device-owners_test.go +++ b/cmd/list-device-owners_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/client/mocks" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-devices_test.go b/cmd/list-devices_test.go index 0f5806f..1bbf4bf 100644 --- a/cmd/list-devices_test.go +++ b/cmd/list-devices_test.go @@ -24,7 +24,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/client/mocks" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-group-members_test.go b/cmd/list-group-members_test.go index eb7342b..f3cf088 100644 --- a/cmd/list-group-members_test.go +++ b/cmd/list-group-members_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/client/mocks" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-group-owners_test.go b/cmd/list-group-owners_test.go index 4d4288c..b1e7eea 100644 --- a/cmd/list-group-owners_test.go +++ b/cmd/list-group-owners_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/client/mocks" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-groups_test.go b/cmd/list-groups_test.go index 7aac385..d931ff2 100644 --- a/cmd/list-groups_test.go +++ b/cmd/list-groups_test.go @@ -24,7 +24,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/client/mocks" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-key-vault-access-policies_test.go b/cmd/list-key-vault-access-policies_test.go index 6d591ff..877fe1f 100644 --- a/cmd/list-key-vault-access-policies_test.go +++ b/cmd/list-key-vault-access-policies_test.go @@ -24,7 +24,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/client/mocks" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-key-vault-contributors_test.go b/cmd/list-key-vault-contributors_test.go index a2c1ccc..d02586b 100644 --- a/cmd/list-key-vault-contributors_test.go +++ b/cmd/list-key-vault-contributors_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/enums" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-key-vault-kvcontributors_test.go b/cmd/list-key-vault-kvcontributors_test.go index f2ad515..cd345d9 100644 --- a/cmd/list-key-vault-kvcontributors_test.go +++ b/cmd/list-key-vault-kvcontributors_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/enums" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-key-vault-owners_test.go b/cmd/list-key-vault-owners_test.go index 5a0d18e..c529689 100644 --- a/cmd/list-key-vault-owners_test.go +++ b/cmd/list-key-vault-owners_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/enums" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-key-vault-role-assignments_test.go b/cmd/list-key-vault-role-assignments_test.go index eb4c830..db7e4c3 100644 --- a/cmd/list-key-vault-role-assignments_test.go +++ b/cmd/list-key-vault-role-assignments_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/constants" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-key-vault-user-access-admins_test.go b/cmd/list-key-vault-user-access-admins_test.go index 420678d..82f7c6e 100644 --- a/cmd/list-key-vault-user-access-admins_test.go +++ b/cmd/list-key-vault-user-access-admins_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/enums" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-key-vaults_test.go b/cmd/list-key-vaults_test.go index ef9c463..269288a 100644 --- a/cmd/list-key-vaults_test.go +++ b/cmd/list-key-vaults_test.go @@ -25,7 +25,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/client/mocks" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-management-group-descendants_test.go b/cmd/list-management-group-descendants_test.go index 66164f5..01806b1 100644 --- a/cmd/list-management-group-descendants_test.go +++ b/cmd/list-management-group-descendants_test.go @@ -25,7 +25,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/client/mocks" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-management-group-owners_test.go b/cmd/list-management-group-owners_test.go index 32722e7..fa7ec0c 100644 --- a/cmd/list-management-group-owners_test.go +++ b/cmd/list-management-group-owners_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/enums" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-management-group-role-assignments_test.go b/cmd/list-management-group-role-assignments_test.go index b047ece..eed6954 100644 --- a/cmd/list-management-group-role-assignments_test.go +++ b/cmd/list-management-group-role-assignments_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/constants" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-management-group-user-access-admins_test.go b/cmd/list-management-group-user-access-admins_test.go index 5b270a8..39c9d1b 100644 --- a/cmd/list-management-group-user-access-admins_test.go +++ b/cmd/list-management-group-user-access-admins_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/enums" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-management-groups_test.go b/cmd/list-management-groups_test.go index 579ba6f..47efe17 100644 --- a/cmd/list-management-groups_test.go +++ b/cmd/list-management-groups_test.go @@ -24,7 +24,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/client/mocks" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-resource-group-owners_test.go b/cmd/list-resource-group-owners_test.go index 55cc9df..b580683 100644 --- a/cmd/list-resource-group-owners_test.go +++ b/cmd/list-resource-group-owners_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/enums" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-resource-group-role-assignments_test.go b/cmd/list-resource-group-role-assignments_test.go index 68c0f23..5c8c8bb 100644 --- a/cmd/list-resource-group-role-assignments_test.go +++ b/cmd/list-resource-group-role-assignments_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/constants" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-resource-group-user-access-admins_test.go b/cmd/list-resource-group-user-access-admins_test.go index 0945fd8..8ba792c 100644 --- a/cmd/list-resource-group-user-access-admins_test.go +++ b/cmd/list-resource-group-user-access-admins_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/enums" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-resource-groups_test.go b/cmd/list-resource-groups_test.go index 8ed39bb..78ac328 100644 --- a/cmd/list-resource-groups_test.go +++ b/cmd/list-resource-groups_test.go @@ -25,7 +25,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/client/mocks" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-role-assignments_test.go b/cmd/list-role-assignments_test.go index dc1b47a..2dd8195 100644 --- a/cmd/list-role-assignments_test.go +++ b/cmd/list-role-assignments_test.go @@ -20,7 +20,7 @@ package cmd import ( "testing" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-roles_test.go b/cmd/list-roles_test.go index 935c217..0805f0a 100644 --- a/cmd/list-roles_test.go +++ b/cmd/list-roles_test.go @@ -24,7 +24,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/client/mocks" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-service-principal-owners_test.go b/cmd/list-service-principal-owners_test.go index a97e1e0..1dff1d1 100644 --- a/cmd/list-service-principal-owners_test.go +++ b/cmd/list-service-principal-owners_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/client/mocks" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-service-principals_test.go b/cmd/list-service-principals_test.go index c4a8bbf..c62f028 100644 --- a/cmd/list-service-principals_test.go +++ b/cmd/list-service-principals_test.go @@ -24,7 +24,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/client/mocks" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-subscription-owners_test.go b/cmd/list-subscription-owners_test.go index 78859ee..7850fef 100644 --- a/cmd/list-subscription-owners_test.go +++ b/cmd/list-subscription-owners_test.go @@ -25,7 +25,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/constants" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-subscription-role-assignments_test.go b/cmd/list-subscription-role-assignments_test.go index fa0a392..1902684 100644 --- a/cmd/list-subscription-role-assignments_test.go +++ b/cmd/list-subscription-role-assignments_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/constants" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-subscription-user-access-admins_test.go b/cmd/list-subscription-user-access-admins_test.go index 4bdfb7a..1a6a8dc 100644 --- a/cmd/list-subscription-user-access-admins_test.go +++ b/cmd/list-subscription-user-access-admins_test.go @@ -25,7 +25,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/constants" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-subscriptions_test.go b/cmd/list-subscriptions_test.go index 8081a9a..51571c5 100644 --- a/cmd/list-subscriptions_test.go +++ b/cmd/list-subscriptions_test.go @@ -24,7 +24,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/client/mocks" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-tenants_test.go b/cmd/list-tenants_test.go index 3111c1b..5f22399 100644 --- a/cmd/list-tenants_test.go +++ b/cmd/list-tenants_test.go @@ -24,7 +24,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/client/mocks" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-users_test.go b/cmd/list-users_test.go index 8692868..d7e6211 100644 --- a/cmd/list-users_test.go +++ b/cmd/list-users_test.go @@ -24,7 +24,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/client/mocks" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-virtual-machine-admin-logins_test.go b/cmd/list-virtual-machine-admin-logins_test.go index a5e766a..df29f72 100644 --- a/cmd/list-virtual-machine-admin-logins_test.go +++ b/cmd/list-virtual-machine-admin-logins_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/enums" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-virtual-machine-avere-contributors_test.go b/cmd/list-virtual-machine-avere-contributors_test.go index 1a6869d..b894045 100644 --- a/cmd/list-virtual-machine-avere-contributors_test.go +++ b/cmd/list-virtual-machine-avere-contributors_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/enums" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-virtual-machine-contributors_test.go b/cmd/list-virtual-machine-contributors_test.go index f176797..3b13458 100644 --- a/cmd/list-virtual-machine-contributors_test.go +++ b/cmd/list-virtual-machine-contributors_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/enums" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-virtual-machine-owners_test.go b/cmd/list-virtual-machine-owners_test.go index 5b9bf30..d4a403e 100644 --- a/cmd/list-virtual-machine-owners_test.go +++ b/cmd/list-virtual-machine-owners_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/enums" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-virtual-machine-role-assignments_test.go b/cmd/list-virtual-machine-role-assignments_test.go index 89ac1d8..dffaf79 100644 --- a/cmd/list-virtual-machine-role-assignments_test.go +++ b/cmd/list-virtual-machine-role-assignments_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/constants" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-virtual-machine-user-access-admins_test.go b/cmd/list-virtual-machine-user-access-admins_test.go index 22d1304..8dd7ff2 100644 --- a/cmd/list-virtual-machine-user-access-admins_test.go +++ b/cmd/list-virtual-machine-user-access-admins_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/enums" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-virtual-machine-vmcontributors_test.go b/cmd/list-virtual-machine-vmcontributors_test.go index 3e1e033..8075d29 100644 --- a/cmd/list-virtual-machine-vmcontributors_test.go +++ b/cmd/list-virtual-machine-vmcontributors_test.go @@ -26,7 +26,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/enums" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/list-virtual-machines_test.go b/cmd/list-virtual-machines_test.go index 13d822c..58b9113 100644 --- a/cmd/list-virtual-machines_test.go +++ b/cmd/list-virtual-machines_test.go @@ -25,7 +25,7 @@ import ( "github.com/bloodhoundad/azurehound/v2/client/mocks" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/models/azure" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func init() { diff --git a/cmd/start.go b/cmd/start.go index 9c7ef62..7460db1 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -36,21 +36,20 @@ import ( "sync/atomic" "time" + "github.com/spf13/cobra" + "github.com/bloodhoundad/azurehound/v2/client/rest" "github.com/bloodhoundad/azurehound/v2/config" "github.com/bloodhoundad/azurehound/v2/constants" "github.com/bloodhoundad/azurehound/v2/models" "github.com/bloodhoundad/azurehound/v2/pipeline" - "github.com/spf13/cobra" ) const ( BHEAuthSignature string = "bhesignature" ) -var ( - ErrExceededRetryLimit = errors.New("exceeded max retry limit for ingest batch, proceeding with next batch...") -) +var ErrExceededRetryLimit = errors.New("exceeded max retry limit for ingest batch, proceeding with next batch...") func init() { configs := append(config.AzureConfig, config.BloodHoundEnterpriseConfig...) @@ -114,6 +113,9 @@ func start(ctx context.Context) { } else if jobQueued.TryLock() { go func() { defer jobQueued.Unlock() + defer bheClient.CloseIdleConnections() + defer azClient.CloseIdleConnections() + log.V(2).Info("checking for available collection jobs") if jobs, err := getAvailableJobs(ctx, *bheInstance, bheClient, updatedClient.ID); err != nil { log.Error(err, "unable to fetch available jobs for azurehound") @@ -158,7 +160,6 @@ func start(ctx context.Context) { message := "Collection completed successfully" if hasIngestErr { message = "Collection completed with errors during ingest" - } if err := endJob(ctx, *bheInstance, bheClient, models.JobStatusComplete, message); err != nil { log.Error(err, "failed to end job") @@ -213,7 +214,7 @@ func ingest(ctx context.Context, bheUrl url.URL, bheClient *http.Client, in <-ch req.Header.Set("Prefer", "wait=60") req.Header.Set("Content-Encoding", "gzip") for retry := 0; retry < maxRetries; retry++ { - //No retries on regular err cases, only on HTTP 504 Gateway Timeout and HTTP 503 Service Unavailable + // No retries on regular err cases, only on HTTP 504 Gateway Timeout and HTTP 503 Service Unavailable if response, err := bheClient.Do(req); err != nil { log.Error(err, unrecoverableErrMsg) return true diff --git a/go.mod b/go.mod index 5c9ca77..69d23eb 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( github.com/go-logr/logr v1.2.0 github.com/gofrs/uuid v4.1.0+incompatible github.com/golang-jwt/jwt v3.2.2+incompatible - github.com/golang/mock v1.6.0 github.com/judwhite/go-svc v1.2.1 github.com/manifoldco/promptui v0.9.0 github.com/rs/zerolog v1.26.0 @@ -14,8 +13,9 @@ require ( github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.10.1 github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a + go.uber.org/mock v0.2.0 golang.org/x/net v0.0.0-20220722155237-a158d28d115b - golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 + golang.org/x/sys v0.1.0 ) require ( @@ -31,7 +31,10 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/subosito/gotenv v1.2.0 // indirect golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect + golang.org/x/mod v0.5.1 // indirect golang.org/x/text v0.3.7 // indirect + golang.org/x/tools v0.1.8 // indirect + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect gopkg.in/ini.v1 v1.66.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index 9f9a43d..76dfd99 100644 --- a/go.sum +++ b/go.sum @@ -141,7 +141,6 @@ github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -372,6 +371,8 @@ go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/mock v0.2.0 h1:TaP3xedm7JaAgScZO7tlvlKrqT0p7I6OsdGB5YNSMDU= +go.uber.org/mock v0.2.0/go.mod h1:J0y0rp9L3xiff1+ZBfKxlC1fz2+aO16tw0tsDOixfuM= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -423,6 +424,8 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= +golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38= +golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -563,8 +566,8 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg= -golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -634,9 +637,12 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= +golang.org/x/tools v0.1.8 h1:P1HhGGuLW4aAclzjtmJdf0mJOjVUZUzOTqkAkWL+l6w= +golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=