Skip to content

refactor: simplify provider management and add Type method#43

Merged
hrntknr merged 3 commits intomainfrom
refactor/simplify-provider-management
Aug 20, 2025
Merged

refactor: simplify provider management and add Type method#43
hrntknr merged 3 commits intomainfrom
refactor/simplify-provider-management

Conversation

@hrntknr
Copy link
Copy Markdown
Member

@hrntknr hrntknr commented Aug 20, 2025

Summary

This PR refactors the provider management system to use a simpler slice-based approach instead of a map, and adds a new Type() method to the Provider interface for better CSS styling support.

Type of Change

  • refactor: A code change that neither fixes a bug nor adds a feature

Related Issues

Changes Made

  • Changed providers from map[string]Provider to []Provider for simpler management
  • Added Type() string method to Provider interface to return CSS-friendly identifiers
  • Updated all provider implementations (GitHub, Google, OIDC, Mock) to implement Type() method
  • Simplified template data structure by removing intermediate ProviderData struct
  • Updated login.html template to use Type() for CSS classes instead of Name()
  • Added OIDC provider styling support in CSS

Benefits

  • Simpler provider management without the need for map-based lookups
  • More consistent CSS class naming for provider buttons
  • Better separation of concerns between display names and technical identifiers
  • Cleaner template code with direct provider usage

- Change providers from map to slice for simpler management
- Add Type() method to Provider interface for CSS class naming
- Update template to use provider Type() for styling instead of Name
- Simplify login template data structure
- Add OIDC provider styling support
Copilot AI review requested due to automatic review settings August 20, 2025 11:46

This comment was marked as outdated.

Update OAuth callback handler to use provider.Name() instead of loop variable providerName for consistency with provider management simplification.
@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 20, 2025

Codecov Report

❌ Patch coverage is 31.03448% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/auth/mock.go 0.00% 8 Missing ⚠️
pkg/auth/auth.go 60.00% 5 Missing and 1 partial ⚠️
pkg/auth/github.go 0.00% 2 Missing ⚠️
pkg/auth/google.go 0.00% 2 Missing ⚠️
pkg/auth/oidc.go 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@hrntknr hrntknr requested a review from Copilot August 20, 2025 11:51
Copy link
Copy Markdown
Contributor

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 refactors the authentication provider management system by simplifying the data structure from map-based to slice-based storage and introducing a new Type() method for better CSS styling support. The changes improve code maintainability while adding styling support for OIDC providers.

Key changes:

  • Replaced map[string]Provider with []Provider for simpler provider management
  • Added Type() method to Provider interface returning CSS-friendly identifiers
  • Updated HTML template to use Type() for CSS classes and direct provider properties

Reviewed Changes

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

Show a summary per file
File Description
pkg/auth/interface.go Added Type() method to Provider interface
pkg/auth/github.go Implemented Type() method returning "github"
pkg/auth/google.go Implemented Type() method returning "google"
pkg/auth/oidc.go Implemented Type() method returning "oidc"
pkg/auth/mock.go Added Type() method to mock provider
pkg/auth/auth.go Refactored from map to slice-based provider storage and simplified template data
pkg/auth/templates/login.html Updated CSS classes to lowercase and template to use Type() and AuthURL()

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread pkg/auth/auth.go
for _, provider := range a.providers {
if provider.Name() == name {
return provider
}
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

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

The getProvider method performs a linear search through the providers slice. For applications with many providers, this could impact performance. Consider adding an index or maintaining a map alongside the slice if provider lookups are frequent.

Suggested change
}
if provider, ok := a.providerMap[name]; ok {
return provider

Copilot uses AI. Check for mistakes.
Add gofmt format checking to ensure consistent code formatting
@hrntknr hrntknr merged commit 64e643b into main Aug 20, 2025
7 checks passed
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