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

Method IssueSignedAppTokenHTML

enterprise/wsproxy/wsproxysdk/wsproxysdk.go:115–155  ·  view source on GitHub ↗

IssueSignedAppTokenHTML issues a new signed app token for the provided app request. The error page will be returned as HTML in most cases, and will be written directly to the provided http.ResponseWriter.

(ctx context.Context, rw http.ResponseWriter, req workspaceapps.IssueTokenRequest, clientIP string)

Source from the content-addressed store, hash-verified

113// request. The error page will be returned as HTML in most cases, and will be
114// written directly to the provided http.ResponseWriter.
115func (c *Client) IssueSignedAppTokenHTML(ctx context.Context, rw http.ResponseWriter, req workspaceapps.IssueTokenRequest, clientIP string) (IssueSignedAppTokenResponse, bool) {
116 writeError := func(rw http.ResponseWriter, err error) {
117 res := codersdk.Response{
118 Message: "Internal server error",
119 Detail: err.Error(),
120 }
121 rw.WriteHeader(http.StatusInternalServerError)
122 _ = json.NewEncoder(rw).Encode(res)
123 }
124
125 resp, err := c.RequestIgnoreRedirects(ctx, http.MethodPost, "/api/v2/workspaceproxies/me/issue-signed-app-token", req, func(r *http.Request) {
126 r.Header.Set("Accept", "text/html")
127 r.Header.Set(CoderWorkspaceProxyRealIPHeader, clientIP)
128 })
129 if err != nil {
130 writeError(rw, xerrors.Errorf("perform issue signed app token request: %w", err))
131 return IssueSignedAppTokenResponse{}, false
132 }
133 defer resp.Body.Close()
134
135 if resp.StatusCode != http.StatusCreated {
136 // Copy the response to the ResponseWriter.
137 for k, v := range resp.Header {
138 rw.Header()[k] = v
139 }
140 rw.WriteHeader(resp.StatusCode)
141 _, err = io.Copy(rw, resp.Body)
142 if err != nil {
143 writeError(rw, xerrors.Errorf("copy response body: %w", err))
144 }
145 return IssueSignedAppTokenResponse{}, false
146 }
147
148 var res IssueSignedAppTokenResponse
149 err = json.NewDecoder(resp.Body).Decode(&res)
150 if err != nil {
151 writeError(rw, xerrors.Errorf("decode response body: %w", err))
152 return IssueSignedAppTokenResponse{}, false
153 }
154 return res, true
155}
156
157type ReportAppStatsRequest struct {
158 Stats []workspaceapps.StatsReport `json:"stats"`

Callers 3

TestIssueSignedAppTokenFunction · 0.80
IssueMethod · 0.80

Calls 9

EncodeMethod · 0.80
SetMethod · 0.65
CloseMethod · 0.65
CopyMethod · 0.65
ErrorMethod · 0.45
WriteHeaderMethod · 0.45
ErrorfMethod · 0.45
HeaderMethod · 0.45

Tested by 2

TestIssueSignedAppTokenFunction · 0.64