Skip to content

Commit cf2c792

Browse files
authored
{Containerapp} Azure Container Apps session execute new api-version (#8249)
1 parent 7db39ab commit cf2c792

16 files changed

+27467
-28300
lines changed

src/containerapp/HISTORY.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ upcoming
77
* 'az containerapp create': Fix Role assignment error when the default Azure Container Registry could not be found
88
* Upgrade api-version to 2024-10-02-preview
99
* 'az containerapp create/update': `--yaml` support property pollingInterval and cooldownPeriod
10+
* 'az containerapp session code-interpreter upload-file/list-files/show-file-content/show-file-metadata/delete-file': Support `--path` to specify the path of code interpreter session file resource
11+
* 'az containerapp session code-interpreter': Update response payload format for api-version 2024-10-02-preview
1012
* 'az containerapp env maintenance-config add/update/list/remove': Support environment maintenance config management
1113
* 'az containerapp sessionpool create': Support managed identity when create session pool with --mi-system-assigned --mi-user-assigned
1214

src/containerapp/azext_containerapp/_clients.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
logger = get_logger(__name__)
2828

2929
PREVIEW_API_VERSION = "2024-10-02-preview"
30-
SESSION_API_VERSION = "2024-02-02-preview"
3130
POLLING_TIMEOUT = 1500 # how many seconds before exiting
3231
POLLING_SECONDS = 2 # how many seconds between requests
3332
POLLING_TIMEOUT_FOR_MANAGED_CERTIFICATE = 1500 # how many seconds before exiting
@@ -1158,11 +1157,11 @@ def list_by_subscription(cls, cmd, formatter=lambda x: x):
11581157

11591158

11601159
class SessionCodeInterpreterPreviewClient():
1161-
api_version = SESSION_API_VERSION
1160+
api_version = PREVIEW_API_VERSION
11621161

11631162
@classmethod
11641163
def execute(cls, cmd, identifier, code_interpreter_envelope, session_pool_endpoint, no_wait=False):
1165-
url_fmt = "{}/code/execute?identifier={}&api-version={}"
1164+
url_fmt = "{}/executions?identifier={}&api-version={}"
11661165
request_url = url_fmt.format(
11671166
session_pool_endpoint,
11681167
identifier,
@@ -1181,10 +1180,11 @@ def execute(cls, cmd, identifier, code_interpreter_envelope, session_pool_endpoi
11811180
return r.json()
11821181

11831182
@classmethod
1184-
def upload(cls, cmd, identifier, filepath, session_pool_endpoint, no_wait=False):
1185-
url_fmt = "{}/files/upload?identifier={}&api-version={}"
1183+
def upload(cls, cmd, identifier, filepath, path, session_pool_endpoint, no_wait=False):
1184+
url_fmt = "{}/files?{}identifier={}&api-version={}"
11861185
request_url = url_fmt.format(
11871186
session_pool_endpoint,
1187+
f"path={path}&" if path is not None else "",
11881188
identifier,
11891189
cls.api_version)
11901190

@@ -1221,11 +1221,13 @@ def upload(cls, cmd, identifier, filepath, session_pool_endpoint, no_wait=False)
12211221
return r.json()
12221222

12231223
@classmethod
1224-
def show_file_content(cls, cmd, identifier, filename, session_pool_endpoint):
1225-
url_fmt = "{}/files/content/{}?identifier={}&api-version={}"
1224+
def show_file_content(cls, cmd, identifier, filename, path, session_pool_endpoint):
1225+
path, filename = cls.extract_path_from_filename(path, filename)
1226+
url_fmt = "{}/files/{}/content?{}identifier={}&api-version={}"
12261227
request_url = url_fmt.format(
12271228
session_pool_endpoint,
12281229
filename,
1230+
f"path={path}&" if path is not None else "",
12291231
identifier,
12301232
cls.api_version)
12311233

@@ -1236,11 +1238,13 @@ def show_file_content(cls, cmd, identifier, filename, session_pool_endpoint):
12361238
return json.dumps(r.content.decode())
12371239

12381240
@classmethod
1239-
def show_file_metadata(cls, cmd, identifier, filename, session_pool_endpoint):
1240-
url_fmt = "{}/files/{}?identifier={}&api-version={}"
1241+
def show_file_metadata(cls, cmd, identifier, filename, path, session_pool_endpoint):
1242+
path, filename = cls.extract_path_from_filename(path, filename)
1243+
url_fmt = "{}/files/{}?{}identifier={}&api-version={}"
12411244
request_url = url_fmt.format(
12421245
session_pool_endpoint,
12431246
filename,
1247+
f"path={path}&" if path is not None else "",
12441248
identifier,
12451249
cls.api_version)
12461250
logger.warning(request_url)
@@ -1249,11 +1253,13 @@ def show_file_metadata(cls, cmd, identifier, filename, session_pool_endpoint):
12491253
return r.json()
12501254

12511255
@classmethod
1252-
def delete_file(cls, cmd, identifier, filename, session_pool_endpoint, no_wait=False):
1253-
url_fmt = "{}/files/{}?identifier={}&api-version={}"
1256+
def delete_file(cls, cmd, identifier, filename, path, session_pool_endpoint, no_wait=False):
1257+
path, filename = cls.extract_path_from_filename(path, filename)
1258+
url_fmt = "{}/files/{}?{}identifier={}&api-version={}"
12541259
request_url = url_fmt.format(
12551260
session_pool_endpoint,
12561261
filename,
1262+
f"path={path}&" if path is not None else "",
12571263
identifier,
12581264
cls.api_version)
12591265

@@ -1282,6 +1288,16 @@ def list_files(cls, cmd, identifier, path, session_pool_endpoint):
12821288
r = send_raw_request(cmd.cli_ctx, "GET", request_url, resource=SESSION_RESOURCE)
12831289
return r.json()
12841290

1291+
@staticmethod
1292+
def extract_path_from_filename(path, filename):
1293+
if '/' not in filename:
1294+
return path, filename
1295+
path_in_filename, filename = filename.rsplit('/', 1)
1296+
if path is None:
1297+
return path_in_filename, filename
1298+
else:
1299+
return path.rstrip("/") + "/" + path_in_filename.lstrip('/'), filename
1300+
12851301

12861302
class DotNetComponentPreviewClient():
12871303
api_version = PREVIEW_API_VERSION

src/containerapp/azext_containerapp/_help.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,7 @@
19841984
- name: Upload a file to a session.
19851985
text: |
19861986
az containerapp session code-interpreter upload-file -n MySessionPool -g MyResourceGroup --identifier MySession \\
1987-
--filepath example.txt
1987+
--filepath example.txt --path /
19881988
"""
19891989

19901990
helps['containerapp session code-interpreter show-file-content'] = """
@@ -1993,7 +1993,7 @@
19931993
examples:
19941994
- name: Show content of file.
19951995
text: az containerapp session code-interpreter show-file-content -n MySessionPool -g MyResourceGroup --identifier MySession \\
1996-
--filename example.txt
1996+
--filename example.txt --path /
19971997
"""
19981998

19991999
helps['containerapp session code-interpreter show-file-metadata'] = """
@@ -2002,7 +2002,7 @@
20022002
examples:
20032003
- name: Show the meta-data details of a file uploaded to a session.
20042004
text: az containerapp session code-interpreter show-file-metadata -n MySessionPool -g MyResourceGroup --identifier MySession \\
2005-
--filename example.txt
2005+
--filename example.txt --path /
20062006
"""
20072007

20082008
helps['containerapp session code-interpreter delete-file'] = """
@@ -2011,7 +2011,7 @@
20112011
examples:
20122012
- name: Delete a file .
20132013
text: az containerapp session code-interpreter delete-file -n MySessionPool -g MyResourceGroup --identifier MySession \\
2014-
--filename example.txt
2014+
--filename example.txt --path /
20152015
"""
20162016

20172017
helps['containerapp session code-interpreter list-files'] = """
@@ -2020,7 +2020,7 @@
20202020
examples:
20212021
- name: List files uploaded in a code-interpreter session.
20222022
text: |
2023-
az containerapp session code-interpreter list-files -n MySessionPool -g MyResourceGroup --identifier MySession
2023+
az containerapp session code-interpreter list-files -n MySessionPool -g MyResourceGroup --identifier MySession --path /
20242024
"""
20252025

20262026
helps['containerapp java'] = """

src/containerapp/azext_containerapp/_models.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,10 @@
321321
}
322322

323323
SessionCodeInterpreterExecution = {
324-
"properties": {
325-
"identifier": None,
326-
"codeInputType": None,
327-
"executionType": None,
328-
"code": None,
329-
"timeoutInSeconds": None
330-
}
324+
"codeInputType": None,
325+
"executionType": None,
326+
"code": None,
327+
"timeoutInSeconds": None
331328
}
332329

333330
DaprComponentResiliency = {

src/containerapp/azext_containerapp/_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def load_arguments(self, _):
444444
with self.argument_context('containerapp session code-interpreter', arg_group='file') as c:
445445
c.argument('filename', help="The file to delete or show from the session")
446446
c.argument('filepath', help="The local path to the file to upload to the session")
447-
c.argument('path', help="The path to list files from the session")
447+
c.argument('path', help="The path of files in the session")
448448

449449
with self.argument_context('containerapp session code-interpreter', arg_group='execute') as c:
450450
c.argument('code', help="The code to execute in the code interpreter session")

src/containerapp/azext_containerapp/containerapp_session_code_interpreter_decorator.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,10 @@ def validate_arguments(self):
8383
"sessionPools")
8484

8585
def construct_payload(self):
86-
self.session_code_interpreter_def["properties"]["identifier"] = self.get_argument_identifier()
87-
88-
self.session_code_interpreter_def["properties"]["codeInputType"] = "inline"
89-
self.session_code_interpreter_def["properties"]["executionType"] = "synchronous"
90-
91-
if self.get_argument_timeout_in_seconds() is not None:
92-
self.session_code_interpreter_def["properties"]["timeoutInSeconds"] = self.get_argument_timeout_in_seconds()
93-
else:
94-
self.session_code_interpreter_def["properties"]["timeoutInSeconds"] = 60
95-
self.session_code_interpreter_def["properties"]["code"] = self.get_argument_code()
86+
self.session_code_interpreter_def["codeInputType"] = "inline"
87+
self.session_code_interpreter_def["executionType"] = "synchronous"
88+
self.session_code_interpreter_def["timeoutInSeconds"] = self.get_argument_timeout_in_seconds()
89+
self.session_code_interpreter_def["code"] = self.get_argument_code()
9690

9791
def execute(self):
9892
try:
@@ -111,6 +105,7 @@ def upload(self):
111105
cmd=self.cmd,
112106
identifier=self.get_argument_identifier(),
113107
filepath=self.get_argument_filepath(),
108+
path=self.get_argument_path(),
114109
session_pool_endpoint=self.get_sessionpool_endpoint(),
115110
no_wait=self.get_argument_no_wait())
116111
except Exception as e:
@@ -122,6 +117,7 @@ def show_file_content(self):
122117
cmd=self.cmd,
123118
identifier=self.get_argument_identifier(),
124119
filename=self.get_argument_filename(),
120+
path=self.get_argument_path(),
125121
session_pool_endpoint=self.get_sessionpool_endpoint())
126122
except Exception as e:
127123
handle_raw_exception(e)
@@ -132,6 +128,7 @@ def show_file_metadata(self):
132128
cmd=self.cmd,
133129
identifier=self.get_argument_identifier(),
134130
filename=self.get_argument_filename(),
131+
path=self.get_argument_path(),
135132
session_pool_endpoint=self.get_sessionpool_endpoint())
136133
except Exception as e:
137134
handle_raw_exception(e)
@@ -152,6 +149,7 @@ def delete_file(self):
152149
cmd=self.cmd,
153150
identifier=self.get_argument_identifier(),
154151
filename=self.get_argument_filename(),
152+
path=self.get_argument_path(),
155153
session_pool_endpoint=self.get_sessionpool_endpoint(),
156154
no_wait=self.get_argument_no_wait())
157155
except Exception as e:

