MCPcopy Index your code
hub / github.com/coder/coder / ResolveWorkspace

Method ResolveWorkspace

codersdk/workspaces.go:636–661  ·  view source on GitHub ↗

ResolveWorkspace fetches a workspace by identifier, which may be a UUID, a bare name (owned by the current user), or an "owner/name" pair. When the identifier parses as a valid UUID but no workspace exists with that ID, the function falls back to a name-based lookup because workspace names can be va

(ctx context.Context, identifier string)

Source from the content-addressed store, hash-verified

634// exists with that ID, the function falls back to a name-based
635// lookup because workspace names can be valid UUID strings.
636func (c *Client) ResolveWorkspace(ctx context.Context, identifier string) (Workspace, error) {
637 if uid, err := uuid.Parse(identifier); err == nil {
638 ws, err := c.Workspace(ctx, uid)
639 if err == nil {
640 return ws, nil
641 }
642 // A workspace name might be a valid UUID string. If the
643 // ID-based lookup returned 404, fall through to name-based
644 // lookup below.
645 var sdkErr *Error
646 if !errors.As(err, &sdkErr) || sdkErr.StatusCode() != http.StatusNotFound {
647 return Workspace{}, err
648 }
649 // A standard dashed UUID (36 chars) cannot be a valid
650 // workspace name (max 32 chars). Skip the wasted
651 // name-based round-trip.
652 if err := NameValid(identifier); err != nil {
653 return Workspace{}, sdkErr
654 }
655 }
656 owner, name, err := SplitWorkspaceIdentifier(identifier)
657 if err != nil {
658 return Workspace{}, err
659 }
660 return c.WorkspaceByOwnerAndName(ctx, owner, name, WorkspaceOptions{})
661}
662
663type WorkspaceQuota struct {
664 CreditsConsumed int `json:"credits_consumed"`

Callers 15

TestResolveWorkspaceFunction · 0.80
toolsdk.goFile · 0.80
findWorkspaceAndAgentFunction · 0.80
logsMethod · 0.80
stopMethod · 0.80
renameMethod · 0.80
startMethod · 0.80
autoupdateMethod · 0.80
favoriteMethod · 0.80
unfavoriteMethod · 0.80
restartMethod · 0.80

Calls 7

WorkspaceMethod · 0.95
StatusCodeMethod · 0.95
NameValidFunction · 0.85
SplitWorkspaceIdentifierFunction · 0.85
AsMethod · 0.80
ParseMethod · 0.65

Tested by 1

TestResolveWorkspaceFunction · 0.64