Skip to content

Commit

Permalink
Merge pull request Azure#4 from Azure/master
Browse files Browse the repository at this point in the history
Sync with the official repo
  • Loading branch information
ShichaoQiu authored Jan 16, 2020
2 parents eb5faf3 + 1bb9f3f commit 0b3436d
Show file tree
Hide file tree
Showing 15 changed files with 319 additions and 97 deletions.
52 changes: 26 additions & 26 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ trigger:
- '*'

jobs:
- job: CredScan
displayName: "Credential Scan"

pool:
vmImage: "windows-2019"
steps:
- task: CredScan@2
inputs:
toolMajorVersion: 'V2'

- task: PostAnalysis@1
inputs:
AllTools: false
APIScan: false
BinSkim: false
CodesignValidation: false
CredScan: true
FortifySCA: false
FxCop: false
ModernCop: false
PoliCheck: false
RoslynAnalyzers: false
SDLNativeRules: false
Semmle: false
TSLint: false
ToolLogsNotFoundAction: 'Standard'
#- job: CredScan
# displayName: "Credential Scan"
#
# pool:
# vmImage: "windows-2019"
# steps:
# - task: CredScan@2
# inputs:
# toolMajorVersion: 'V2'
#
# - task: PostAnalysis@1
# inputs:
# AllTools: false
# APIScan: false
# BinSkim: false
# CodesignValidation: false
# CredScan: true
# FortifySCA: false
# FxCop: false
# ModernCop: false
# PoliCheck: false
# RoslynAnalyzers: false
# SDLNativeRules: false
# Semmle: false
# TSLint: false
# ToolLogsNotFoundAction: 'Standard'

- job: StaticAnalysis
displayName: "Static Analysis"
Expand Down
13 changes: 10 additions & 3 deletions scripts/ci/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@
continue

# Running in Azure DevOps
cmd_tpl = 'git --no-pager diff --name-only origin/{commit_start} {commit_end} {code_dir}'
cmd_tpl = 'git --no-pager diff --name-only origin/{commit_start} {commit_end} -- {code_dir}'
ado_branch_last_commit = os.environ.get('ADO_PULL_REQUEST_LATEST_COMMIT')
ado_target_branch = os.environ.get('ADO_PULL_REQUEST_TARGET_BRANCH')
if ado_branch_last_commit and ado_target_branch:
cmd = cmd_tpl.format(commit_start=ado_target_branch, commit_end=ado_branch_last_commit, code_dir=src_d_full)
if not check_output(shlex.split(cmd)):
if ado_branch_last_commit == '$(System.PullRequest.SourceCommitId)':
# default value if ADO_PULL_REQUEST_LATEST_COMMIT not set in ADO
continue
elif ado_target_branch == '$(System.PullRequest.TargetBranch)':
# default value if ADO_PULL_REQUEST_TARGET_BRANCH not set in ADO
continue
else:
cmd = cmd_tpl.format(commit_start=ado_target_branch, commit_end=ado_branch_last_commit, code_dir=src_d_full)
if not check_output(shlex.split(cmd)):
continue

# Find the package and check it has tests
if pkg_name and os.path.isdir(os.path.join(src_d_full, pkg_name, 'tests')):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,71 @@ def list_cluster_user_credentials(
return deserialized
list_cluster_user_credentials.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/listClusterUserCredential'}

def list_cluster_monitoring_user_credentials(
self, resource_group_name, resource_name, custom_headers=None, raw=False, **operation_config):
"""Gets cluster monitoring user credential of a managed cluster.
Gets cluster monitoring user credential of the managed cluster with a
specified resource group and name.
:param resource_group_name: The name of the resource group.
:type resource_group_name: str
:param resource_name: The name of the managed cluster resource.
:type resource_name: str
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
:param operation_config: :ref:`Operation configuration
overrides<msrest:optionsforoperations>`.
:return: CredentialResults or ClientRawResponse if raw=true
:rtype:
~azure.mgmt.containerservice.v2020_01_01.models.CredentialResults or
~msrest.pipeline.ClientRawResponse
:raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>`
"""
# Construct URL
url = self.list_cluster_monitoring_user_credentials.metadata['url']
path_format_arguments = {
'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'),
'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', min_length=1),
'resourceName': self._serialize.url("resource_name", resource_name, 'str', max_length=63, min_length=1, pattern=r'^[a-zA-Z0-9]$|^[a-zA-Z0-9][-_a-zA-Z0-9]{0,61}[a-zA-Z0-9]$')
}
url = self._client.format_url(url, **path_format_arguments)

