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

[Fix] Fail fast when authenticating if host is not configured #1033

Merged
merged 4 commits into from
Aug 30, 2024

Conversation

mgyucht
Copy link
Contributor

@mgyucht mgyucht commented Aug 30, 2024

Changes

The SDK currently hangs when making API requests if the Host is set to a non-empty but invalid endpoint, such as https://:443. This PR adds a check during authentication to ensure that the hostname is defined, failing early if not. The underlying error is exported so other clients, such as the CLI or Terraform Provider, can provide specific advice when this happens.

Tests

Added a unit test for this case.

  • make test passing
  • make fmt applied
  • relevant integration tests applied

@mgyucht mgyucht requested a review from tanmay-db August 30, 2024 12:10
config/config.go Outdated
@@ -373,6 +373,9 @@ func (c *Config) authenticateIfNeeded() error {
c.credentialsProvider = credentialsProvider
c.AuthType = c.Credentials.Name()
c.fixHostIfNeeded()
if err := c.assertHostIsSet(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this something that we should do inside fixHostIfNeeded()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, fixHostIfNeeded is called before Configure() and from other places, and the Configure() credential providers are responsible for populating the host if the user specified an azure workspace resource ID. If we could separate those elements from one another, then we could have the following logic:

  1. populate host if needed
  2. fixHostIfNeeded: at this point, host must be set, so it can fail.
  3. Configure()

However, because fixHostIfNeeded is called from different codepaths, it may not be safe to have this method error if host is not set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, fixHostIfNeeded is only called from CanonicalHostname() and this pathway, so I think it is better to do it as you describe. However, we can ignore ErrNoHostConfigured in the first call.

@mgyucht mgyucht enabled auto-merge August 30, 2024 12:37
@mgyucht mgyucht added this pull request to the merge queue Aug 30, 2024
Merged via the queue into main with commit 4886afe Aug 30, 2024
8 checks passed
@mgyucht mgyucht deleted the fail-fast-when-host-not-configured branch August 30, 2024 12:44
mgyucht added a commit that referenced this pull request Sep 4, 2024
### Bug Fixes

 * Fail fast when authenticating if host is not configured ([#1033](#1033)).
 * Improve non-JSON error handling ([#1031](#1031)).

### Internal Changes

 * Add TestAccCreateOboTokenOnAws to flaky test list ([#1029](#1029)).
 * Add workflows manage integration tests checks ([#1032](#1032)).
 * Fix TestMwsAccWorkspaces cleanup ([#1028](#1028)).
 * Improve integration test comment ([#1035](#1035)).
 * Temporary ignore Metastore test failures ([#1027](#1027)).
 * Update test to support new accounts ([#1026](#1026)).
 * Use statuses instead of checks ([#1036](#1036)).

### API Changes:

 * Added `RegenerateDashboard` method for [w.QualityMonitors](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/catalog#QualityMonitorsAPI) workspace-level service.
 * Added [catalog.RegenerateDashboardRequest](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/catalog#RegenerateDashboardRequest) and [catalog.RegenerateDashboardResponse](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/catalog#RegenerateDashboardResponse).
 * Added [jobs.QueueDetails](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#QueueDetails), [jobs.QueueDetailsCodeCode](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#QueueDetailsCodeCode), [jobs.RunLifecycleStateV2State](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#RunLifecycleStateV2State), [jobs.RunStatus](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#RunStatus), [jobs.TerminationCodeCode](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#TerminationCodeCode), [jobs.TerminationDetails](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#TerminationDetails) and [jobs.TerminationTypeType](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#TerminationTypeType).
 * Added `Status` field for [jobs.BaseRun](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#BaseRun).
 * Added `Status` field for [jobs.RepairHistoryItem](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#RepairHistoryItem).
 * Added `Status` field for [jobs.Run](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#Run).
 * Added `Status` field for [jobs.RunTask](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#RunTask).
 * Added `MaxProvisionedThroughput` and `MinProvisionedThroughput` fields for [serving.ServedModelInput](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServedModelInput).
 * Added `ColumnsToSync` field for [vectorsearch.DeltaSyncVectorIndexSpecRequest](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/vectorsearch#DeltaSyncVectorIndexSpecRequest).
 * Changed `WorkloadSize` field for [serving.ServedModelInput](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServedModelInput) to no longer be required.

OpenAPI SHA: d05898328669a3f8ab0c2ecee37db2673d3ea3f7, Date: 2024-09-04
github-merge-queue bot pushed a commit that referenced this pull request Sep 4, 2024
### Bug Fixes

* Fail fast when authenticating if host is not configured
([#1033](#1033)).
* Improve non-JSON error handling
([#1031](#1031)).


### Internal Changes

* Add TestAccCreateOboTokenOnAws to flaky test list
([#1029](#1029)).
* Add workflows manage integration tests checks
([#1032](#1032)).
* Fix TestMwsAccWorkspaces cleanup
([#1028](#1028)).
* Improve integration test comment
([#1035](#1035)).
* Temporary ignore Metastore test failures
([#1027](#1027)).
* Update test to support new accounts
([#1026](#1026)).
* Use statuses instead of checks
([#1036](#1036)).


### API Changes:

* Added `RegenerateDashboard` method for
[w.QualityMonitors](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/catalog#QualityMonitorsAPI)
workspace-level service.
* Added
[catalog.RegenerateDashboardRequest](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/catalog#RegenerateDashboardRequest)
and
[catalog.RegenerateDashboardResponse](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/catalog#RegenerateDashboardResponse).
* Added
[jobs.QueueDetails](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#QueueDetails),
[jobs.QueueDetailsCodeCode](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#QueueDetailsCodeCode),
[jobs.RunLifecycleStateV2State](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#RunLifecycleStateV2State),
[jobs.RunStatus](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#RunStatus),
[jobs.TerminationCodeCode](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#TerminationCodeCode),
[jobs.TerminationDetails](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#TerminationDetails)
and
[jobs.TerminationTypeType](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#TerminationTypeType).
* Added `Status` field for
[jobs.BaseRun](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#BaseRun).
* Added `Status` field for
[jobs.RepairHistoryItem](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#RepairHistoryItem).
* Added `Status` field for
[jobs.Run](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#Run).
* Added `Status` field for
[jobs.RunTask](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#RunTask).
* Added `MaxProvisionedThroughput` and `MinProvisionedThroughput` fields
for
[serving.ServedModelInput](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServedModelInput).
* Added `ColumnsToSync` field for
[vectorsearch.DeltaSyncVectorIndexSpecRequest](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/vectorsearch#DeltaSyncVectorIndexSpecRequest).
* Changed `WorkloadSize` field for
[serving.ServedModelInput](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServedModelInput)
to no longer be required.

OpenAPI SHA: d05898328669a3f8ab0c2ecee37db2673d3ea3f7, Date: 2024-09-04
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