Skip to content

Commit

Permalink
Add endpoint to export workspace config
Browse files Browse the repository at this point in the history
  • Loading branch information
jsun-m committed Dec 19, 2024
1 parent 53b5657 commit dd67719
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions pkg/api/v1/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewWorkspaceGroup(g *echo.Group, backendRepo repository.BackendRepository,

g.POST("", group.CreateWorkspace)
g.GET("/current", auth.WithAuth(group.CurrentWorkspace))
g.GET("/export", auth.WithAuth(group.ExportWorkspaceConfig))
g.GET("/:workspaceId/export", auth.WithWorkspaceAuth(group.ExportWorkspaceConfig))

return group
}
Expand Down Expand Up @@ -59,25 +59,23 @@ func (g *WorkspaceGroup) CurrentWorkspace(ctx echo.Context) error {
}

type WorkspaceConfigExport struct {
GatewayHTTPURL string `json:"gateway_url"`
GatewayHTTPPort int `json:"gateway_port"`
GatewayHTTPURL string `json:"gateway_http_url"`
GatewayHTTPPort int `json:"gateway_http_port"`
GatewayGRPCURL string `json:"gateway_grpc_url"`
GatewayGRPCPort int `json:"gateway_grpc_port"`
WorkspaceID string `json:"workspace_id"`
Token string `json:"token"`
}

func (g *WorkspaceGroup) ExportWorkspaceConfig(ctx echo.Context) error {
authContext, _ := ctx.(*auth.HttpAuthContext)
workspace := authContext.AuthInfo.Workspace
workspaceId := ctx.Param("workspaceId")

config := WorkspaceConfigExport{
GatewayHTTPURL: g.config.GatewayService.HTTP.ExternalHost,
GatewayHTTPPort: g.config.GatewayService.HTTP.Port,
GatewayGRPCURL: g.config.GatewayService.GRPC.ExternalHost,
GatewayGRPCPort: g.config.GatewayService.GRPC.Port,
WorkspaceID: workspace.ExternalId,
Token: authContext.AuthInfo.Token.Key,
WorkspaceID: workspaceId,
}

return ctx.JSON(http.StatusOK, config)
Expand Down

0 comments on commit dd67719

Please sign in to comment.