Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Add workspace proxy enterprise cli commands#7123

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

Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
22 commits
Select commitHold shift + click to select a range
7271e8f
feat: Add workspace proxy enterprise cli commands
EmyrkApr 13, 2023
0a1af72
chore: Handle custom workspace proxy options. Remove excess
EmyrkApr 13, 2023
9fc8078
Add primary access url
EmyrkApr 13, 2023
56d0ad7
Include app security key
EmyrkApr 13, 2023
4d7daed
Add output formats for registering a proxy
EmyrkApr 13, 2023
62f676b
Fix formats
EmyrkApr 13, 2023
913aef1
Add cli cmd to get app security key
EmyrkApr 13, 2023
9c37e16
Add deleting proxies
EmyrkApr 13, 2023
9d4591c
feat: Allow workspace proxy spawn in develop.sh
EmyrkApr 14, 2023
cc29ffc
Make gen
EmyrkApr 14, 2023
54a6fc5
Import ordeR
EmyrkApr 14, 2023
139c309
Quote shell var
EmyrkApr 14, 2023
6ce0dec
Imports
EmyrkApr 14, 2023
ffc3877
Fix lint
EmyrkApr 14, 2023
db78701
Tabs vs spaces
EmyrkApr 14, 2023
e49f96c
remove unused command
EmyrkApr 17, 2023
5f05cbf
Fix compile and make gen
EmyrkApr 17, 2023
0d9da63
Fix slim cmd to include extra proxy cmds
EmyrkApr 17, 2023
60fb59e
Import order
EmyrkApr 17, 2023
b9283d8
Import order
EmyrkApr 17, 2023
dab84e3
Fix comment
EmyrkApr 17, 2023
ea3593d
Fix compile with name
EmyrkApr 17, 2023
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
10 changes: 10 additions & 0 deletionscli/clibase/option.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,6 +80,16 @@ func (s *OptionSet) Add(opts ...Option) {
*s = append(*s, opts...)
}

func (s OptionSet) Filter(filter func(opt Option) bool) OptionSet {
cpy := make(OptionSet, 0)
for _, opt := range s {
if filter(opt) {
cpy = append(cpy, opt)
}
}
return cpy
}

