Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved context when exiting with error #26

Merged
merged 3 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var configureCmd = &cobra.Command{

func configureCmdImpl(cmd *cobra.Command, args []string) {
if err := configure(); err != nil {
exit(err)
exit(fmt.Errorf("failed to configure cobra CLI: %w", err))
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/install_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ func installCmdImpl(cmd *cobra.Command, args []string) {
)

if err := configureService(); err != nil {
exit(err)
exit(fmt.Errorf("failed to configure service: %w", err))
} else if err := installService(constants.DisplayName, config, recoveryActions); err != nil {
exit(err)
exit(fmt.Errorf("failed to install service: %w", err))
}
}

Expand Down
19 changes: 7 additions & 12 deletions cmd/list-app-owners.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,13 @@ func listAppOwnersCmdImpl(cmd *cobra.Command, args []string) {
defer gracefulShutdown(stop)

log.V(1).Info("testing connections")
if err := testConnections(); err != nil {
exit(err)
} else if azClient, err := newAzureClient(); err != nil {
exit(err)
} else {
log.Info("collecting azure app owners...")
start := time.Now()
stream := listAppOwners(ctx, azClient, listApps(ctx, azClient))
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}
azClient := connectAndCreateClient()
log.Info("collecting azure app owners...")
start := time.Now()
stream := listAppOwners(ctx, azClient, listApps(ctx, azClient))
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}

func listAppOwners(ctx context.Context, client client.AzureClient, apps <-chan interface{}) <-chan interface{} {
Expand Down
21 changes: 8 additions & 13 deletions cmd/list-app-role-assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,14 @@ func listAppRoleAssignmentsCmdImpl(cmd *cobra.Command, args []string) {
defer gracefulShutdown(stop)

log.V(1).Info("testing connections")
if err := testConnections(); err != nil {
exit(err)
} else if azClient, err := newAzureClient(); err != nil {
exit(err)
} else {
log.Info("collecting azure active directory app role assignments...")
start := time.Now()
servicePrincipals := listServicePrincipals(ctx, azClient)
stream := listAppRoleAssignments(ctx, azClient, servicePrincipals)
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}
azClient := connectAndCreateClient()
log.Info("collecting azure active directory app role assignments...")
start := time.Now()
servicePrincipals := listServicePrincipals(ctx, azClient)
stream := listAppRoleAssignments(ctx, azClient, servicePrincipals)
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}

func listAppRoleAssignments(ctx context.Context, client client.AzureClient, servicePrincipals <-chan interface{}) <-chan interface{} {
Expand Down
19 changes: 7 additions & 12 deletions cmd/list-apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,13 @@ func listAppsCmdImpl(cmd *cobra.Command, args []string) {
defer gracefulShutdown(stop)

log.V(1).Info("testing connections")
if err := testConnections(); err != nil {
exit(err)
} else if azClient, err := newAzureClient(); err != nil {
exit(err)
} else {
log.Info("collecting azure active directory applications...")
start := time.Now()
stream := listApps(ctx, azClient)
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}
azClient := connectAndCreateClient()
log.Info("collecting azure active directory applications...")
start := time.Now()
stream := listApps(ctx, azClient)
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}

func listApps(ctx context.Context, client client.AzureClient) <-chan interface{} {
Expand Down
21 changes: 8 additions & 13 deletions cmd/list-automation-account-role-assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,14 @@ func listAutomationAccountRoleAssignmentImpl(cmd *cobra.Command, args []string)
defer gracefulShutdown(stop)

log.V(1).Info("testing connections")
if err := testConnections(); err != nil {
exit(err)
} else if azClient, err := newAzureClient(); err != nil {
exit(err)
} else {
log.Info("collecting azure automation account role assignments...")
start := time.Now()
subscriptions := listSubscriptions(ctx, azClient)
stream := listAutomationAccountRoleAssignments(ctx, azClient, listAutomationAccounts(ctx, azClient, subscriptions))
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}
azClient := connectAndCreateClient()
log.Info("collecting azure automation account role assignments...")
start := time.Now()
subscriptions := listSubscriptions(ctx, azClient)
stream := listAutomationAccountRoleAssignments(ctx, azClient, listAutomationAccounts(ctx, azClient, subscriptions))
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}

func listAutomationAccountRoleAssignments(ctx context.Context, client client.AzureClient, automationAccounts <-chan interface{}) <-chan interface{} {
Expand Down
19 changes: 7 additions & 12 deletions cmd/list-automation-accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,13 @@ func listAutomationAccountsCmdImpl(cmd *cobra.Command, args []string) {
defer gracefulShutdown(stop)

log.V(1).Info("testing connections")
if err := testConnections(); err != nil {
exit(err)
} else if azClient, err := newAzureClient(); err != nil {
exit(err)
} else {
log.Info("collecting azure automation accounts...")
start := time.Now()
stream := listAutomationAccounts(ctx, azClient, listSubscriptions(ctx, azClient))
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}
azClient := connectAndCreateClient()
log.Info("collecting azure automation accounts...")
start := time.Now()
stream := listAutomationAccounts(ctx, azClient, listSubscriptions(ctx, azClient))
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}

func listAutomationAccounts(ctx context.Context, client client.AzureClient, subscriptions <-chan interface{}) <-chan interface{} {
Expand Down
19 changes: 7 additions & 12 deletions cmd/list-azure-ad.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,13 @@ func listAzureADCmdImpl(cmd *cobra.Command, args []string) {
defer gracefulShutdown(stop)

log.V(1).Info("testing connections")
if err := testConnections(); err != nil {
exit(err)
} else if azClient, err := newAzureClient(); err != nil {
exit(err)
} else {
log.Info("collecting azure ad objects...")
start := time.Now()
stream := listAllAD(ctx, azClient)
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}
azClient := connectAndCreateClient()
log.Info("collecting azure ad objects...")
start := time.Now()
stream := listAllAD(ctx, azClient)
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}

func listAllAD(ctx context.Context, client client.AzureClient) <-chan interface{} {
Expand Down
19 changes: 7 additions & 12 deletions cmd/list-azure-rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,13 @@ func listAzureRMCmdImpl(cmd *cobra.Command, args []string) {
defer gracefulShutdown(stop)

log.V(1).Info("testing connections")
if err := testConnections(); err != nil {
exit(err)
} else if azClient, err := newAzureClient(); err != nil {
exit(err)
} else {
log.Info("collecting azure resource management objects...")
start := time.Now()
stream := listAllRM(ctx, azClient)
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}
azClient := connectAndCreateClient()
log.Info("collecting azure resource management objects...")
start := time.Now()
stream := listAllRM(ctx, azClient)
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}

func listAllRM(ctx context.Context, client client.AzureClient) <-chan interface{} {
Expand Down
19 changes: 7 additions & 12 deletions cmd/list-device-owners.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,13 @@ func listDeviceOwnersCmdImpl(cmd *cobra.Command, args []string) {
defer gracefulShutdown(stop)

log.V(1).Info("testing connections")
if err := testConnections(); err != nil {
exit(err)
} else if azClient, err := newAzureClient(); err != nil {
exit(err)
} else {
log.Info("collecting azure device owners...")
start := time.Now()
stream := listDeviceOwners(ctx, azClient, listDevices(ctx, azClient))
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}
azClient := connectAndCreateClient()
log.Info("collecting azure device owners...")
start := time.Now()
stream := listDeviceOwners(ctx, azClient, listDevices(ctx, azClient))
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}

func listDeviceOwners(ctx context.Context, client client.AzureClient, devices <-chan interface{}) <-chan interface{} {
Expand Down
19 changes: 7 additions & 12 deletions cmd/list-devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,13 @@ func listDevicesCmdImpl(cmd *cobra.Command, args []string) {
defer gracefulShutdown(stop)

log.V(1).Info("testing connections")
if err := testConnections(); err != nil {
exit(err)
} else if azClient, err := newAzureClient(); err != nil {
exit(err)
} else {
log.Info("collecting azure active directory devices...")
start := time.Now()
stream := listDevices(ctx, azClient)
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}
azClient := connectAndCreateClient()
log.Info("collecting azure active directory devices...")
start := time.Now()
stream := listDevices(ctx, azClient)
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}

func listDevices(ctx context.Context, client client.AzureClient) <-chan interface{} {
Expand Down
21 changes: 8 additions & 13 deletions cmd/list-function-app-role-assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,14 @@ func listFunctionAppRoleAssignmentImpl(cmd *cobra.Command, args []string) {
defer gracefulShutdown(stop)

log.V(1).Info("testing connections")
if err := testConnections(); err != nil {
exit(err)
} else if azClient, err := newAzureClient(); err != nil {
exit(err)
} else {
log.Info("collecting azure function app role assignments...")
start := time.Now()
subscriptions := listSubscriptions(ctx, azClient)
stream := listFunctionAppRoleAssignments(ctx, azClient, listFunctionApps(ctx, azClient, subscriptions))
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}
azClient := connectAndCreateClient()
log.Info("collecting azure function app role assignments...")
start := time.Now()
subscriptions := listSubscriptions(ctx, azClient)
stream := listFunctionAppRoleAssignments(ctx, azClient, listFunctionApps(ctx, azClient, subscriptions))
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}

func listFunctionAppRoleAssignments(ctx context.Context, client client.AzureClient, functionApps <-chan interface{}) <-chan interface{} {
Expand Down
19 changes: 7 additions & 12 deletions cmd/list-function-apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,13 @@ func listFunctionAppsCmdImpl(cmd *cobra.Command, args []string) {
defer gracefulShutdown(stop)

log.V(1).Info("testing connections")
if err := testConnections(); err != nil {
exit(err)
} else if azClient, err := newAzureClient(); err != nil {
exit(err)
} else {
log.Info("collecting azure function apps...")
start := time.Now()
stream := listFunctionApps(ctx, azClient, listSubscriptions(ctx, azClient))
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}
azClient := connectAndCreateClient()
log.Info("collecting azure function apps...")
start := time.Now()
stream := listFunctionApps(ctx, azClient, listSubscriptions(ctx, azClient))
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}

func listFunctionApps(ctx context.Context, client client.AzureClient, subscriptions <-chan interface{}) <-chan interface{} {
Expand Down
19 changes: 7 additions & 12 deletions cmd/list-group-members.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,13 @@ func listGroupMembersCmdImpl(cmd *cobra.Command, args []string) {
defer gracefulShutdown(stop)

log.V(1).Info("testing connections")
if err := testConnections(); err != nil {
exit(err)
} else if azClient, err := newAzureClient(); err != nil {
exit(err)
} else {
log.Info("collecting azure group members...")
start := time.Now()
stream := listGroupMembers(ctx, azClient, listGroups(ctx, azClient))
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}
azClient := connectAndCreateClient()
log.Info("collecting azure group members...")
start := time.Now()
stream := listGroupMembers(ctx, azClient, listGroups(ctx, azClient))
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}

func listGroupMembers(ctx context.Context, client client.AzureClient, groups <-chan interface{}) <-chan interface{} {
Expand Down
19 changes: 7 additions & 12 deletions cmd/list-group-owners.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,13 @@ func listGroupOwnersCmdImpl(cmd *cobra.Command, args []string) {
defer gracefulShutdown(stop)

log.V(1).Info("testing connections")
if err := testConnections(); err != nil {
exit(err)
} else if azClient, err := newAzureClient(); err != nil {
exit(err)
} else {
log.Info("collecting azure group owners...")
start := time.Now()
stream := listGroupOwners(ctx, azClient, listGroups(ctx, azClient))
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}
azClient := connectAndCreateClient()
log.Info("collecting azure group owners...")
start := time.Now()
stream := listGroupOwners(ctx, azClient, listGroups(ctx, azClient))
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}

func listGroupOwners(ctx context.Context, client client.AzureClient, groups <-chan interface{}) <-chan interface{} {
Expand Down
19 changes: 7 additions & 12 deletions cmd/list-groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,13 @@ func listGroupsCmdImpl(cmd *cobra.Command, args []string) {
defer gracefulShutdown(stop)

log.V(1).Info("testing connections")
if err := testConnections(); err != nil {
exit(err)
} else if azClient, err := newAzureClient(); err != nil {
exit(err)
} else {
log.Info("collecting azure active directory groups...")
start := time.Now()
stream := listGroups(ctx, azClient)
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}
azClient := connectAndCreateClient()
log.Info("collecting azure active directory groups...")
start := time.Now()
stream := listGroups(ctx, azClient)
outputStream(ctx, stream)
duration := time.Since(start)
log.Info("collection completed", "duration", duration.String())
}

func listGroups(ctx context.Context, client client.AzureClient) <-chan interface{} {
Expand Down
Loading