Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

chore: use access url from env resource pool #216

Merged
merged 10 commits into from
Jan 15, 2021
Prev Previous commit
Next Next commit
fixup! chore: use access url from env resource pool
  • Loading branch information
cmoog committed Jan 14, 2021
commit 9010f771cdadc52858642123bf7a657d15de0c20
2 changes: 2 additions & 0 deletions internal/coderutil/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package coderutil providers utilities for high-level operations on coder-sdk entities.
package coderutil
4 changes: 4 additions & 0 deletions internal/coderutil/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"nhooyr.io/websocket"
)

// DialEnvWsep dials the executor endpoint using the https://github.com/cdr/wsep message protocol.
// The proper resource pool access URL is used.
func DialEnvWsep(ctx context.Context, client *coder.Client, env *coder.Environment) (*websocket.Conn, error) {
resourcePool, err := client.ResourcePoolByID(ctx, env.ResourcePoolID)
if err != nil {
Expand All @@ -26,11 +28,13 @@ func DialEnvWsep(ctx context.Context, client *coder.Client, env *coder.Environme
return conn, nil
}

// EnvWithPool composes an Environment entity with its associated ResourcePool.
type EnvWithPool struct {
Env coder.Environment
Pool coder.ResourcePool
}

// EnvsWithPool performs the composition of each Environment with its associated ResourcePool.
func EnvsWithPool(ctx context.Context, client *coder.Client, envs []coder.Environment) ([]EnvWithPool, error) {
pooledEnvs := make([]EnvWithPool, len(envs))
pools, err := client.ResourcePools(ctx)
Expand Down