refactor: ptr.Ptr to ptr.To

Signed-off-by: Jan Larwig <jan@larwig.com>
This commit is contained in:
Jan Larwig 2025-11-16 22:04:22 +01:00
parent 137decb1ec
commit 0eec65e230
No known key found for this signature in database
GPG Key ID: C2172BFA220A037A
18 changed files with 149 additions and 152 deletions

View File

@ -123,26 +123,26 @@ redirect_url="http://localhost:4180/oauth2/callback"
opts.RawRedirectURL = "http://localhost:4180/oauth2/callback"
opts.UpstreamServers = options.UpstreamConfig{
ProxyRawPath: ptr.Ptr(false),
ProxyRawPath: ptr.To(false),
Upstreams: []options.Upstream{
{
ID: "/",
Path: "/",
URI: "http://httpbin",
FlushInterval: ptr.Ptr(options.DefaultUpstreamFlushInterval),
PassHostHeader: ptr.Ptr(true),
ProxyWebSockets: ptr.Ptr(true),
Timeout: ptr.Ptr(options.DefaultUpstreamTimeout),
Static: ptr.Ptr(false),
InsecureSkipTLSVerify: ptr.Ptr(false),
DisableKeepAlives: ptr.Ptr(false),
FlushInterval: ptr.To(options.DefaultUpstreamFlushInterval),
PassHostHeader: ptr.To(true),
ProxyWebSockets: ptr.To(true),
Timeout: ptr.To(options.DefaultUpstreamTimeout),
Static: ptr.To(false),
InsecureSkipTLSVerify: ptr.To(false),
DisableKeepAlives: ptr.To(false),
},
},
}
authHeader := options.Header{
Name: "Authorization",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []options.HeaderValue{
{
ClaimSource: &options.ClaimSource{
@ -165,11 +165,11 @@ redirect_url="http://localhost:4180/oauth2/callback"
Type: "google",
ClientSecret: "b2F1dGgyLXByb3h5LWNsaWVudC1zZWNyZXQK",
ClientID: "oauth2-proxy",
UseSystemTrustStore: ptr.Ptr(false),
SkipClaimsFromProfileURL: ptr.Ptr(false),
UseSystemTrustStore: ptr.To(false),
SkipClaimsFromProfileURL: ptr.To(false),
GoogleConfig: options.GoogleOptions{
AdminEmail: "admin@example.com",
UseApplicationDefaultCredentials: ptr.Ptr(false),
UseApplicationDefaultCredentials: ptr.To(false),
TargetPrincipal: "principal",
},
AzureConfig: options.AzureOptions{
@ -181,16 +181,16 @@ redirect_url="http://localhost:4180/oauth2/callback"
UserIDClaim: "email",
AudienceClaims: []string{"aud"},
ExtraAudiences: []string{},
InsecureSkipNonce: ptr.Ptr(true),
InsecureAllowUnverifiedEmail: ptr.Ptr(false),
InsecureSkipIssuerVerification: ptr.Ptr(false),
SkipDiscovery: ptr.Ptr(false),
InsecureSkipNonce: ptr.To(true),
InsecureAllowUnverifiedEmail: ptr.To(false),
InsecureSkipIssuerVerification: ptr.To(false),
SkipDiscovery: ptr.To(false),
},
MicrosoftEntraIDConfig: options.MicrosoftEntraIDOptions{
FederatedTokenAuth: ptr.Ptr(false),
FederatedTokenAuth: ptr.To(false),
},
ADFSConfig: options.ADFSOptions{
SkipScope: ptr.Ptr(false),
SkipScope: ptr.To(false),
},
LoginURLParameters: []options.LoginURLParameter{
{Name: "approval_prompt", Default: []string{"force"}},

View File

@ -507,7 +507,7 @@ func TestStaticProxyUpstream(t *testing.T) {
ProxyUpstream: options.Upstream{
ID: "static-proxy",
Path: "/static-proxy",
Static: ptr.Ptr(true),
Static: ptr.To(true),
},
})
if err != nil {
@ -2224,7 +2224,7 @@ func TestTrustedIPs(t *testing.T) {
{
ID: "static",
Path: "/",
Static: ptr.Ptr(true),
Static: ptr.To(true),
},
},
}

View File

@ -64,7 +64,7 @@ type ClaimSource struct {
// EnsureDefaults sets any default values for Header fields.
func (h *Header) EnsureDefaults() {
if h.PreserveRequestValue == nil {
h.PreserveRequestValue = ptr.Ptr(DefaultHeaderPreserveRequestValue)
h.PreserveRequestValue = ptr.To(DefaultHeaderPreserveRequestValue)
}
for i := range h.Values {
h.Values[i].EnsureDefaults()

View File

@ -166,7 +166,7 @@ func (l *LegacyUpstreams) convert() (UpstreamConfig, error) {
logger.Errorf("unable to convert %q to int, use default \"200\"", u.Host)
responseCode = 200
}
upstream.Static = ptr.Ptr(true)
upstream.Static = ptr.To(true)
upstream.StaticCode = &responseCode
// This is not allowed to be empty and must be unique
@ -177,8 +177,8 @@ func (l *LegacyUpstreams) convert() (UpstreamConfig, error) {
// Force defaults compatible with static responses
upstream.URI = ""
upstream.InsecureSkipTLSVerify = ptr.Ptr(false)
upstream.DisableKeepAlives = ptr.Ptr(false)
upstream.InsecureSkipTLSVerify = ptr.To(false)
upstream.DisableKeepAlives = ptr.To(false)
upstream.PassHostHeader = nil
upstream.ProxyWebSockets = nil
upstream.FlushInterval = nil
@ -255,7 +255,7 @@ func (l *LegacyHeaders) getRequestHeaders() []Header {
}
for i := range requestHeaders {
requestHeaders[i].PreserveRequestValue = ptr.Ptr(!l.SkipAuthStripHeaders)
requestHeaders[i].PreserveRequestValue = ptr.To(!l.SkipAuthStripHeaders)
}
return requestHeaders
@ -290,7 +290,7 @@ func getBasicAuthHeader(preferEmailToUser bool, basicAuthPassword string) Header
return Header{
Name: "Authorization",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -309,7 +309,7 @@ func getPassUserHeaders(preferEmailToUser bool) []Header {
headers := []Header{
{
Name: "X-Forwarded-Groups",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -324,7 +324,7 @@ func getPassUserHeaders(preferEmailToUser bool) []Header {
return append(headers,
Header{
Name: "X-Forwarded-User",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -339,7 +339,7 @@ func getPassUserHeaders(preferEmailToUser bool) []Header {
return append(headers,
Header{
Name: "X-Forwarded-User",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -350,7 +350,7 @@ func getPassUserHeaders(preferEmailToUser bool) []Header {
},
Header{
Name: "X-Forwarded-Email",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -365,7 +365,7 @@ func getPassUserHeaders(preferEmailToUser bool) []Header {
func getPassAccessTokenHeader() Header {
return Header{
Name: "X-Forwarded-Access-Token",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -379,7 +379,7 @@ func getPassAccessTokenHeader() Header {
func getAuthorizationHeader() Header {
return Header{
Name: "Authorization",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -394,7 +394,7 @@ func getAuthorizationHeader() Header {
func getPreferredUsernameHeader() Header {
return Header{
Name: "X-Forwarded-Preferred-Username",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -409,7 +409,7 @@ func getXAuthRequestHeaders() []Header {
headers := []Header{
{
Name: "X-Auth-Request-User",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -420,7 +420,7 @@ func getXAuthRequestHeaders() []Header {
},
{
Name: "X-Auth-Request-Email",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -431,7 +431,7 @@ func getXAuthRequestHeaders() []Header {
},
{
Name: "X-Auth-Request-Preferred-Username",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -442,7 +442,7 @@ func getXAuthRequestHeaders() []Header {
},
{
Name: "X-Auth-Request-Groups",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -459,7 +459,7 @@ func getXAuthRequestHeaders() []Header {
func getXAuthRequestAccessTokenHeader() Header {
return Header{
Name: "X-Auth-Request-Access-Token",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{

View File

@ -36,9 +36,9 @@ var _ = Describe("Legacy Options", func() {
Path: "/baz",
URI: "http://foo.bar/baz",
FlushInterval: &flushInterval,
InsecureSkipTLSVerify: ptr.Ptr(true),
PassHostHeader: ptr.Ptr(true),
ProxyWebSockets: ptr.Ptr(true),
InsecureSkipTLSVerify: ptr.To(true),
PassHostHeader: ptr.To(true),
ProxyWebSockets: ptr.To(true),
Timeout: &timeout,
DisableKeepAlives: &legacyOpts.LegacyUpstreams.DisableKeepAlives,
},
@ -47,9 +47,9 @@ var _ = Describe("Legacy Options", func() {
Path: "/bar",
URI: "file:///var/lib/website",
FlushInterval: &flushInterval,
InsecureSkipTLSVerify: ptr.Ptr(true),
PassHostHeader: ptr.Ptr(true),
ProxyWebSockets: ptr.Ptr(true),
InsecureSkipTLSVerify: ptr.To(true),
PassHostHeader: ptr.To(true),
ProxyWebSockets: ptr.To(true),
Timeout: &timeout,
DisableKeepAlives: &legacyOpts.LegacyUpstreams.DisableKeepAlives,
},
@ -57,10 +57,10 @@ var _ = Describe("Legacy Options", func() {
ID: "static://204",
Path: "/",
URI: "",
Static: ptr.Ptr(true),
Static: ptr.To(true),
StaticCode: &staticCode,
FlushInterval: nil,
InsecureSkipTLSVerify: ptr.Ptr(false),
InsecureSkipTLSVerify: ptr.To(false),
PassHostHeader: nil,
ProxyWebSockets: nil,
Timeout: nil,
@ -72,7 +72,7 @@ var _ = Describe("Legacy Options", func() {
opts.InjectRequestHeaders = []Header{
{
Name: "X-Forwarded-Groups",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -83,7 +83,7 @@ var _ = Describe("Legacy Options", func() {
},
{
Name: "X-Forwarded-User",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -94,7 +94,7 @@ var _ = Describe("Legacy Options", func() {
},
{
Name: "X-Forwarded-Email",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -105,7 +105,7 @@ var _ = Describe("Legacy Options", func() {
},
{
Name: "X-Forwarded-Preferred-Username",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -126,8 +126,8 @@ var _ = Describe("Legacy Options", func() {
opts.Providers[0].ClientID = "oauth-proxy"
opts.Providers[0].OIDCConfig.AudienceClaims = []string{"aud"}
opts.Providers[0].OIDCConfig.ExtraAudiences = []string{}
opts.Providers[0].OIDCConfig.InsecureSkipNonce = ptr.Ptr(true)
opts.Providers[0].OIDCConfig.InsecureSkipIssuerVerification = ptr.Ptr(false)
opts.Providers[0].OIDCConfig.InsecureSkipNonce = ptr.To(true)
opts.Providers[0].OIDCConfig.InsecureSkipIssuerVerification = ptr.To(false)
opts.Providers[0].LoginURLParameters = []LoginURLParameter{
{Name: "approval_prompt", Default: []string{"force"}},
}
@ -202,14 +202,14 @@ var _ = Describe("Legacy Options", func() {
ID: validStatic,
Path: "/",
URI: "",
Static: ptr.Ptr(true),
Static: ptr.To(true),
StaticCode: &validStaticCode,
InsecureSkipTLSVerify: ptr.Ptr(false),
InsecureSkipTLSVerify: ptr.To(false),
PassHostHeader: nil,
ProxyWebSockets: nil,
FlushInterval: nil,
Timeout: nil,
DisableKeepAlives: ptr.Ptr(false),
DisableKeepAlives: ptr.To(false),
}
invalidStatic := "static://abc"
@ -218,14 +218,14 @@ var _ = Describe("Legacy Options", func() {
ID: invalidStatic,
Path: "/",
URI: "",
Static: ptr.Ptr(true),
Static: ptr.To(true),
StaticCode: &invalidStaticCode,
InsecureSkipTLSVerify: ptr.Ptr(false),
InsecureSkipTLSVerify: ptr.To(false),
PassHostHeader: nil,
ProxyWebSockets: nil,
FlushInterval: nil,
Timeout: nil,
DisableKeepAlives: ptr.Ptr(false),
DisableKeepAlives: ptr.To(false),
}
invalidHTTP := ":foo"
@ -318,7 +318,7 @@ var _ = Describe("Legacy Options", func() {
xForwardedUser := Header{
Name: "X-Forwarded-User",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -330,7 +330,7 @@ var _ = Describe("Legacy Options", func() {
xForwardedEmail := Header{
Name: "X-Forwarded-Email",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -342,7 +342,7 @@ var _ = Describe("Legacy Options", func() {
xForwardedGroups := Header{
Name: "X-Forwarded-Groups",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -354,7 +354,7 @@ var _ = Describe("Legacy Options", func() {
xForwardedPreferredUsername := Header{
Name: "X-Forwarded-Preferred-Username",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -366,7 +366,7 @@ var _ = Describe("Legacy Options", func() {
basicAuthHeader := Header{
Name: "Authorization",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -382,7 +382,7 @@ var _ = Describe("Legacy Options", func() {
xForwardedUserWithEmail := Header{
Name: "X-Forwarded-User",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -394,7 +394,7 @@ var _ = Describe("Legacy Options", func() {
xForwardedAccessToken := Header{
Name: "X-Forwarded-Access-Token",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -406,7 +406,7 @@ var _ = Describe("Legacy Options", func() {
basicAuthHeaderWithEmail := Header{
Name: "Authorization",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -422,7 +422,7 @@ var _ = Describe("Legacy Options", func() {
xAuthRequestUser := Header{
Name: "X-Auth-Request-User",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -434,7 +434,7 @@ var _ = Describe("Legacy Options", func() {
xAuthRequestEmail := Header{
Name: "X-Auth-Request-Email",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -446,7 +446,7 @@ var _ = Describe("Legacy Options", func() {
xAuthRequestGroups := Header{
Name: "X-Auth-Request-Groups",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -458,7 +458,7 @@ var _ = Describe("Legacy Options", func() {
xAuthRequestPreferredUsername := Header{
Name: "X-Auth-Request-Preferred-Username",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -470,7 +470,7 @@ var _ = Describe("Legacy Options", func() {
xAuthRequestAccessToken := Header{
Name: "X-Auth-Request-Access-Token",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -482,7 +482,7 @@ var _ = Describe("Legacy Options", func() {
authorizationHeader := Header{
Name: "Authorization",
PreserveRequestValue: ptr.Ptr(false),
PreserveRequestValue: ptr.To(false),
Values: []HeaderValue{
{
ClaimSource: &ClaimSource{
@ -948,14 +948,14 @@ var _ = Describe("Legacy Options", func() {
}
defaultOIDCOptions := OIDCOptions{
SkipDiscovery: ptr.Ptr(false),
InsecureSkipNonce: ptr.Ptr(false),
InsecureAllowUnverifiedEmail: ptr.Ptr(false),
InsecureSkipIssuerVerification: ptr.Ptr(false),
SkipDiscovery: ptr.To(false),
InsecureSkipNonce: ptr.To(false),
InsecureAllowUnverifiedEmail: ptr.To(false),
InsecureSkipIssuerVerification: ptr.To(false),
}
defaultGoogleOptions := GoogleOptions{
UseApplicationDefaultCredentials: ptr.Ptr(false),
UseApplicationDefaultCredentials: ptr.To(false),
}
defaultLegacyProvider := LegacyProvider{
@ -970,8 +970,8 @@ var _ = Describe("Legacy Options", func() {
OIDCConfig: defaultOIDCOptions,
GoogleConfig: defaultGoogleOptions,
LoginURLParameters: defaultURLParams,
UseSystemTrustStore: ptr.Ptr(false),
SkipClaimsFromProfileURL: ptr.Ptr(false),
UseSystemTrustStore: ptr.To(false),
SkipClaimsFromProfileURL: ptr.To(false),
}
defaultLegacyProviderWithPrompt := LegacyProvider{
@ -989,8 +989,8 @@ var _ = Describe("Legacy Options", func() {
LoginURLParameters: []LoginURLParameter{
{Name: "prompt", Default: []string{"switch_user"}},
},
UseSystemTrustStore: ptr.Ptr(false),
SkipClaimsFromProfileURL: ptr.Ptr(false),
UseSystemTrustStore: ptr.To(false),
SkipClaimsFromProfileURL: ptr.To(false),
}
displayNameLegacyProvider := LegacyProvider{
@ -1007,8 +1007,8 @@ var _ = Describe("Legacy Options", func() {
OIDCConfig: defaultOIDCOptions,
GoogleConfig: defaultGoogleOptions,
LoginURLParameters: defaultURLParams,
UseSystemTrustStore: ptr.Ptr(false),
SkipClaimsFromProfileURL: ptr.Ptr(false),
UseSystemTrustStore: ptr.To(false),
SkipClaimsFromProfileURL: ptr.To(false),
}
internalConfigProvider := Provider{
@ -1020,11 +1020,11 @@ var _ = Describe("Legacy Options", func() {
AdminEmail: "email@email.com",
ServiceAccountJSON: "test.json",
Groups: []string{"1", "2"},
UseApplicationDefaultCredentials: ptr.Ptr(false),
UseApplicationDefaultCredentials: ptr.To(false),
},
LoginURLParameters: defaultURLParams,
UseSystemTrustStore: ptr.Ptr(false),
SkipClaimsFromProfileURL: ptr.Ptr(false),
UseSystemTrustStore: ptr.To(false),
SkipClaimsFromProfileURL: ptr.To(false),
}
internalConfigLegacyProvider := LegacyProvider{

View File

@ -334,9 +334,9 @@ func providerDefaults() Providers {
Tenant: "common",
},
OIDCConfig: OIDCOptions{
InsecureAllowUnverifiedEmail: ptr.Ptr(DefaultInsecureAllowUnverifiedEmail),
InsecureSkipNonce: ptr.Ptr(DefaultInsecureSkipNonce),
SkipDiscovery: ptr.Ptr(DefaultSkipDiscovery),
InsecureAllowUnverifiedEmail: ptr.To(DefaultInsecureAllowUnverifiedEmail),
InsecureSkipNonce: ptr.To(DefaultInsecureSkipNonce),
SkipDiscovery: ptr.To(DefaultSkipDiscovery),
UserIDClaim: OIDCEmailClaim, // Deprecated: Use OIDCEmailClaim
EmailClaim: OIDCEmailClaim,
GroupsClaim: OIDCGroupsClaim,
@ -358,10 +358,10 @@ func (p Providers) EnsureDefaults() {
// EnsureDefaults sets any default values for Provider fields.
func (p *Provider) EnsureDefaults() {
if p.SkipClaimsFromProfileURL == nil {
p.SkipClaimsFromProfileURL = ptr.Ptr(DefaultSkipClaimsFromProfileURL)
p.SkipClaimsFromProfileURL = ptr.To(DefaultSkipClaimsFromProfileURL)
}
if p.UseSystemTrustStore == nil {
p.UseSystemTrustStore = ptr.Ptr(DefaultUseSystemTrustStore)
p.UseSystemTrustStore = ptr.To(DefaultUseSystemTrustStore)
}
p.OIDCConfig.EnsureDefaults()
@ -374,13 +374,13 @@ func (p *Provider) EnsureDefaults() {
func (o *OIDCOptions) EnsureDefaults() {
// Ensure OIDC defaults
if o.InsecureAllowUnverifiedEmail == nil {
o.InsecureAllowUnverifiedEmail = ptr.Ptr(DefaultInsecureAllowUnverifiedEmail)
o.InsecureAllowUnverifiedEmail = ptr.To(DefaultInsecureAllowUnverifiedEmail)
}
if o.InsecureSkipNonce == nil {
o.InsecureSkipNonce = ptr.Ptr(DefaultInsecureSkipNonce)
o.InsecureSkipNonce = ptr.To(DefaultInsecureSkipNonce)
}
if o.SkipDiscovery == nil {
o.SkipDiscovery = ptr.Ptr(DefaultSkipDiscovery)
o.SkipDiscovery = ptr.To(DefaultSkipDiscovery)
}
if o.UserIDClaim == "" {
o.UserIDClaim = OIDCEmailClaim
@ -399,20 +399,20 @@ func (o *OIDCOptions) EnsureDefaults() {
// EnsureDefaults sets any default values for MicrosoftEntraIDOptions fields.
func (me *MicrosoftEntraIDOptions) EnsureDefaults() {
if me.FederatedTokenAuth == nil {
me.FederatedTokenAuth = ptr.Ptr(DefaultMicrosoftEntraIDUseFederatedToken)
me.FederatedTokenAuth = ptr.To(DefaultMicrosoftEntraIDUseFederatedToken)
}
}
// EnsureDefaults sets any default values for ADFSOptions fields.
func (a *ADFSOptions) EnsureDefaults() {
if a.SkipScope == nil {
a.SkipScope = ptr.Ptr(DefaultADFSSkipScope)
a.SkipScope = ptr.To(DefaultADFSSkipScope)
}
}
// EnsureDefaults sets any default values for GoogleOptions fields.
func (g *GoogleOptions) EnsureDefaults() {
if g.UseApplicationDefaultCredentials == nil {
g.UseApplicationDefaultCredentials = ptr.Ptr(DefaultUseApplicationDefaultCredentials)
g.UseApplicationDefaultCredentials = ptr.To(DefaultUseApplicationDefaultCredentials)
}
}

View File

@ -128,7 +128,7 @@ type Upstream struct {
// EnsureDefaults sets any default values for UpstreamConfig fields.
func (uc *UpstreamConfig) EnsureDefaults() {
if uc.ProxyRawPath == nil {
uc.ProxyRawPath = ptr.Ptr(DefaultUpstreamProxyRawPath)
uc.ProxyRawPath = ptr.To(DefaultUpstreamProxyRawPath)
}
for i := range uc.Upstreams {
uc.Upstreams[i].EnsureDefaults()
@ -138,24 +138,24 @@ func (uc *UpstreamConfig) EnsureDefaults() {
// EnsureDefaults sets any default values for Upstream fields.
func (u *Upstream) EnsureDefaults() {
if u.InsecureSkipTLSVerify == nil {
u.InsecureSkipTLSVerify = ptr.Ptr(DefaultUpsteamInsecureSkipTLSVerify)
u.InsecureSkipTLSVerify = ptr.To(DefaultUpsteamInsecureSkipTLSVerify)
}
if u.Static == nil {
u.Static = ptr.Ptr(DefaultUpstreamStatic)
u.Static = ptr.To(DefaultUpstreamStatic)
}
if u.FlushInterval == nil {
u.FlushInterval = ptr.Ptr(DefaultUpstreamFlushInterval)
u.FlushInterval = ptr.To(DefaultUpstreamFlushInterval)
}
if u.PassHostHeader == nil {
u.PassHostHeader = ptr.Ptr(DefaultUpstreamPassHostHeader)
u.PassHostHeader = ptr.To(DefaultUpstreamPassHostHeader)
}
if u.ProxyWebSockets == nil {
u.ProxyWebSockets = ptr.Ptr(DefaultUpstreamProxyWebSockets)
u.ProxyWebSockets = ptr.To(DefaultUpstreamProxyWebSockets)
}
if u.Timeout == nil {
u.Timeout = ptr.Ptr(DefaultUpstreamTimeout)
u.Timeout = ptr.To(DefaultUpstreamTimeout)
}
if u.DisableKeepAlives == nil {
u.DisableKeepAlives = ptr.Ptr(DefaultUpstreamDisableKeepAlives)
u.DisableKeepAlives = ptr.To(DefaultUpstreamDisableKeepAlives)
}
}

View File

@ -8,15 +8,12 @@ import (
"time"
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/encryption"
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/util/ptr"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func timePtr(t time.Time) *time.Time {
return &t
}
func TestCreatedAtNow(t *testing.T) {
g := NewWithT(t)
ss := &SessionState{}
@ -137,10 +134,10 @@ func TestString(t *testing.T) {
}
func TestIsExpired(t *testing.T) {
s := &SessionState{ExpiresOn: timePtr(time.Now().Add(time.Duration(-1) * time.Minute))}
s := &SessionState{ExpiresOn: ptr.To(time.Now().Add(time.Duration(-1) * time.Minute))}
assert.Equal(t, true, s.IsExpired())
s = &SessionState{ExpiresOn: timePtr(time.Now().Add(time.Duration(1) * time.Minute))}
s = &SessionState{ExpiresOn: ptr.To(time.Now().Add(time.Duration(1) * time.Minute))}
assert.Equal(t, false, s.IsExpired())
s = &SessionState{}
@ -154,7 +151,7 @@ func TestAge(t *testing.T) {
assert.Equal(t, time.Duration(0), ss.Age())
// Set CreatedAt to 1 hour ago
ss.CreatedAt = timePtr(time.Now().Add(-1 * time.Hour))
ss.CreatedAt = ptr.To(time.Now().Add(-1 * time.Hour))
assert.Equal(t, time.Hour, ss.Age().Round(time.Minute))
}

View File

@ -116,7 +116,7 @@ var _ = Describe("Headers Suite", func() {
headers: []options.Header{
{
Name: "Claim",
PreserveRequestValue: ptr.Ptr(true),
PreserveRequestValue: ptr.To(true),
Values: []options.HeaderValue{
{
ClaimSource: &options.ClaimSource{
@ -161,7 +161,7 @@ var _ = Describe("Headers Suite", func() {
headers: []options.Header{
{
Name: "Claim",
PreserveRequestValue: ptr.Ptr(true),
PreserveRequestValue: ptr.To(true),
Values: []options.HeaderValue{
{
ClaimSource: &options.ClaimSource{
@ -386,7 +386,7 @@ var _ = Describe("Headers Suite", func() {
headers: []options.Header{
{
Name: "Claim",
PreserveRequestValue: ptr.Ptr(true),
PreserveRequestValue: ptr.To(true),
Values: []options.HeaderValue{
{
ClaimSource: &options.ClaimSource{
@ -433,7 +433,7 @@ var _ = Describe("Headers Suite", func() {
headers: []options.Header{
{
Name: "Claim",
PreserveRequestValue: ptr.Ptr(true),
PreserveRequestValue: ptr.To(true),
Values: []options.HeaderValue{
{
ClaimSource: &options.ClaimSource{

View File

@ -63,8 +63,8 @@ var _ = Describe("HTTP Upstream Suite", func() {
upstream := options.Upstream{
ID: in.id,
PassHostHeader: &in.passUpstreamHostHeader,
ProxyWebSockets: ptr.Ptr(false),
InsecureSkipTLSVerify: ptr.Ptr(false),
ProxyWebSockets: ptr.To(false),
InsecureSkipTLSVerify: ptr.To(false),
FlushInterval: &flush,
Timeout: &timeout,
}
@ -342,9 +342,9 @@ var _ = Describe("HTTP Upstream Suite", func() {
upstream := options.Upstream{
ID: "noPassHost",
PassHostHeader: ptr.Ptr(false),
ProxyWebSockets: ptr.Ptr(false),
InsecureSkipTLSVerify: ptr.Ptr(false),
PassHostHeader: ptr.To(false),
ProxyWebSockets: ptr.To(false),
InsecureSkipTLSVerify: ptr.To(false),
FlushInterval: &defaultFlushInterval,
Timeout: &defaultTimeout,
}
@ -486,9 +486,9 @@ var _ = Describe("HTTP Upstream Suite", func() {
timeout := options.DefaultUpstreamTimeout
upstream := options.Upstream{
ID: "websocketProxy",
PassHostHeader: ptr.Ptr(true),
ProxyWebSockets: ptr.Ptr(true),
InsecureSkipTLSVerify: ptr.Ptr(false),
PassHostHeader: ptr.To(true),
ProxyWebSockets: ptr.To(true),
InsecureSkipTLSVerify: ptr.To(false),
FlushInterval: &flush,
Timeout: &timeout,
}

View File

@ -61,19 +61,19 @@ var _ = Describe("Proxy Suite", func() {
{
ID: "static-backend",
Path: "/static/",
Static: ptr.Ptr(true),
Static: ptr.To(true),
StaticCode: &ok,
},
{
ID: "static-backend-no-trailing-slash",
Path: "/static",
Static: ptr.Ptr(true),
Static: ptr.To(true),
StaticCode: &accepted,
},
{
ID: "static-backend-long",
Path: "/static/long",
Static: ptr.Ptr(true),
Static: ptr.To(true),
StaticCode: &accepted,
},
{
@ -84,7 +84,7 @@ var _ = Describe("Proxy Suite", func() {
{
ID: "single-path-backend",
Path: "/single-path",
Static: ptr.Ptr(true),
Static: ptr.To(true),
StaticCode: &ok,
},
{
@ -347,7 +347,7 @@ var _ = Describe("Proxy Suite", func() {
upstream: "",
}),
Entry("containing an escaped '/' with ProxyRawPath", &proxyTableInput{
upstreams: options.UpstreamConfig{ProxyRawPath: ptr.Ptr(true)},
upstreams: options.UpstreamConfig{ProxyRawPath: ptr.To(true)},
target: "http://example.localhost/%2F/test1/%2F/test2",
response: testHTTPResponse{
code: 404,

View File

@ -1,7 +1,7 @@
package ptr
// Ptr generically returns a pointer to the given value.
func Ptr[T any](v T) *T {
// To generically returns a pointer to the given value.
func To[T any](v T) *T {
return &v
}

View File

@ -6,22 +6,22 @@ import (
"github.com/stretchr/testify/assert"
)
func TestPtr(t *testing.T) {
p := Ptr(42)
func TestTo(t *testing.T) {
p := To(42)
assert.NotNil(t, p)
assert.Equal(t, 42, *p)
s := Ptr("hello")
s := To("hello")
assert.NotNil(t, s)
assert.Equal(t, "hello", *s)
b := Ptr(true)
b := To(true)
assert.NotNil(t, b)
assert.True(t, *b)
}
func TestDeref(t *testing.T) {
v := Deref(Ptr(99), 0)
v := Deref(To(99), 0)
assert.Equal(t, 99, v)
v = Deref[int](nil, 123)
@ -30,7 +30,7 @@ func TestDeref(t *testing.T) {
s := Deref[string](nil, "default")
assert.Equal(t, "default", s)
b := Deref(Ptr(true), false)
b := Deref(To(true), false)
assert.True(t, b)
b = Deref[bool](nil, false)

View File

@ -69,7 +69,7 @@ func TestGoogleGroupOptionsWithoutServiceAccountJSON(t *testing.T) {
func TestGoogleGroupOptionsWithoutAdminEmail(t *testing.T) {
o := testOptions()
o.Providers[0].GoogleConfig.UseApplicationDefaultCredentials = ptr.Ptr(true)
o.Providers[0].GoogleConfig.UseApplicationDefaultCredentials = ptr.To(true)
err := Validate(o)
assert.NotEqual(t, nil, err)
@ -82,7 +82,7 @@ func TestGoogleGroupOptionsWithoutGroups(t *testing.T) {
o := testOptions()
// Set admin email and application default credentials but no groups - should still require them
o.Providers[0].GoogleConfig.AdminEmail = "admin@example.com"
o.Providers[0].GoogleConfig.UseApplicationDefaultCredentials = ptr.Ptr(true)
o.Providers[0].GoogleConfig.UseApplicationDefaultCredentials = ptr.To(true)
err := Validate(o)
// Should pass validation since google-group is now optional
assert.Equal(t, nil, err)

View File

@ -26,7 +26,7 @@ var _ = Describe("Upstreams", func() {
validStaticUpstream := options.Upstream{
ID: "validStaticUpstream",
Path: "/validStaticUpstream",
Static: ptr.Ptr(true),
Static: ptr.To(true),
}
validFileUpstream := options.Upstream{
ID: "validFileUpstream",
@ -145,11 +145,11 @@ var _ = Describe("Upstreams", func() {
ID: "foo",
Path: "/foo",
URI: "ftp://foo",
Static: ptr.Ptr(true),
Static: ptr.To(true),
FlushInterval: &flushInterval,
PassHostHeader: ptr.Ptr(true),
ProxyWebSockets: ptr.Ptr(true),
InsecureSkipTLSVerify: ptr.Ptr(true),
PassHostHeader: ptr.To(true),
ProxyWebSockets: ptr.To(true),
InsecureSkipTLSVerify: ptr.To(true),
},
},
},

View File

@ -173,7 +173,7 @@ var _ = Describe("ADFS Provider Tests", func() {
ProtectedResource: resource,
Scope: "",
}, options.Provider{
ADFSConfig: options.ADFSOptions{SkipScope: ptr.Ptr(true)},
ADFSConfig: options.ADFSOptions{SkipScope: ptr.To(true)},
})
result := p.GetLoginURL("https://example.com/adfs/oauth2/", "", "", url.Values{})

View File

@ -25,7 +25,7 @@ func TestAzureEntraOIDCProviderNewMultiTenant(t *testing.T) {
provider := NewMicrosoftEntraIDProvider(&ProviderData{},
options.Provider{OIDCConfig: options.OIDCOptions{
IssuerURL: "https://login.microsoftonline.com/common/v2.0",
InsecureSkipIssuerVerification: ptr.Ptr(true),
InsecureSkipIssuerVerification: ptr.To(true),
}},
)
g.Expect(provider.Data().ProviderName).To(Equal("Microsoft Entra ID"))
@ -91,8 +91,8 @@ func TestAzureEntraOIDCProviderValidateSessionAllowedTenants(t *testing.T) {
options.Provider{
OIDCConfig: options.OIDCOptions{
IssuerURL: "https://login.microsoftonline.com/common/v2.0",
InsecureSkipIssuerVerification: ptr.Ptr(true),
InsecureSkipNonce: ptr.Ptr(true),
InsecureSkipIssuerVerification: ptr.To(true),
InsecureSkipNonce: ptr.To(true),
},
MicrosoftEntraIDConfig: options.MicrosoftEntraIDOptions{
AllowedTenants: []string{"85d7d600-7804-4d92-8d43-9c33c21c130c"},

View File

@ -82,7 +82,7 @@ func TestSkipOIDCDiscovery(t *testing.T) {
ClientSecretFile: clientSecret,
OIDCConfig: options.OIDCOptions{
IssuerURL: msIssuerURL,
SkipDiscovery: ptr.Ptr(true),
SkipDiscovery: ptr.To(true),
},
}
@ -109,7 +109,7 @@ func TestURLsCorrectlyParsed(t *testing.T) {
RedeemURL: msTokenURL,
OIDCConfig: options.OIDCOptions{
IssuerURL: msIssuerURL,
SkipDiscovery: ptr.Ptr(true),
SkipDiscovery: ptr.To(true),
JwksURL: msKeysURL,
},
}
@ -217,7 +217,7 @@ func TestScope(t *testing.T) {
AllowedGroups: tc.allowedGroups,
OIDCConfig: options.OIDCOptions{
IssuerURL: msIssuerURL,
SkipDiscovery: ptr.Ptr(true),
SkipDiscovery: ptr.To(true),
JwksURL: msKeysURL,
},
}
@ -298,7 +298,7 @@ func TestEmailClaimCorrectlySet(t *testing.T) {
RedeemURL: msTokenURL,
OIDCConfig: options.OIDCOptions{
IssuerURL: msIssuerURL,
SkipDiscovery: ptr.Ptr(true),
SkipDiscovery: ptr.To(true),
JwksURL: msKeysURL,
UserIDClaim: tc.userIDClaim,
EmailClaim: tc.emailClaim,