Skip to content

chore: Remove url and wildcard url from moon create #7224

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 7 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 0 additions & 6 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions coderd/database/dbfake/databasefake.go
Original file line number Diff line number Diff line change
Expand Up @@ -5191,8 +5191,6 @@ func (q *fakeQuerier) InsertWorkspaceProxy(_ context.Context, arg database.Inser
Name: arg.Name,
DisplayName: arg.DisplayName,
Icon: arg.Icon,
Url: arg.Url,
WildcardHostname: arg.WildcardHostname,
TokenHashedSecret: arg.TokenHashedSecret,
CreatedAt: arg.CreatedAt,
UpdatedAt: arg.UpdatedAt,
Expand Down
16 changes: 12 additions & 4 deletions coderd/database/dbgen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,19 +343,27 @@ func WorkspaceProxy(t testing.TB, db database.Store, orig database.WorkspaceProx
require.NoError(t, err, "generate secret")
hashedSecret := sha256.Sum256([]byte(secret))

resource, err := db.InsertWorkspaceProxy(context.Background(), database.InsertWorkspaceProxyParams{
proxy, err := db.InsertWorkspaceProxy(context.Background(), database.InsertWorkspaceProxyParams{
ID: takeFirst(orig.ID, uuid.New()),
Name: takeFirst(orig.Name, namesgenerator.GetRandomName(1)),
DisplayName: takeFirst(orig.DisplayName, namesgenerator.GetRandomName(1)),
Icon: takeFirst(orig.Icon, namesgenerator.GetRandomName(1)),
Url: takeFirst(orig.Url, fmt.Sprintf("https://%s.com", namesgenerator.GetRandomName(1))),
WildcardHostname: takeFirst(orig.WildcardHostname, fmt.Sprintf("*.%s.com", namesgenerator.GetRandomName(1))),
TokenHashedSecret: hashedSecret[:],
CreatedAt: takeFirst(orig.CreatedAt, database.Now()),
UpdatedAt: takeFirst(orig.UpdatedAt, database.Now()),
})
require.NoError(t, err, "insert proxy")
return resource, secret

// Also set these fields if the caller wants them.
if orig.Url != "" || orig.WildcardHostname != "" {
proxy, err = db.RegisterWorkspaceProxy(context.Background(), database.RegisterWorkspaceProxyParams{
Url: orig.Url,
WildcardHostname: orig.WildcardHostname,
ID: proxy.ID,
})
require.NoError(t, err, "update proxy")
}
return proxy, secret
}

func File(t testing.TB, db database.Store, orig database.File) database.File {
Expand Down
10 changes: 3 additions & 7 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions coderd/database/queries/proxies.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
INSERT INTO
workspace_proxies (
id,
url,
wildcard_hostname,
name,
display_name,
icon,
url,
wildcard_hostname,
token_hashed_secret,
created_at,
updated_at,
deleted
)
VALUES
($1, $2, $3, $4, $5, $6, $7, $8, $9, false) RETURNING *;
($1, '', '', $2, $3, $4, $5, $6, $7, false) RETURNING *;

-- name: RegisterWorkspaceProxy :one
UPDATE
Expand Down
8 changes: 3 additions & 5 deletions codersdk/workspaceproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ type WorkspaceProxy struct {
}

type CreateWorkspaceProxyRequest struct {
Name string `json:"name"`
DisplayName string `json:"display_name"`
Icon string `json:"icon"`
URL string `json:"url"`
WildcardHostname string `json:"wildcard_hostname"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
Icon string `json:"icon"`
}

type CreateWorkspaceProxyResponse struct {
Expand Down
4 changes: 1 addition & 3 deletions docs/api/enterprise.md
Original file line number Diff line number Diff line change
Expand Up @@ -1236,9 +1236,7 @@ curl -X POST http://coder-server:8080/api/v2/workspaceproxies \
{
"display_name": "string",
"icon": "string",
"name": "string",
"url": "string",
"wildcard_hostname": "string"
"name": "string"
}
```

Expand Down
16 changes: 6 additions & 10 deletions docs/api/schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -1557,21 +1557,17 @@ CreateParameterRequest is a structure used to create a new parameter value for a
{
"display_name": "string",
"icon": "string",
"name": "string",
"url": "string",
"wildcard_hostname": "string"
"name": "string"
}
```

### Properties

| Name | Type | Required | Restrictions | Description |
| ------------------- | ------ | -------- | ------------ | ----------- |
| `display_name` | string | false | | |
| `icon` | string | false | | |
| `name` | string | false | | |
| `url` | string | false | | |
| `wildcard_hostname` | string | false | | |
| Name | Type | Required | Restrictions | Description |
| -------------- | ------ | -------- | ------------ | ----------- |
| `display_name` | string | false | | |
| `icon` | string | false | | |
| `name` | string | false | | |

## codersdk.CreateWorkspaceRequest

Expand Down
30 changes: 8 additions & 22 deletions enterprise/cli/workspaceproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,11 @@ func (r *RootCmd) deleteProxy() *clibase.Cmd {

func (r *RootCmd) createProxy() *clibase.Cmd {
var (
proxyName string
displayName string
proxyIcon string
proxyURL string
proxyWildcardHostname string
onlyToken bool
formatter = cliui.NewOutputFormatter(
proxyName string
displayName string
proxyIcon string
onlyToken bool
formatter = cliui.NewOutputFormatter(
// Text formatter should be human readable.
cliui.ChangeFormatterData(cliui.TextFormat(), func(data any) (any, error) {
response, ok := data.(codersdk.CreateWorkspaceProxyResponse)
Expand Down Expand Up @@ -94,11 +92,9 @@ func (r *RootCmd) createProxy() *clibase.Cmd {
Handler: func(inv *clibase.Invocation) error {
ctx := inv.Context()
resp, err := client.CreateWorkspaceProxy(ctx, codersdk.CreateWorkspaceProxyRequest{
Name: proxyName,
DisplayName: displayName,
Icon: proxyIcon,
URL: proxyURL,
WildcardHostname: proxyWildcardHostname,
Name: proxyName,
DisplayName: displayName,
Icon: proxyIcon,
})
if err != nil {
return xerrors.Errorf("create workspace proxy: %w", err)
Expand Down Expand Up @@ -136,16 +132,6 @@ func (r *RootCmd) createProxy() *clibase.Cmd {
Description: "Display icon of the proxy.",
Value: clibase.StringOf(&proxyIcon),
},
clibase.Option{
Flag: "access-url",
Description: "Access URL of the proxy.",
Value: clibase.StringOf(&proxyURL),
},
clibase.Option{
Flag: "wildcard-access-url",
Description: "(Optional) Access url of the proxy for subdomain based apps.",
Value: clibase.StringOf(&proxyWildcardHostname),
},
clibase.Option{
Flag: "only-token",
Description: "Only print the token. This is useful for scripting.",
Expand Down
2 changes: 0 additions & 2 deletions enterprise/cli/workspaceproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func Test_ProxyCRUD(t *testing.T) {
"--name", expectedName,
"--display-name", "Test Proxy",
"--icon", "/emojis/1f4bb.png",
"--access-url", "http://localhost:3010",
"--only-token",
)

Expand Down Expand Up @@ -99,7 +98,6 @@ func Test_ProxyCRUD(t *testing.T) {
Name: expectedName,
DisplayName: "Test Proxy",
Icon: "/emojis/us.png",
URL: "http://localhost:3010",
})
require.NoError(t, err, "failed to create workspace proxy")

Expand Down
6 changes: 2 additions & 4 deletions enterprise/coderd/coderdenttest/proxytest.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,8 @@ func NewWorkspaceProxy(t *testing.T, coderdAPI *coderd.API, owner *codersdk.Clie
}

proxyRes, err := owner.CreateWorkspaceProxy(ctx, codersdk.CreateWorkspaceProxyRequest{
Name: options.Name,
Icon: "/emojis/flag.png",
URL: accessURL.String(),
WildcardHostname: options.AppHostname,
Name: options.Name,
Icon: "/emojis/flag.png",
})
require.NoError(t, err, "failed to create workspace proxy")

Expand Down
20 changes: 0 additions & 20 deletions enterprise/coderd/workspaceproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,6 @@ func (api *API) postWorkspaceProxy(rw http.ResponseWriter, r *http.Request) {
return
}

if err := validateProxyURL(req.URL); err != nil {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "URL is invalid.",
Detail: err.Error(),
})
return
}

if req.WildcardHostname != "" {
if _, err := httpapi.CompileHostnamePattern(req.WildcardHostname); err != nil {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "Wildcard URL is invalid.",
Detail: err.Error(),
})
return
}
}

id := uuid.New()
secret, err := cryptorand.HexString(64)
if err != nil {
Expand All @@ -121,8 +103,6 @@ func (api *API) postWorkspaceProxy(rw http.ResponseWriter, r *http.Request) {
Name: req.Name,
DisplayName: req.DisplayName,
Icon: req.Icon,
Url: req.URL,
WildcardHostname: req.WildcardHostname,
TokenHashedSecret: hashedSecret[:],
CreatedAt: database.Now(),
UpdatedAt: database.Now(),
Expand Down
18 changes: 6 additions & 12 deletions enterprise/coderd/workspaceproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ func TestWorkspaceProxyCRUD(t *testing.T) {
})
ctx := testutil.Context(t, testutil.WaitLong)
proxyRes, err := client.CreateWorkspaceProxy(ctx, codersdk.CreateWorkspaceProxyRequest{
Name: namesgenerator.GetRandomName(1),
Icon: "/emojis/flag.png",
URL: "https://" + namesgenerator.GetRandomName(1) + ".com",
WildcardHostname: "*.sub.example.com",
Name: namesgenerator.GetRandomName(1),
Icon: "/emojis/flag.png",
})
require.NoError(t, err)

Expand Down Expand Up @@ -84,10 +82,8 @@ func TestWorkspaceProxyCRUD(t *testing.T) {
})
ctx := testutil.Context(t, testutil.WaitLong)
proxyRes, err := client.CreateWorkspaceProxy(ctx, codersdk.CreateWorkspaceProxyRequest{
Name: namesgenerator.GetRandomName(1),
Icon: "/emojis/flag.png",
URL: "https://" + namesgenerator.GetRandomName(1) + ".com",
WildcardHostname: "*.sub.example.com",
Name: namesgenerator.GetRandomName(1),
Icon: "/emojis/flag.png",
})
require.NoError(t, err)

Expand Down Expand Up @@ -153,10 +149,8 @@ func TestIssueSignedAppToken(t *testing.T) {

createProxyCtx := testutil.Context(t, testutil.WaitLong)
proxyRes, err := client.CreateWorkspaceProxy(createProxyCtx, codersdk.CreateWorkspaceProxyRequest{
Name: namesgenerator.GetRandomName(1),
Icon: "/emojis/flag.png",
URL: "https://" + namesgenerator.GetRandomName(1) + ".com",
WildcardHostname: "*.sub.example.com",
Name: namesgenerator.GetRandomName(1),
Icon: "/emojis/flag.png",
})
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion scripts/develop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ fatal() {
# Attempt to delete the proxy first, in case it already exists.
"${CODER_DEV_SHIM}" proxy delete local-proxy || true
# Create the proxy
proxy_session_token=$("${CODER_DEV_SHIM}" proxy create --name=local-proxy --display-name="Local Proxy" --icon="/emojis/1f4bb.png" --access-url=http://localhost:3010 --only-token)
proxy_session_token=$("${CODER_DEV_SHIM}" proxy create --name=local-proxy --display-name="Local Proxy" --icon="/emojis/1f4bb.png" --only-token)
# Start the proxy
start_cmd PROXY "" "${CODER_DEV_SHIM}" proxy server --http-address=localhost:3010 --proxy-session-token="${proxy_session_token}" --primary-access-url=http://localhost:3000
) || echo "Failed to create workspace proxy. No workspace proxy created."
Expand Down
2 changes: 0 additions & 2 deletions site/src/api/typesGenerated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ export interface CreateWorkspaceProxyRequest {
readonly name: string
readonly display_name: string
readonly icon: string
readonly url: string
readonly wildcard_hostname: string
}

// From codersdk/workspaceproxy.go
Expand Down