Skip to content

Commit

Permalink
provide more error context and move to closer location
Browse files Browse the repository at this point in the history
  • Loading branch information
austingebauer committed Jul 21, 2023
1 parent 2b2bf18 commit 3bcea36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (p *azureProvider) MSGraphClient() (client.MSGraphClient, error) {

msGraphAppClient, err := client.NewMSGraphApplicationClient(p.settings.GraphURI, cred)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to create MS graph client: %w", err)
}

return msGraphAppClient, nil
Expand All @@ -165,7 +165,7 @@ func (p *azureProvider) ComputeClient(subscriptionID string) (client.ComputeClie
clientOptions := p.getClientOptions()
client, err := armcompute.NewVirtualMachinesClient(subscriptionID, cred, clientOptions)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to create virtual machines client: %w", err)
}

return client, nil
Expand All @@ -180,7 +180,7 @@ func (p *azureProvider) VMSSClient(subscriptionID string) (client.VMSSClient, er
clientOptions := p.getClientOptions()
client, err := armcompute.NewVirtualMachineScaleSetsClient(subscriptionID, cred, clientOptions)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to create virtual machine scale sets client: %w", err)
}

return client, nil
Expand All @@ -195,7 +195,7 @@ func (p *azureProvider) MSIClient(subscriptionID string) (client.MSIClient, erro
clientOptions := p.getClientOptions()
client, err := armmsi.NewUserAssignedIdentitiesClient(subscriptionID, cred, clientOptions)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to create user assigned identity client: %w", err)
}

return client, nil
Expand All @@ -210,7 +210,7 @@ func (p *azureProvider) ProvidersClient(subscriptionID string) (client.Providers
clientOptions := p.getClientOptions()
client, err := armresources.NewProvidersClient(subscriptionID, cred, clientOptions)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to create providers client: %w", err)
}

return client, nil
Expand All @@ -225,7 +225,7 @@ func (p *azureProvider) ResourceClient(subscriptionID string) (client.ResourceCl
clientOptions := p.getClientOptions()
client, err := armresources.NewClient(subscriptionID, cred, clientOptions)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to create resource client: %w", err)
}

return client, nil
Expand Down Expand Up @@ -254,7 +254,7 @@ func (p *azureProvider) getTokenCredential() (azcore.TokenCredential, error) {
cred, err := azidentity.NewClientSecretCredential(p.settings.TenantID, p.settings.ClientID,
p.settings.ClientSecret, options)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to create client secret token credential: %w", err)
}

return cred, nil
Expand All @@ -266,7 +266,7 @@ func (p *azureProvider) getTokenCredential() (azcore.TokenCredential, error) {
}
cred, err := azidentity.NewManagedIdentityCredential(options)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to create managed identity token credential: %w", err)
}

return cred, nil
Expand Down
12 changes: 6 additions & 6 deletions path_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func (b *azureAuthBackend) verifyResource(ctx context.Context, subscriptionID, r
case vmssName != "":
client, err := b.provider.VMSSClient(subscriptionID)
if err != nil {
return fmt.Errorf("unable to create vmss client: %w", err)
return err
}

// Omit armcompute.ExpandTypesForGetVMScaleSetsUserData since we do not need that information for purpose of authenticating an instance
Expand Down Expand Up @@ -322,7 +322,7 @@ func (b *azureAuthBackend) verifyResource(ctx context.Context, subscriptionID, r
// must look up the user-assigned identity using the MSI client
msiClient, err := b.provider.MSIClient(msiID.SubscriptionID)
if err != nil {
return fmt.Errorf("unable to create msi client: %w", err)
return fmt.Errorf("failed to create client to retrieve user-assigned identity: %w", err)
}
userIdentityResponse, err := msiClient.Get(ctx, msiID.ResourceGroupName, msiID.Name, nil)
if err != nil {
Expand All @@ -336,7 +336,7 @@ func (b *azureAuthBackend) verifyResource(ctx context.Context, subscriptionID, r
case vmName != "":
client, err := b.provider.ComputeClient(subscriptionID)
if err != nil {
return fmt.Errorf("unable to create compute client: %w", err)
return err
}

instanceView := armcompute.InstanceViewTypesInstanceView
Expand Down Expand Up @@ -380,7 +380,7 @@ func (b *azureAuthBackend) verifyResource(ctx context.Context, subscriptionID, r

client, err := b.provider.ResourceClient(subscriptionID)
if err != nil {
return fmt.Errorf("unable to create resource client: %w", err)
return err
}

resp, err := client.GetByID(ctx, resourceID, apiVersion, nil)
Expand Down Expand Up @@ -419,7 +419,7 @@ func (b *azureAuthBackend) verifyResource(ctx context.Context, subscriptionID, r
}

clientIDs := map[string]struct{}{}
c, err := b.provider.MSIClient(subscriptionID) // this is the second time we're calling this, is there a way to reuse that?
c, err := b.provider.MSIClient(subscriptionID)
if err != nil {
return fmt.Errorf("failed to create client to retrieve app ids: %w", err)
}
Expand Down Expand Up @@ -526,7 +526,7 @@ func (b *azureAuthBackend) getAPIVersionForResource(ctx context.Context, subscri

client, err := b.provider.ProvidersClient(subscriptionID)
if err != nil {
return "", fmt.Errorf("unable to create providers client: %w", err)
return "", err
}

response, err := client.Get(ctx, resourceType.Namespace, nil)
Expand Down

0 comments on commit 3bcea36

Please sign in to comment.