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

Merged
merged 19 commits into from
May 27, 2025
Merged

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

@ndyakov ndyakov force-pushed the ndyakov/examples branch 7 times, most recently from 4bbeadc to b01271c Compare May 23, 2025 14:32
@ndyakov ndyakov force-pushed the ndyakov/examples branch from b01271c to 9efc9d1 Compare May 23, 2025 14:35
@ndyakov ndyakov force-pushed the ndyakov/examples branch from 9efc9d1 to 31f7b95 Compare May 23, 2025 14:41
@ndyakov ndyakov force-pushed the ndyakov/examples branch from a3add67 to c3cd920 Compare May 23, 2025 20:47
@ndyakov ndyakov changed the base branch from intro to main May 23, 2025 20:58
@ndyakov ndyakov force-pushed the ndyakov/examples branch 2 times, most recently from 237660c to ce9c51b Compare May 23, 2025 21:14
@ndyakov ndyakov force-pushed the ndyakov/examples branch from ce9c51b to a0235fb Compare May 23, 2025 21:24
@ndyakov ndyakov requested a review from Copilot May 23, 2025 21:48
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 runnable examples and test configurations for various authentication flows using Redis with Azure identity providers, aimed at helping developers validate and understand the package usage.

  • Added new examples for system-assigned managed identity, client secret, client certificate, default and custom identity providers.
  • Updated module definitions, configuration files, tests, and README to reflect the new usage patterns.

Reviewed Changes

Copilot reviewed 54 out of 54 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
examples/entraid/managedidentity_systemassigned/go.mod Module file for system-assigned managed identity example.
examples/entraid/endpoints.json New JSON config with various endpoint setups.
examples/entraid/defaultcredentials/main.go Example using default Azure credentials with token refresh testing.
examples/entraid/clientsecret/main.go Example using client secret authentication.
examples/entraid/clientcert/main.go Example using client certificate authentication and custom certificate parsing.
examples/default_azure_identity/main.go Example using default Azure identity provider.
examples/custom_idp/main.go Example demonstrating a custom identity provider.
README.md Updated documentation and example usage with revised import paths and naming.
.testcoverage.yml Updated to exclude examples from test coverage.
Other test and source files Updated import paths and references to the new module names.

