|
2 | 2 | # Copyright (c) Microsoft Corporation. All rights reserved. |
3 | 3 | # Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | # -------------------------------------------------------------------------------------------- |
5 | | - |
6 | | -from ast import NotEq |
7 | 5 | import json |
8 | 6 | import time |
9 | 7 | import sys |
@@ -523,3 +521,85 @@ def list_by_resource_group(cls, cmd, resource_group_name, formatter=lambda x: x) |
523 | 521 | env_list.append(formatted) |
524 | 522 |
|
525 | 523 | return env_list |
| 524 | + |
| 525 | +class GitHubActionClient(): |
| 526 | + @classmethod |
| 527 | + def create_or_update(cls, cmd, resource_group_name, name, github_action_envelope, headers, no_wait=False): |
| 528 | + management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager |
| 529 | + api_version = NEW_API_VERSION |
| 530 | + sub_id = get_subscription_id(cmd.cli_ctx) |
| 531 | + url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/containerApps/{}/sourcecontrols/current?api-version={}" |
| 532 | + request_url = url_fmt.format( |
| 533 | + management_hostname.strip('/'), |
| 534 | + sub_id, |
| 535 | + resource_group_name, |
| 536 | + name, |
| 537 | + api_version) |
| 538 | + |
| 539 | + r = send_raw_request(cmd.cli_ctx, "PUT", request_url, body=json.dumps(github_action_envelope), headers=headers) |
| 540 | + |
| 541 | + if no_wait: |
| 542 | + return r.json() |
| 543 | + elif r.status_code == 201: |
| 544 | + url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/containerApps/{}/sourcecontrols/current?api-version={}" |
| 545 | + request_url = url_fmt.format( |
| 546 | + management_hostname.strip('/'), |
| 547 | + sub_id, |
| 548 | + resource_group_name, |
| 549 | + name, |
| 550 | + api_version) |
| 551 | + return poll(cmd, request_url, "inprogress") |
| 552 | + |
| 553 | + return r.json() |
| 554 | + |
| 555 | + @classmethod |
| 556 | + def show(cls, cmd, resource_group_name, name): |
| 557 | + management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager |
| 558 | + api_version = NEW_API_VERSION |
| 559 | + sub_id = get_subscription_id(cmd.cli_ctx) |
| 560 | + url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/containerApps/{}/sourcecontrols/current?api-version={}" |
| 561 | + request_url = url_fmt.format( |
| 562 | + management_hostname.strip('/'), |
| 563 | + sub_id, |
| 564 | + resource_group_name, |
| 565 | + name, |
| 566 | + api_version) |
| 567 | + |
| 568 | + r = send_raw_request(cmd.cli_ctx, "GET", request_url) |
| 569 | + return r.json() |
| 570 | + |
| 571 | + #TODO |
| 572 | + @classmethod |
| 573 | + def delete(cls, cmd, resource_group_name, name, headers, no_wait=False): |
| 574 | + management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager |
| 575 | + api_version = NEW_API_VERSION |
| 576 | + sub_id = get_subscription_id(cmd.cli_ctx) |
| 577 | + url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/containerApps/{}/sourcecontrols/current?api-version={}" |
| 578 | + request_url = url_fmt.format( |
| 579 | + management_hostname.strip('/'), |
| 580 | + sub_id, |
| 581 | + resource_group_name, |
| 582 | + name, |
| 583 | + api_version) |
| 584 | + |
| 585 | + r = send_raw_request(cmd.cli_ctx, "DELETE", request_url, headers=headers) |
| 586 | + |
| 587 | + if no_wait: |
| 588 | + return # API doesn't return JSON (it returns no content) |
| 589 | + elif r.status_code in [200, 201, 202, 204]: |
| 590 | + url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/containerApps/{}/sourcecontrols/current?api-version={}" |
| 591 | + request_url = url_fmt.format( |
| 592 | + management_hostname.strip('/'), |
| 593 | + sub_id, |
| 594 | + resource_group_name, |
| 595 | + name, |
| 596 | + api_version) |
| 597 | + |
| 598 | + if r.status_code == 202: |
| 599 | + from azure.cli.core.azclierror import ResourceNotFoundError |
| 600 | + try: |
| 601 | + poll(cmd, request_url, "cancelled") |
| 602 | + except ResourceNotFoundError: |
| 603 | + pass |
| 604 | + logger.warning('Containerapp github action successfully deleted') |
| 605 | + return |
0 commit comments