// FlagSet returns a pflag.FlagSet for the OptionSet.
func (s *OptionSet) FlagSet() *pflag.FlagSet {
if s == nil {
Expand Down
27 changes: 27 additions & 0 deletionscli/cliui/output.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -192,3 +192,30 @@ func (textFormat) AttachOptions(_ *clibase.OptionSet) {}
func (textFormat) Format(_ context.Context, data any) (string, error) {
return fmt.Sprintf("%s", data), nil
}

type DataChangeFormat struct {
format OutputFormat
change func(data any) (any, error)
}

// ChangeFormatterData allows manipulating the data passed to an output
// format.
func ChangeFormatterData(format OutputFormat, change func(data any) (any, error)) *DataChangeFormat {
return &DataChangeFormat{format: format, change: change}
}

func (d *DataChangeFormat) ID() string {
return d.format.ID()
}

func (d *DataChangeFormat) AttachOptions(opts *clibase.OptionSet) {
d.format.AttachOptions(opts)
}

func (d *DataChangeFormat) Format(ctx context.Context, data any) (string, error) {
newData, err := d.change(data)
if err != nil {
return "", err
}
return d.format.Format(ctx, newData)
}
24 changes: 24 additions & 0 deletionscli/server.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -163,6 +163,19 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
var (
cfg = new(codersdk.DeploymentValues)
opts = cfg.Options()
// For the develop.sh script, it is helpful to make this key deterministic.
devAppSecurityKey string
)
opts.Add(
clibase.Option{
Name: "App Security Key (Development Only)",
Description: "Used to override the app security key stored in the database. This should never be used in production.",
Flag: "dangerous-dev-app-security-key",
Default: "",
Value: clibase.StringOf(&devAppSecurityKey),
Annotations: clibase.Annotations{}.Mark("secret", "true"),
Hidden: true,
},
)
serverCmd := &clibase.Cmd{
Use: "server",
Expand DownExpand Up@@ -621,6 +634,17 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
}
}

if devAppSecurityKey != "" {
_, err := workspaceapps.KeyFromString(devAppSecurityKey)
if err != nil {
return xerrors.Errorf("invalid dev app security key: %w", err)
}
err = tx.UpsertAppSecurityKey(ctx, devAppSecurityKey)
if err != nil {
return xerrors.Errorf("Insert dev app security key: %w", err)
}
}

// Read the app signing key from the DB. We store it hex encoded
// since the config table uses strings for the value and we
// don't want to deal with automatic encoding issues.
Expand Down
46 changes: 43 additions & 3 deletionscoderd/apidoc/docs.go
View file
Open in desktop

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

42 changes: 37 additions & 5 deletionscoderd/apidoc/swagger.json
View file
Open in desktop

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

4 changes: 4 additions & 0 deletionscoderd/database/dbauthz/querier.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1697,6 +1697,10 @@ func (q *querier) GetWorkspaceProxyByID(ctx context.Context, id uuid.UUID) (data
return fetch(q.log, q.auth, q.db.GetWorkspaceProxyByID)(ctx, id)
}

func (q *querier) GetWorkspaceProxyByName(ctx context.Context, name string) (database.WorkspaceProxy, error) {
return fetch(q.log, q.auth, q.db.GetWorkspaceProxyByName)(ctx, name)
}

func (q *querier) GetWorkspaceProxyByHostname(ctx context.Context, hostname string) (database.WorkspaceProxy, error) {
return fetch(q.log, q.auth, q.db.GetWorkspaceProxyByHostname)(ctx, hostname)
}
Expand Down
12 changes: 12 additions & 0 deletionscoderd/database/dbfake/databasefake.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5097,6 +5097,18 @@ func (q *fakeQuerier) GetWorkspaceProxyByID(_ context.Context, id uuid.UUID) (da
return database.WorkspaceProxy{}, sql.ErrNoRows
}

func (q *fakeQuerier) GetWorkspaceProxyByName(_ context.Context, name string) (database.WorkspaceProxy, error) {
q.mutex.Lock()
defer q.mutex.Unlock()

for _, proxy := range q.workspaceProxies {
if proxy.Name == name {
return proxy, nil
}
}
return database.WorkspaceProxy{}, sql.ErrNoRows
}

func (q *fakeQuerier) GetWorkspaceProxyByHostname(_ context.Context, hostname string) (database.WorkspaceProxy, error) {
q.mutex.Lock()
defer q.mutex.Unlock()
Expand Down
1 change: 1 addition & 0 deletionscoderd/database/querier.go
View file
Open in desktop

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

29 changes: 29 additions & 0 deletionscoderd/database/queries.sql.go
View file
Open in desktop

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

10 changes: 10 additions & 0 deletionscoderd/database/queries/proxies.sql
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,6 +49,16 @@ WHERE
LIMIT
1;

-- name: GetWorkspaceProxyByName :one
SELECT
*
FROM
workspace_proxies
WHERE
name = $1
LIMIT
1;

-- Finds a workspace proxy that has an access URL or app hostname that matches
-- the provided hostname. This is to check if a hostname matches any workspace
-- proxy.
Expand Down
51 changes: 51 additions & 0 deletionscoderd/httpmw/workspaceproxy.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,7 @@ import (
"net/http"
"strings"

"github.com/go-chi/chi/v5"
"github.com/google/uuid"
"golang.org/x/xerrors"

Expand DownExpand Up@@ -156,3 +157,53 @@ func ExtractWorkspaceProxy(opts ExtractWorkspaceProxyConfig) func(http.Handler)
})
}
}

type workspaceProxyParamContextKey struct{}

// WorkspaceProxyParam returns the worksace proxy from the ExtractWorkspaceProxyParam handler.
func WorkspaceProxyParam(r *http.Request) database.WorkspaceProxy {
user, ok := r.Context().Value(workspaceProxyParamContextKey{}).(database.WorkspaceProxy)
if !ok {
panic("developer error: workspace proxy parameter middleware not provided")
}
return user
}

// ExtractWorkspaceProxyParam extracts a workspace proxy from an ID/name in the {workspaceproxy} URL
// parameter.
//
//nolint:revive
func ExtractWorkspaceProxyParam(db database.Store) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()

proxyQuery := chi.URLParam(r, "workspaceproxy")
if proxyQuery == "" {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "\"workspaceproxy\" must be provided.",
})
return
}

var proxy database.WorkspaceProxy
var dbErr error
if proxyID, err := uuid.Parse(proxyQuery); err == nil {
proxy, dbErr = db.GetWorkspaceProxyByID(ctx, proxyID)
} else {
proxy, dbErr = db.GetWorkspaceProxyByName(ctx, proxyQuery)
}
if httpapi.Is404Error(dbErr) {
httpapi.ResourceNotFound(rw)
return
}
if dbErr != nil {
httpapi.InternalServerError(rw, dbErr)
return
}

ctx = context.WithValue(ctx, workspaceProxyParamContextKey{}, proxy)
next.ServeHTTP(rw, r.WithContext(ctx))
})
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp