Skip to content

Commit 4da9637

Browse files
authored
Merge pull request #1948 from tharindu1st/version-bump
change the spec to support 0.5.0 and 0.6.0
2 parents d1dd1d7 + 0208419 commit 4da9637

13 files changed

Lines changed: 1288 additions & 274 deletions

File tree

distribution/all-in-one/docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ services:
5050
condition: service_healthy
5151

5252
platform-api:
53+
image: ghcr.io/wso2/api-platform/platform-api:latest
5354
build:
5455
context: ../../platform-api
5556
dockerfile: Dockerfile

gateway/gateway-controller/api/management-openapi.yaml

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3761,7 +3761,7 @@ components:
37613761
description: Custom virtual host/domain for sandbox traffic
37623762
pattern: '^[a-zA-Z0-9\.\-]+$'
37633763
example: sandbox-api.example.com
3764-
policies:
3764+
allChannels:
37653765
$ref: '#/components/schemas/WebSubAllChannelPolicies'
37663766
channels:
37673767
type: object
@@ -3779,35 +3779,40 @@ components:
37793779
WebSubChannel:
37803780
type: object
37813781
description: A single channel definition with optional per-channel policy overrides.
3782+
properties:
3783+
on_subscription:
3784+
$ref: '#/components/schemas/WebSubEventPolicies'
3785+
on_unsubscription:
3786+
$ref: '#/components/schemas/WebSubEventPolicies'
3787+
on_message_received:
3788+
$ref: '#/components/schemas/WebSubEventPolicies'
3789+
on_message_delivery:
3790+
$ref: '#/components/schemas/WebSubEventPolicies'
3791+
3792+
# WebSubEventPolicies defines policies for a single event type.
3793+
WebSubEventPolicies:
3794+
type: object
3795+
description: Policies for a single event type.
37823796
properties:
37833797
policies:
3784-
$ref: '#/components/schemas/WebSubChannelPolicies'
3798+
type: array
3799+
description: List of policies applied for this event type.
3800+
items:
3801+
$ref: '#/components/schemas/Policy'
37853802

37863803
# WebSubAllChannelPolicies defines policies applied to all channels for each event type.
37873804
WebSubAllChannelPolicies:
37883805
type: object
37893806
description: Policies applied to all channels, organized by event type.
37903807
properties:
37913808
on_subscription:
3792-
type: array
3793-
description: Policies applied when a client subscribes to a channel (e.g., api-key-auth)
3794-
items:
3795-
$ref: '#/components/schemas/Policy'
3809+
$ref: '#/components/schemas/WebSubEventPolicies'
37963810
on_unsubscription:
3797-
type: array
3798-
description: Policies applied when a client unsubscribes from a channel (e.g., api-key-auth)
3799-
items:
3800-
$ref: '#/components/schemas/Policy'
3811+
$ref: '#/components/schemas/WebSubEventPolicies'
38013812
on_message_received:
3802-
type: array
3803-
description: Policies applied when a message is received from the publisher via webhook (e.g., hmac-signature-validation)
3804-
items:
3805-
$ref: '#/components/schemas/Policy'
3813+
$ref: '#/components/schemas/WebSubEventPolicies'
38063814
on_message_delivery:
3807-
type: array
3808-
description: Policies applied when delivering a message to a subscriber callback URL (e.g., hmac-sign-messages)
3809-
items:
3810-
$ref: '#/components/schemas/Policy'
3815+
$ref: '#/components/schemas/WebSubEventPolicies'
38113816

38123817
# WebSubChannelPolicies defines per-channel policies organized by event type.
38133818
WebSubChannelPolicies:

gateway/gateway-controller/pkg/api/management/generated.go

