-
Notifications
You must be signed in to change notification settings - Fork 42
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
Handle Azure authentication when WorkspaceResourceID is provided #597
Conversation
Codecov ReportPatch coverage is
📢 Thoughts on this report? Let us know!. |
config/auth_azure_cli.go
Outdated
if subscription != "" { | ||
extendedArgs := make([]string, len(args)) | ||
copy(extendedArgs, args) | ||
extendedArgs = append(extendedArgs, "--subscription", subscription) | ||
// This will fail if the user has access to the workspace, but not to the subscription | ||
// itself. | ||
// In such case, we fall back to not using the subscription. | ||
result, err := exec.Command("az", extendedArgs...).Output() | ||
if err != nil { | ||
logger.Warnf(context.Background(), "Failed to get token for subscription. Using resource only token.") | ||
} else { | ||
out = result | ||
} | ||
} | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot get access token: %v", err) | ||
if out == nil { | ||
result, err := exec.Command("az", args...).Output() | ||
if ee, ok := err.(*exec.ExitError); ok { | ||
return nil, fmt.Errorf("cannot get access token: %s", string(ee.Stderr)) | ||
} | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot get access token: %v", err) | ||
} | ||
out = result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behavior LGTM, but let's refactor this into a method:
func (...) getTokenBytes() ([]byte, error) {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small nit, otherwise LGTM!
config/auth_azure_cli.go
Outdated
return nil, fmt.Errorf("cannot get access token: %s", string(ee.Stderr)) | ||
} | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot get access token: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use %w
to wrap errors, unless for some reason we don't want to expose the underlying error?
Changes
Handle Azure authentication when WorkspaceResourceID is provided
Get token for the correct subscription
Tests
make test
passingmake fmt
appliedhttps://github.com/databricks/eng-dev-ecosystem/actions/runs/6038851262/job/16386160429