From 3c4bcdb5bd9d89a24871b58f18967dd5c3ef8d96 Mon Sep 17 00:00:00 2001 From: zhen Date: Tue, 21 Nov 2023 15:39:34 +0800 Subject: [PATCH] [pfs] Request of get connection exposes with_secrets (#1214) # Description Please add an informative description that covers that changes made by the pull request and link all relevant issues. # All Promptflow Contribution checklist: - [ ] **The pull request does not introduce [breaking changes].** - [ ] **CHANGELOG is updated for new features, bug fixes or other significant changes.** - [ ] **I have read the [contribution guidelines](../CONTRIBUTING.md).** - [ ] **Create an issue and link to the pull request to get dedicated review from promptflow team. Learn more: [suggested workflow](../CONTRIBUTING.md#suggested-workflow).** ## General Guidelines and Best Practices - [ ] Title of the pull request is clear and informative. - [ ] There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, [see this page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md). ### Testing Guidelines - [ ] Pull request includes test coverage for the included changes. --- .../_sdk/_service/apis/connection.py | 18 +++-- .../promptflow/_sdk/_service/swagger.json | 67 +++++++++++++------ 2 files changed, 59 insertions(+), 26 deletions(-) diff --git a/src/promptflow/promptflow/_sdk/_service/apis/connection.py b/src/promptflow/promptflow/_sdk/_service/apis/connection.py index a191636e68f..c1580170c85 100644 --- a/src/promptflow/promptflow/_sdk/_service/apis/connection.py +++ b/src/promptflow/promptflow/_sdk/_service/apis/connection.py @@ -64,11 +64,7 @@ class Connection(Resource): @local_user_only def get(self, name: str): connection_op = ConnectionOperations() - # parse query parameters - with_secrets = request.args.get("with_secrets", default=False, type=bool) - raise_error = request.args.get("raise_error", default=True, type=bool) - - connection = connection_op.get(name=name, with_secrets=with_secrets, raise_error=raise_error) + connection = connection_op.get(name=name, raise_error=True) connection_dict = connection._to_dict() return jsonify(connection_dict) @@ -102,3 +98,15 @@ def put(self, name: str): def delete(self, name: str): connection_op = ConnectionOperations() connection_op.delete(name=name) + + +@api.route("//listsecrets") +class ConnectionWithSecret(Resource): + @api.doc(description="Get connection with secret") + @api.response(code=200, description="Connection details with secret", model=dict_field) + @local_user_only + def get(self, name: str): + connection_op = ConnectionOperations() + connection = connection_op.get(name=name, with_secrets=True, raise_error=True) + connection_dict = connection._to_dict() + return jsonify(connection_dict) diff --git a/src/promptflow/promptflow/_sdk/_service/swagger.json b/src/promptflow/promptflow/_sdk/_service/swagger.json index 65b52fdc879..57ce48e48bd 100644 --- a/src/promptflow/promptflow/_sdk/_service/swagger.json +++ b/src/promptflow/promptflow/_sdk/_service/swagger.json @@ -32,7 +32,7 @@ "type": "string" } ], - "get": { + "put": { "responses": { "200": { "description": "Connection details", @@ -41,13 +41,21 @@ } } }, - "description": "Get connection", - "operationId": "get_connection", + "description": "Update connection", + "operationId": "put_connection", + "parameters": [ + { + "name": "connection_dict", + "in": "query", + "type": "string", + "required": true + } + ], "tags": [ "Connections" ] }, - "post": { + "get": { "responses": { "200": { "description": "Connection details", @@ -56,21 +64,25 @@ } } }, - "description": "Create connection", - "operationId": "post_connection", - "parameters": [ - { - "name": "connection_dict", - "in": "query", - "type": "string", - "required": true + "description": "Get connection", + "operationId": "get_connection", + "tags": [ + "Connections" + ] + }, + "delete": { + "responses": { + "200": { + "description": "Success" } - ], + }, + "description": "Delete connection", + "operationId": "delete_connection", "tags": [ "Connections" ] }, - "put": { + "post": { "responses": { "200": { "description": "Connection details", @@ -79,8 +91,8 @@ } } }, - "description": "Update connection", - "operationId": "put_connection", + "description": "Create connection", + "operationId": "post_connection", "parameters": [ { "name": "connection_dict", @@ -92,15 +104,28 @@ "tags": [ "Connections" ] - }, - "delete": { + } + }, + "/Connections/{name}/listsecrets": { + "parameters": [ + { + "name": "name", + "in": "path", + "required": true, + "type": "string" + } + ], + "get": { "responses": { "200": { - "description": "Success" + "description": "Connection details with secret", + "schema": { + "$ref": "#/definitions/ConnectionDict" + } } }, - "description": "Delete connection", - "operationId": "delete_connection", + "description": "Get connection with secret", + "operationId": "get_connection_with_secret", "tags": [ "Connections" ]