Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2307,7 +2307,10 @@
examples:
- name: Create static app in a subscription.
text: az staticwebapp create -n MyStaticAppName -g MyExistingRg
-s https://github.com/JohnDoe/my-first-static-web-app -l WestUs2 -b master
-s https://github.com/JohnDoe/my-first-static-web-app -l WestUs2 -b master -t MyAccessToken
- name: Create static app in a subscription, retrieving token interactively
text: az staticwebapp create -n MyStaticAppName -g MyExistingRg
-s https://github.com/JohnDoe/my-first-static-web-app -l WestUs2 -b master --login-with-github
"""

helps['staticwebapp update'] = """
Expand All @@ -2332,6 +2335,8 @@
examples:
- name: Connect a repo and branch to static app.
text: az staticwebapp reconnect -n MyStaticAppName --source MyGitHubRepo -b master --token MyAccessToken
- name: Connect a repo and branch to static app, retrieving token interactively
text: az staticwebapp reconnect -n MyStaticAppName --source MyGitHubRepo -b master --login-with-github
"""

helps['staticwebapp delete'] = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -984,8 +984,9 @@ def load_arguments(self, _):
c.argument('token', options_list=['--token', '-t'],
help="A user's github repository token. This is used to setup the Github Actions workflow file and "
"API secrets. If you need to create a Github Personal Access Token, "
"please follow the steps found at the following link:\n"
"please run with the '--login-with-github' flag or follow the steps found at the following link:\n"
"https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line")
c.argument('login_with_github', help="Interactively log in with Github to retrieve the Personal Access Token")
c.argument('branch', options_list=['--branch', '-b'], help="The target branch in the repository.")
with self.argument_context('staticwebapp environment') as c:
c.argument('environment_name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ def disconnect_staticsite(cmd, name, resource_group_name=None, no_wait=False):
resource_group_name=resource_group_name, name=name)


def reconnect_staticsite(cmd, name, source, branch, token=None, resource_group_name=None, no_wait=False):
def reconnect_staticsite(cmd, name, source, branch, token=None, resource_group_name=None, login_with_github=False,
no_wait=False):
client = _get_staticsites_client_factory(cmd.cli_ctx)
if not resource_group_name:
resource_group_name = _get_resource_group_name_of_staticsite(client, name)

location = _get_staticsite_location(client, name, resource_group_name)

return create_staticsites(cmd, resource_group_name, name, location,
source, branch, token, no_wait=no_wait)
source, branch, token, login_with_github=login_with_github, no_wait=no_wait)


def list_staticsite_environments(cmd, name, resource_group_name=None):
Expand Down Expand Up @@ -192,9 +193,13 @@ def update_staticsite_users(cmd, name, roles, authentication_provider=None, user
def create_staticsites(cmd, resource_group_name, name, location,
source, branch, token=None,
app_location='.', api_location='.', output_location='.github/workflows',
tags=None, no_wait=False, sku='Free'):
if not token:
tags=None, no_wait=False, sku='Free', login_with_github=False):
if not token and not login_with_github:
_raise_missing_token_suggestion()
elif not token:
from ._github_oauth import get_github_access_token
scopes = ["admin:repo_hook", "repo", "workflow"]
token = get_github_access_token(cmd, scopes)

StaticSiteARMResource, StaticSiteBuildProperties, SkuDescription = cmd.get_models(
'StaticSiteARMResource', 'StaticSiteBuildProperties', 'SkuDescription')
Expand Down Expand Up @@ -273,7 +278,8 @@ def _raise_missing_token_suggestion():
pat_documentation = "https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line"
raise CLIError("GitHub access token is required to authenticate to your repositories. "
"If you need to create a Github Personal Access Token, "
"please follow the steps found at the following link:\n{0}".format(pat_documentation))
"please run with the '--login-with-github' flag or follow "
"the steps found at the following link:\n{0}".format(pat_documentation))


def _get_staticsite_location(client, static_site_name, resource_group_name):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def test_reconnect_staticapp_with_resourcegroup(self, create_staticsites_mock):
resource_group_name=self.rg1)

create_staticsites_mock.assert_called_once_with(self.mock_cmd, self.rg1, self.name1, self.location1,
self.source1, self.branch1, self.token1, no_wait=False)
self.source1, self.branch1, self.token1, login_with_github=False, no_wait=False)

@mock.patch('azure.cli.command_modules.appservice.static_sites.create_staticsites', autospec=True)
def test_reconnect_staticapp_without_resourcegroup(self, create_staticsites_mock):
Expand All @@ -209,7 +209,7 @@ def test_reconnect_staticapp_without_resourcegroup(self, create_staticsites_mock
reconnect_staticsite(self.mock_cmd, self.name1, self.source1, self.branch1, self.token1)

create_staticsites_mock.assert_called_once_with(self.mock_cmd, self.rg1, self.name1, self.location1,
self.source1, self.branch1, self.token1, no_wait=False)
self.source1, self.branch1, self.token1, login_with_github=False, no_wait=False)

def test_list_staticsite_environments_with_resourcegroup(self):
list_staticsite_environments(self.mock_cmd, self.name1, self.rg1)
Expand Down