Skip to content

Commit

Permalink
[App Service] az staticwebapp create: Allow creating Static Web App…
Browse files Browse the repository at this point in the history
…s not connected to a github repo (#22042)
  • Loading branch information
StrawnSC authored Apr 13, 2022
1 parent 85dd9f5 commit 7978dd4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/azure-cli/azure/cli/command_modules/appservice/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -2331,14 +2331,16 @@

helps['staticwebapp create'] = """
type: command
short-summary: Create a static app with content from a GitHub repository URL and on the provided branch. If the repo is under a Github organization, please ensure that the Azure CLI Github App has access to the organization. Access can be requested in the browser when using the "--login-with-github" argument. Access must be granted by the organization's admin.
short-summary: Create a static app. To provide content to the static web app and integrate with a Github repo, provide the Github repository URL (--source) and a branch (--branch). If the repo is under a Github organization, please ensure that the Azure CLI Github App has access to the organization. Access can be requested in the browser when using the "--login-with-github" argument. Access must be granted by the organization's admin.
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 -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
- name: Create a static web app without any content and without a github integration
text: az staticwebapp create -n MyStaticAppName -g MyExistingRg
"""

helps['staticwebapp update'] = """
Expand Down
12 changes: 6 additions & 6 deletions src/azure-cli/azure/cli/command_modules/appservice/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,16 +986,16 @@ def load_arguments(self, _):
c.argument('hostname', options_list=['--hostname', '-n'], help='Name of the custom domain')

with self.argument_context('staticwebapp', validator=validate_public_cloud) as c:
c.ignore('format_output')
c.argument('name', options_list=['--name', '-n'], metavar='NAME', help="Name of the static site")
c.argument('source', options_list=['--source', '-s'], help="URL for the repository of the static site.")
c.argument('token', options_list=['--token', '-t'],
c.argument('source', options_list=['--source', '-s'], help="URL for the repository of the static site.", arg_group="Github")
c.argument('token', options_list=['--token', '-t'], arg_group="Github",
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 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.")
c.argument('login_with_github', help="Interactively log in with Github to retrieve the Personal Access Token", arg_group="Github")
c.argument('branch', options_list=['--branch', '-b'], help="The target branch in the repository.", arg_group="Github")
c.ignore('format_output')
c.argument('name', options_list=['--name', '-n'], metavar='NAME', help="Name of the static site")
with self.argument_context('staticwebapp environment') as c:
c.argument('environment_name',
options_list=['--environment-name'], help="Name of the environment of static site")
Expand Down
25 changes: 15 additions & 10 deletions src/azure-cli/azure/cli/command_modules/appservice/static_sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ def update_staticsite_users(cmd, name, roles, authentication_provider=None, user
static_site_user_envelope=user_envelope)


def create_staticsites(cmd, resource_group_name, name, location, # pylint: disable=too-many-locals,
source, branch, token=None,
def create_staticsites(cmd, resource_group_name, name, location="centralus", # pylint: disable=too-many-locals,
source=None, branch=None, token=None,
app_location="/", api_location=None, output_location=None,
tags=None, no_wait=False, sku='Free', login_with_github=False, format_output=True):
from azure.core.exceptions import ResourceNotFoundError as _ResourceNotFoundError
Expand All @@ -377,14 +377,19 @@ def create_staticsites(cmd, resource_group_name, name, location, # pylint: disa
except _ResourceNotFoundError:
pass

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)
elif token and login_with_github:
logger.warning("Both token and --login-with-github flag are provided. Will use provided token")
if source or branch or login_with_github or token:
if not source:
raise ValidationError("--source is required to make a static web app connected to a github repo")
if not branch:
raise ValidationError("--branch is required to make a static web app connected to a github repo")
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)
elif token and login_with_github:
logger.warning("Both token and --login-with-github flag are provided. Will use provided token")

StaticSiteARMResource, StaticSiteBuildProperties, SkuDescription = cmd.get_models(
'StaticSiteARMResource', 'StaticSiteBuildProperties', 'SkuDescription')
Expand Down

0 comments on commit 7978dd4

Please sign in to comment.