Skip to content

Commit d967f26

Browse files
committed
Added proxy auth support
1 parent a776b63 commit d967f26

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

model/authentication.go

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,24 @@ import (
2121

2222
// AuthenticationPolicy Defines an authentication policy.
2323
type AuthenticationPolicy struct {
24-
Basic *BasicAuthenticationPolicy `json:"basic,omitempty"`
25-
Bearer *BearerAuthenticationPolicy `json:"bearer,omitempty"`
26-
Digest *DigestAuthenticationPolicy `json:"digest,omitempty"`
27-
OAuth2 *OAuth2AuthenticationPolicy `json:"oauth2,omitempty"`
28-
OIDC *OpenIdConnectAuthenticationPolicy `json:"oidc,omitempty"`
24+
Basic *BasicAuthenticationPolicy `json:"basic,omitempty"`
25+
Bearer *BearerAuthenticationPolicy `json:"bearer,omitempty"`
26+
ProxyBearer *ProxyBearerAuthenticationPolicy `json:"proxy_bearer,omitempty"`
27+
Digest *DigestAuthenticationPolicy `json:"digest,omitempty"`
28+
OAuth2 *OAuth2AuthenticationPolicy `json:"oauth2,omitempty"`
29+
OIDC *OpenIdConnectAuthenticationPolicy `json:"oidc,omitempty"`
2930
}
3031

3132
// UnmarshalJSON for AuthenticationPolicy to enforce "oneOf" behavior.
3233
func (ap *AuthenticationPolicy) UnmarshalJSON(data []byte) error {
3334
// Create temporary maps to detect which field is populated
3435
temp := struct {
35-
Basic json.RawMessage `json:"basic"`
36-
Bearer json.RawMessage `json:"bearer"`
37-
Digest json.RawMessage `json:"digest"`
38-
OAuth2 json.RawMessage `json:"oauth2"`
39-
OIDC json.RawMessage `json:"oidc"`
36+
Basic json.RawMessage `json:"basic"`
37+
Bearer json.RawMessage `json:"bearer"`
38+
ProxyBearer json.RawMessage `json:"proxy_bearer"`
39+
Digest json.RawMessage `json:"digest"`
40+
OAuth2 json.RawMessage `json:"oauth2"`
41+
OIDC json.RawMessage `json:"oidc"`
4042
}{}
4143

4244
if err := json.Unmarshal(data, &temp); err != nil {
@@ -59,6 +61,13 @@ func (ap *AuthenticationPolicy) UnmarshalJSON(data []byte) error {
5961
return err
6062
}
6163
}
64+
if len(temp.ProxyBearer) > 0 {
65+
count++
66+
ap.ProxyBearer = &ProxyBearerAuthenticationPolicy{}
67+
if err := json.Unmarshal(temp.ProxyBearer, ap.ProxyBearer); err != nil {
68+
return err
69+
}
70+
}
6271
if len(temp.Digest) > 0 {
6372
count++
6473
ap.Digest = &DigestAuthenticationPolicy{}
@@ -96,6 +105,9 @@ func (ap *AuthenticationPolicy) MarshalJSON() ([]byte, error) {
96105
if ap.Bearer != nil {
97106
return json.Marshal(map[string]interface{}{"bearer": ap.Bearer})
98107
}
108+
if ap.ProxyBearer != nil {
109+
return json.Marshal(map[string]interface{}{"proxy_bearer": ap.ProxyBearer})
110+
}
99111
if ap.Digest != nil {
100112
return json.Marshal(map[string]interface{}{"digest": ap.Digest})
101113
}
@@ -173,6 +185,11 @@ type BearerAuthenticationPolicy struct {
173185
Use string `json:"use,omitempty" validate:"required_without=Token"`
174186
}
175187

188+
type ProxyBearerAuthenticationPolicy struct {
189+
Token string `json:"token,omitempty" validate:"required_without=Use,proxy_bearer_policy"`
190+
Use string `json:"use,omitempty" validate:"required"`
191+
}
192+
176193
// DigestAuthenticationPolicy supports either inline properties (username/password) or a secret reference (use).
177194
type DigestAuthenticationPolicy struct {
178195
Username string `json:"username,omitempty" validate:"required_without=Use"`

0 commit comments

Comments
 (0)