Skip to content

Added pointer support for dynamic config #4

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

michaelbeutler
Copy link
Contributor

@michaelbeutler michaelbeutler commented Apr 1, 2025

This pull request includes several changes aimed at improving the flexibility and robustness of the OAuth2 configuration and usage within the codebase. The primary focus is on converting configuration fields from basic types to pointers, allowing for better handling of optional and default values.

Changes to Configuration Handling:

  • pkg/auth/config.go: Updated the Config struct to use pointer types for fields such as ClientId, ClientSecret, DeviceAuthorizationEndpoint, TokenEndpoint, Scopes, Audience, StorageProvider, and GrantType. This change allows these fields to be optional and simplifies the handling of default values.
  • pkg/auth/config.go: Modified various With* functions to accept pointers, aligning with the updated Config struct. This includes functions like WithClientID, WithClientSecret, WithDeviceAuthorizationEndpoint, WithTokenEndpoint, WithScopes, WithAudience, WithDiscoveryURL, WithStorageProvider, and WithGrantType. [1] [2]

Changes to Example Commands:

Changes to Authentication Logic:

  • pkg/auth/access_token.go: Updated the PollForAccessToken function to use pointer dereferencing for ClientId, ClientSecret, and TokenEndpoint fields in the Config struct. [1] [2] [3]
  • pkg/auth/client_credentials.go: Modified the FetchClientCredentialsToken function to use pointer dereferencing for ClientId, ClientSecret, TokenEndpoint, Scopes, and Audience fields in the Config struct.

Changes to Command Execution:

  • pkg/auth/cmd.go: Updated various command functions to use pointer dereferencing for ClientId and GrantType fields in the Config struct, ensuring consistent handling of these fields. [1] [2] [3] [4]

Changes to Tests:

  • pkg/auth/config_test.go: Updated tests to accommodate the changes in the Config struct, including the use of helper functions like strPtr to create string pointers and updating mock storage provider initialization. [1] [2] [3]
  • pkg/auth/access_token_test.go: Added a helper function strPtr to create string pointers and updated the TestPollForAccessToken function to use these pointers. [1] [2]

These changes collectively enhance the flexibility and robustness of the OAuth2 configuration and usage, making the codebase more adaptable to different scenarios and configurations.

@michaelbeutler michaelbeutler requested a review from Copilot April 1, 2025 14:13
@michaelbeutler michaelbeutler self-assigned this Apr 1, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@michaelbeutler michaelbeutler requested a review from Copilot April 1, 2025 14:13
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request converts several configuration fields from basic types to pointers to improve optional handling and default value management in the OAuth2 configuration. The key changes include:

  • Updating the Config struct and its accessor functions to use pointers.
  • Adjusting tests and example commands to accommodate the new pointer-based configuration.
  • Modifying the authentication logic to handle pointer dereferencing consistently.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/auth/device_code.go Updated to dereference pointer fields when constructing the request.
pkg/auth/config_test.go Updated tests to build config with pointer values and perform pointer-based comparisons.
pkg/auth/config.go Changed Config struct fields and Option functions to use pointers; potential issue in WithDiscoveryURL.
pkg/auth/cmd.go Updated command functions to dereference pointer fields.
pkg/auth/client_credentials.go Updated payload construction to use pointers for config fields.
pkg/auth/access_token_test.go Updated tests to use helper function for pointer creation.
pkg/auth/access_token.go Modified pointer dereferencing in HTTP request construction.
examples/client_credentials/cmd/root.go Changed constant credentials to variables and updated pointers usage.
examples/basic/cmd/root.go Changed constant credentials to variables and updated pointers usage.

Copy link

codecov bot commented Apr 1, 2025

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

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.

1 participant