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: Refactored Go SDK to use Go oauth2 client, added x-looker-appid header to Go requests #1069

Merged
merged 11 commits into from
Apr 25, 2022

Conversation

jeremytchang
Copy link
Collaborator

@jeremytchang jeremytchang commented Apr 21, 2022

Fixes #1027

  • Refactored to use Go's standard oauth2 client to handle our client credentials flow. The client will automatically fetch and refresh the token when it is expired. Removed all the manual authorization implementation.

  • Also updated the the AuthSession to maintain only one client instead of creating a new one per request. As recommended by Go docs. Clients and Transports are safe for concurrent use by multiple goroutines and for efficiency should only be created once and re-used. client docs

  • Added x-looker-appid header with standard go http middleware, the RoundTripper interface. Article because the docs are sparse on this one.

  • Removed auth implementation specific tests. Added couple auth sanity tests even though the go client itself is well tested. Updated tests to properly call NewAuthSession to properly create the client.

@github-actions
Copy link
Contributor

Go Tests

  6 files  ±0    6 suites  ±0   4m 10s ⏱️ -41s
39 tests  - 3  39 ✔️  - 3  0 💤 ±0  0 ❌ ±0 
96 runs   - 6  96 ✔️  - 6  0 💤 ±0  0 ❌ ±0 

Results for commit 2ed10f0. ± Comparison against base commit 350d32d.

This pull request removes 13 and adds 10 tests. Note that renamed tests count towards both.
rtl ‑ TestAuthSession_Authenticate
rtl ‑ TestAuthSession_Authenticate/Authenticate()_errors_if_/login_errors_when_fetching_new_Access_Token_if_old_AccessToken_is_expired
rtl ‑ TestAuthSession_Authenticate/Authenticate()_fetches_new_Access_Token_from_/login_and_sets_header_with_it_if_old_AccessToken_is_expired
rtl ‑ TestAuthSession_Authenticate/Authenticate()_sets_header_with_current_AccessToken_if_not_expired
rtl ‑ TestAuthSession_Do
rtl ‑ TestAuthSession_Do/Do()_json_decodes_response_as_map[string]interface{}_type_if_result_is_interface{}_type
rtl ‑ TestAuthSession_Do/Do()_json_decodes_response_as_struct_type_if_result_is_struct_type
rtl ‑ TestAuthSession_Do/Do()_parses_response_as_string_type_if_result_is_string_type
rtl ‑ TestAuthSession_Do/Do()_unmarshals_num_type_field_to_string_type_field
rtl ‑ TestAuthSession_Do/Do()_unmarshals_string_type_field_to_num_type_field
…
rtl ‑ TestAuthSession_Do_Authorization
rtl ‑ TestAuthSession_Do_Authorization/Do()_sets_Authorization_header_with_access_token_fetched_from_/login
rtl ‑ TestAuthSession_Do_Authorization/Do()_sets_Authorization_header_with_new_access_token_fetched_from_/login_if_previous_access_token_expired
rtl ‑ TestAuthSession_Do_Parse
rtl ‑ TestAuthSession_Do_Parse/Do()_json_decodes_response_as_map[string]interface{}_type_if_result_is_interface{}_type
rtl ‑ TestAuthSession_Do_Parse/Do()_json_decodes_response_as_struct_type_if_result_is_struct_type
rtl ‑ TestAuthSession_Do_Parse/Do()_parses_response_as_string_type_if_result_is_string_type
rtl ‑ TestAuthSession_Do_Parse/Do()_unmarshals_num_type_field_to_string_type_field
rtl ‑ TestAuthSession_Do_Parse/Do()_unmarshals_string_type_field_to_num_type_field
rtl ‑ TestAuthSession_Do_Parse/Do{}_unmarshals_struct_with_mixed_string_and_num_types_correctly

@jeremytchang jeremytchang changed the title fix: Added x-looker-appid header to Go SDK Requests, refactored to use Go oauth2 client fix: Refactored Go SDK to use Go oauth2 client, added x-looker-appid header to Go requests Apr 21, 2022
@github-actions
Copy link
Contributor

Go Tests

  6 files    6 suites   4m 42s ⏱️
39 tests 39 ✔️ 0 💤 0 ❌
96 runs  96 ✔️ 0 💤 0 ❌

Results for commit 38e0d5c.

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. Nice cleanup.

@github-actions
Copy link
Contributor

Go Tests

  6 files    6 suites   5m 0s ⏱️
39 tests 39 ✔️ 0 💤 0 ❌
96 runs  96 ✔️ 0 💤 0 ❌

Results for commit 7a4dd9e.

