Skip to content

Commit c56826f

Browse files
committed
add relationships endpoint
1 parent 17843ae commit c56826f

File tree

8 files changed

+321
-157
lines changed

8 files changed

+321
-157
lines changed

apps/web/app/routes/ws/relationship-rules.tsx

Lines changed: 0 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -17,155 +17,6 @@ export function meta() {
1717
];
1818
}
1919

20-
type Selector = { json?: unknown } | { cel?: string };
21-
22-
type PropertyMatcher = {
23-
fromProperty: string[];
24-
toProperty: string[];
25-
operator:
26-
| "equals"
27-
| "notEquals"
28-
| "contains"
29-
| "startsWith"
30-
| "endsWith"
31-
| "regex";
32-
};
33-
34-
type Matcher = { cel: string } | { properties: PropertyMatcher[] };
35-
36-
type RelationshipRule = {
37-
id: string;
38-
reference: string;
39-
name: string;
40-
description?: string;
41-
fromType: string;
42-
fromSelector?: Selector;
43-
toType: string;
44-
toSelector?: Selector;
45-
matcher: Matcher;
46-
relationshipType: string;
47-
metadata: Record<string, string>;
48-
workspaceId: string;
49-
};
50-
51-
// Mock data - in production this would come from API
52-
const mockRules: RelationshipRule[] = [
53-
{
54-
id: "1",
55-
workspaceId: "workspace-1",
56-
reference: "deployment-to-environment",
57-
name: "Deployment Environment Relationship",
58-
description: "Links deployments to their target environments",
59-
fromType: "deployment",
60-
toType: "environment",
61-
matcher: {
62-
properties: [
63-
{
64-
fromProperty: ["metadata", "environment-id"],
65-
toProperty: ["id"],
66-
operator: "equals",
67-
},
68-
],
69-
},
70-
relationshipType: "deploys_to",
71-
metadata: {
72-
category: "orchestration",
73-
},
74-
},
75-
{
76-
id: "2",
77-
workspaceId: "workspace-1",
78-
reference: "environment-to-resources",
79-
name: "Environment Resources",
80-
description: "Maps environments to their associated resources",
81-
fromType: "environment",
82-
toType: "resource",
83-
fromSelector: {
84-
json: { type: "production" },
85-
},
86-
matcher: {
87-
properties: [
88-
{
89-
fromProperty: ["name"],
90-
toProperty: ["metadata", "environment"],
91-
operator: "equals",
92-
},
93-
],
94-
},
95-
relationshipType: "contains",
96-
metadata: {
97-
category: "inventory",
98-
},
99-
},
100-
{
101-
id: "3",
102-
workspaceId: "workspace-1",
103-
reference: "service-dependencies",
104-
name: "Service Dependencies",
105-
description: "Tracks dependencies between microservices",
106-
fromType: "resource",
107-
toType: "resource",
108-
fromSelector: {
109-
json: { kind: "service" },
110-
},
111-
toSelector: {
112-
json: { kind: "database" },
113-
},
114-
matcher: {
115-
properties: [
116-
{
117-
fromProperty: ["metadata", "database-name"],
118-
toProperty: ["name"],
119-
operator: "equals",
120-
},
121-
],
122-
},
123-
relationshipType: "depends_on",
124-
metadata: {
125-
category: "dependencies",
126-
},
127-
},
128-
{
129-
id: "4",
130-
workspaceId: "workspace-1",
131-
reference: "region-based-resources",
132-
name: "Regional Resource Grouping",
133-
description: "Groups resources by AWS region",
134-
fromType: "resource",
135-
toType: "resource",
136-
matcher: {
137-
properties: [
138-
{
139-
fromProperty: ["metadata", "region"],
140-
toProperty: ["metadata", "region"],
141-
operator: "equals",
142-
},
143-
],
144-
},
145-
relationshipType: "same_region",
146-
metadata: {
147-
category: "topology",
148-
provider: "aws",
149-
},
150-
},
151-
{
152-
id: "5",
153-
workspaceId: "workspace-1",
154-
reference: "cel-matcher-example",
155-
name: "Complex CEL Matcher",
156-
description: "Uses CEL expression for complex matching logic",
157-
fromType: "deployment",
158-
toType: "resource",
159-
matcher: {
160-
cel: 'from.metadata.environment == to.metadata.environment && to.metadata.type == "database"',
161-
},
162-
relationshipType: "uses",
163-
metadata: {
164-
category: "advanced",
165-
},
166-
},
167-
];
168-
16920
export default function RelationshipRules() {
17021
return (
17122
<>

apps/workspace-engine/oapi/openapi.json

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,6 +2807,105 @@
28072807
"summary": "Get release targets for a policy"
28082808
}
28092809
},
2810+
"/v1/workspaces/{workspaceId}/relationship-rules": {
2811+
"get": {
2812+
"description": "Returns all relationship rules for the specified workspace.",
2813+
"operationId": "getRelationshipRules",
2814+
"parameters": [
2815+
{
2816+
"description": "ID of the workspace",
2817+
"in": "path",
2818+
"name": "workspaceId",
2819+
"required": true,
2820+
"schema": {
2821+
"type": "string"
2822+
}
2823+
},
2824+
{
2825+
"description": "Number of items to skip",
2826+
"in": "query",
2827+
"name": "offset",
2828+
"required": false,
2829+
"schema": {
2830+
"default": 0,
2831+
"minimum": 0,
2832+
"type": "integer"
2833+
}
2834+
},
2835+
{
2836+
"description": "Maximum number of items to return",
2837+
"in": "query",
2838+
"name": "limit",
2839+
"required": false,
2840+
"schema": {
2841+
"default": 50,
2842+
"maximum": 1000,
2843+
"minimum": 1,
2844+
"type": "integer"
2845+
}
2846+
}
2847+
],
2848+
"responses": {
2849+
"200": {
2850+
"content": {
2851+
"application/json": {
2852+
"schema": {
2853+
"properties": {
2854+
"items": {
2855+
"items": {
2856+
"$ref": "#/components/schemas/RelationshipRule"
2857+
},
2858+
"type": "array"
2859+
},
2860+
"limit": {
2861+
"description": "Maximum number of items returned",
2862+
"type": "integer"
2863+
},
2864+
"offset": {
2865+
"description": "Number of items skipped",
2866+
"type": "integer"
2867+
},
2868+
"total": {
2869+
"description": "Total number of items available",
2870+
"type": "integer"
2871+
}
2872+
},
2873+
"required": [
2874+
"items",
2875+
"total",
2876+
"limit",
2877+
"offset"
2878+
],
2879+
"type": "object"
2880+
}
2881+
}
2882+
},
2883+
"description": "Paginated list of items"
2884+
},
2885+
"400": {
2886+
"content": {
2887+
"application/json": {
2888+
"schema": {
2889+
"$ref": "#/components/schemas/ErrorResponse"
2890+
}
2891+
}
2892+
},
2893+
"description": "Invalid request"
2894+
},
2895+
"404": {
2896+
"content": {
2897+
"application/json": {
2898+
"schema": {
2899+
"$ref": "#/components/schemas/ErrorResponse"
2900+
}
2901+
}
2902+
},
2903+
"description": "Resource not found"
2904+
}
2905+
},
2906+
"summary": "Get relationship rules for a given workspace"
2907+
}
2908+
},
28102909
"/v1/workspaces/{workspaceId}/release-targets/evaluate": {
28112910
"post": {
28122911
"description": "Evaluates all policies and rules that apply to a given release target and returns the evaluation results.",

apps/workspace-engine/oapi/spec/paths/relationship.jsonnet

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
local openapi = import '../lib/openapi.libsonnet';
22

33
{
4+
'/v1/workspaces/{workspaceId}/relationship-rules': {
5+
get: {
6+
summary: 'Get relationship rules for a given workspace',
7+
operationId: 'getRelationshipRules',
8+
description: 'Returns all relationship rules for the specified workspace.',
9+
parameters: [
10+
openapi.workspaceIdParam(),
11+
openapi.offsetParam(),
12+
openapi.limitParam(),
13+
],
14+
responses: openapi.paginatedResponse(openapi.schemaRef('RelationshipRule'))
15+
+ openapi.notFoundResponse()
16+
+ openapi.badRequestResponse(),
17+
},
18+
},
419
'/v1/workspaces/{workspaceId}/entities/{relatableEntityType}/{entityId}/relationships': {
520
get: {
621
summary: 'Get related entities for a given entity',

apps/workspace-engine/pkg/oapi/oapi.gen.go

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

apps/workspace-engine/pkg/server/openapi/deployments/server.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,8 @@ func (s *Deployments) GetDeploymentResources(c *gin.Context, workspaceId string,
6666
total := len(resourceList)
6767

6868
// Apply pagination
69-
start := offset
70-
if start > total {
71-
start = total
72-
}
73-
end := start + limit
74-
if end > total {
75-
end = total
76-
}
69+
start := min(offset, total)
70+
end := min(start + limit, total)
7771
paginatedResources := resourceList[start:end]
7872

7973
c.JSON(http.StatusOK, gin.H{

0 commit comments

Comments
 (0)