MCPcopy Create free account
hub / github.com/rilldata/rill / ResolveComponent

Method ResolveComponent

runtime/server/canvases.go:43–113  ·  view source on GitHub ↗
(ctx context.Context, req *runtimev1.ResolveComponentRequest)

Source from the content-addressed store, hash-verified

41}
42
43func (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)

Callers

nothing calls this directly

Calls 14

AddRequestAttributesFunction · 0.92
GetClaimsFunction · 0.92
CanMethod · 0.80
ControllerMethod · 0.80
InstanceMethod · 0.80
StringMethod · 0.65
GetMethod · 0.65
ErrorfMethod · 0.65
ErrorMethod · 0.45
GetComponentMethod · 0.45

Tested by

no test coverage detected