-
Notifications
You must be signed in to change notification settings - Fork 961
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kacpersaw
wants to merge
6
commits into
kacpersaw/feat-coder-attach-database
Choose a base branch
from
kacpersaw/feat-coder-attach-api
base: kacpersaw/feat-coder-attach-database
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,457
−61
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
71a653c
feat: add support for external agents to API's and provisioner
kacpersaw c627aa1
generate api model
kacpersaw a4268ea
move /external-agent/{agent}/credentials endpoint to enterprise
kacpersaw ba367a3
add Content-Digest header to init script response
kacpersaw 0cf5381
implement license checks for external agents in workspace builds and …
kacpersaw 6352a4a
Update license_test.go
kacpersaw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
feat: add support for external agents to API's and provisioner
- Loading branch information
commit 71a653c3d67ac8e59efba2bb4148044561183c3b
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package coderd | ||
|
||
import ( | ||
"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") | ||
|
||
rw.Header().Set("Content-Type", "text/plain; charset=utf-8") | ||
rw.WriteHeader(http.StatusOK) | ||
_, _ = rw.Write([]byte(script)) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package coderd_test | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/coder/coder/v2/coderd/coderdtest" | ||
"github.com/coder/coder/v2/codersdk" | ||
) | ||
|
||
func TestInitScript(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("OK Windows", func(t *testing.T) { | ||
t.Parallel() | ||
client := coderdtest.New(t, nil) | ||
script, err := client.InitScript(context.Background(), "windows", "amd64") | ||
require.NoError(t, err) | ||
require.NotEmpty(t, script) | ||
require.Contains(t, script, "$env:CODER_AGENT_AUTH = \"token\"") | ||
}) | ||
|
||
t.Run("OK Linux", func(t *testing.T) { | ||
t.Parallel() | ||
client := coderdtest.New(t, nil) | ||
script, err := client.InitScript(context.Background(), "linux", "amd64") | ||
require.NoError(t, err) | ||
require.NotEmpty(t, script) | ||
require.Contains(t, script, "export CODER_AGENT_AUTH=\"token\"") | ||
}) | ||
|
||
t.Run("BadRequest", func(t *testing.T) { | ||
t.Parallel() | ||
client := coderdtest.New(t, nil) | ||
_, err := client.InitScript(context.Background(), "darwin", "armv7") | ||
require.Error(t, err) | ||
var apiErr *codersdk.Error | ||
require.ErrorAs(t, err, &apiErr) | ||
require.Equal(t, http.StatusBadRequest, apiErr.StatusCode()) | ||
require.Equal(t, "Unknown os/arch: darwin/armv7", apiErr.Message) | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should make one of these
arm64
for variety, and also assert that the string/bin/coder-OS-ARCH[.exe]
shows up