Skip to content

Commit eb60845

Browse files
committed
feat: add support for EventFlow in TargetEndpoint and ProxyEndpoint
Fixes #37
1 parent a4ced55 commit eb60845

File tree

5 files changed

+129
-0
lines changed

5 files changed

+129
-0
lines changed

pkg/apigee/v1/apiproxymodel_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ func TestNewAPIProxyModel(t *testing.T) {
5353
{
5454
"google-id-token-auth",
5555
},
56+
{
57+
"event-flow",
58+
},
5659
}
5760
for _, tt := range tests {
5861
ttDir := filepath.Join("testdata", "yaml-first", tt.name)

pkg/apigee/v1/eventflow.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package v1
16+
17+
import "fmt"
18+
19+
type EventFlow struct {
20+
Name string `xml:"name,attr,omitempty"`
21+
ContentType string `xml:"content-type,attr"`
22+
Description string `xml:"Description,omitempty"`
23+
Response *Response `xml:"Response,omitempty"`
24+
25+
UnknownNode AnyList `xml:",any"`
26+
}
27+
28+
func ValidateEventFlow(v *EventFlow, path string) []error {
29+
if v == nil {
30+
return nil
31+
}
32+
33+
subPath := fmt.Sprintf("%s.EventFlow", path)
34+
if len(v.UnknownNode) > 0 {
35+
return []error{NewUnknownNodeError(subPath, v.UnknownNode[0])}
36+
}
37+
38+
var subErrors []error
39+
subErrors = append(subErrors, ValidateResponse(v.Response, subPath)...)
40+
41+
return subErrors
42+
}

pkg/apigee/v1/proxyendpoint.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type ProxyEndpoint struct {
2626
FaultRules *FaultRules `xml:"FaultRules"`
2727
DefaultFaultRule *DefaultFaultRule `xml:"DefaultFaultRule,omitempty"`
2828
PreFlow *PreFlow `xml:"PreFlow,omitempty"`
29+
EventFlow *EventFlow `xml:"EventFlow,omitempty"`
2930
Flows *Flows `xml:"Flows,omitempty"`
3031
PostFlow *PostFlow `xml:"PostFlow,omitempty"`
3132
PostClientFlow *PostClientFlow `xml:"PostClientFlow,omitempty"`
@@ -64,6 +65,7 @@ func ValidateProxyEndpoint(v *ProxyEndpoint, path string) []error {
6465
var subErrors []error
6566
subErrors = append(subErrors, ValidateHTTPProxyConnection(v.HTTPProxyConnection, subPath)...)
6667
subErrors = append(subErrors, ValidatePreFlow(v.PreFlow, subPath)...)
68+
subErrors = append(subErrors, ValidateEventFlow(v.EventFlow, subPath)...)
6769
subErrors = append(subErrors, ValidateFlows(v.Flows, subPath)...)
6870
subErrors = append(subErrors, ValidatePostFlow(v.PostFlow, subPath)...)
6971
subErrors = append(subErrors, ValidateRouteRules(v.RouteRules, subPath)...)

pkg/apigee/v1/targetendpoint.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type TargetEndpoint struct {
2626
FaultRules *FaultRules `xml:"FaultRules,omitempty"`
2727
DefaultFaultRule *DefaultFaultRule `xml:"DefaultFaultRule,omitempty"`
2828
PreFlow PreFlow `xml:"PreFlow"`
29+
EventFlow *EventFlow `xml:"EventFlow,omitempty"`
2930
Flows Flows `xml:"Flows"`
3031
PostFlow PostFlow `xml:"PostFlow"`
3132
HTTPTargetConnection *HTTPTargetConnection `xml:"HTTPTargetConnection,omitempty"`
@@ -63,6 +64,7 @@ func ValidateTargetEndpoint(v *TargetEndpoint, path string) []error {
6364
var subErrors []error
6465
subErrors = append(subErrors, ValidateHTTPTargetConnection(v.HTTPTargetConnection, subPath)...)
6566
subErrors = append(subErrors, ValidatePreFlow(&v.PreFlow, subPath)...)
67+
subErrors = append(subErrors, ValidateEventFlow(v.EventFlow, subPath)...)
6668
subErrors = append(subErrors, ValidateFlows(&v.Flows, subPath)...)
6769
subErrors = append(subErrors, ValidatePostFlow(&v.PostFlow, subPath)...)
6870
subErrors = append(subErrors, ValidateFaultRules(v.FaultRules, subPath)...)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http:#www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
APIProxy:
15+
.revision: 1
16+
.name: httpbin
17+
Policies:
18+
- RaiseFault:
19+
.name: RF-InvalidCred
20+
DisplayName: RF-InvalidCred
21+
FaultResponse:
22+
Set:
23+
- StatusCode: 401
24+
- ReasonPhrase: Unauthorized
25+
- Payload:
26+
.contentType: application/json
27+
-Data: '{"error": "Unauthorized", "message": "Invalid access token"}'
28+
- Headers:
29+
Header:
30+
.name: Content-Type
31+
-Data: application/json
32+
- Javascript:
33+
.name: JS-combine-resp
34+
.timeLimit: 200
35+
.languageVersion: VERSION_ES6
36+
DisplayName: JS-combine-resp
37+
Source: |
38+
// Access a variable from the flow
39+
var myVariable = context.getVariable("myFlowVariable");
40+
41+
// Set a new variable
42+
context.setVariable("javascript.policy.executed", true);
43+
44+
print("JS-combine-resp policy executed!");
45+
- SanitizeModelResponse:
46+
.name: SMR-ModelResp
47+
DisplayName: SMR-ModelResp
48+
ModelArmor:
49+
TemplateName: projects/{organization.name}/locations/{system.region.name}/templates/default-template
50+
UserPromptSource: request.content
51+
LLMResponseSource: response.content
52+
ProxyEndpoints:
53+
- ProxyEndpoint:
54+
.name: default
55+
EventFlow:
56+
.name: EF-1
57+
.content-type: text/event-stream
58+
Response:
59+
- Step:
60+
Name: RF-InvalidCred
61+
Condition: fault.name equals "invalid_access_token"
62+
HTTPProxyConnection:
63+
BasePath: /httpbin
64+
RouteRule:
65+
.name: default
66+
TargetEndpoint: default
67+
TargetEndpoints:
68+
- TargetEndpoint:
69+
.name: default
70+
EventFlow:
71+
.name: EventFlow
72+
.content-type: text/event-stream
73+
Response:
74+
- Step:
75+
Name: JS-combine-resp
76+
- Step:
77+
Condition: buff_ready = true
78+
Name: SMR-ModelResp
79+
HTTPTargetConnection:
80+
URL: https://httpbin.org/

0 commit comments

Comments
 (0)