1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2024-11-24 08:52:25 +02:00

Fixed name for GoogleGroups env variable + unit tests (#2221)

* Fixed name for GoogleGroups env variable + unit tests

* Added changelog

---------

Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
This commit is contained in:
Koen van Zuijlen 2023-09-08 17:27:15 +02:00 committed by GitHub
parent 5f2f95e118
commit f3269b3f26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 3 deletions

View File

@ -7,6 +7,8 @@
## Breaking Changes ## Breaking Changes
## Changes since v7.5.0 ## Changes since v7.5.0
- [#2221](https://github.com/oauth2-proxy/oauth2-proxy/pull/2221) Backwards compatible fix for wrong environment variable name (OAUTH2_PROXY_GOOGLE_GROUPS) (@kvanzuijlen)
- [#1989](https://github.com/oauth2-proxy/oauth2-proxy/pull/1989) Fix default scope for keycloak-oidc provider - [#1989](https://github.com/oauth2-proxy/oauth2-proxy/pull/1989) Fix default scope for keycloak-oidc provider
# V7.5.0 # V7.5.0

View File

@ -3,6 +3,7 @@ package options
import ( import (
"fmt" "fmt"
"net/url" "net/url"
"reflect"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -494,7 +495,8 @@ type LegacyProvider struct {
GitHubUsers []string `flag:"github-user" cfg:"github_users"` GitHubUsers []string `flag:"github-user" cfg:"github_users"`
GitLabGroup []string `flag:"gitlab-group" cfg:"gitlab_groups"` GitLabGroup []string `flag:"gitlab-group" cfg:"gitlab_groups"`
GitLabProjects []string `flag:"gitlab-project" cfg:"gitlab_projects"` GitLabProjects []string `flag:"gitlab-project" cfg:"gitlab_projects"`
GoogleGroups []string `flag:"google-group" cfg:"google_group"` GoogleGroupsLegacy []string `flag:"google-group" cfg:"google_group"`
GoogleGroups []string `flag:"google-group" cfg:"google_groups"`
GoogleAdminEmail string `flag:"google-admin-email" cfg:"google_admin_email"` GoogleAdminEmail string `flag:"google-admin-email" cfg:"google_admin_email"`
GoogleServiceAccountJSON string `flag:"google-service-account-json" cfg:"google_service_account_json"` GoogleServiceAccountJSON string `flag:"google-service-account-json" cfg:"google_service_account_json"`
GoogleUseApplicationDefaultCredentials bool `flag:"google-use-application-default-credentials" cfg:"google_use_application_default_credentials"` GoogleUseApplicationDefaultCredentials bool `flag:"google-use-application-default-credentials" cfg:"google_use_application_default_credentials"`
@ -727,6 +729,13 @@ func (l *LegacyProvider) convert() (Providers, error) {
Repository: l.BitbucketRepository, Repository: l.BitbucketRepository,
} }
case "google": case "google":
if len(l.GoogleGroupsLegacy) != 0 && !reflect.DeepEqual(l.GoogleGroupsLegacy, l.GoogleGroups) {
// Log the deprecation notice
logger.Error(
"WARNING: The 'OAUTH2_PROXY_GOOGLE_GROUP' environment variable is deprecated and will likely be removed in the next major release. Use 'OAUTH2_PROXY_GOOGLE_GROUPS' instead.",
)
l.GoogleGroups = l.GoogleGroupsLegacy
}
provider.GoogleConfig = GoogleOptions{ provider.GoogleConfig = GoogleOptions{
Groups: l.GoogleGroups, Groups: l.GoogleGroups,
AdminEmail: l.GoogleAdminEmail, AdminEmail: l.GoogleAdminEmail,

View File

@ -991,6 +991,14 @@ var _ = Describe("Legacy Options", func() {
GoogleServiceAccountJSON: "test.json", GoogleServiceAccountJSON: "test.json",
GoogleGroups: []string{"1", "2"}, GoogleGroups: []string{"1", "2"},
} }
legacyConfigLegacyProvider := LegacyProvider{
ClientID: clientID,
ProviderType: "google",
GoogleAdminEmail: "email@email.com",
GoogleServiceAccountJSON: "test.json",
GoogleGroupsLegacy: []string{"1", "2"},
}
DescribeTable("convertLegacyProviders", DescribeTable("convertLegacyProviders",
func(in *convertProvidersTableInput) { func(in *convertProvidersTableInput) {
providers, err := in.legacyProvider.convert() providers, err := in.legacyProvider.convert()
@ -1024,6 +1032,11 @@ var _ = Describe("Legacy Options", func() {
expectedProviders: Providers{internalConfigProvider}, expectedProviders: Providers{internalConfigProvider},
errMsg: "", errMsg: "",
}), }),
Entry("with legacy provider config", &convertProvidersTableInput{
legacyProvider: legacyConfigLegacyProvider,
expectedProviders: Providers{internalConfigProvider},
errMsg: "",
}),
) )
}) })
}) })

View File

@ -43,8 +43,8 @@ func Load(configFileName string, flagSet *pflag.FlagSet, into interface{}) error
return fmt.Errorf("unable to register flags: %w", err) return fmt.Errorf("unable to register flags: %w", err)
} }
// UnmarhsalExact will return an error if the config includes options that are // UnmarshalExact will return an error if the config includes options that are
// not mapped to felds of the into struct // not mapped to fields of the into struct
err = v.UnmarshalExact(into, decodeFromCfgTag) err = v.UnmarshalExact(into, decodeFromCfgTag)
if err != nil { if err != nil {
return fmt.Errorf("error unmarshalling config: %w", err) return fmt.Errorf("error unmarshalling config: %w", err)