git.iko.soy/typeable/oauth2-proxy
on master help sign in
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>

commitf3269b3f260b6af1f584cf9ff8a28d802eb71751 authorKoen van Zuijlen <8818390+kvanzuijlen@users.noreply.github.com> dateFri 8 Sep 2023, 17:27 (3 years ago) parent5f2f95e
4 files changed+27−3
CHANGELOG.md+2 pkg/apis/options/legacy_options.go+10−1 pkg/apis/options/legacy_options_test.go+13 pkg/apis/options/load.go+2−2
CHANGELOG.md+2
@@ -7,6 +7,8 @@
77## Breaking Changes
88
99## Changes since v7.5.0
10+
11+- [#2221](https://github.com/oauth2-proxy/oauth2-proxy/pull/2221) Backwards compatible fix for wrong environment variable name (OAUTH2_PROXY_GOOGLE_GROUPS) (@kvanzuijlen)
1012- [#1989](https://github.com/oauth2-proxy/oauth2-proxy/pull/1989) Fix default scope for keycloak-oidc provider
1113
1214# V7.5.0
pkg/apis/options/legacy_options.go+10−1
@@ -3,6 +3,7 @@ package options
33import (
44 "fmt"
55 "net/url"
6+ "reflect"
67 "strconv"
78 "strings"
89 "time"
@@ -494,7 +495,8 @@ type LegacyProvider struct {
494495 GitHubUsers []string `flag:"github-user" cfg:"github_users"`
495496 GitLabGroup []string `flag:"gitlab-group" cfg:"gitlab_groups"`
496497 GitLabProjects []string `flag:"gitlab-project" cfg:"gitlab_projects"`
497− GoogleGroups []string `flag:"google-group" cfg:"google_group"`
498+ GoogleGroupsLegacy []string `flag:"google-group" cfg:"google_group"`
499+ GoogleGroups []string `flag:"google-group" cfg:"google_groups"`
498500 GoogleAdminEmail string `flag:"google-admin-email" cfg:"google_admin_email"`
499501 GoogleServiceAccountJSON string `flag:"google-service-account-json" cfg:"google_service_account_json"`
500502 GoogleUseApplicationDefaultCredentials bool `flag:"google-use-application-default-credentials" cfg:"google_use_application_default_credentials"`
@@ -727,6 +729,13 @@ func (l *LegacyProvider) convert() (Providers, error) {
727729 Repository: l.BitbucketRepository,
728730 }
729731 case "google":
732+ if len(l.GoogleGroupsLegacy) != 0 && !reflect.DeepEqual(l.GoogleGroupsLegacy, l.GoogleGroups) {
733+ // Log the deprecation notice
734+ logger.Error(
735+ "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.",
736+ )
737+ l.GoogleGroups = l.GoogleGroupsLegacy
738+ }
730739 provider.GoogleConfig = GoogleOptions{
731740 Groups: l.GoogleGroups,
732741 AdminEmail: l.GoogleAdminEmail,
pkg/apis/options/legacy_options_test.go+13
@@ -991,6 +991,14 @@ var _ = Describe("Legacy Options", func() {
991991 GoogleServiceAccountJSON: "test.json",
992992 GoogleGroups: []string{"1", "2"},
993993 }
994+
995+ legacyConfigLegacyProvider := LegacyProvider{
996+ ClientID: clientID,
997+ ProviderType: "google",
998+ GoogleAdminEmail: "email@email.com",
999+ GoogleServiceAccountJSON: "test.json",
1000+ GoogleGroupsLegacy: []string{"1", "2"},
1001+ }
9941002 DescribeTable("convertLegacyProviders",
9951003 func(in *convertProvidersTableInput) {
9961004 providers, err := in.legacyProvider.convert()
@@ -1024,6 +1032,11 @@ var _ = Describe("Legacy Options", func() {
10241032 expectedProviders: Providers{internalConfigProvider},
10251033 errMsg: "",
10261034 }),
1035+ Entry("with legacy provider config", &convertProvidersTableInput{
1036+ legacyProvider: legacyConfigLegacyProvider,
1037+ expectedProviders: Providers{internalConfigProvider},
1038+ errMsg: "",
1039+ }),
10271040 )
10281041 })
10291042})
pkg/apis/options/load.go+2−2
@@ -43,8 +43,8 @@ func Load(configFileName string, flagSet *pflag.FlagSet, into interface{}) error
4343 return fmt.Errorf("unable to register flags: %w", err)
4444 }
4545
46− // UnmarhsalExact will return an error if the config includes options that are
47− // not mapped to felds of the into struct
46+ // UnmarshalExact will return an error if the config includes options that are
47+ // not mapped to fields of the into struct
4848 err = v.UnmarshalExact(into, decodeFromCfgTag)
4949 if err != nil {
5050 return fmt.Errorf("error unmarshalling config: %w", err)