This repository was archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
chore: use access url from env resource pool #216
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c669eb5
chore: use access url from env resource pool
cmoog ad6830a
fixup! chore: use access url from env resource pool
cmoog 6adc01b
fixup! chore: use access url from env resource pool
cmoog b646d95
fixup! chore: use access url from env resource pool
cmoog 9010f77
fixup! chore: use access url from env resource pool
cmoog 19e53c7
fix: use proper SSH enabled bool flag
cmoog 8cd4a49
fixup! fix: use proper SSH enabled bool flag
cmoog 4df1a57
fixup! fix: use proper SSH enabled bool flag
cmoog 8f039a9
fixup! fix: use proper SSH enabled bool flag
cmoog 4dea056
fixup! fix: use proper SSH enabled bool flag
cmoog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package coderutil | ||
|
||
import ( | ||
"context" | ||
"net/url" | ||
|
||
"cdr.dev/coder-cli/coder-sdk" | ||
"golang.org/x/xerrors" | ||
"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 { | ||
return nil, xerrors.Errorf("get env resource pool: %w", err) | ||
} | ||
accessURL, err := url.Parse(resourcePool.AccessURL) | ||
if err != nil { | ||
return nil, xerrors.Errorf("invalid resource pool access url: %w", err) | ||
} | ||
|
||
conn, err := client.DialWsep(ctx, accessURL, env.ID) | ||
if err != nil { | ||
return nil, xerrors.Errorf("dial websocket: %w", err) | ||
} | ||
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) | ||
if err != nil { | ||
return nil, err | ||
} | ||
poolMap := make(map[string]coder.ResourcePool, len(pools)) | ||
for _, p := range pools { | ||
poolMap[p.ID] = p | ||
} | ||
for _, e := range envs { | ||
envPool, ok := poolMap[e.ResourcePoolID] | ||
if !ok { | ||
return nil, xerrors.Errorf("fetch env resource pool: %w", coder.ErrNotFound) | ||
} | ||
pooledEnvs = append(pooledEnvs, EnvWithPool{ | ||
Env: e, | ||
Pool: envPool, | ||
}) | ||
} | ||
return pooledEnvs, nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we keep canConnectSSH?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was kinda dumb anyway....