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

feat: Add Go SDK custom header support and README #1288

Merged
merged 7 commits into from
Apr 5, 2023
Merged

Conversation

jeremytchang
Copy link
Collaborator

@jeremytchang jeremytchang commented Mar 29, 2023

Following our node sdk's design, allow developers to set custom headers on Go SDK requests. Request specific custom headers will override headers defined in the sdk's settings/config. This will allow the Go SDK caller to set Accept headers and other custom headers. Also add README for Go SDK.

Also fixes issue stated in #1075. (Not the main one, but other one brought up by Go SDK users)

@@ -125,70 +125,6 @@ func TestAuthSession_Do_Authorization(t *testing.T) {
})
}

func TestAuthSession_Do_UserAgent(t *testing.T) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved these tests to header section.

@github-actions
Copy link
Contributor

Go Tests

    6 files  ±0      6 suites  ±0   13m 52s ⏱️ + 1m 45s
  50 tests +1    48 ✔️  - 1  0 💤 ±0  2 ❌ +2 
120 runs  +2  118 ✔️ ±0  0 💤 ±0  2 ❌ +2 

For more details on these failures, see this check.

Results for commit 295df8c. ± Comparison against base commit 44974ec.

This pull request removes 6 and adds 7 tests. Note that renamed tests count towards both.
rtl ‑ TestAuthSession_Do_Content_Type
rtl ‑ TestAuthSession_Do_Content_Type/Do()_sets_Content-Type_header_to_'application/json'_if_body_is_json
rtl ‑ TestAuthSession_Do_Content_Type/Do()_sets_Content-Type_header_to_'text/plain'_if_body_is_a_string
rtl ‑ TestAuthSession_Do_UserAgent
rtl ‑ TestAuthSession_Do_UserAgent/Do()_sets_User-Agent_header_with_AuthSession_config's_AgentTag
rtl ‑ TestAuthSession_Do_UserAgent/Do()_sets_User-Agent_header_with_Do's_option's_AgentTag,_which_will_overwrite__AuthSession_config
rtl ‑ TestAuthSession_Do_Headers
rtl ‑ TestAuthSession_Do_Headers/Do()'s_options.Headers_will_overwrite_the_Headers_in_the_AuthSession's_api_settings
rtl ‑ TestAuthSession_Do_Headers/Do()_sets_Content-Type_header_to_'application/json'_if_body_is_json
rtl ‑ TestAuthSession_Do_Headers/Do()_sets_Content-Type_header_to_'text/plain'_if_body_is_a_string
rtl ‑ TestAuthSession_Do_Headers/Do()_sets_User-Agent_header_with_AuthSession_config's_AgentTag
rtl ‑ TestAuthSession_Do_Headers/Do()_sets_User-Agent_header_with_Do's_option's_AgentTag,_which_will_overwrite__AuthSession_config
rtl ‑ TestAuthSession_Do_Headers/Do()_sets_custom_headers_if_Headers_is_set_in_the_AuthSession's_api_settings

@github-actions
Copy link
Contributor

Go Tests

    6 files  ±0      6 suites  ±0   13m 16s ⏱️ + 1m 9s
  50 tests +1    48 ✔️  - 1  0 💤 ±0  2 ❌ +2 
120 runs  +2  118 ✔️ ±0  0 💤 ±0  2 ❌ +2 

For more details on these failures, see this check.

Results for commit 295df8c. ± Comparison against base commit 44974ec.

This pull request removes 6 and adds 7 tests. Note that renamed tests count towards both.
rtl ‑ TestAuthSession_Do_Content_Type
rtl ‑ TestAuthSession_Do_Content_Type/Do()_sets_Content-Type_header_to_'application/json'_if_body_is_json
rtl ‑ TestAuthSession_Do_Content_Type/Do()_sets_Content-Type_header_to_'text/plain'_if_body_is_a_string
rtl ‑ TestAuthSession_Do_UserAgent
rtl ‑ TestAuthSession_Do_UserAgent/Do()_sets_User-Agent_header_with_AuthSession_config's_AgentTag
rtl ‑ TestAuthSession_Do_UserAgent/Do()_sets_User-Agent_header_with_Do's_option's_AgentTag,_which_will_overwrite__AuthSession_config
rtl ‑ TestAuthSession_Do_Headers
rtl ‑ TestAuthSession_Do_Headers/Do()'s_options.Headers_will_overwrite_the_Headers_in_the_AuthSession's_api_settings
rtl ‑ TestAuthSession_Do_Headers/Do()_sets_Content-Type_header_to_'application/json'_if_body_is_json
rtl ‑ TestAuthSession_Do_Headers/Do()_sets_Content-Type_header_to_'text/plain'_if_body_is_a_string
rtl ‑ TestAuthSession_Do_Headers/Do()_sets_User-Agent_header_with_AuthSession_config's_AgentTag
rtl ‑ TestAuthSession_Do_Headers/Do()_sets_User-Agent_header_with_Do's_option's_AgentTag,_which_will_overwrite__AuthSession_config
rtl ‑ TestAuthSession_Do_Headers/Do()_sets_custom_headers_if_Headers_is_set_in_the_AuthSession's_api_settings

