@Summary Get agent init script @ID get-agent-init-script @Produce text/plain @Tags InitScript @Param os path string true "Operating system" @Param arch path string true "Architecture" @Success 200 "Success" @Router /api/v2/init-script/{os}/{arch} [get]
(rw http.ResponseWriter, r *http.Request)
| 23 | // @Success 200 "Success" |
| 24 | // @Router /api/v2/init-script/{os}/{arch} [get] |
| 25 | func (api *API) initScript(rw http.ResponseWriter, r *http.Request) { |
| 26 | os := strings.ToLower(chi.URLParam(r, "os")) |
| 27 | arch := strings.ToLower(chi.URLParam(r, "arch")) |
| 28 | |
| 29 | script, exists := provisionersdk.AgentScriptEnv()[fmt.Sprintf("CODER_AGENT_SCRIPT_%s_%s", os, arch)] |
| 30 | if !exists { |
| 31 | httpapi.Write(r.Context(), rw, http.StatusBadRequest, codersdk.Response{ |
| 32 | Message: fmt.Sprintf("Unknown os/arch: %s/%s", os, arch), |
| 33 | }) |
| 34 | return |
| 35 | } |
| 36 | script = strings.ReplaceAll(script, "${ACCESS_URL}", api.AccessURL.String()+"/") |
| 37 | script = strings.ReplaceAll(script, "${AUTH_TYPE}", "token") |
| 38 | |
| 39 | scriptBytes := []byte(script) |
| 40 | hash := sha256.Sum256(scriptBytes) |
| 41 | rw.Header().Set("Content-Digest", fmt.Sprintf("sha256:%x", base64.StdEncoding.EncodeToString(hash[:]))) |
| 42 | rw.Header().Set("Content-Type", "text/plain; charset=utf-8") |
| 43 | rw.WriteHeader(http.StatusOK) |
| 44 | _, _ = rw.Write(scriptBytes) |
| 45 | } |
nothing calls this directly
no test coverage detected