Skip to content

Commit

Permalink
add option for key credential (Azure#24437)
Browse files Browse the repository at this point in the history
  • Loading branch information
msyyc authored May 18, 2022
1 parent 7170a7c commit 8df107b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scripts/quickstart_tooling_dpg/dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
jinja2
jinja2==3.1.2
18 changes: 15 additions & 3 deletions scripts/quickstart_tooling_dpg/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from jinja2 import Environment, FileSystemLoader
from subprocess import check_call
import time
from typing import Any
from typing import Any, Dict

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -106,6 +106,11 @@ def build_package(**kwargs) -> None:
_LOGGER.info("Build complete: %s", package_name)


def validate_params(**kwargs):
if not kwargs.get("security_scope") and not kwargs.get("security_header_name"):
raise Exception('At least one of "security-scope" and "security-header-name" is needed')


def main(**kwargs):
build_package(**kwargs)

Expand All @@ -132,8 +137,14 @@ def main(**kwargs):
parser.add_argument(
"--security-scope", "-c",
dest="security_scope",
required=True,
help="Each service for data plan should have specific scopes",
required=False,
help="If authentication is AADToken, this param is necessary",
)
parser.add_argument(
"--security-header-name",
dest="security_header_name",
required=False,
help="If authentication is api key, this param is necessary",
)
parser.add_argument(
"--package-name", "-p",
Expand All @@ -160,4 +171,5 @@ def main(**kwargs):
main_logger.setLevel(logging.INFO)

parameters = vars(args)
validate_params(**parameters)
main(**parameters)
5 changes: 5 additions & 0 deletions scripts/quickstart_tooling_dpg/template/swagger_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ no-namespace-folders: true
title: {{ client_name }}
version-tolerant: true
package-version: 1.0.0b1
{%- if security_scope %}
security: AADToken
security-scopes: {{ security_scope }}
{%- elif security_header_name %}
security: AzureKey
security-header-name: {{ security_header_name }}
{%- endif %}
```

0 comments on commit 8df107b

Please sign in to comment.