8000 chore: Force codersdk to not import anything from database by Emyrk · Pull Request #1576 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

chore: Force codersdk to not import anything from database #1576

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 15 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Unified Diff View
Unified
Prev Previous commit
Merge remote-tracking branch 'origin/main' into stevenmasley/clean_co…
…dersdk
  • Loading branch information
Emyrk committed May 19, 2022
commit ce24743ab23e086fabf0f8025657540f7a4f3012
2 changes: 1 addition & 1 deletion coderd/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (api *api) workspaces(rw http.ResponseWriter, r *http.Request) {

// Empty strings mean no filter
orgFilter := r.URL.Query().Get("organization_id")
ownerFilter := r.URL.Query().Get("owner_id")
ownerFilter := r.URL.Query().Get("owner")

filter := database.GetWorkspacesWithFilterParams{Deleted: false}
if orgFilter != "" {
Expand Down
2 changes: 1 addition & 1 deletion codersdk/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (f WorkspaceFilter) asRequestOption() requestOption {
q.Set("organization_id", f.OrganizationID.String())
}
if f.Owner != "" {
q.Set("owner_id", f.Owner)
q.Set("owner", f.Owner)
}
r.URL.RawQuery = q.Encode()
}
Expand Down
5 changes: 4 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
version: "3.9"
services:
coder:
image: ghcr.io/coder/coder:v${CODER_VERSION:-0.5.6}-${ARCH:-amd64}
image: ghcr.io/coder/coder:v${CODER_VERSION:-0.5.10}-${ARCH:-amd64}
ports:
- "7080:7080"
environment:
CODER_PG_CONNECTION_URL: "postgresql://${POSTGRES_USER:-username}:${POSTGRES_PASSWORD:-password}@database/${POSTGRES_DB:-coder}?sslmode=disable"
CODER_ADDRESS: "0.0.0.0:7080"
# You'll need to set CODER_ACCESS_URL to an
# externally-reachable IP to use non-Docker examples!
CODER_ACCESS_URL: "${CODER_ACCESS_URL:-http://host.docker.internal:7080}"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
Expand Down
3 changes: 0 additions & 3 deletions examples/docker-image-builds/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ provider "docker" {
}

provider "coder" {
# The below assumes your Coder deployment is running in docker-compose.
# If this is not the case, either comment or edit the below.
url = "http://host.docker.internal:7080"
}

data "coder_workspace" "me" {
Expand Down
3 changes: 0 additions & 3 deletions examples/docker/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ provider "docker" {
}

provider "coder" {
# The below assumes your Coder deployment is running in docker-compose.
# If this is not the case, either comment or edit the below.
url = "http://host.docker.internal:7080"
}

data "coder_workspace" "me" {
Expand Down
1 change: 1 addition & 0 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"postinstall": "yarn typegen",
"build": "NODE_ENV=production webpack build --config=webpack.prod.ts",
"build:analyze": "NODE_ENV=production webpack --profile --progress --json --config=webpack.prod.ts > out/stats.json && webpack-bundle-analyzer out/stats.json out",
"check:all": "yarn format:check && yarn lint && yarn test",
"chromatic": "chromatic",
"dev": "webpack-dev-server --config=webpack.dev.ts",
"format:check": "prettier --check '**/*.{css,html,js,json,jsx,md,ts,tsx,yaml,yml}'",
Expand Down
15 changes: 14 additions & 1 deletion site/src/api/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from "axios"
import { getApiKey, login, logout } from "./api"
import { getApiKey, getWorkspacesURL, login, logout } from "./api"
import * as TypesGen from "./typesGenerated"

describe("api.ts", () => {
Expand Down Expand Up @@ -113,4 +113,17 @@ describe("api.ts", () => {
}
})
})

describe("getWorkspacesURL", () => {
it.each<[TypesGen.WorkspaceFilter | undefined, string]>([
[undefined, "/api/v2/workspaces"],

[{ OrganizationID: "1", Owner: "" }, "/api/v2/workspaces?organization_id=1"],
[{ OrganizationID: "", Owner: "1" }, "/api/v2/workspaces?owner=1"],

[{ OrganizationID: "1", Owner: "me" }, "/api/v2/workspaces?organization_id=1&owner=me"],
])(`getWorkspacesURL(%p) returns %p`, (filter, expected) => {
expect(getWorkspacesURL(filter)).toBe(expected)
})
})
})
23 changes: 19 additions & 4 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,25 @@ export const getWorkspace = async (workspaceId: string): Promise<TypesGen.Worksp
return response.data
}

// TODO: @emyrk add query params as arguments. Supports 'organization_id' and 'owner'
// 'owner' can be a username, user_id, or 'me'
export const getWorkspaces = async (): Promise<TypesGen.Workspace[]> => {
const response = await axios.get<TypesGen.Workspace[]>(`/api/v2/workspaces`)
export const getWorkspacesURL = (filter?: TypesGen.WorkspaceFilter): string => {
const basePath = "/api/v2/workspaces"
const searchParams = new URLSearchParams()

if (filter?.OrganizationID) {
searchParams.append("organization_id", filter.OrganizationID)
}
if (filter?.Owner) {
searchParams.append("owner", filter.Owner)
}

const searchString = searchParams.toString()

return searchString ? `${basePath}?${searchString}` : basePath
}

export const getWorkspaces = async (filter?: TypesGen.WorkspaceFilter): Promise<TypesGen.Workspace[]> => {
const url = getWorkspacesURL(filter)
const response = await axios.get<TypesGen.Workspace[]>(url)
return response.data
}

Expand Down
29 changes: 0 additions & 29 deletions site/src/forms/CreateTemplateForm.test.tsx

This file was deleted.

155 changes: 0 additions & 155 deletions site/src/forms/CreateTemplateForm.tsx

This file was deleted.

9 changes: 6 additions & 3 deletions site/src/testHelpers/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ export const handlers = [
rest.post("/api/v2/users/me/workspaces", async (req, res, ctx) => {
return res(ctx.status(200), ctx.json(M.MockWorkspace))
}),
rest.get("/api/v2/workspaces", async (req, res, ctx) => {
return res(ctx.status(200), ctx.json([M.MockWorkspace]))
}),
rest.get("/api/v2/users/me/organizations", (req, res, ctx) => {
return res(ctx.status(200), ctx.json([M.MockOrganization]))
}),
Expand Down Expand Up @@ -79,6 +76,12 @@ export const handlers = [
}),

// workspaces

// REMARK: This endpoint works with query parameters, but they won't be
// reflected in the return.
rest.get("/api/v2/workspaces", async (req, res, ctx) => {
return res(ctx.status(200), ctx.json([M.MockWorkspace]))
}),
rest.get("/api/v2/organizations/:organizationId/workspaces/:userName/:workspaceName", (req, res, ctx) => {
if (req.params.workspaceName !== M.MockWorkspace.name) {
return res(
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0