or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

clients.mdenvironments.mdindex.mdssh-keys.md

clients.mddocs/

0

# Client Management

1

2

Client initialization, configuration, and lifecycle management for both synchronous and asynchronous Google Cloud Shell API operations.

3

4

## Capabilities

5

6

### Synchronous Client

7

8

Main client class for synchronous operations with Google Cloud Shell environments.

9

10

```python { .api }

11

class CloudShellServiceClient:

12

"""API for interacting with Google Cloud Shell environments."""

13

14

def __init__(

15

self,

16

*,

17

credentials: Optional[ga_credentials.Credentials] = None,

18

transport: Optional[Union[str, CloudShellServiceTransport, Callable[..., CloudShellServiceTransport]]] = None,

19

client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None,

20

client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,

21

) -> None:

22

"""

23

Initialize the Cloud Shell Service client.

24

25

Args:

26

credentials: The authorization credentials to attach to requests

27

transport: The transport to use for API calls. Options: "grpc", "rest", or transport instance

28

client_options: Client options for configuring the client

29

client_info: gRPC client info used to create user-agent string

30

"""

31

```

32

33

#### Factory Methods

34

35

Create client instances from service account credentials.

36

37

```python { .api }

38

@classmethod

39

def from_service_account_info(

40

cls,

41

info: dict,

42

*args,

43

**kwargs

44

) -> CloudShellServiceClient:

45

"""

46

Create client instance from service account info dictionary.

47

48

Args:

49

info: Service account info in Google format

50

*args: Additional arguments to pass to constructor

51

**kwargs: Additional keyword arguments to pass to constructor

52

53

Returns:

54

CloudShellServiceClient instance

55

"""

56

57

@classmethod

58

def from_service_account_file(

59

cls,

60

filename: str,

61

*args,

62

**kwargs

63

) -> CloudShellServiceClient:

64

"""

65

Create client instance from service account JSON file.

66

67

Args:

68

filename: Path to service account JSON file

69

*args: Additional arguments to pass to constructor

70

**kwargs: Additional keyword arguments to pass to constructor

71

72

Returns:

73

CloudShellServiceClient instance

74

"""

75

76

from_service_account_json = from_service_account_file # Alias for compatibility

77

```

78

79

#### Properties

80

81

Access client configuration and transport information.

82

83

```python { .api }

84

@property

85

def transport(self) -> CloudShellServiceTransport:

86

"""Returns the transport used by the client instance."""

87

88

@property

89

def api_endpoint(self) -> str:

90

"""Return the API endpoint used by the client instance."""

91

92

@property

93

def universe_domain(self) -> str:

94

"""Return the universe domain used by the client instance."""

95

```

96

97

#### Context Manager Support

98

99

Use client as context manager for automatic resource cleanup.

100

101

```python { .api }

102

def __enter__(self) -> "CloudShellServiceClient":

103

"""Enter context manager."""

104

105

def __exit__(self, type, value, traceback) -> None:

106

"""Exit context manager."""

107

```

108

109

### Asynchronous Client

110

111

Async version of the Cloud Shell client for non-blocking operations.

112

113

```python { .api }

114

class CloudShellServiceAsyncClient:

115

"""Async API for interacting with Google Cloud Shell environments."""

116

117

def __init__(

118

self,

119

*,

120

credentials: Optional[ga_credentials.Credentials] = None,

121

transport: Optional[Union[str, CloudShellServiceTransport, Callable[..., CloudShellServiceTransport]]] = "grpc_asyncio",

122

client_options: Optional[ClientOptions] = None,

123

client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,

124

) -> None:

125

"""

126

Initialize the async Cloud Shell Service client.

127

128

Args:

129

credentials: The authorization credentials to attach to requests

130

transport: The transport to use for API calls. Default: "grpc_asyncio"

131

client_options: Client options for configuring the client

132

client_info: gRPC client info used to create user-agent string

133

"""

134

```

135

136

#### Async Context Manager Support

137

138

Use async client as async context manager for automatic resource cleanup.

139

140

```python { .api }

141

async def __aenter__(self) -> "CloudShellServiceAsyncClient":

142

"""Enter async context manager."""

143

144

async def __aexit__(self, exc_type, exc, tb) -> None:

145

"""Exit async context manager."""

146

```

147

148

### Resource Path Helpers

149

150