@jeremytchang jeremytchang merged commit d51a675 into main Apr 25, 2022
@jeremytchang jeremytchang deleted the jc/go_appid branch April 25, 2022 18:07
@github-actions

This comment has been minimized.

jkaster added a commit that referenced this pull request Jul 13, 2022
🤖 I have created a release \*beep\* \*boop\*
---
<details><summary>sdk-codegen-all: 2.4.0</summary>


### Features

* Add ExtensionProvider40 component ([#1068](https://www.github.com/looker-open-source/sdk-codegen/issues/1068)) ([425aee5](https://www.github.com/looker-open-source/sdk-codegen/commit/425aee5097361b580b3ff7e93f227d6d34f21eb3))
* generate SDK 22.6 ([#1102](https://www.github.com/looker-open-source/sdk-codegen/issues/1102)) ([2162860](https://www.github.com/looker-open-source/sdk-codegen/commit/2162860f0bf292bce0a79f8115f7c9fc5628057f))


### Bug Fixes

* add children property to ExtensionProvider type ([#1070](https://www.github.com/looker-open-source/sdk-codegen/issues/1070)) ([9524583](https://www.github.com/looker-open-source/sdk-codegen/commit/9524583fd99f0b46bba443a1dfa59cc6f42d081c))
* correct HTTP status code values ([#1101](https://www.github.com/looker-open-source/sdk-codegen/issues/1101)) ([3d0f902](https://www.github.com/looker-open-source/sdk-codegen/commit/3d0f902b67d6384c08641579ae959829c78d1994))
* description sync issues in diff scene ([#1086](https://www.github.com/looker-open-source/sdk-codegen/issues/1086)) ([a37aa50](https://www.github.com/looker-open-source/sdk-codegen/commit/a37aa50064bb41ca5af2c9d19371e2ef7973e6d9))
* example miner github permalinks do not use `.git` in the repository name ([#1063](https://www.github.com/looker-open-source/sdk-codegen/issues/1063)) ([e150b33](https://www.github.com/looker-open-source/sdk-codegen/commit/e150b33ff974575d731f48f2f1488bdbeeb9118c))
* package refs for API Explorer extension ([#1055](https://www.github.com/looker-open-source/sdk-codegen/issues/1055)) ([5fcf358](https://www.github.com/looker-open-source/sdk-codegen/commit/5fcf3588e1f4e87fc6d1d5789e00f66cf4fe92d9))
* Refactored Go SDK to use Go oauth2 client, added `x-looker-appid` header to Go requests ([#1069](https://www.github.com/looker-open-source/sdk-codegen/issues/1069)) ([d51a675](https://www.github.com/looker-open-source/sdk-codegen/commit/d51a6750f7d5f22efa84278492a71336e39d92e1))
* Register Go Fuzzy JSON Decoders once on init ([#1054](https://www.github.com/looker-open-source/sdk-codegen/issues/1054)) ([350d32d](https://www.github.com/looker-open-source/sdk-codegen/commit/350d32dfecb42679cff06e0c4508bebcf7fa6809))
* remove generated files from examples index ([#1076](https://www.github.com/looker-open-source/sdk-codegen/issues/1076)) ([d75bce8](https://www.github.com/looker-open-source/sdk-codegen/commit/d75bce8dc25d41fd6bc5e2e513782eaa6009fd10))
* replacing unimported exception ([#1066](https://www.github.com/looker-open-source/sdk-codegen/issues/1066)) ([d85b1b8](https://www.github.com/looker-open-source/sdk-codegen/commit/d85b1b889c9d27e337a5e8d38fc3f32e013cc4d8))
* Sidenav Methods Panel Open & Closing ([#1097](https://www.github.com/looker-open-source/sdk-codegen/issues/1097)) ([c49fae4](https://www.github.com/looker-open-source/sdk-codegen/commit/c49fae4ca6a7a30feb61f021ec878a8091eaa078))
* Update prod entrypoint to match dev entrypoint (pull [#1059](https://www.github.com/looker-open-source/sdk-codegen/issues/1059)) ([0e4c3f4](https://www.github.com/looker-open-source/sdk-codegen/commit/0e4c3f47782d23f6c8e5509bd2942b0934e44ea2))
</details>
<details><summary>@looker/api-explorer: 0.9.33</summary>


### Bug Fixes

* description sync issues in diff scene ([#1086](https://www.github.com/looker-open-source/sdk-codegen/issues/1086)) ([a37aa50](https://www.github.com/looker-open-source/sdk-codegen/commit/a37aa50064bb41ca5af2c9d19371e2ef7973e6d9))
* remove generated files from examples index ([#1076](https://www.github.com/looker-open-source/sdk-codegen/issues/1076)) ([d75bce8](https://www.github.com/looker-open-source/sdk-codegen/commit/d75bce8dc25d41fd6bc5e2e513782eaa6009fd10))
* Sidenav Methods Panel Open & Closing ([#1097](https://www.github.com/looker-open-source/sdk-codegen/issues/1097)) ([c49fae4](https://www.github.com/looker-open-source/sdk-codegen/commit/c49fae4ca6a7a30feb61f021ec878a8091eaa078))
* Update prod entrypoint to match dev entrypoint (pull [#1059](https://www.github.com/looker-open-source/sdk-codegen/issues/1059)) ([0e4c3f4](https://www.github.com/looker-open-source/sdk-codegen/commit/0e4c3f47782d23f6c8e5509bd2942b0934e44ea2))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/extension-utils bumped from ^0.1.9 to ^0.1.10
    * @looker/code-editor bumped from ^0.1.21 to ^0.1.22
    * @looker/run-it bumped from ^0.9.32 to ^0.9.33
    * @looker/sdk bumped from ^22.4.2 to ^22.6.0
    * @looker/sdk-codegen bumped from ^21.5.2 to ^21.6.0
    * @looker/sdk-rtl bumped from ^21.3.3 to ^21.3.4
  * devDependencies
    * @looker/sdk-codegen-scripts bumped from ^21.3.3 to ^21.3.4
    * @looker/sdk-node bumped from ^22.4.2 to ^22.6.0
</details>
<details><summary>@looker/extension-api-explorer: 22.6.0</summary>


### Bug Fixes

* package refs for API Explorer extension ([#1055](https://www.github.com/looker-open-source/sdk-codegen/issues/1055)) ([5fcf358](https://www.github.com/looker-open-source/sdk-codegen/commit/5fcf3588e1f4e87fc6d1d5789e00f66cf4fe92d9))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/api-explorer bumped from ^0.9.32 to ^0.9.33
    * @looker/extension-sdk bumped from ^22.4.2 to ^22.6.0
    * @looker/extension-sdk-react bumped from ^22.4.2 to ^22.6.0
    * @looker/extension-utils bumped from ^0.1.9 to ^0.1.10
    * @looker/run-it bumped from ^0.9.32 to ^0.9.33
    * @looker/sdk bumped from ^22.4.2 to ^22.6.0
    * @looker/sdk-codegen bumped from ^21.5.2 to ^21.6.0
</details>
<details><summary>@looker/extension-sdk-react: 22.6.0</summary>


### Features

* Add ExtensionProvider40 component ([#1068](https://www.github.com/looker-open-source/sdk-codegen/issues/1068)) ([425aee5](https://www.github.com/looker-open-source/sdk-codegen/commit/425aee5097361b580b3ff7e93f227d6d34f21eb3))


### Bug Fixes

* add children property to ExtensionProvider type ([#1070](https://www.github.com/looker-open-source/sdk-codegen/issues/1070)) ([9524583](https://www.github.com/looker-open-source/sdk-codegen/commit/9524583fd99f0b46bba443a1dfa59cc6f42d081c))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/extension-sdk bumped from ^22.4.2 to ^22.6.0
    * @looker/sdk bumped from ^22.4.2 to ^22.6.0
    * @looker/sdk-rtl bumped from ^21.3.3 to ^21.3.4
</details>
<details><summary>@looker/sdk: 22.6.0</summary>


### Features

* generate SDK 22.6 ([#1102](https://www.github.com/looker-open-source/sdk-codegen/issues/1102)) ([2162860](https://www.github.com/looker-open-source/sdk-codegen/commit/2162860f0bf292bce0a79f8115f7c9fc5628057f))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/sdk-rtl bumped from ^21.3.3 to ^21.3.4
</details>
<details><summary>@looker/sdk-codegen: 21.6.0</summary>


### Features

* generate SDK 22.6 ([#1102](https://www.github.com/looker-open-source/sdk-codegen/issues/1102)) ([2162860](https://www.github.com/looker-open-source/sdk-codegen/commit/2162860f0bf292bce0a79f8115f7c9fc5628057f))


### Bug Fixes

* remove generated files from examples index ([#1076](https://www.github.com/looker-open-source/sdk-codegen/issues/1076)) ([d75bce8](https://www.github.com/looker-open-source/sdk-codegen/commit/d75bce8dc25d41fd6bc5e2e513782eaa6009fd10))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/sdk-rtl bumped from ^21.3.3 to ^21.3.4
</details>
<details><summary>@looker/sdk-codegen-scripts: 21.3.4</summary>


### Bug Fixes

* example miner github permalinks do not use `.git` in the repository name ([#1063](https://www.github.com/looker-open-source/sdk-codegen/issues/1063)) ([e150b33](https://www.github.com/looker-open-source/sdk-codegen/commit/e150b33ff974575d731f48f2f1488bdbeeb9118c))
* remove generated files from examples index ([#1076](https://www.github.com/looker-open-source/sdk-codegen/issues/1076)) ([d75bce8](https://www.github.com/looker-open-source/sdk-codegen/commit/d75bce8dc25d41fd6bc5e2e513782eaa6009fd10))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/sdk bumped from ^22.4.2 to ^22.6.0
    * @looker/sdk-codegen bumped from ^21.5.2 to ^21.6.0
    * @looker/sdk-node bumped from ^22.4.2 to ^22.6.0
    * @looker/sdk-rtl bumped from ^21.3.3 to ^21.3.4
</details>
<details><summary>@looker/sdk-rtl: 21.3.4</summary>


### Bug Fixes

* correct HTTP status code values ([#1101](https://www.github.com/looker-open-source/sdk-codegen/issues/1101)) ([3d0f902](https://www.github.com/looker-open-source/sdk-codegen/commit/3d0f902b67d6384c08641579ae959829c78d1994))
</details>
<details><summary>looker_sdk: 22.6.0</summary>


### Features

* generate SDK 22.6 ([#1102](https://www.github.com/looker-open-source/sdk-codegen/issues/1102)) ([2162860](https://www.github.com/looker-open-source/sdk-codegen/commit/2162860f0bf292bce0a79f8115f7c9fc5628057f))


### Documentation

* Fixed link to issues ([#1079](https://www.github.com/looker-open-source/sdk-codegen/issues/1079)) ([7f22f7b](https://www.github.com/looker-open-source/sdk-codegen/commit/7f22f7b1958ac6df9a09a5bfc4a0356237be069f)), closes [#1077](https://www.github.com/looker-open-source/sdk-codegen/issues/1077)
</details>
<details><summary>@looker/extension-sdk: 22.6.0</summary>


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/sdk bumped from ^22.4.2 to ^22.6.0
    * @looker/sdk-rtl bumped from ^21.3.3 to ^21.3.4
</details>
<details><summary>@looker/sdk-node: 22.6.0</summary>


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/sdk bumped from ^22.4.2 to ^22.6.0
    * @looker/sdk-rtl bumped from ^21.3.3 to ^21.3.4
</details>
<details><summary>@looker/code-editor: 0.1.22</summary>


### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @looker/sdk-codegen bumped from ^21.5.2 to ^21.6.0
</details>
<details><summary>@looker/wholly-sheet: 0.5.29</summary>


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/sdk bumped from ^22.4.2 to ^22.6.0
    * @looker/sdk-rtl bumped from ^21.3.3 to ^21.3.4
  * devDependencies
    * @looker/sdk-node bumped from ^22.4.2 to ^22.6.0
</details>
<details><summary>@looker/extension-utils: 0.1.10</summary>


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/extension-sdk bumped from ^22.4.2 to ^22.6.0
    * @looker/extension-sdk-react bumped from ^22.4.2 to ^22.6.0
    * @looker/sdk-rtl bumped from ^21.3.3 to ^21.3.4
</details>
<details><summary>@looker/hackathon: 22.6.0</summary>


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/code-editor bumped from ^0.1.21 to ^0.1.22
    * @looker/extension-sdk bumped from ^22.4.2 to ^22.6.0
    * @looker/extension-sdk-react bumped from ^22.4.2 to ^22.6.0
    * @looker/extension-utils bumped from ^0.1.9 to ^0.1.10
    * @looker/sdk bumped from ^22.4.2 to ^22.6.0
    * @looker/sdk-rtl bumped from ^21.3.3 to ^21.3.4
    * @looker/wholly-sheet bumped from ^0.5.28 to ^0.5.29
</details>
<details><summary>@looker/run-it: 0.9.33</summary>


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/code-editor bumped from ^0.1.21 to ^0.1.22
    * @looker/extension-utils bumped from ^0.1.9 to ^0.1.10
    * @looker/sdk bumped from ^22.4.2 to ^22.6.0
    * @looker/sdk-codegen bumped from ^21.5.2 to ^21.6.0
    * @looker/sdk-rtl bumped from ^21.3.3 to ^21.3.4
</details>


This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: John Kaster <kaster@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.

Support x-looker-appid for Go SDK identification like the other SDKs have
2 participants