src/containerapp/azext_containerapp/custom.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2994,6 +2994,7 @@ def upload_session_code_interpreter(cmd,
29942994
resource_group_name,
29952995
identifier,
29962996
filepath,
2997+
path=None,
29972998
session_pool_location=None):
29982999
raw_parameters = locals()
29993000
session_code_interpreter_decorator = SessionCodeInterpreterCommandsPreviewDecorator(
@@ -3014,6 +3015,7 @@ def show_file_content_session_code_interpreter(cmd,
30143015
resource_group_name,
30153016
identifier,
30163017
filename,
3018+
path=None,
30173019
session_pool_location=None):
30183020
raw_parameters = locals()
30193021
session_code_interpreter_decorator = SessionCodeInterpreterCommandsPreviewDecorator(
@@ -3034,6 +3036,7 @@ def show_file_metadata_session_code_interpreter(cmd,
30343036
resource_group_name,
30353037
identifier,
30363038
filename,
3039+
path=None,
30373040
session_pool_location=None):
30383041
raw_parameters = locals()
30393042
session_code_interpreter_decorator = SessionCodeInterpreterCommandsPreviewDecorator(
@@ -3074,6 +3077,7 @@ def delete_file_session_code_interpreter(cmd,
30743077
resource_group_name,
30753078
identifier,
30763079
filename,
3080+
path=None,
30773081
session_pool_location=None):
30783082
raw_parameters = locals()
30793083
session_code_interpreter_decorator = SessionCodeInterpreterCommandsPreviewDecorator(

0 commit comments

Comments
 (0)