Table of Contents

Workspaces and pagination

Workspaces

A workspace is the isolation boundary for sandboxes, providers, templates, and the other resources. Every operation runs in one: OpenShellClientOptions.DefaultWorkspace, which defaults to default. InWorkspace returns a view bound to another workspace that shares the same connection; disposing the view does not close the connection.

client.Workspaces (IWorkspaceClient) creates, lists, and deletes workspaces, and manages their members (WorkspaceRole: User or Admin).

// Operations run in OpenShellClientOptions.DefaultWorkspace ("default" unless set).
Console.WriteLine(client.Workspace);

await client.Workspaces.CreateAsync("team-a", new Dictionary<string, string> { ["cost-center"] = "42" });
await client.Workspaces.AddMemberAsync("team-a", "user:alice@example.com", WorkspaceRole.Admin);

// A view bound to another workspace that shares the connection. Disposing it does not close the connection.
var teamA = client.InWorkspace("team-a");
var sandboxes = await teamA.Sandboxes.List().ToListAsync();

await foreach (var member in client.Workspaces.ListMembers("team-a"))
{
    Console.WriteLine($"{member.PrincipalSubject}: {member.Role}");
}

Pagination

List methods return a lazy Pager<T>: nothing is fetched until you enumerate it, and each page is fetched as you reach it. Enumerate it for items, call PagesAsync() for Page<T>s, or ToListAsync() for everything.

// Items: the pager fetches the next page as you enumerate.
await foreach (var sandbox in client.Sandboxes.List(new ListOptions { PageSize = 50 }))
{
    Console.WriteLine($"{sandbox.Workspace}/{sandbox.Name}: {sandbox.Phase}");
}

// Pages: for example to show one page at a time and resume from its token later.
await foreach (var page in client.Sandboxes.List(new ListOptions { PageSize = 50 }).PagesAsync())
{
    Console.WriteLine($"{page.Items.Count} sandboxes, more: {page.HasMore}, next token: {page.NextPageToken}");
}

// Everything at once, across workspaces where the resource supports it.
var all = await client.Sandboxes.List(new ListOptions { AllWorkspaces = true }).ToListAsync();

ListOptions sets the page size (0 leaves it to the gateway), a starting page token, a label selector (team=platform), and AllWorkspaces to list across every workspace the caller can see (sandboxes, templates, providers, and services). Each enumeration starts over from the first page (or PageToken).