@jeremytchang jeremytchang changed the title feat: Add Go SDK custom header support feat: Add Go SDK custom header support and README Apr 4, 2023
@jeremytchang jeremytchang requested review from jkaster and removed request for jkaster April 4, 2023 23:55
@github-actions
Copy link
Contributor

github-actions bot commented Apr 4, 2023

Go Tests

    6 files  ±0      1 errors  5 suites   - 1   13m 22s ⏱️ + 1m 15s
  50 tests +1    48 ✔️  -   1  0 💤 ±0  2 ❌ +2 
110 runs   - 8  108 ✔️  - 10  0 💤 ±0  2 ❌ +2 

For more details on these parsing errors and failures, see this check.

Results for commit 36e8a02. ± Comparison against base commit 44974ec.

This pull request removes 6 and adds 7 tests. Note that renamed tests count towards both.
rtl ‑ TestAuthSession_Do_Content_Type
rtl ‑ TestAuthSession_Do_Content_Type/Do()_sets_Content-Type_header_to_'application/json'_if_body_is_json
rtl ‑ TestAuthSession_Do_Content_Type/Do()_sets_Content-Type_header_to_'text/plain'_if_body_is_a_string
rtl ‑ TestAuthSession_Do_UserAgent
rtl ‑ TestAuthSession_Do_UserAgent/Do()_sets_User-Agent_header_with_AuthSession_config's_AgentTag
rtl ‑ TestAuthSession_Do_UserAgent/Do()_sets_User-Agent_header_with_Do's_option's_AgentTag,_which_will_overwrite__AuthSession_config
rtl ‑ TestAuthSession_Do_Headers
rtl ‑ TestAuthSession_Do_Headers/Do()'s_options.Headers_will_overwrite_the_Headers_in_the_AuthSession's_api_settings
rtl ‑ TestAuthSession_Do_Headers/Do()_sets_Content-Type_header_to_'application/json'_if_body_is_json
rtl ‑ TestAuthSession_Do_Headers/Do()_sets_Content-Type_header_to_'text/plain'_if_body_is_a_string
rtl ‑ TestAuthSession_Do_Headers/Do()_sets_User-Agent_header_with_AuthSession_config's_AgentTag
rtl ‑ TestAuthSession_Do_Headers/Do()_sets_User-Agent_header_with_Do's_option's_AgentTag,_which_will_overwrite__AuthSession_config
rtl ‑ TestAuthSession_Do_Headers/Do()_sets_custom_headers_if_Headers_is_set_in_the_AuthSession's_api_settings

@github-actions
Copy link
Contributor

github-actions bot commented Apr 5, 2023

Go Tests

    6 files      6 suites   12m 20s ⏱️
  50 tests   50 ✔️ 0 💤 0 ❌
120 runs  120 ✔️ 0 💤 0 ❌

Results for commit 0f60c79.

Copy link
Contributor

@jkaster jkaster left a comment

Choose a reason for hiding this comment

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

This is going to be some appreciated new functionality

@@ -142,7 +142,7 @@ func (s *AuthSession) Do(result interface{}, method, ver, path string, reqPars m
}

// set headers
req.Header.Add("Content-Type", contentTypeHeader)
req.Header.Set("Content-Type", contentTypeHeader)

