MCPcopy Index your code
hub / github.com/coder/coder / templateVersionDynamicParameters

Method templateVersionDynamicParameters

coderd/parameters.go:78–113  ·  view source on GitHub ↗

The `listen` control flag determines whether to open a websocket connection to handle the request or not. This same function is used to 'evaluate' a template as a single invocation, or to 'listen' for a back and forth interaction with the user to update the form as they type. nolint:revive // liste

(listen bool, initial codersdk.DynamicParametersRequest)

Source from the content-addressed store, hash-verified

76//
77//nolint:revive // listen is a control flag
78func (api *API) templateVersionDynamicParameters(listen bool, initial codersdk.DynamicParametersRequest) func(rw http.ResponseWriter, r *http.Request) {
79 return func(rw http.ResponseWriter, r *http.Request) {
80 ctx := r.Context()
81 templateVersion := httpmw.TemplateVersionParam(r)
82
83 renderer, err := dynamicparameters.Prepare(ctx, api.Database, api.FileCache, templateVersion.ID,
84 dynamicparameters.WithTemplateVersion(templateVersion),
85 )
86 if err != nil {
87 if httpapi.Is404Error(err) {
88 httpapi.ResourceNotFound(rw)
89 return
90 }
91
92 if xerrors.Is(err, dynamicparameters.ErrTemplateVersionNotReady) {
93 httpapi.Write(ctx, rw, http.StatusTooEarly, codersdk.Response{
94 Message: "Template version job has not finished",
95 })
96 return
97 }
98
99 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
100 Message: "Internal error fetching template version data.",
101 Detail: err.Error(),
102 })
103 return
104 }
105 defer renderer.Close()
106
107 if listen {
108 api.handleParameterWebsocket(rw, r, initial, renderer)
109 } else {
110 api.handleParameterEvaluate(rw, r, initial, renderer)
111 }
112 }
113}
114
115func (*API) handleParameterEvaluate(rw http.ResponseWriter, r *http.Request, initial codersdk.DynamicParametersRequest, render dynamicparameters.Renderer) {
116 ctx := r.Context()

Calls 12

TemplateVersionParamFunction · 0.92
PrepareFunction · 0.92
WithTemplateVersionFunction · 0.92
Is404ErrorFunction · 0.92
ResourceNotFoundFunction · 0.92
WriteFunction · 0.92
ContextMethod · 0.65
CloseMethod · 0.65
IsMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected