- Notifications
You must be signed in to change notification settings - Fork928
chore: Add watch workspace endpoint#1493
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
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
13 commits Select commitHold shift + click to select a range
0760f8d
chore: Add watch workspace endpoint
f0ssel0551613
Add comment
f0sselda9c744
Make WorkspaceWatcher
f0sseldbaeb2c
add tests
f0ssel596cb8c
lint
f0ssel31b14ad
Add test for query param session token
f0ssel078c711
fix auth test
f0ssel184cd47
fix lint
f0ssel509beef
fix auth test
f0sselbe27df5
fix auth again
f0sself029650
move to channel over WorkspaceWatcher
f0ssel534bcdb
rebase and fix tests
f0sseldb49672
rebase and fix merge
f0sselFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletionscoderd/coderd.go
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
1 change: 1 addition & 0 deletionscoderd/coderd_test.go
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
22 changes: 14 additions & 8 deletionscoderd/httpmw/apikey.go
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 |
---|---|---|
@@ -17,8 +17,8 @@ import ( | ||
"github.com/coder/coder/coderd/httpapi" | ||
) | ||
//SessionTokenKey represents the name of the cookie or query paramater the API key is stored in. | ||
constSessionTokenKey = "session_token" | ||
Comment on lines +20 to +21 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Wise rename. | ||
type apiKeyContextKey struct{} | ||
@@ -43,18 +43,24 @@ type OAuth2Configs struct { | ||
func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) http.Handler { | ||
return func(next http.Handler) http.Handler { | ||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { | ||
var cookieValue string | ||
cookie, err := r.Cookie(SessionTokenKey) | ||
if err != nil { | ||
cookieValue = r.URL.Query().Get(SessionTokenKey) | ||
} else { | ||
cookieValue = cookie.Value | ||
} | ||
if cookieValue == "" { | ||
httpapi.Write(rw, http.StatusUnauthorized, httpapi.Response{ | ||
Message: fmt.Sprintf("%q cookieor query parametermust be provided",SessionTokenKey), | ||
}) | ||
return | ||
} | ||
parts := strings.Split(cookieValue, "-") | ||
// APIKeys are formatted: ID-SECRET | ||
if len(parts) != 2 { | ||
httpapi.Write(rw, http.StatusUnauthorized, httpapi.Response{ | ||
Message: fmt.Sprintf("invalid %q cookie api key format",SessionTokenKey), | ||
}) | ||
return | ||
} | ||
@@ -63,13 +69,13 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h | ||
// Ensuring key lengths are valid. | ||
if len(keyID) != 10 { | ||
httpapi.Write(rw, http.StatusUnauthorized, httpapi.Response{ | ||
Message: fmt.Sprintf("invalid %q cookie api key id",SessionTokenKey), | ||
}) | ||
return | ||
} | ||
if len(keySecret) != 22 { | ||
httpapi.Write(rw, http.StatusUnauthorized, httpapi.Response{ | ||
Message: fmt.Sprintf("invalid %q cookie api key secret",SessionTokenKey), | ||
}) | ||
return | ||
} | ||
53 changes: 42 additions & 11 deletionscoderd/httpmw/apikey_test.go
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
2 changes: 1 addition & 1 deletioncoderd/httpmw/authorize_test.go
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
2 changes: 1 addition & 1 deletioncoderd/httpmw/organizationparam_test.go
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
2 changes: 1 addition & 1 deletioncoderd/httpmw/templateparam_test.go
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
2 changes: 1 addition & 1 deletioncoderd/httpmw/templateversionparam_test.go
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
2 changes: 1 addition & 1 deletioncoderd/httpmw/userparam_test.go
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
4 changes: 2 additions & 2 deletionscoderd/httpmw/workspaceagent.go
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
2 changes: 1 addition & 1 deletioncoderd/httpmw/workspaceagent_test.go
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
2 changes: 1 addition & 1 deletioncoderd/httpmw/workspaceagentparam_test.go
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
2 changes: 1 addition & 1 deletioncoderd/httpmw/workspacebuildparam_test.go
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
2 changes: 1 addition & 1 deletioncoderd/httpmw/workspaceparam_test.go
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
4 changes: 2 additions & 2 deletionscoderd/users.go
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
2 changes: 1 addition & 1 deletioncoderd/users_test.go
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
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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.