if s.Config.AgentTag != "" {
req.Header.Set("User-Agent", s.Config.AgentTag)
Copy link
Contributor

Choose a reason for hiding this comment

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

you should also set x-looker-appid like the other SDKs do. There are some request routers that will modify the User-Agent header. Currently this is set in the existing auth.go and the intent is that AgentTag overwrites that default header value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good callout, was unaware of the behavior of AgentTag in relation to x-looker-appid. Will have a separate ticket to tackle that.

go/README.md Outdated
Comment on lines 16 to 34
func main() {
// Get settings from either looker.ini file OR environment:
// looker.ini file
cfg, err := rtl.NewSettingsFromFile("path/to/looker.ini", nil)
// environment
cfg, err := rtl.NewSettingsFromEnv()

// Create new auth session with sdk settings.
// The auth session will fetch/refresh the access
// token from your Looker instance's `login` endpoint.
session := rtl.NewAuthSession(cfg)

// Create new instance of the Go Looker SDK
sdk := v4.NewLookerSDK(session)

// Call the Looker API e.g. get your user's name
me, err := sdk.Me("", nil)
fmt.Printf("Your name is %s %s\n", *(me.first), *(me.last))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

code alignment seems strange here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed!


You can set a custom timeout (in seconds) on Looker Go SDK's requests. The timeout defaults to 120 seconds. A timeout can either be applied to all outgoing requests or per outgoing request.

#### Timeout for all requests
Copy link
Contributor

Choose a reason for hiding this comment

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

great addition!

}
```

#### Custom headers per request
Copy link
Contributor

Choose a reason for hiding this comment

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

This will definitely be handy in some use cases

go/README.md Outdated
Comment on lines 107 to 116
cfg, err := rtl.NewSettingsFromFile("path/to/looker.ini", nil)
session := rtl.NewAuthSession(cfg)
sdk := v4.NewLookerSDK(session)

// Set the timeout in the options passed into the SDK method
me, err := sdk.Me("", &ApiSettings{Timeout: 60})

if errors.Is(err, context.DeadlineExceeded) {
// Timeout exceeded
}
Copy link
Contributor

Choose a reason for hiding this comment

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

strange indentation again? is it mixed tabs and spaces?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup mixed by accident. Fixed!

@github-actions
Copy link
Contributor

github-actions bot commented Apr 5, 2023

Go Tests

    6 files      1 errors  5 suites   10m 31s ⏱️
  50 tests   48 ✔️ 0 💤 2 ❌
110 runs  108 ✔️ 0 💤 2 ❌

For more details on these parsing errors and failures, see this check.

Results for commit fd2887f.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 5, 2023

Go Tests

    6 files      6 suites   14m 57s ⏱️
  50 tests   48 ✔️ 0 💤 2 ❌
120 runs  118 ✔️ 0 💤 2 ❌

For more details on these failures, see this check.

Results for commit 513d940.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 5, 2023

Go Tests

    6 files      6 suites   14m 19s ⏱️
  50 tests   50 ✔️ 0 💤 0 ❌
120 runs  120 ✔️ 0 💤 0 ❌

Results for commit 513d940.

Copy link
Contributor

@jkaster jkaster left a comment

Choose a reason for hiding this comment

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

LGTM with the follow-up ticket

@jeremytchang jeremytchang merged commit 308b419 into main Apr 5, 2023
@jeremytchang jeremytchang deleted the customheadergo branch April 5, 2023 20:52
@github-actions

This comment has been minimized.

zeckertG pushed a commit that referenced this pull request Apr 7, 2023
Following our node sdk's design, allow developers to set custom headers on Go SDK requests. Request specific custom headers will override headers defined in the sdk's settings/config. This will allow the Go SDK caller to set Accept headers and other custom headers. Also add README for Go SDK.

Also fixes issue stated in #1075. (Not the main one, but other one brought up by Go SDK users)
zeckertG added a commit that referenced this pull request Apr 11, 2023
* Update state variables before moving to redux

* Updating state variable names

* fix isConfigured function

* fix: Set Go SDK's User-Agent header (#1285)

Implement AgentTag defined in settings and set Go SDK's outgoing Do requests with the User-Agent header.

Fixes issue: #1274

---------

Co-authored-by: Colin Gooding <cgooding@vendasta.com>

* fix: Implement Go SDK timeout (#1287)

Implement the Timeout field in our config/settings. Make use of request context to control timeout. Timeout defaults to 120 seconds. Hopefully the unit tests are not flaky with the new timeout tests.

Fixes issue #692

* feat: generate SDKs for Looker 23.4 (#1290)

Release-As: 23.4.0

* chore: release main (#1281)

* feat: Add Go SDK custom header support and README (#1288)

Following our node sdk's design, allow developers to set custom headers on Go SDK requests. Request specific custom headers will override headers defined in the sdk's settings/config. This will allow the Go SDK caller to set Accept headers and other custom headers. Also add README for Go SDK.

Also fixes issue stated in #1075. (Not the main one, but other one brought up by Go SDK users)

* Updating OAuthForm function names

---------

Co-authored-by: jeremytchang <78522362+jeremytchang@users.noreply.github.com>
Co-authored-by: Colin Gooding <cgooding@vendasta.com>
Co-authored-by: looker-open-source-automation-bot <looker-open-source-automation-bot@google.com>
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