-
Notifications
You must be signed in to change notification settings - Fork 23
feat: reference variables can path into related resource's variables #1005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -214,13 +214,17 @@ func (g *PostgresGetter) LoadCandidates( | |
| if err != nil { | ||
| return nil, fmt.Errorf("list resources for workspace %s: %w", workspaceID, err) | ||
| } | ||
| varsByResource, err := loadResourceVariablesByWorkspace(ctx, q, workspaceID) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| candidates := make([]eval.EntityData, 0, len(rows)) | ||
| for _, r := range rows { | ||
| candidates = append(candidates, eval.EntityData{ | ||
| ID: r.ID, | ||
| WorkspaceID: r.WorkspaceID, | ||
| EntityType: "resource", | ||
| Raw: resourceRowToMap(r), | ||
| Raw: resourceRowToMap(r, varsByResource[r.ID]), | ||
| }) | ||
|
Comment on lines
+217
to
228
|
||
| } | ||
| return candidates, nil | ||
|
|
@@ -275,11 +279,15 @@ func (g *PostgresGetter) GetEntityByID( | |
| if err != nil { | ||
| return nil, fmt.Errorf("get resource %s: %w", entityID, err) | ||
| } | ||
| vars, err := loadResourceVariables(ctx, q, r.ID) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return &eval.EntityData{ | ||
| ID: r.ID, | ||
| WorkspaceID: r.WorkspaceID, | ||
| EntityType: "resource", | ||
| Raw: resourceRowToMap(db.ListActiveResourcesByWorkspaceRow(r)), | ||
| Raw: resourceRowToMap(db.ListActiveResourcesByWorkspaceRow(r), vars), | ||
| }, nil | ||
|
|
||
| case "deployment": | ||
|
|
@@ -311,7 +319,10 @@ func (g *PostgresGetter) GetEntityByID( | |
| } | ||
| } | ||
|
|
||
| func resourceRowToMap(r db.ListActiveResourcesByWorkspaceRow) map[string]any { | ||
| func resourceRowToMap( | ||
| r db.ListActiveResourcesByWorkspaceRow, | ||
| vars map[string]oapi.Value, | ||
| ) map[string]any { | ||
| m := map[string]any{ | ||
| "type": "resource", | ||
| "id": r.ID.String(), | ||
|
|
@@ -325,9 +336,54 @@ func resourceRowToMap(r db.ListActiveResourcesByWorkspaceRow) map[string]any { | |
| if r.ProviderID != uuid.Nil { | ||
| m["providerId"] = r.ProviderID.String() | ||
| } | ||
| if len(vars) > 0 { | ||
| m["variables"] = vars | ||
| } | ||
| return m | ||
| } | ||
|
|
||
| func loadResourceVariables( | ||
| ctx context.Context, | ||
| q *db.Queries, | ||
| resourceID uuid.UUID, | ||
| ) (map[string]oapi.Value, error) { | ||
| rows, err := q.ListResourceVariablesByResourceID(ctx, resourceID) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("list variables for resource %s: %w", resourceID, err) | ||
| } | ||
| if len(rows) == 0 { | ||
| return nil, nil | ||
| } | ||
| vars := make(map[string]oapi.Value, len(rows)) | ||
| for _, row := range rows { | ||
| v := db.ToOapiResourceVariable(row) | ||
| vars[v.Key] = v.Value | ||
| } | ||
| return vars, nil | ||
| } | ||
|
|
||
| func loadResourceVariablesByWorkspace( | ||
| ctx context.Context, | ||
| q *db.Queries, | ||
| workspaceID uuid.UUID, | ||
| ) (map[uuid.UUID]map[string]oapi.Value, error) { | ||
| rows, err := q.ListResourceVariablesByWorkspaceID(ctx, workspaceID) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("list variables for workspace %s: %w", workspaceID, err) | ||
| } | ||
| result := make(map[uuid.UUID]map[string]oapi.Value) | ||
| for _, row := range rows { | ||
| v := db.ToOapiResourceVariable(row) | ||
| m := result[row.ResourceID] | ||
| if m == nil { | ||
| m = make(map[string]oapi.Value) | ||
| result[row.ResourceID] = m | ||
| } | ||
| m[v.Key] = v.Value | ||
| } | ||
| return result, nil | ||
| } | ||
|
|
||
| func deploymentRowToMap(r db.ListDeploymentsByWorkspaceRow) map[string]any { | ||
| m := map[string]any{ | ||
| "type": "deployment", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New
variablespath handling for resources (getResourceVariableProperty) isn’t covered by the existing property extraction unit tests. Adding tests forvariables/<key>and nested object traversal (plus key-missing / non-literal cases) would help prevent regressions.