Skip to content

Commit

Permalink
auth by stub id
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-lombardi committed Dec 31, 2024
1 parent b736b0e commit f296b47
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pkg/abstractions/shell/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"sync"
"time"

apiv1 "github.com/beam-cloud/beta9/pkg/api/v1"
"github.com/beam-cloud/beta9/pkg/auth"
"github.com/beam-cloud/beta9/pkg/types"
"github.com/labstack/echo/v4"
)

Expand All @@ -25,9 +27,21 @@ func registerShellRoutes(g *echo.Group, ss *SSHShellService) *shellGroup {
}

func (g *shellGroup) ShellConnect(ctx echo.Context) error {
cc, _ := ctx.(*auth.HttpAuthContext)

containerId := ctx.Param("containerId")
stubId := ctx.Param("stubId")

stub, err := g.ss.backendRepo.GetStubByExternalId(ctx.Request().Context(), stubId, types.QueryFilter{
Field: "workspace_id",
Value: cc.AuthInfo.Token.Workspace.ExternalId,
})
if err != nil {
return apiv1.HTTPInternalServerError("Failed to retrieve stub")
} else if stub == nil {
return apiv1.HTTPNotFound()
}

log.Println("stubId", stubId)

// TODO: auth by stub ID
Expand All @@ -37,7 +51,7 @@ func (g *shellGroup) ShellConnect(ctx echo.Context) error {
defer cancel()

// Use the new method to wait for the container to be running
err := g.ss.waitForContainerRunning(timeoutCtx, containerId, 5*time.Second)
err = g.ss.waitForContainerRunning(timeoutCtx, containerId, 5*time.Second)
if err != nil {
return ctx.String(http.StatusBadGateway, err.Error())
}
Expand Down

0 comments on commit f296b47

Please sign in to comment.