- Notifications
You must be signed in to change notification settings - Fork1k
feat(coderd): add support for external agents to API's and provisioner#19286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
60dc330
10fc9fe
5f344a1
28243e3
d560e5c
732bc1d
5ca172e
10e6853
760de9a
3e2288b
ee58237
b91397d
fb7bc71
0baf2b3
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package coderd | ||
import ( | ||
"crypto/sha256" | ||
"encoding/base64" | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
"github.com/go-chi/chi/v5" | ||
"github.com/coder/coder/v2/coderd/httpapi" | ||
"github.com/coder/coder/v2/codersdk" | ||
"github.com/coder/coder/v2/provisionersdk" | ||
) | ||
// @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 /init-script/{os}/{arch} [get] | ||
func (api *API) initScript(rw http.ResponseWriter, r *http.Request) { | ||
os := strings.ToLower(chi.URLParam(r, "os")) | ||
arch := strings.ToLower(chi.URLParam(r, "arch")) | ||
script, exists := provisionersdk.AgentScriptEnv()[fmt.Sprintf("CODER_AGENT_SCRIPT_%s_%s", os, arch)] | ||
if !exists { | ||
httpapi.Write(r.Context(), rw, http.StatusBadRequest, codersdk.Response{ | ||
Message: fmt.Sprintf("Unknown os/arch: %s/%s", os, arch), | ||
}) | ||
return | ||
} | ||
script = strings.ReplaceAll(script, "${ACCESS_URL}", api.AccessURL.String()+"/") | ||
script = strings.ReplaceAll(script, "${AUTH_TYPE}", "token") | ||
scriptBytes := []byte(script) | ||
hash := sha256.Sum256(scriptBytes) | ||
rw.Header().Set("Content-Digest", fmt.Sprintf("sha256:%x", base64.StdEncoding.EncodeToString(hash[:]))) | ||
rw.Header().Set("Content-Type", "text/plain; charset=utf-8") | ||
rw.WriteHeader(http.StatusOK) | ||
_, _ = rw.Write(scriptBytes) | ||
} |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.