mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
This update exposes the workspace name and owner, and changes authentication methods to be explicit. Implicit authentication added unnecessary complexity and introduced inconsistency.
58 lines
1.7 KiB
Go
58 lines
1.7 KiB
Go
package provisionersdk
|
|
|
|
import "fmt"
|
|
|
|
var (
|
|
// A mapping of operating-system ($GOOS) to architecture ($GOARCH)
|
|
// to agent install and run script. ${DOWNLOAD_URL} is replaced
|
|
// with strings.ReplaceAll() when being consumed.
|
|
agentScripts = map[string]map[string]string{
|
|
"windows": {
|
|
"amd64": `
|
|
$ProgressPreference = "SilentlyContinue"
|
|
Invoke-WebRequest -Uri ${ACCESS_URL}bin/coder-windows-amd64.exe -OutFile $env:TEMP\coder.exe
|
|
$env:CODER_AUTH = "${AUTH_TYPE}"
|
|
$env:CODER_URL = "${ACCESS_URL}"
|
|
Start-Process -FilePath $env:TEMP\coder.exe -ArgumentList "workspaces","agent" -PassThru
|
|
`,
|
|
},
|
|
"linux": {
|
|
"amd64": `
|
|
#!/usr/bin/env sh
|
|
set -eu pipefail
|
|
export BINARY_LOCATION=$(mktemp -d)/coder
|
|
curl -fsSL ${ACCESS_URL}bin/coder-linux-amd64 -o $BINARY_LOCATION
|
|
chmod +x $BINARY_LOCATION
|
|
export CODER_AUTH="${AUTH_TYPE}"
|
|
export CODER_URL="${ACCESS_URL}"
|
|
exec $BINARY_LOCATION workspaces agent
|
|
`,
|
|
},
|
|
"darwin": {
|
|
"amd64": `
|
|
#!/usr/bin/env sh
|
|
set -eu pipefail
|
|
export BINARY_LOCATION=$(mktemp -d)/coder
|
|
curl -fsSL ${ACCESS_URL}bin/coder-darwin-amd64 -o $BINARY_LOCATION
|
|
chmod +x $BINARY_LOCATION
|
|
export CODER_AUTH="${AUTH_TYPE}"
|
|
export CODER_URL="${ACCESS_URL}"
|
|
exec $BINARY_LOCATION workspaces agent
|
|
`,
|
|
},
|
|
}
|
|
)
|
|
|
|
// AgentScriptEnv returns a key-pair of scripts that are consumed
|
|
// by the Coder Terraform Provider. See:
|
|
// https://github.com/coder/terraform-provider-coder/blob/main/internal/provider/provider.go#L97
|
|
func AgentScriptEnv() map[string]string {
|
|
env := map[string]string{}
|
|
for operatingSystem, scripts := range agentScripts {
|
|
for architecture, script := range scripts {
|
|
env[fmt.Sprintf("CODER_AGENT_SCRIPT_%s_%s", operatingSystem, architecture)] = script
|
|
}
|
|
}
|
|
return env
|
|
}
|