Lines changed: 122 additions & 124 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gateway/gateway-controller/pkg/policy/builder.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,13 @@ func DerivePolicyFromAPIConfig(cfg *models.StoredConfig, routerConfig *config.Ro
6868
channels = *apiData.Channels
6969
}
7070
for chName, ch := range channels {
71-
var chPolicies api.WebSubChannelPolicies
72-
if ch.Policies != nil {
73-
chPolicies = *ch.Policies
74-
}
7571
var finalPolicies []policyenginev1.PolicyInstance
7672

77-
// Policy execution order: policies (on_subscription) -> per-channel policies
73+
// Policy execution order: allChannels (on_subscription) -> per-channel policies
7874
// Start with API-level subscription policies
79-
if apiData.Policies != nil && apiData.Policies.OnSubscription != nil {
80-
finalPolicies = make([]policyenginev1.PolicyInstance, 0, len(*apiData.Policies.OnSubscription))
81-
for _, p := range *apiData.Policies.OnSubscription {
75+
if apiData.AllChannels != nil && apiData.AllChannels.OnSubscription != nil && apiData.AllChannels.OnSubscription.Policies != nil {
76+
finalPolicies = make([]policyenginev1.PolicyInstance, 0, len(*apiData.AllChannels.OnSubscription.Policies))
77+
for _, p := range *apiData.AllChannels.OnSubscription.Policies {
8278
resolved, err := config.ResolvePolicyVersion(policyDefinitions, latestVersions, p.Name, p.Version)
8379
if err != nil {
8480
slog.Error("Failed to resolve policy version for all-channel subscription policy", "policy_name", p.Name, "error", err)
@@ -89,8 +85,8 @@ func DerivePolicyFromAPIConfig(cfg *models.StoredConfig, routerConfig *config.Ro
8985
}
9086

9187
// Append channel-level on_subscription policies
92-
if chPolicies.OnSubscription != nil && len(*chPolicies.OnSubscription) > 0 {
93-
for _, opPolicy := range *chPolicies.OnSubscription {
88+
if ch.OnSubscription != nil && ch.OnSubscription.Policies != nil && len(*ch.OnSubscription.Policies) > 0 {
89+
for _, opPolicy := range *ch.OnSubscription.Policies {
9490
resolved, err := config.ResolvePolicyVersion(policyDefinitions, latestVersions, opPolicy.Name, opPolicy.Version)
9591
if err != nil {
9692
slog.Error("Failed to resolve policy version for channel-level policy", "policy_name", opPolicy.Name, "channel_name", chName, "error", err)
@@ -111,9 +107,9 @@ func DerivePolicyFromAPIConfig(cfg *models.StoredConfig, routerConfig *config.Ro
111107

112108
// Build UNSUB (unsubscription) policy chain for this channel
113109
var unsubPolicies []policyenginev1.PolicyInstance
114-
if apiData.Policies != nil && apiData.Policies.OnUnsubscription != nil {
115-
unsubPolicies = make([]policyenginev1.PolicyInstance, 0, len(*apiData.Policies.OnUnsubscription))
116-
for _, p := range *apiData.Policies.OnUnsubscription {
110+
if apiData.AllChannels != nil && apiData.AllChannels.OnUnsubscription != nil && apiData.AllChannels.OnUnsubscription.Policies != nil {
111+
unsubPolicies = make([]policyenginev1.PolicyInstance, 0, len(*apiData.AllChannels.OnUnsubscription.Policies))
112+
for _, p := range *apiData.AllChannels.OnUnsubscription.Policies {
117113
resolved, err := config.ResolvePolicyVersion(policyDefinitions, latestVersions, p.Name, p.Version)
118114
if err != nil {
119115
slog.Error("Failed to resolve policy version for all-channel unsubscription policy", "policy_name", p.Name, "error", err)
@@ -122,8 +118,8 @@ func DerivePolicyFromAPIConfig(cfg *models.StoredConfig, routerConfig *config.Ro
122118
unsubPolicies = append(unsubPolicies, ConvertAPIPolicyToModel(p, policyv1alpha.LevelAPI, versionutil.MajorVersion(resolved)))
123119
}
124120
}
125-
if chPolicies.OnUnsubscription != nil && len(*chPolicies.OnUnsubscription) > 0 {
126-
for _, opPolicy := range *chPolicies.OnUnsubscription {
121+
if ch.OnUnsubscription != nil && ch.OnUnsubscription.Policies != nil && len(*ch.OnUnsubscription.Policies) > 0 {
122+
for _, opPolicy := range *ch.OnUnsubscription.Policies {
127123
resolved, err := config.ResolvePolicyVersion(policyDefinitions, latestVersions, opPolicy.Name, opPolicy.Version)
128124
if err != nil {
129125
slog.Error("Failed to resolve policy version for channel-level unsubscription policy", "policy_name", opPolicy.Name, "channel_name", chName, "error", err)

gateway/gateway-controller/pkg/policyxds/event_channel_translator.go

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,26 @@ func (t *Translator) buildEventChannelResource(uuid string, webSubCfg *api.WebSu
8181
sort.Strings(sortedKeys)
8282
for _, chName := range sortedKeys {
8383
ch := channels[chName]
84-
var chPolicies api.WebSubChannelPolicies
85-
if ch.Policies != nil {
86-
chPolicies = *ch.Policies
84+
var subPolicies, unsubPolicies, inboundPolicies, outboundPolicies []interface{}
85+
if ch.OnSubscription != nil {
86+
subPolicies = buildPolicyList(ch.OnSubscription.Policies)
87+
}
88+
if ch.OnUnsubscription != nil {
89+
unsubPolicies = buildPolicyList(ch.OnUnsubscription.Policies)
90+
}
91+
if ch.OnMessageReceived != nil {
92+
inboundPolicies = buildPolicyList(ch.OnMessageReceived.Policies)
93+
}
94+
if ch.OnMessageDelivery != nil {
95+
outboundPolicies = buildPolicyList(ch.OnMessageDelivery.Policies)
8796
}
8897
chEntry := map[string]interface{}{
8998
"name": chName,
9099
"policies": map[string]interface{}{
91-
"subscribe": buildPolicyList(chPolicies.OnSubscription),
92-
"unsubscribe": buildPolicyList(chPolicies.OnUnsubscription),
93-
"inbound": buildPolicyList(chPolicies.OnMessageReceived),
94-
"outbound": buildPolicyList(chPolicies.OnMessageDelivery),
100+
"subscribe": subPolicies,
101+
"unsubscribe": unsubPolicies,
102+
"inbound": inboundPolicies,
103+
"outbound": outboundPolicies,
95104
},
96105
}
97106
channelEntries = append(channelEntries, chEntry)
@@ -102,11 +111,19 @@ func (t *Translator) buildEventChannelResource(uuid string, webSubCfg *api.WebSu
102111
unsubscribePolicies := []interface{}{}
103112
inboundPolicies := []interface{}{}
104113
outboundPolicies := []interface{}{}
105-
if spec.Policies != nil {
106-
subscribePolicies = buildPolicyList(spec.Policies.OnSubscription)
107-
unsubscribePolicies = buildPolicyList(spec.Policies.OnUnsubscription)
108-
inboundPolicies = buildPolicyList(spec.Policies.OnMessageReceived)
109-
outboundPolicies = buildPolicyList(spec.Policies.OnMessageDelivery)
114+
if spec.AllChannels != nil {
115+
if spec.AllChannels.OnSubscription != nil {
116+
subscribePolicies = buildPolicyList(spec.AllChannels.OnSubscription.Policies)
117+
}
118+
if spec.AllChannels.OnUnsubscription != nil {
119+
unsubscribePolicies = buildPolicyList(spec.AllChannels.OnUnsubscription.Policies)
120+
}
121+
if spec.AllChannels.OnMessageReceived != nil {
122+
inboundPolicies = buildPolicyList(spec.AllChannels.OnMessageReceived.Policies)
123+
}
124+
if spec.AllChannels.OnMessageDelivery != nil {
125+
outboundPolicies = buildPolicyList(spec.AllChannels.OnMessageDelivery.Policies)
126+
}
110127
}
111128

112129
data := map[string]interface{}{

platform-api/src/api/generated.go

Lines changed: 16 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

platform-api/src/internal/model/deployment.go

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,16 @@ type WebSubAPIDeploymentYAML struct {
121121

122122
// WebSubAPIDeploymentSpec represents the spec section of the WebSub API deployment YAML
123123
type WebSubAPIDeploymentSpec struct {
124-
DisplayName string `yaml:"displayName"`
125-
Version string `yaml:"version"`
126-
Context string `yaml:"context"`
127-
Vhosts *WebSubAPIDeploymentVhosts `yaml:"vhosts,omitempty"`
128-
Policies *WebSubDeployAllChannelPolicies `yaml:"policies,omitempty"`
129-
Channels map[string]WebSubDeployChannel `yaml:"channels,omitempty"`
124+
DisplayName string `yaml:"displayName"`
125+
Version string `yaml:"version"`
126+
Context string `yaml:"context"`
127+
Vhosts *WebSubAPIDeploymentVhosts `yaml:"vhosts,omitempty"`
128+
AllChannels *WebSubDeployAllChannelPolicies `yaml:"allChannels,omitempty"`
129+
Receiver *WebSubDeployReceiver `yaml:"receiver,omitempty"`
130+
Hub *WebSubDeployHub `yaml:"hub,omitempty"`
131+
Delivery *WebSubDeployDelivery `yaml:"delivery,omitempty"`
132+
Channels map[string]WebSubDeployChannel `yaml:"channels,omitempty"`
133+
DeploymentState string `yaml:"deploymentState,omitempty"`
130134
}
131135

132136
// WebSubAPIDeploymentVhosts represents vhost configuration in the WebSub API deployment YAML
@@ -135,23 +139,47 @@ type WebSubAPIDeploymentVhosts struct {
135139
Sandbox *string `yaml:"sandbox,omitempty"`
136140
}
137141

138-
// WebSubDeployAllChannelPolicies represents policies for all channels in the deployment YAML, organized by event type.
139-
type WebSubDeployAllChannelPolicies struct {
140-
OnSubscription *[]Policy `yaml:"on_subscription,omitempty"`
141-
OnUnsubscription *[]Policy `yaml:"on_unsubscription,omitempty"`
142-
OnMessageReceived *[]Policy `yaml:"on_message_received,omitempty"`
143-
OnMessageDelivery *[]Policy `yaml:"on_message_delivery,omitempty"`
142+
// WebSubDeployEventPolicies wraps a list of policies for a single event type,
143+
// matching the gateway controller's WebSubEventPolicies schema.
144+
type WebSubDeployEventPolicies struct {
145+
Policies *[]Policy `yaml:"policies,omitempty"`
144146
}
145147

146-
// WebSubDeployChannelPolicies represents per-channel policies in the deployment YAML, organized by event type.
147-
type WebSubDeployChannelPolicies struct {
148-
OnSubscription *[]Policy `yaml:"on_subscription,omitempty"`
149-
OnUnsubscription *[]Policy `yaml:"on_unsubscription,omitempty"`
150-
OnMessageReceived *[]Policy `yaml:"on_message_received,omitempty"`
151-
OnMessageDelivery *[]Policy `yaml:"on_message_delivery,omitempty"`
148+
// WebSubDeployAllChannelPolicies represents policies for all channels in the deployment YAML, organized by event type.
149+
type WebSubDeployAllChannelPolicies struct {
150+
OnSubscription *WebSubDeployEventPolicies `yaml:"on_subscription,omitempty"`
151+
OnUnsubscription *WebSubDeployEventPolicies `yaml:"on_unsubscription,omitempty"`
152+
OnMessageReceived *WebSubDeployEventPolicies `yaml:"on_message_received,omitempty"`
153+
OnMessageDelivery *WebSubDeployEventPolicies `yaml:"on_message_delivery,omitempty"`
152154
}
153155

154156
// WebSubDeployChannel represents a single channel entry in the deployment YAML.
157+
// Event policies are at the top level to match the gateway-controller's WebSubChannel schema.
155158
type WebSubDeployChannel struct {
156-
Policies *WebSubDeployChannelPolicies `yaml:"policies,omitempty"`
159+
OnSubscription *WebSubDeployEventPolicies `yaml:"on_subscription,omitempty"`
160+
OnUnsubscription *WebSubDeployEventPolicies `yaml:"on_unsubscription,omitempty"`
161+
OnMessageReceived *WebSubDeployEventPolicies `yaml:"on_message_received,omitempty"`
162+
OnMessageDelivery *WebSubDeployEventPolicies `yaml:"on_message_delivery,omitempty"`
163+
}
164+
165+
// WebSubDeployReceiver represents the receiver section in the deployment YAML.
166+
type WebSubDeployReceiver struct {
167+
Policies []Policy `yaml:"policies"`
168+
}
169+
170+
// WebSubDeployHub represents the hub section in the deployment YAML.
171+
type WebSubDeployHub struct {
172+
Policies []Policy `yaml:"policies"`
173+
Channels []WebSubDeployHubChannel `yaml:"channels,omitempty"`
174+
}
175+
176+
// WebSubDeployHubChannel represents a channel entry under the hub section in the deployment YAML.
177+
type WebSubDeployHubChannel struct {
178+
Name string `yaml:"name"`
179+
Policies []Policy `yaml:"policies"`
180+
}
181+
182+
// WebSubDeployDelivery represents the delivery section in the deployment YAML.
183+
type WebSubDeployDelivery struct {
184+
Policies []Policy `yaml:"policies"`
157185
}

0 commit comments

Comments
 (0)