Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[App Service] az staticwebapp create: Allow creating Static Web Apps not connected to a github repo #22042

Merged
merged 1 commit into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we want to make location optional & Default to CentralUs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we want to make location optional & Default to CentralUs?

Hi StrawnSC,
Can you confirm with this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is what @simonaco put on the ADO work item

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