(ctx context.Context, req *runtimev1.ResolveComponentRequest)
| 41 | } |
| 42 | |
| 43 | func (s *Server) ResolveComponent(ctx context.Context, req *runtimev1.ResolveComponentRequest) (*runtimev1.ResolveComponentResponse, error) { |
| 44 | // Add observability attributes |
| 45 | s.addInstanceRequestAttributes(ctx, req.InstanceId) |
| 46 | observability.AddRequestAttributes(ctx, |
| 47 | attribute.String("args.instance_id", req.InstanceId), |
| 48 | attribute.String("args.component", req.Component), |
| 49 | ) |
| 50 | |
| 51 | // Check if user has access to query for component data (we use the ReadAPI permission for this for now) |
| 52 | claims := auth.GetClaims(ctx, req.InstanceId) |
| 53 | if !claims.Can(runtime.ReadAPI) { |
| 54 | return nil, status.Error(codes.PermissionDenied, "does not have access to component data") |
| 55 | } |
| 56 | |
| 57 | // Find the component spec |
| 58 | ctrl, err := s.runtime.Controller(ctx, req.InstanceId) |
| 59 | if err != nil { |
| 60 | return nil, err |
| 61 | } |
| 62 | res, err := ctrl.Get(ctx, &runtimev1.ResourceName{Kind: runtime.ResourceKindComponent, Name: req.Component}, false) |
| 63 | if err != nil { |
| 64 | return nil, err |
| 65 | } |
| 66 | spec := res.GetComponent().State.ValidSpec |
| 67 | if spec == nil { |
| 68 | return nil, status.Errorf(codes.FailedPrecondition, "component %q is invalid", req.Component) |
| 69 | } |
| 70 | |
| 71 | // Get current instance metadata |
| 72 | inst, err := s.runtime.Instance(ctx, req.InstanceId) |
| 73 | if err != nil { |
| 74 | return nil, err |
| 75 | } |
| 76 | |
| 77 | // Parse args |
| 78 | args := req.Args.AsMap() |
| 79 | |
| 80 | // Setup templating data |
| 81 | td := parser.TemplateData{ |
| 82 | Environment: inst.Environment, |
| 83 | User: claims.UserAttributes, |
| 84 | Variables: inst.ResolveVariables(false), |
| 85 | ExtraProps: map[string]any{ |
| 86 | "args": args, |
| 87 | }, |
| 88 | } |
| 89 | |
| 90 | // Resolve templating in the renderer properties |
| 91 | var rendererProps *structpb.Struct |
| 92 | if spec.RendererProperties != nil { |
| 93 | v, err := parser.ResolveTemplateRecursively(spec.RendererProperties.AsMap(), td, false) |
| 94 | if err != nil { |
| 95 | return nil, status.Errorf(codes.InvalidArgument, "failed to resolve renderer properties: %s", err.Error()) |
| 96 | } |
| 97 | |
| 98 | props, ok := v.(map[string]any) |
| 99 | if !ok { |
| 100 | return nil, status.Errorf(codes.Internal, "failed to convert resolved renderer properties to map: %v", v) |
nothing calls this directly
no test coverage detected