# Construct parameters
query_parameters = {}
query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')

# Construct headers
header_parameters = {}
header_parameters['Accept'] = 'application/json'
if self.config.generate_client_request_id:
header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
if custom_headers:
header_parameters.update(custom_headers)
if self.config.accept_language is not None:
header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')

# Construct and send request
request = self._client.post(url, query_parameters, header_parameters)
response = self._client.send(request, stream=False, **operation_config)

if response.status_code not in [200]:
exp = CloudError(response)
exp.request_id = response.headers.get('x-ms-request-id')
raise exp

deserialized = None
if response.status_code == 200:
deserialized = self._deserialize('CredentialResults', response)

if raw:
client_raw_response = ClientRawResponse(deserialized, response)
return client_raw_response

return deserialized
list_cluster_monitoring_user_credentials.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/listClusterMonitoringUserCredential'}

def get(
self, resource_group_name, resource_name, custom_headers=None, raw=False, **operation_config):
"""Gets a managed cluster.
Expand Down
6 changes: 5 additions & 1 deletion src/hack/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ Release History
0.3.0
++++++
* Clarified deployment URL
* Fixed deployment user creation
* Fixed deployment user creation

0.4.0
++++++
* Added support for app level git credentials
61 changes: 28 additions & 33 deletions src/hack/azext_hack/_website_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# # --------------------------------------------------------------------------------------------

from uuid import uuid4
from azure.cli.command_modules.appservice._client_factory import (
web_client_factory
)
from azure.cli.command_modules.appservice.custom import (
create_app_service_plan,
create_webapp,
update_app_settings,
set_deployment_user,
list_app_service_plans,
get_app_settings
get_app_settings,
list_publishing_credentials
)
from azure.cli.command_modules.resource.custom import move_resource
from knack.log import get_logger
Expand Down Expand Up @@ -54,21 +50,17 @@ def __init__(self, cmd, name: str, location: str, runtime: str):
self.name = name
self.location = location
self.runtime = runtime
self.deployment_user_name = None
self.deployment_user_password = None
self.deployment_url = None
self.host_name = None
self.resource_group = None
self.id = None
self.__cmd = cmd
self.__deployment_info = None

def create(self):
app_service_plan = self.__get_or_create_app_service_plan()
self.__set_deployment_user()

webapp = self.__create_webapp(app_service_plan)

self.deployment_url = 'https://{}.scm.azurewebsites.net/{}.git'.format(self.name, self.name)
self.host_name = 'https://' + webapp.host_names[0]

def update_settings(self, settings):
Expand All @@ -90,18 +82,36 @@ def finalize_resource_group(self):
self.resource_group = self.name

def show(self):
output = {}
output = {'Application name': self.name}

settings = {}
for setting in get_app_settings(self.__cmd, resource_group_name=self.name, name=self.name):
settings.update({setting['name']: setting['value']})
output.update({'App settings': settings})
urls = {}
repo_url = 'https://{}.scm.azurewebsites.net/{}.git'.format(self.name, self.name)
urls.update({'Git url': repo_url})
urls.update({'Website url': repo_url.replace('scm.', '')})
output.update({'URLs': urls})
if settings:
output.update({'Application settings (stored as environmental variables on server)': settings})

output.update({'Deployment info': {
'Git url': self.deployment_info.git_url,
'User name': self.deployment_info.name,
'User password': self.deployment_info.password
}})

output.update({'Website url': 'https://{}.azurewebsites.net'.format(self.name)})

return output

@property
def deployment_info(self):
if not self.__deployment_info:
publishing_info = list_publishing_credentials(self.__cmd, resource_group_name=self.name, name=self.name)
self.__deployment_info = type('DeploymentInfo', (object, ), {
'name': publishing_info.name,
'password': publishing_info.publishing_password,
'git_url': 'https://{}.scm.azurewebsites.net/{}.git'.format(self.name, self.name)
})()

return self.__deployment_info

def __get_or_create_app_service_plan(self) -> str:
plans = list_app_service_plans(self.__cmd)
for plan in plans:
Expand All @@ -127,18 +137,3 @@ def __create_webapp(self, app_service_plan):
self.resource_group = app_service_plan.resource_group
self.id = webapp.id
return webapp

def __set_deployment_user(self):
deployment_user = web_client_factory(
self.__cmd.cli_ctx).get_publishing_user()
# Check for existing deployment user
if not deployment_user or not deployment_user.publishing_user_name:
# Create random password, set name to base of app name
logger.warning('Creating deployment user')
password = str(uuid4())
user_name = self.name
set_deployment_user(self.__cmd, user_name=user_name, password=password)
self.deployment_user_name = user_name
self.deployment_user_password = password
else:
self.deployment_user_name = deployment_user.publishing_user_name
31 changes: 4 additions & 27 deletions src/hack/azext_hack/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,38 +67,15 @@ def create_hack(cmd, name, runtime, location, database=None, ai=None):
website.update_settings(app_settings)
website.finalize_resource_group()

output = {
'Application name': name
}

deployment_info = {
'Deployment url': website.deployment_url,
'Git login': website.deployment_user_name,
}

if website.deployment_user_password:
deployment_info.update(
{'Git password': website.deployment_user_password})
else:
password_info = 'Cannot retrieve password. To change, use `az webapp deployment user set --user-name {}`'
deployment_info.update(
{'Git password info': password_info.format(website.deployment_user_name)})

deployment_steps = {
output = website.show()

output.update({'Deployment steps': {
'1- Create git repository': 'git init',
'2- Add all code': 'git add .',
'3- Commit code': 'git commit -m \'Initial commit\'',
'4- Add remote to git': 'git remote add azure ' + website.deployment_url,
'4- Add remote to git': 'git remote add azure ' + website.deployment_info.git_url,
'5- Deploy to Azure': 'git push -u azure master'
}

output.update({'Settings and keys': {
'Note': 'All values are stored as environmental variables on website',
'Values': app_settings
}})
output.update({'Deployment info': deployment_info})
output.update({'Deployment steps': deployment_steps})
output.update({'Website url': website.host_name})

return output

Expand Down
2 changes: 1 addition & 1 deletion src/hack/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# TODO: Confirm this is the right version number you want and it matches your
# HISTORY.rst entry.
VERSION = '0.3.0'
VERSION = '0.4.0'

# The full list of classifiers is available at
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand Down
8 changes: 4 additions & 4 deletions src/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -1333,8 +1333,8 @@
],
"hack": [
{
"downloadUrl": "https://azhackcli.blob.core.windows.net/whl/hack-0.3.0-py2.py3-none-any.whl",
"filename": "hack-0.3.0-py2.py3-none-any.whl",
"downloadUrl": "https://azhackcli.blob.core.windows.net/whl/hack-0.4.0-py2.py3-none-any.whl",
"filename": "hack-0.4.0-py2.py3-none-any.whl",
"metadata": {
"azext.isPreview": true,
"azext.maxCliCoreVersion": "2.1.0",
Expand Down Expand Up @@ -1374,9 +1374,9 @@
"metadata_version": "2.0",
"name": "hack",
"summary": "Microsoft Azure Command-Line Tools Hack Extension",
"version": "0.3.0"
"version": "0.4.0"
},
"sha256Digest": "dd420f747f7ffef861089a3a6c2e50911b57524399f3d9739691002c8dd0e7b4"
"sha256Digest": "7d5d9d4474429c1bed613d9c3183a25b029c8b9b75b9b0ee4a61e49493f1fec2"
}
],
"healthcareapis": [
Expand Down
5 changes: 5 additions & 0 deletions src/spring-cloud/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
Release History
===============

0.2.0
++++++
* Support the log streaming feature.
* Add command for log streaming: az spring-cloud app log tail.

0.1.1
++++++
* Improve the verbosity for the long running commands.
Expand Down
12 changes: 12 additions & 0 deletions src/spring-cloud/azext_spring_cloud/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@
short-summary: Show build log of the last deploy, only apply to source code deploy, default to production deployment.
"""

helps['spring-cloud app log tail'] = """
type: command
short-summary: Show logs of an app or a instance, logs will be streamed when set --follow.
"""

helps['spring-cloud app set-deployment'] = """
type: command
short-summary: Set production deployment of an app.
Expand All @@ -150,6 +155,13 @@
text: az spring-cloud app set-deployment -d green-deployment -n MyApp -s MyCluster -g MyResourceGroup
"""


helps['spring-cloud app log'] = """
type: group
short-summary: Commands to tail app instances logs with multiple options. If the app has only one instance, the instance name is optional.
"""


helps['spring-cloud app deployment'] = """
type: group
short-summary: Commands to manage life cycle of deployments of an app in Azure Spring Cloud. More operations on deployments can be done on app level with parameter --deployment. e.g. az spring-cloud app deploy --deployment <staging deployment>
Expand Down
Loading

0 comments on commit 0b3436d

Please sign in to comment.