Skip to content

[Feature] Migrate U2M Code to SDKs #2076

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

Merged
merged 21 commits into from
Apr 11, 2025
Merged

[Feature] Migrate U2M Code to SDKs #2076

merged 21 commits into from
Apr 11, 2025

Conversation

mgyucht
Copy link
Contributor

@mgyucht mgyucht commented Jan 3, 2025

Changes

Ports the SDK to this change: databricks/databricks-sdk-go#1108. This eliminates the need for the SDK to invoke itself (!) when loading an OAuth token. It also allows us to respond with more suitable errors when fetching tokens. Functionally, this should behave identically to the existing CLI from an external perspective.

One concrete improvement with this change is that the error message returned when a refresh token is invalid now provides the correct command to run, including the appropriate --profile flag.

Users will see the following message when using the CLI with a profile/host with an expired refresh token:
Screenshot 2025-01-20 at 13 18 59

Tests

Mostly this change involves refactoring existing code/tests to use/mock the Go SDK interfaces, so there aren't too many substantial test changes. token_test.go is rewritten using the table test approach to reduce boilerplate.

Copy link

github-actions bot commented Jan 3, 2025

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/cli

Inputs:

  • PR number: 2076
  • Commit SHA: c6cbc42b4e4cc0855a3ed826a571d9f021027637

Checks will be approved automatically on success.

@mgyucht mgyucht temporarily deployed to test-trigger-is January 3, 2025 13:47 — with GitHub Actions Inactive
@denik denik mentioned this pull request Jan 6, 2025
@mgyucht mgyucht temporarily deployed to test-trigger-is January 7, 2025 17:01 — with GitHub Actions Inactive
@mgyucht mgyucht temporarily deployed to test-trigger-is January 7, 2025 17:04 — with GitHub Actions Inactive
@mgyucht mgyucht temporarily deployed to test-trigger-is January 7, 2025 17:08 — with GitHub Actions Inactive
@mgyucht mgyucht temporarily deployed to test-trigger-is January 8, 2025 11:02 — with GitHub Actions Inactive
@mgyucht mgyucht temporarily deployed to test-trigger-is January 8, 2025 11:11 — with GitHub Actions Inactive
@andrewnester andrewnester marked this pull request as draft February 27, 2025 14:00
@mgyucht mgyucht temporarily deployed to test-trigger-is March 26, 2025 10:57 — with GitHub Actions Inactive
@mgyucht mgyucht changed the title [WIP] Migrate U2M Code to SDKs [Feature] Migrate U2M Code to SDKs Apr 3, 2025
@mgyucht mgyucht temporarily deployed to test-trigger-is April 3, 2025 09:55 — with GitHub Actions Inactive
@mgyucht mgyucht temporarily deployed to test-trigger-is April 10, 2025 11:07 — with GitHub Actions Inactive
@mgyucht mgyucht marked this pull request as ready for review April 10, 2025 11:08
@mgyucht mgyucht requested a review from anton-107 as a code owner April 10, 2025 11:08
Copy link
Contributor

@shreyas-goenka shreyas-goenka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Approving to unblock.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming the file to cmd/auth/in_memory_test.go seems like a mistake.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually intentional. It is an in-memory implementation of the token cache used only for tests and is not meant to be part of the normal build. Because it is used in the token_test.go tests which are in package auth, this should also be in package auth. At least, I will unexport this type.

@@ -23,4 +24,4 @@ func (i *InMemoryTokenCache) Store(key string, t *oauth2.Token) error {
return nil
}

var _ TokenCache = (*InMemoryTokenCache)(nil)
var _ cache.TokenCache = (*InMemoryTokenCache)(nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this line of code? What's the purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line just ensures that the InMemoryTokenCache implements the cache.TokenCache interface, similar to OAuthEndpointSupplier and MockApiClient below.

}

func getContextForTest(f fixtures.HTTPFixture) context.Context {
var _ u2m.OAuthEndpointSupplier = (*MockApiClient)(nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line just ensures that the MockApiClient implements the OAuthEndpointSupplier interface. If I had a typo in one of the method names or parameter lists, it wouldn't implement that interface. For tests, this isn't terribly important since this is only used in the context of this test.

@mgyucht mgyucht temporarily deployed to test-trigger-is April 11, 2025 08:25 — with GitHub Actions Inactive
@mgyucht mgyucht added this pull request to the merge queue Apr 11, 2025
Merged via the queue into main with commit e619b01 Apr 11, 2025
9 checks passed
@mgyucht mgyucht deleted the move-u2m-to-sdks branch April 11, 2025 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants