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)
| 634 | // exists with that ID, the function falls back to a name-based |
| 635 | // lookup because workspace names can be valid UUID strings. |
| 636 | func (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 | |
| 663 | type WorkspaceQuota struct { |
| 664 | CreditsConsumed int `json:"credits_consumed"` |