buildCELVariablesForDataExport builds CEL variables for DATABASE_EXPORT issues.
(ctx context.Context, stores *store.Store, issue *store.IssueMessage)
| 659 | |
| 660 | // buildCELVariablesForDataExport builds CEL variables for DATABASE_EXPORT issues. |
| 661 | func buildCELVariablesForDataExport(ctx context.Context, stores *store.Store, issue *store.IssueMessage) ([]map[string]any, bool, error) { |
| 662 | if issue.PlanUID == nil { |
| 663 | return nil, false, errors.Errorf("expected plan UID in issue %v", issue.UID) |
| 664 | } |
| 665 | plan, err := stores.GetPlan(ctx, &store.FindPlanMessage{ProjectID: issue.ProjectID, UID: issue.PlanUID}) |
| 666 | if err != nil { |
| 667 | return nil, false, errors.Wrapf(err, "failed to get plan %v", *issue.PlanUID) |
| 668 | } |
| 669 | if plan == nil { |
| 670 | return nil, false, errors.Errorf("plan %v not found", *issue.PlanUID) |
| 671 | } |
| 672 | |
| 673 | // Unfold database groups and get all targets (only EXPORT_DATA targets) |
| 674 | targets, err := unfoldSpecTargets(ctx, stores, plan.Config.GetSpecs(), issue.ProjectID) |
| 675 | if err != nil { |
| 676 | return nil, false, errors.Wrap(err, "failed to unfold spec targets") |
| 677 | } |
| 678 | |
| 679 | var celVarsList []map[string]any |
| 680 | for _, target := range targets { |
| 681 | envID := "" |
| 682 | if target.database.EffectiveEnvironmentID != nil { |
| 683 | envID = *target.database.EffectiveEnvironmentID |
| 684 | } |
| 685 | |
| 686 | celVars := map[string]any{ |
| 687 | common.CELAttributeResourceEnvironmentID: envID, |
| 688 | common.CELAttributeResourceProjectID: issue.ProjectID, |
| 689 | common.CELAttributeResourceInstanceID: target.database.InstanceID, |
| 690 | common.CELAttributeResourceDatabaseName: target.database.DatabaseName, |
| 691 | common.CELAttributeResourceDBEngine: target.database.Engine.String(), |
| 692 | } |
| 693 | celVarsList = append(celVarsList, celVars) |
| 694 | } |
| 695 | |
| 696 | if len(celVarsList) == 0 { |
| 697 | celVarsList = append(celVarsList, map[string]any{}) |
| 698 | } |
| 699 | |
| 700 | return celVarsList, true, nil |
| 701 | } |
| 702 | |
| 703 | // buildCELVariablesForRoleGrant builds CEL variables for ROLE_GRANT issues. |
| 704 | func buildCELVariablesForRoleGrant(ctx context.Context, stores *store.Store, issue *store.IssueMessage) ([]map[string]any, bool, error) { |
no test coverage detected