-
Notifications
You must be signed in to change notification settings - Fork 929
feat: Refactor API routes to use UUIDs instead of friendly names #401
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
051edda
Add client for agent
kylecarbs 1aec36d
Cleanup code
kylecarbs 7180233
Fix linting error
kylecarbs 2f56c6d
Rename routes to be simpler
kylecarbs a30cf22
Rename workspace history to workspace build
kylecarbs b67f8d4
Refactor HTTP middlewares to use UUIDs
kylecarbs 7b0899c
Cleanup routes
kylecarbs db0ca76
Compiles!
kylecarbs 7979681
Fix files and organizations
kylecarbs 1726ead
Fix querying
kylecarbs 29a019a
Fix agent lock
kylecarbs bdea345
Cleanup database abstraction
kylecarbs e903072
Add parameters
kylecarbs e73e0a5
Merge branch 'main' into agentroutes
kylecarbs 3d0f7ad
Fix linting errors
kylecarbs abd4b50
Fix log race
kylecarbs 83eb9ca
Lock on close wait
kylecarbs ebf2f77
Fix log cleanup
kylecarbs 74e8f43
Fix e2e tests
kylecarbs a9a19b7
Fix upstream version of opencensus-go
kylecarbs 9597b0c
Update coderdtest.go
kylecarbs 878738c
Fix coverpkg
kylecarbs 4293914
Fix codecov ignore
kylecarbs 3bc28ab
Merge branch 'main' into agentroutes
kylecarbs 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
Fix querying
- Loading branch information
commit 1726eadca554a80f8fa90b685deed8f882d25ed7
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
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 |
---|---|---|
|
@@ -142,8 +142,8 @@ func NewProvisionerDaemon(t *testing.T, client *codersdk.Client) io.Closer { | |
|
||
// CreateFirstUser creates a user with preset credentials and authenticates | ||
// with the passed in codersdk client. | ||
func CreateFirstUser(t *testing.T, client *codersdk.Client) coderd.CreateUserResponse { | ||
req := coderd.CreateUserRequest{ | ||
func CreateFirstUser(t *testing.T, client *codersdk.Client) coderd.CreateFirstUserResponse { | ||
req := coderd.CreateFirstUserRequest{ | ||
Email: "[email protected]", | ||
Username: "testuser", | ||
Password: "testpass", | ||
|
@@ -161,6 +161,28 @@ func CreateFirstUser(t *testing.T, client *codersdk.Client) coderd.CreateUserRes | |
return resp | ||
} | ||
|
||
// CreateAnotherUser creates and authenticates a new user. | ||
func CreateAnotherUser(t *testing.T, client *codersdk.Client, organization string) *codersdk.Client { | ||
req := coderd.CreateUserRequest{ | ||
Email: namesgenerator.GetRandomName(1) + "@coder.com", | ||
Username: randomUsername(), | ||
Password: "testpass", | ||
OrganizationID: organization, | ||
} | ||
_, err := client.CreateUser(context.Background(), req) | ||
require.NoError(t, err) | ||
|
||
login, err := client.LoginWithPassword(context.Background(), coderd.LoginWithPasswordRequest{ | ||
Email: req.Email, | ||
Password: req.Password, | ||
}) | ||
require.NoError(t, err) | ||
|
||
other := codersdk.New(client.URL) | ||
other.SessionToken = login.SessionToken | ||
return other | ||
} | ||
|
||
// CreateProjectVersion creates a project import provisioner job | ||
// with the responses provided. It uses the "echo" provisioner for compatibility | ||
// with testing. | ||
|
@@ -190,27 +212,47 @@ func CreateProject(t *testing.T, client *codersdk.Client, organization string, v | |
} | ||
|
||
// AwaitProjectImportJob awaits for an import job to reach completed status. | ||
func AwaitProjectImportJob(t *testing.T, client *codersdk.Client, organization string, job uuid.UUID) coderd.ProvisionerJob { | ||
var provisionerJob coderd.ProvisionerJob | ||
// require.Eventually(t, func() bool { | ||
// var err error | ||
// provisionerJob, err = client.ProjectImportJob(context.Background(), organization, job) | ||
// require.NoError(t, err) | ||
// return provisionerJob.Status.Completed() | ||
// }, 5*time.Second, 25*time.Millisecond) | ||
return provisionerJob | ||
func AwaitProjectVersionJob(t *testing.T, client *codersdk.Client, version uuid.UUID) coderd.ProjectVersion { | ||
var projectVersion coderd.ProjectVersion | ||
require.Eventually(t, func() bool { | ||
var err error | ||
projectVersion, err = client.ProjectVersion(context.Background(), version) | ||
require.NoError(t, err) | ||
return projectVersion.Job.CompletedAt != nil | ||
}, 5*time.Second, 25*time.Millisecond) | ||
return projectVersion | ||
} | ||
|
||
// AwaitWorkspaceBuildJob waits for a workspace provision job to reach completed status. | ||
func AwaitWorkspaceBuildJob(t *testing.T, client *codersdk.Client, build uuid.UUID) coderd.WorkspaceBuild { | ||
var workspaceBuild coderd.WorkspaceBuild | ||
require.Eventually(t, func() bool { | ||
var err error | ||
workspaceBuild, err = client.WorkspaceBuild(context.Background(), build) | ||
require.NoError(t, err) | ||
return workspaceBuild.Job.CompletedAt != nil | ||
}, 5*time.Second, 25*time.Millisecond) | ||
return workspaceBuild | ||
} | ||
|
||
// AwaitWorkspaceProvisionJob awaits for a workspace provision job to reach completed status. | ||
func AwaitWorkspaceProvisionJob(t *testing.T, client *codersdk.Client, organization string, job uuid.UUID) coderd.ProvisionerJob { | ||
var provisionerJob coderd.ProvisionerJob | ||
// AwaitWorkspaceAgents waits for all resources with agents to be connected. | ||
func AwaitWorkspaceAgents(t *testing.T, client *codersdk.Client, build uuid.UUID) []coderd.WorkspaceResource { | ||
var resources []coderd.WorkspaceResource | ||
require.Eventually(t, func() bool { | ||
var err error | ||
provisionerJob, err = client.WorkspaceProvisionJob(context.Background(), organization, job) | ||
resources, err = client.WorkspaceResourcesByBuild(context.Background(), build) | ||
require.NoError(t, err) | ||
return provisionerJob.Status.Completed() | ||
for _, resource := range resources { | ||
if resource.Agent == nil { | ||
continue | ||
} | ||
if resource.Agent.UpdatedAt.IsZero() { | ||
return false | ||
} | ||
} | ||
return true | ||
}, 5*time.Second, 25*time.Millisecond) | ||
return provisionerJob | ||
return resources | ||
} | ||
|
||
// CreateWorkspace creates a workspace for the user and project provided. | ||
|
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
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.
Hmm, it doesn't seem like this would be used here?
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.
It ensures the caller has access to the organization the project resides in. Otherwise, users could access projects inside organizations they aren't in.