Skip to content

test(examples): Add runnable examples for testing #2

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 12 commits into
base: intro
Choose a base branch
from

Conversation

ndyakov
Copy link
Member

@ndyakov ndyakov commented Apr 15, 2025

The examples placed in examples/entraid can be executed with the proper env setup.
The rest of the examples in the examples folder are there to show developers how the package can be used with custom identity providers or with the default azure credentials provider.

@ndyakov ndyakov changed the title Add Custom Identity Provider example. Add examples. Apr 25, 2025
@ndyakov ndyakov requested a review from Copilot April 25, 2025 12:33
@ndyakov ndyakov marked this pull request as ready for review April 25, 2025 12:33
Copy link
Contributor

@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 PR introduces several example applications to demonstrate different identity providers and updates the token model accordingly. Key changes include:

  • Reordering the rawToken field in the Token struct constructor.
  • Adding example implementations for managed, default Azure, custom, and confidential identity providers.
  • Including a mock identity provider implementation to simulate token generation and parsing.

Reviewed Changes

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

Show a summary per file
File Description
token/token.go Reordered rawToken field to align with constructor parameters.
examples/managed_identity/main.go Added example for system and user-assigned managed identity.
examples/default_azure_identity/main.go Added example for default Azure identity credentials provider.
examples/custom_idp/main.go Added custom identity provider example with a fake provider.
examples/confidential_identity/main.go Added example for confidential identity with client secret auth.
Files not reviewed (2)
  • examples/custom_idp/go.mod: Language not supported
  • go.mod: Language not supported
Comments suppressed due to low confidence (1)

examples/custom_idp/main.go:32

  • The variable 'redis' shadows the imported package name 'redis'. Consider renaming it to 'redisClient' to improve code clarity.
redis := redis.NewClient(&redis.Options{

@ndyakov ndyakov requested a review from Copilot May 20, 2025 14:40
Copy link
Contributor

@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 PR adds a variety of example implementations for different authentication methods (managed identity, default credentials, client secret, client certificate, and a custom identity provider) to demonstrate the wiring for a custom identity provider using the library. Key changes include:

  • New example programs and go.mod files for different authentication scenarios under the examples/ folder.
  • Updates to the README to reflect the new import paths and configuration details.
  • Minor adjustments to test files and internal package imports.

Reviewed Changes

Copilot reviewed 48 out of 48 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
examples/entraid//.go and go.mod Addition of example authentication methods and updated dependency refs
examples/entraid/config/* New configuration loader and endpoints JSON for examples
examples/custom_idp/* New custom identity provider example with fake provider implementation
entraid*, credentials_provider* Updated imports to use the correct package naming
README.md Updated documentation and code snippets to match new import conventions
Comments suppressed due to low confidence (1)

README.md:430

  • [nitpick] Ensure that the environment variable name for user-assigned identities ('AZURE_USER_ASSIGNED_MANAGED_ID') is consistently used across the code and documentation. This consistency will help avoid confusion when setting up configuration.
UserAssignedClientID: os.Getenv("AZURE_USER_ASSIGNED_MANAGED_ID"),

@ndyakov ndyakov requested a review from Copilot May 20, 2025 14:45
@ndyakov ndyakov changed the title Add examples. test(examples): Add runnable examples for testing May 20, 2025
Copy link
Contributor

@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

Adds standalone example applications demonstrating various Azure identity authentication methods and a custom identity provider for the go-redis-entraid library, along with a shared configuration loader and sample endpoints.

  • Introduces multiple example modules (managedidentity_user, managedidentity_system, defaultcredentials, clientsecret, clientcert, default_azure_identity, custom_idp) showing different credential providers in action.
  • Adds a config package with LoadConfig and GetRedisScopes for loading JSON and environment-based settings.
  • Updates import paths and test files to use the new repository location (github.com/redis/go-redis-entraid).

Reviewed Changes

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

Show a summary per file
File Description
examples/entraid/managedidentity_user/go.mod Adds module and dependencies for user-assigned managed identity example
examples/entraid/managedidentity_system/main.go Example for system-assigned identity provider with Redis client
examples/entraid/managedidentity_system/go.mod Module setup for system-assigned identity example
examples/entraid/defaultcredentials/main.go Default Azure credentials example using built-in identity chain
examples/entraid/defaultcredentials/go.mod Module setup for default credentials example
examples/entraid/clientsecret/main.go Example for client-secret authentication provider
examples/entraid/clientsecret/go.mod Module setup for client-secret example
examples/entraid/clientcert/main.go Example for client-certificate authentication provider
examples/entraid/clientcert/go.mod Module setup for client-certificate example
examples/entraid/config/config.go Shared config loader for JSON and environment variables
examples/entraid/config/go.mod Module setup for shared config package
examples/entraid/endpoints.json Sample Redis endpoints configuration
examples/default_azure_identity/main.go Minimal default Azure identity example
examples/custom_idp/main.go Custom identity provider example with a fake provider
examples/custom_idp/go.mod Module setup for custom identity provider example
entraid.go Updated import path for shared package
credentials_provider.go Updated import paths for manager and token packages
entraid_test.go, credentials_provider_test.go Test imports updated to new module path
README.md Updated examples and import references to the new repository path
Comments suppressed due to low confidence (6)

examples/custom_idp/go.mod:1

  • [nitpick] The module name custom_example does not match its directory name custom_idp, which can be confusing. Consider renaming the module to custom_idp or updating the directory name.
module custom_example

examples/entraid/config/config.go:49

  • The code uses fmt.Errorf but the fmt package is not imported, which will cause a compile error. Add import "fmt" to the import block.
return nil, fmt.Errorf("failed to open configuration file: %v", err)

examples/custom_idp/main.go:23

  • The error returned by NewTokenManager is not checked. Add an if err != nil { ... } block immediately after to handle initialization failures.
tm, err := manager.NewTokenManager(idp, manager.TokenManagerOptions{

examples/entraid/managedidentity_system/main.go:30

  • [nitpick] Hard-coded string literal for ManagedIdentityType. Consider using the provided constant identity.SystemAssignedIdentity to avoid typos and improve readability.
ManagedIdentityType: "SystemAssigned",

examples/entraid/managedidentity_system/main.go:50

  • Only Addrs is passed to ClusterOptions, dropping authentication and TLS settings parsed by redis.ParseURL. Propagate clusterOpts fields (e.g., Username, Password, TLSConfig) to ensure the client connects correctly.
clusterClient := redis.NewClusterClient(&redis.ClusterOptions{

examples/entraid/defaultcredentials/go.mod:7

  • [nitpick] The placeholder version v0.0.0-00010101000000-000000000000 is not a valid published tag and may confuse users. Consider using a real version or relying solely on a local replace directive.
github.com/redis/go-redis-entraid v0.0.0-00010101000000-000000000000

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