Static methods for constructing and parsing Google Cloud resource paths.

151

152

#### Environment Paths

153

154

```python { .api }

155

@staticmethod

156

def environment_path(user: str, environment: str) -> str:

157

"""

158

Returns fully-qualified environment string.

159

160

Args:

161

user: User email or "me" for current user

162

environment: Environment ID (e.g., "default")

163

164

Returns:

165

Resource path: users/{user}/environments/{environment}

166

"""

167

168

@staticmethod

169

def parse_environment_path(path: str) -> Dict[str, str]:

170

"""

171

Parses environment path into component segments.

172

173

Args:

174

path: Environment resource path

175

176

Returns:

177

Dictionary with 'user' and 'environment' keys

178

"""

179

```

180

181

#### Common Resource Paths

182

183

Helper methods for other Google Cloud resource types.

184

185

```python { .api }

186

@staticmethod

187

def common_billing_account_path(billing_account: str) -> str:

188

"""Returns fully-qualified billing account string."""

189

190

@staticmethod

191

def parse_common_billing_account_path(path: str) -> Dict[str, str]:

192

"""Parse billing account path into component segments."""

193

194

@staticmethod

195

def common_folder_path(folder: str) -> str:

196

"""Returns fully-qualified folder string."""

197

198

@staticmethod

199

def parse_common_folder_path(path: str) -> Dict[str, str]:

200

"""Parse folder path into component segments."""

201

202

@staticmethod

203

def common_organization_path(organization: str) -> str:

204

"""Returns fully-qualified organization string."""

205

206

@staticmethod

207

def parse_common_organization_path(path: str) -> Dict[str, str]:

208

"""Parse organization path into component segments."""

209

210

@staticmethod

211

def common_project_path(project: str) -> str:

212

"""Returns fully-qualified project string."""

213

214

@staticmethod

215

def parse_common_project_path(path: str) -> Dict[str, str]:

216

"""Parse project path into component segments."""

217

218

@staticmethod

219

def common_location_path(project: str, location: str) -> str:

220

"""Returns fully-qualified location string."""

221

222

@staticmethod

223

def parse_common_location_path(path: str) -> Dict[str, str]:

224

"""Parse location path into component segments."""

225

```

226

227

## Usage Examples

228

229

### Basic Client Initialization

230

231

```python

232

from google.cloud.shell import CloudShellServiceClient

233

234

# Use default credentials

235

client = CloudShellServiceClient()

236

237

# Use specific service account

238

client = CloudShellServiceClient.from_service_account_file(

239

"path/to/service-account.json"

240

)

241

242

# Use custom transport

243

client = CloudShellServiceClient(transport="rest")

244

```

245

246

### Context Manager Usage

247

248

```python

249

from google.cloud.shell import CloudShellServiceClient

250

251

# Automatic cleanup

252

with CloudShellServiceClient() as client:

253

environment = client.get_environment(

254

name="users/me/environments/default"

255

)

256

print(f"Environment state: {environment.state}")

257

```

258

259

### Async Client Usage

260

261

```python

262

import asyncio

263

from google.cloud.shell import CloudShellServiceAsyncClient

264

265

async def main():

266

async with CloudShellServiceAsyncClient() as client:

267

environment = await client.get_environment(

268

name="users/me/environments/default"

269

)

270

print(f"Environment state: {environment.state}")

271

272

asyncio.run(main())

273

```

274

275

### Resource Path Construction

276

277

```python

278

from google.cloud.shell import CloudShellServiceClient

279

280

# Build environment path

281

env_path = CloudShellServiceClient.environment_path(

282

user="me",

283

environment="default"

284

)

285

print(env_path) # users/me/environments/default

286

287

# Parse environment path

288

components = CloudShellServiceClient.parse_environment_path(env_path)

289

print(components) # {'user': 'me', 'environment': 'default'}

290

```

291

292

## Constants

293

294

```python { .api }

295

DEFAULT_ENDPOINT = "cloudshell.googleapis.com"

296

DEFAULT_MTLS_ENDPOINT = "cloudshell.mtls.googleapis.com"

297

```

298

299

## Transport Options

300

301

- `"grpc"` - gRPC transport (default for synchronous client)

302

- `"grpc_asyncio"` - AsyncIO gRPC transport (default for asynchronous client)

303

- `"rest"` - REST transport