forked from wso2/api-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeployment.go
More file actions
185 lines (162 loc) · 8.28 KB
/
deployment.go
File metadata and controls
185 lines (162 loc) · 8.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
* Copyright (c) 2026, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package model
import (
"time"
)
// Deployment represents an immutable artifact deployment
// Status and UpdatedAt are populated from deployment_status table via JOIN
// If Status is nil, the deployment is ARCHIVED (not currently active or undeployed)
type Deployment struct {
DeploymentID string `json:"deploymentId" db:"deployment_id"`
Name string `json:"name" db:"name"`
ArtifactID string `json:"artifactId" db:"artifact_uuid"`
OrganizationID string `json:"organizationId" db:"organization_uuid"`
GatewayID string `json:"gatewayId" db:"gateway_uuid"`
BaseDeploymentID *string `json:"baseDeploymentId,omitempty" db:"base_deployment_id"`
Content []byte `json:"-" db:"content"`
Metadata map[string]any `json:"metadata,omitempty" db:"metadata"`
CreatedAt time.Time `json:"createdAt" db:"created_at"`
// Lifecycle state fields (from deployment_status table via JOIN)
// nil values indicate ARCHIVED state (no record in status table)
Status *DeploymentStatus `json:"status,omitempty" db:"status"`
UpdatedAt *time.Time `json:"updatedAt,omitempty" db:"status_updated_at"`
StatusReason *string `json:"statusReason,omitempty" db:"status_reason"`
}
// TableName returns the table name for the Deployment model
func (Deployment) TableName() string {
return "deployments"
}
// DeploymentContent holds the artifact content for a single deployment,
// used internally when constructing batch archive responses.
type DeploymentContent struct {
DeploymentID string
ArtifactID string
Kind string
Content []byte
}
// DeploymentStatus represents the status of a deployment
// Note: ARCHIVED is a derived state (not stored in database)
type DeploymentStatus string
const (
DeploymentStatusDeployed DeploymentStatus = "DEPLOYED"
DeploymentStatusUndeployed DeploymentStatus = "UNDEPLOYED"
DeploymentStatusDeploying DeploymentStatus = "DEPLOYING"
DeploymentStatusUndeploying DeploymentStatus = "UNDEPLOYING"
DeploymentStatusFailed DeploymentStatus = "FAILED"
DeploymentStatusArchived DeploymentStatus = "ARCHIVED" // Derived state: exists in history but not in status table
)
// DeploymentInfo is a lightweight representation of a deployment
// Contains only the essential fields needed for listing deployments
type DeploymentInfo struct {
DeploymentID string `json:"deploymentId" db:"deployment_id"`
ArtifactID string `json:"artifactId" db:"artifact_uuid"`
Handle string `json:"handle" db:"handle"` // Artifact handle (apiId)
Kind string `json:"kind" db:"kind"` // Artifact kind: RestAPI, LLMProvider, LLMProxy, MCPProxy
Status DeploymentStatus `json:"status" db:"status"`
PerformedAt time.Time `json:"performedAt" db:"performed_at"` // When the deploy/undeploy action was initiated
}
// DeploymentMetadata represents the metadata section of the API deployment YAML
type DeploymentMetadata struct {
Name string `yaml:"name" binding:"required"`
Labels map[string]string `yaml:"labels,omitempty"`
}
// MCPProxyDeploymentYAML represents the structure of the YAML used for deploying an MCP proxy
type MCPProxyDeploymentYAML struct {
ApiVersion string `yaml:"apiVersion" binding:"required"`
Kind string `yaml:"kind" binding:"required"`
Metadata DeploymentMetadata `yaml:"metadata" binding:"required"`
Spec MCPProxyDeploymentSpec `yaml:"spec" binding:"required"`
}
// MCPProxyDeploymentSpec represents the spec section of the MCP proxy deployment YAML
type MCPProxyDeploymentSpec struct {
DisplayName string `yaml:"displayName" binding:"required"`
Version string `yaml:"version" binding:"required"`
Context string `yaml:"context" binding:"required"`
Vhost *string `yaml:"vhost" binding:"required"`
Upstream MCPProxyUpstream `yaml:"upstream" binding:"required"`
SpecVersion string `yaml:"specVersion" binding:"required"`
Policies []Policy `yaml:"policies,omitempty"`
}
// Adding this type to support the model in the gateway side
type MCPProxyUpstream struct {
URL string `yaml:"url" binding:"required"`
Auth *UpstreamAuth `json:"auth,omitempty"`
}
// WebSubAPIDeploymentYAML represents the structure of the YAML used for deploying a WebSub API
type WebSubAPIDeploymentYAML struct {
ApiVersion string `yaml:"apiVersion"`
Kind string `yaml:"kind"`
Metadata DeploymentMetadata `yaml:"metadata"`
Spec WebSubAPIDeploymentSpec `yaml:"spec"`
}
// WebSubAPIDeploymentSpec represents the spec section of the WebSub API deployment YAML
type WebSubAPIDeploymentSpec struct {
DisplayName string `yaml:"displayName"`
Version string `yaml:"version"`
Context string `yaml:"context"`
Vhosts *WebSubAPIDeploymentVhosts `yaml:"vhosts,omitempty"`
AllChannels *WebSubDeployAllChannelPolicies `yaml:"allChannels,omitempty"`
Receiver *WebSubDeployReceiver `yaml:"receiver,omitempty"`
Hub *WebSubDeployHub `yaml:"hub,omitempty"`
Delivery *WebSubDeployDelivery `yaml:"delivery,omitempty"`
Channels map[string]WebSubDeployChannel `yaml:"channels,omitempty"`
DeploymentState string `yaml:"deploymentState,omitempty"`
}
// WebSubAPIDeploymentVhosts represents vhost configuration in the WebSub API deployment YAML
type WebSubAPIDeploymentVhosts struct {
Main string `yaml:"main"`
Sandbox *string `yaml:"sandbox,omitempty"`
}
// WebSubDeployEventPolicies wraps a list of policies for a single event type,
// matching the gateway controller's WebSubEventPolicies schema.
type WebSubDeployEventPolicies struct {
Policies *[]Policy `yaml:"policies,omitempty"`
}
// WebSubDeployAllChannelPolicies represents policies for all channels in the deployment YAML, organized by event type.
type WebSubDeployAllChannelPolicies struct {
OnSubscription *WebSubDeployEventPolicies `yaml:"on_subscription,omitempty"`
OnUnsubscription *WebSubDeployEventPolicies `yaml:"on_unsubscription,omitempty"`
OnMessageReceived *WebSubDeployEventPolicies `yaml:"on_message_received,omitempty"`
OnMessageDelivery *WebSubDeployEventPolicies `yaml:"on_message_delivery,omitempty"`
}
// WebSubDeployChannel represents a single channel entry in the deployment YAML.
// Event policies are at the top level to match the gateway-controller's WebSubChannel schema.
type WebSubDeployChannel struct {
OnSubscription *WebSubDeployEventPolicies `yaml:"on_subscription,omitempty"`
OnUnsubscription *WebSubDeployEventPolicies `yaml:"on_unsubscription,omitempty"`
OnMessageReceived *WebSubDeployEventPolicies `yaml:"on_message_received,omitempty"`
OnMessageDelivery *WebSubDeployEventPolicies `yaml:"on_message_delivery,omitempty"`
}
// WebSubDeployReceiver represents the receiver section in the deployment YAML.
type WebSubDeployReceiver struct {
Policies []Policy `yaml:"policies"`
}
// WebSubDeployHub represents the hub section in the deployment YAML.
type WebSubDeployHub struct {
Policies []Policy `yaml:"policies"`
Channels []WebSubDeployHubChannel `yaml:"channels,omitempty"`
}
// WebSubDeployHubChannel represents a channel entry under the hub section in the deployment YAML.
type WebSubDeployHubChannel struct {
Name string `yaml:"name"`
Policies []Policy `yaml:"policies"`
}
// WebSubDeployDelivery represents the delivery section in the deployment YAML.
type WebSubDeployDelivery struct {
Policies []Policy `yaml:"policies"`
}