Skip to content

Commit

Permalink
Codespaces CLI release v0.2.0 (#1856)
Browse files Browse the repository at this point in the history
  • Loading branch information
derekbekoe authored Jun 20, 2020
1 parent c4799e6 commit 464901c
Show file tree
Hide file tree
Showing 36 changed files with 785 additions and 938 deletions.
12 changes: 11 additions & 1 deletion src/codespaces/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
Release History
===============

0.2.0
++++++
* Update to latest resource provider API version, 2020-05-26.
* Plan creation: Set plan defaults (default sku, default suspend timeout).
* Plan creation: `--subnet` argument to create a plan with a vnet.
* Codespace creation: Plan defaults will be used for --instance-type and --suspend-after if available and you haven't specified to override the defaults.
* New `az codespace update` command (support for editing sku/suspend timeout of a Suspended codespace).
* `az codespace list` new behavior: By default, we now only show your codespaces. Add `--all` flag to `az codespace list` command to list codespaces of all users.
* Support Secrets Management.

0.1.0
++++++
* Initial release.
* Initial release.
28 changes: 28 additions & 0 deletions src/codespaces/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,31 @@ Microsoft Azure CLI 'codespaces' Extension
Visual Studio Codespaces - Cloud-powered development environments accessible from anywhere.

https://azure.microsoft.com/en-us/services/visual-studio-online/

Updating the vendored SDK
-------------------------

```
cd /specification/vsonline/resource-manager
autorest --python readme.md
```

Custom changes made to auto-generated SDK:
1. Remove trailing `/` from `list_by_resource_group` and `list_by_subscription` plan operations as server will reject request otherwise.
2. Add support for custom API version to be set.

Before submitting a PR
----------------------

```
azdev style codespaces
azdev linter codespaces
azdev test codespaces
```

Test extension on fresh set up:
```
azdev extension build codespaces
docker run -v .../azure-cli-extensions/dist:/ext -it microsoft/azure-cli
az extension add --source /ext/codespaces-VERSION-py2.py3-none-any.whl
```
29 changes: 25 additions & 4 deletions src/codespaces/azext_codespaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,49 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.events import EVENT_INVOKER_POST_PARSE_ARGS
from knack.log import get_logger
from azure.cli.core import AzCommandsLoader

from azext_codespaces._help import helps # pylint: disable=unused-import
from ._help import helps # pylint: disable=unused-import
from ._config import get_rp_api_version, get_service_domain, DEFAULT_SERVICE_DOMAIN

logger = get_logger(__name__)


def log_custom_config_message(cli_ctx):
custom_rp_api_version = get_rp_api_version(cli_ctx)
if custom_rp_api_version:
logger.warning("Codespaces: Using custom resource provider api version %s", custom_rp_api_version)
custom_service_domain = get_service_domain(cli_ctx)
if custom_service_domain != DEFAULT_SERVICE_DOMAIN:
logger.warning("Codespaces: Using custom service domain %s", custom_service_domain)


def event_handler(cli_ctx, **kwargs):
cmd = kwargs.get('command', None)
if cmd and cmd.startswith('codespace'):
log_custom_config_message(cli_ctx)


class CodespacesCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
from azext_codespaces._client_factory import cf_codespaces
from ._client_factory import cf_codespaces
codespaces_custom = CliCommandType(
operations_tmpl='azext_codespaces.custom#{}',
client_factory=cf_codespaces)
cli_ctx.register_event(EVENT_INVOKER_POST_PARSE_ARGS, event_handler)
super(CodespacesCommandsLoader, self).__init__(cli_ctx=cli_ctx, custom_command_type=codespaces_custom)

def load_command_table(self, args):
from azext_codespaces.commands import load_command_table
from .commands import load_command_table
load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
from azext_codespaces._params import load_arguments
from ._params import load_arguments
load_arguments(self, command)


Expand Down
5 changes: 4 additions & 1 deletion src/codespaces/azext_codespaces/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from ._config import get_rp_api_version


def cf_codespaces(cli_ctx, *_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from .vendored_sdks.vsonline.vs_online_client import VSOnlineClient
return get_mgmt_service_client(cli_ctx, VSOnlineClient)
custom_api_version = get_rp_api_version(cli_ctx)
return get_mgmt_service_client(cli_ctx, VSOnlineClient, api_version=custom_api_version)


def cf_codespaces_plan(cli_ctx, *_):
Expand Down
30 changes: 30 additions & 0 deletions src/codespaces/azext_codespaces/_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

DEFAULT_SERVICE_DOMAIN = "online.visualstudio.com"

CONFIG_SECTION = 'codespaces'
KEY_RESOURCE_PROVIDER_API_VERSION = 'resource_provider_api_version'
KEY_SERVICE_DOMAIN = 'service_domain'


def get_rp_api_version(cli_ctx):
return cli_ctx.config.get(CONFIG_SECTION, KEY_RESOURCE_PROVIDER_API_VERSION, fallback=None)


def get_service_domain(cli_ctx):
return cli_ctx.config.get(CONFIG_SECTION, KEY_SERVICE_DOMAIN, fallback=None) or DEFAULT_SERVICE_DOMAIN


def get_current_config(cli_ctx):
return cli_ctx.config.items(CONFIG_SECTION)


def set_rp_api_version(cli_ctx, val):
cli_ctx.config.set_value(CONFIG_SECTION, KEY_RESOURCE_PROVIDER_API_VERSION, val)


def set_service_domain(cli_ctx, val):
cli_ctx.config.set_value(CONFIG_SECTION, KEY_SERVICE_DOMAIN, val)
85 changes: 76 additions & 9 deletions src/codespaces/azext_codespaces/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,24 @@
short-summary: Information on available regions.
"""

helps['codespace plan'] = """
type: group
short-summary: Manage Codespace plans.
"""

helps['codespace secret'] = """
type: group
short-summary: Manage plan secrets.
"""

helps['codespace location list'] = """
type: command
short-summary: List available regions.
"""

helps['codespace location show'] = """
type: command
short-summary: Show details on a region.
"""

helps['codespace plan'] = """
type: group
short-summary: Manage Codespace plans.
short-summary: Show details of a region.
"""

helps['codespace plan create'] = """
Expand All @@ -41,7 +46,13 @@
- name: Create a plan in a specific region
text: az codespace plan create -g my-rg -n my-plan -l westus2
- name: Create a plan with tags
text: az codespace plan create -g my-rg -n my-plan -l westus2 --tags tagname=tagvalue
text: az codespace plan create -g my-rg -n my-plan --tags tagname=tagvalue
- name: Create a plan with a default instance type
text: az codespace plan create -g my-rg -n my-plan --default-instance-type premiumLinux
- name: Create a plan with a default suspend after
text: az codespace plan create -g my-rg -n my-plan --default-suspend-after 120
- name: Create a plan associated with a subnet
text: az codespace plan create -g my-rg -n my-plan --subnet /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/default
"""

helps['codespace plan list'] = """
Expand Down Expand Up @@ -79,7 +90,7 @@
populator-commands:
- az codespace location show
examples:
- name: Create a Codespace with default settings
- name: Create a Codespace with default plan settings
text: az codespace create -g my-rg --plan my-plan --name my-codespace
- name: Create a Codespace with a different instance type with custom suspend time
text: az codespace create -g my-rg --plan my-plan --name my-codespace --instance-type premiumLinux --suspend-after 5
Expand All @@ -95,7 +106,7 @@
examples:
- name: List Codespaces
text: az codespace list -g my-rg --plan my-plan
- name: List Codespaces given plan id and Codespace name
- name: List Codespaces given plan id
text: az codespace list --plan /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.VSOnline/plans/my-plan
"""

Expand All @@ -109,7 +120,16 @@
text: az codespace delete -g my-rg --plan my-plan --id 00000000-0000-0000-0000-000000000000
- name: Delete a Codespace given plan id and Codespace name
text: az codespace delete --plan /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.VSOnline/plans/my-plan --name my-codespace
"""

helps['codespace update'] = """
type: command
short-summary: Update a Codespace.
examples:
- name: Update a Codespace with a different instance type
text: az codespace update -g my-rg --plan my-plan --name my-codespace --instance-type premiumLinux
- name: Update a Codespace with a different suspend after
text: az codespace update -g my-rg --plan my-plan --name my-codespace --suspend-after 30
"""

helps['codespace show'] = """
Expand Down Expand Up @@ -160,5 +180,52 @@
text: az codespace open -g my-rg --plan my-plan --id 00000000-0000-0000-0000-000000000000
- name: Open a Codespace given plan id and Codespace name
text: az codespace open --plan /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.VSOnline/plans/my-plan --name my-codespace
"""

helps['codespace secret create'] = """
type: command
short-summary: Create a plan secret.
examples:
- name: Create a plan secret.
text: az codespace secret create -g my-rg --plan my-plan --name API_KEY --value "secretkey" --note "service api key"
- name: Create a plan secret with filters.
text: az codespace secret create -g my-rg --plan my-plan --name API_KEY --value "secretkey" --filters GitRepo=https://github.com/repo/name CodespaceName=mycodespace
"""

helps['codespace secret update'] = """
type: command
short-summary: Update a plan secret.
examples:
- name: Update a plan secret with new values.
text: az codespace secret update -g my-rg --plan my-plan --id 00000000-0000-0000-0000-000000000000 --name API_KEY --value "newsecretkey" --note "service api key"
- name: Update a plan secret with new filters.
text: az codespace secret update -g my-rg --plan my-plan --id 00000000-0000-0000-0000-000000000000 --filters GitRepo=https://github.com/repo/name CodespaceName=mycodespace
- name: Update a plan secret and clear existing filters.
text: az codespace secret update -g my-rg --plan my-plan --id 00000000-0000-0000-0000-000000000000 --filters ''
"""

helps['codespace secret delete'] = """
type: command
short-summary: Delete a plan secret.
examples:
- name: Delete a plan secret.
text: az codespace secret delete -g my-rg --plan my-plan --id 00000000-0000-0000-0000-000000000000
"""

helps['codespace secret list'] = """
type: command
short-summary: List plan secrets.
examples:
- name: List plan secrets.
text: az codespace secret list -g my-rg --plan my-plan
"""

helps['codespace set-config'] = """
type: command
short-summary: Set configuration for codespace commands.
"""

helps['codespace show-config'] = """
type: command
short-summary: Show current configuration for codespace commands.
"""
Loading

0 comments on commit 464901c

Please sign in to comment.