Copy link

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/redis/go-redis-entraid 93.26% (+93.26%) 🌟
github.com/redis/go-redis-entraid/examples/custom_idp 0.00% (ø)
github.com/redis/go-redis-entraid/examples/default_azure_identity 0.00% (ø)
github.com/redis/go-redis-entraid/examples/entraid/clientcert 0.00% (ø)
github.com/redis/go-redis-entraid/examples/entraid/clientsecret 0.00% (ø)
github.com/redis/go-redis-entraid/examples/entraid/config 0.00% (ø)
github.com/redis/go-redis-entraid/examples/entraid/defaultcredentials 0.00% (ø)
github.com/redis/go-redis-entraid/examples/entraid/managedidentity_systemassigned 0.00% (ø)
github.com/redis/go-redis-entraid/examples/entraid/managedidentity_userassigned 0.00% (ø)
github.com/redis/go-redis-entraid/examples/entraid/runscript_test 50.00% (+50.00%) 🌟
github.com/redis/go-redis-entraid/identity 97.80% (+97.80%) 🌟
github.com/redis/go-redis-entraid/manager 98.24% (+98.24%) 🌟
github.com/redis/go-redis-entraid/shared 100.00% (+100.00%) 🌟
github.com/redis/go-redis-entraid/token 100.00% (+100.00%) 🌟

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/redis/go-redis-entraid/credentials_provider.go 90.20% (+90.20%) 51 (+51) 46 (+46) 5 (+5) 🌟
github.com/redis/go-redis-entraid/entraid.go 0.00% (ø) 0 0 0
github.com/redis/go-redis-entraid/examples/custom_idp/main.go 0.00% (ø) 0 0 0
github.com/redis/go-redis-entraid/examples/default_azure_identity/main.go 0.00% (ø) 9 (+9) 0 9 (+9)
github.com/redis/go-redis-entraid/examples/entraid/clientcert/main.go 0.00% (ø) 0 0 0
github.com/redis/go-redis-entraid/examples/entraid/clientsecret/main.go 0.00% (ø) 0 0 0
github.com/redis/go-redis-entraid/examples/entraid/config/config.go 0.00% (ø) 0 0 0
github.com/redis/go-redis-entraid/examples/entraid/defaultcredentials/main.go 0.00% (ø) 0 0 0
github.com/redis/go-redis-entraid/examples/entraid/managedidentity_systemassigned/main.go 0.00% (ø) 0 0 0
github.com/redis/go-redis-entraid/examples/entraid/managedidentity_userassigned/main.go 0.00% (ø) 0 0 0
github.com/redis/go-redis-entraid/examples/entraid/runscript_test/main.go 50.00% (+50.00%) 2 (+2) 1 (+1) 1 (+1) 🌟
github.com/redis/go-redis-entraid/identity/azure_default_identity_provider.go 100.00% (+100.00%) 14 (+14) 14 (+14) 0 🌟
github.com/redis/go-redis-entraid/identity/confidential_identity_provider.go 100.00% (+100.00%) 41 (+41) 41 (+41) 0 🌟
github.com/redis/go-redis-entraid/identity/managed_identity_provider.go 92.00% (+92.00%) 25 (+25) 23 (+23) 2 (+2) 🌟
github.com/redis/go-redis-entraid/identity/providers.go 0.00% (ø) 0 0 0
github.com/redis/go-redis-entraid/manager/defaults.go 100.00% (+100.00%) 69 (+69) 69 (+69) 0 🌟
github.com/redis/go-redis-entraid/manager/entraid_manager.go 96.81% (+96.81%) 94 (+94) 91 (+91) 3 (+3) 🌟
github.com/redis/go-redis-entraid/manager/token_manager.go 100.00% (+100.00%) 7 (+7) 7 (+7) 0 🌟
github.com/redis/go-redis-entraid/providers.go 97.06% (+97.06%) 34 (+34) 33 (+33) 1 (+1) 🌟
github.com/redis/go-redis-entraid/shared/identity_provider_response.go 100.00% (+100.00%) 1 (+1) 1 (+1) 0 🌟
github.com/redis/go-redis-entraid/token/token.go 100.00% (+100.00%) 13 (+13) 13 (+13) 0 🌟
github.com/redis/go-redis-entraid/token_listener.go 100.00% (+100.00%) 3 (+3) 3 (+3) 0 🌟

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/redis/go-redis-entraid/credentials_provider_test.go
  • github.com/redis/go-redis-entraid/entraid_test.go
  • github.com/redis/go-redis-entraid/examples/entraid/config/config_test.go
  • github.com/redis/go-redis-entraid/examples/entraid/runscript_test/main_test.go
  • github.com/redis/go-redis-entraid/identity/azure_default_identity_provider_test.go
  • github.com/redis/go-redis-entraid/identity/confidential_identity_provider_test.go
  • github.com/redis/go-redis-entraid/identity/managed_identity_provider_test.go
  • github.com/redis/go-redis-entraid/identity/providers_test.go
  • github.com/redis/go-redis-entraid/manager/manager_test.go
  • github.com/redis/go-redis-entraid/manager/token_manager_test.go
  • github.com/redis/go-redis-entraid/providers_test.go
  • github.com/redis/go-redis-entraid/shared/identity_provider_response_test.go
  • github.com/redis/go-redis-entraid/token_listener_test.go

@ndyakov ndyakov requested a review from Copilot May 27, 2025 09:19
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 a set of runnable examples demonstrating various authentication methods and configurations for testing the package with different identity providers. Key changes include:

  • New examples for system-assigned managed identity, default credentials, client secret, client certificate, and a custom identity provider.
  • Updates to go.mod files across examples and imports to reflect the new module naming convention.
  • README.md revisions and test coverage configuration adjustments to support the examples.

Reviewed Changes

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

Show a summary per file
File Description
examples/entraid/managedidentity_systemassigned/go.mod New module file for system-assigned managed identity example.
examples/entraid/endpoints.json Added endpoints configuration for various Redis setups.
examples/entraid/defaultcredentials/* Example demonstrating use of default Azure credentials for both standalone and cluster.
examples/entraid/config/* Configuration files and tests for loading and parsing endpoint and Azure settings.
examples/entraid/clientsecret/* Example using client secret authentication.
examples/entraid/clientcert/* Example using client certificate authentication with base64 decoding.
examples/default_azure_identity/main.go Example using the default Azure identity chain for authentication.
examples/custom_idp/* Example with a custom identity provider and associated fake response parser.
entraid*, credentials_provider*, README.md Package-level changes updating import paths and documentation to align with renaming.
.testcoverage.yml Updated to exclude examples from test coverage reporting.
Comments suppressed due to low confidence (2)

README.md:181

  • Ensure the label 'UserAssignedObjectID' clearly replaces the previous 'UserAssignedIdentity' terminology to avoid confusion in the examples and documentation.
C -->|No| F[UserAssignedObjectID]

.testcoverage.yml:41

  • Review whether excluding the examples folder from test coverage is intentional, as adding automated tests for example code can help ensure their continued functionality.
    - ^examples

@ndyakov ndyakov merged commit 8ff1c69 into main May 27, 2025
7 checks passed
@ndyakov ndyakov deleted the ndyakov/examples branch May 30, 2025 09:54
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