55package v1
66
77import (
8+ "errors"
89 "net/url"
910 "path"
1011
@@ -19,10 +20,16 @@ type RealmSpec struct {
1920 // Gateway is the Gateway that is associated with the Realm
2021 // If empty, the realm considered a virtual realm
2122 Gateway * types.ObjectRef `json:"gateway,omitempty"`
22- // Url is the URL of the Gateway when its used as an upstream
23- Url string `json:"url"`
24- // IssuerUrl is the URL of the issuer of the Token sent by the Gateway when its used as a downstream
25- IssuerUrl string `json:"issuerUrl"`
23+ // Urls is the list of Gateway URLs that this realm should accept traffic from
24+ // +listType=set
25+ // +kubebuilder:validation:MinItems=1
26+ // +kubebuilder:validation:items:Format=uri
27+ Urls []string `json:"urls"`
28+ // IssuerUrls is the list of token issuer URLs that are trusted for this realm
29+ // +listType=set
30+ // +kubebuilder:validation:MinItems=1
31+ // +kubebuilder:validation:items:Format=uri
32+ IssuerUrls []string `json:"issuerUrls"`
2633 // DefaultConsumers is a list of consumers that are allowed to access the Realm for all Routes
2734 // +listType=set
2835 // +kubebuilder:default={}
@@ -72,7 +79,11 @@ func (r *Realm) SetCondition(condition metav1.Condition) bool {
7279}
7380
7481func (r * Realm ) AsUpstream (apiBasePath string ) (ups Upstream , err error ) {
75- url , err := url .Parse (r .Spec .Url )
82+ // Use the first URL as the upstream URL
83+ if len (r .Spec .Urls ) == 0 {
84+ return ups , errors .New ("realm has no URLs configured" )
85+ }
86+ url , err := url .Parse (r .Spec .Urls [0 ])
7687 if err != nil {
7788 return ups , err
7889 }
@@ -86,15 +97,24 @@ func (r *Realm) AsUpstream(apiBasePath string) (ups Upstream, err error) {
8697}
8798
8899func (r * Realm ) AsDownstream (apiBasePath string ) (dws Downstream , err error ) {
89- url , err := url .Parse (r .Spec .Url )
100+ // Use the first URL as the downstream URL
101+ if len (r .Spec .Urls ) == 0 {
102+ return dws , errors .New ("realm has no URLs configured" )
103+ }
104+ url , err := url .Parse (r .Spec .Urls [0 ])
90105 if err != nil {
91106 return dws , err
92107 }
108+ // Use the first issuer URL
109+ issuerUrl := ""
110+ if len (r .Spec .IssuerUrls ) > 0 {
111+ issuerUrl = r .Spec .IssuerUrls [0 ]
112+ }
93113 dws = Downstream {
94114 Host : url .Hostname (),
95115 Port : GetPortOrDefaultFromScheme (url ),
96116 Path : path .Join (url .Path , apiBasePath ),
97- IssuerUrl : r . Spec . IssuerUrl ,
117+ IssuerUrl : issuerUrl ,
98118 }
99119 return
100120}
0 commit comments