Skip to content

Commit 8fbbe16

Browse files
mgmt, DPG, update codegen (Azure#27033)
* mgmt, LLC, update codegen * update script, use security option from autorest * change to use security options in automation
1 parent 9b38787 commit 8fbbe16

File tree

4 files changed

+38
-26
lines changed

4 files changed

+38
-26
lines changed

eng/mgmt/automation/generate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def generate(
6666
tag_option = '--tag={0}'.format(tag) if tag else ''
6767
version_option = '--package-version={0}'.format(version) if version else ''
6868

69-
command = 'autorest --version={0} --use={1} --java.azure-libraries-for-java-folder={2} --java.output-folder={3} --java.namespace={4} {5}'.format(
69+
command = 'autorest --version={0} --use={1} --java --java.azure-libraries-for-java-folder={2} --java.output-folder={3} --java.namespace={4} {5}'.format(
7070
autorest,
7171
use,
7272
os.path.abspath(sdk_root),

eng/mgmt/automation/generate_data.py

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
GROUP_ID = 'com.azure'
21-
LLC_ARGUMENTS = '--java --low-level-client --sdk-integration --generate-samples'
21+
LLC_ARGUMENTS = '--low-level-client --sdk-integration --generate-samples'
2222

2323

2424
def sdk_automation(config: dict) -> List[dict]:
@@ -38,14 +38,11 @@ def sdk_automation(config: dict) -> List[dict]:
3838
service = match.group(1)
3939
file_name = match.group(2)
4040
file_name_sans = ''.join(c for c in file_name if c.isalnum())
41-
module = 'azure-{0}-{1}'.format(service, file_name_sans)
41+
module = 'azure-{0}-{1}'.format(service, file_name_sans).lower()
4242
input_file = os.path.join(spec_root, file_path)
43-
# placeholder, for lack of information
44-
credential_types = 'tokencredential'
45-
credential_scopes = 'https://{0}.azure.com/.default'.format(service)
4643

4744
succeeded = generate(sdk_root, input_file,
48-
service, module, credential_types, credential_scopes, '',
45+
service, module, '', '', '',
4946
AUTOREST_CORE_VERSION, AUTOREST_JAVA, '')
5047

5148
generated_folder = 'sdk/{0}/{1}'.format(service, module)
@@ -79,8 +76,8 @@ def generate(
7976
input_file: str,
8077
service: str,
8178
module: str,
82-
credential_types: str,
83-
credential_scopes: str,
79+
security: str,
80+
security_scopes: str,
8481
title: str,
8582
autorest: str,
8683
use: str,
@@ -96,7 +93,7 @@ def generate(
9693
shutil.rmtree(os.path.join(output_dir, 'src/samples/java', namespace.replace('.', '/'), 'generated'),
9794
ignore_errors=True)
9895

99-
readme_relative_path = update_readme(output_dir, input_file, credential_types, credential_scopes, title)
96+
readme_relative_path = update_readme(output_dir, input_file, security, security_scopes, title)
10097
if readme_relative_path:
10198
logging.info('[GENERATE] Autorest from README {}'.format(readme_relative_path))
10299

@@ -114,17 +111,19 @@ def generate(
114111
else:
115112
logging.info('[GENERATE] Autorest from JSON {}'.format(input_file))
116113

117-
credential_arguments = '--java.credential-types={0}'.format(credential_types)
118-
if credential_scopes:
119-
credential_arguments += ' --java.credential-scopes={0}'.format(credential_scopes)
114+
security_arguments = ''
115+
if security:
116+
security_arguments += '--security={0}'.format(security)
117+
if security_scopes:
118+
security_arguments += ' --security-scopes={0}'.format(security_scopes)
120119

121120
input_arguments = '--input-file={0}'.format(input_file)
122121

123122
artifact_arguments = '--artifact-id={0}'.format(module)
124123
if title:
125124
artifact_arguments += ' --title={0}'.format(title)
126125

127-
command = 'autorest --version={0} --use={1} ' \
126+
command = 'autorest --version={0} --use={1} --java ' \
128127
'--java.azure-libraries-for-java-folder={2} --java.output-folder={3} ' \
129128
'--java.namespace={4} {5}'\
130129
.format(
@@ -133,7 +132,7 @@ def generate(
133132
os.path.abspath(sdk_root),
134133
os.path.abspath(output_dir),
135134
namespace,
136-
' '.join((LLC_ARGUMENTS, input_arguments, credential_arguments, artifact_arguments, autorest_options))
135+
' '.join((LLC_ARGUMENTS, input_arguments, security_arguments, artifact_arguments, autorest_options))
137136
)
138137
logging.info(command)
139138
if os.system(command) != 0:
@@ -159,7 +158,7 @@ def compile_package(sdk_root: str, group_id: str, module: str) -> bool:
159158
return True
160159

161160

162-
def update_readme(output_dir: str, input_file: str, credential_types: str, credential_scopes: str, title: str) -> str:
161+
def update_readme(output_dir: str, input_file: str, security: str, security_scopes: str, title: str) -> str:
163162
readme_relative_path = ''
164163

165164
swagger_dir = os.path.join(output_dir, 'swagger')
@@ -179,10 +178,10 @@ def update_readme(output_dir: str, input_file: str, credential_types: str, crede
179178
yaml_json['input-file'] = [input_file]
180179
if title:
181180
yaml_json['title'] = title
182-
if credential_types:
183-
yaml_json['credential-types'] = credential_types
184-
if credential_scopes:
185-
yaml_json['credential-scopes'] = credential_scopes
181+
if security:
182+
yaml_json['security'] = security
183+
if security_scopes:
184+
yaml_json['security-scopes'] = security_scopes
186185

187186
# write updated yaml
188187
updated_yaml_str = yaml.dump(yaml_json,
@@ -226,17 +225,30 @@ def parse_args() -> argparse.Namespace:
226225
required=True,
227226
help='Module name under sdk/<service>/. Sample: azure-storage-blob',
228227
)
228+
parser.add_argument(
229+
'--security',
230+
required=False,
231+
help='Security schemes for authentication. '
232+
'Sample: "AADToken" for AAD credential for OAuth 2.0 authentication; '
233+
'"AzureKey" for Azure key credential; "[AADToken,AzureKey]" for both',
234+
)
235+
parser.add_argument(
236+
'--security-scopes',
237+
required=False,
238+
help='OAuth 2.0 scopes when "security" includes "AADToken". '
239+
'Sample: https://storage.azure.com/.default',
240+
)
229241
parser.add_argument(
230242
'--credential-types',
231-
required=True,
232-
help='Credential types. '
243+
required=False,
244+
help='[DEPRECATED] Credential types. '
233245
'Sample: "tokencredential" for AAD credential for OAuth 2.0 authentication; '
234246
'"azurekeycredential" for Azure key credential',
235247
)
236248
parser.add_argument(
237249
'--credential-scopes',
238250
required=False,
239-
help='OAuth 2.0 scopes when credential-types includes "tokencredential". '
251+
help='[DEPRECATED] OAuth 2.0 scopes when "credential-types" includes "tokencredential". '
240252
'Sample: https://storage.azure.com/.default',
241253
)
242254
parser.add_argument(

eng/mgmt/automation/generation_data.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ steps:
3333
- bash: |
3434
export PATH=$JAVA_HOME_11_X64/bin:$PATH
3535
java -version
36-
./eng/mgmt/automation/generate_data.py --input-file="$(INPUT_FILE)" --service="$(SERVICE)" --module="$(MODULE)" --credential-types="$(CREDENTIAL_TYPES)" --credential-scopes="$(CREDENTIAL_SCOPES)" --title="$(TITLE)"
36+
./eng/mgmt/automation/generate_data.py --input-file="$(INPUT_FILE)" --service="$(SERVICE)" --module="$(MODULE)" --security="$(SECURITY)" --security-scopes="$(SECURITY_SCOPES)" --title="$(TITLE)"
3737
displayName: Generation
3838

3939
- template: /eng/common/pipelines/templates/steps/create-pull-request.yml

eng/mgmt/automation/parameters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
SDK_ROOT = '../../../' # related to file dir
1818
AUTOREST_CORE_VERSION = '3.6.6'
19-
AUTOREST_JAVA = '@autorest/java@4.0.47'
19+
AUTOREST_JAVA = '@autorest/java@4.0.50'
2020
DEFAULT_VERSION = '1.0.0-beta.1'
2121
GROUP_ID = 'com.azure.resourcemanager'
2222
API_SPECS_FILE = 'api-specs.yaml'
@@ -28,7 +28,7 @@
2828
CHANGELOG_FORMAT = 'sdk/{service}/{artifact_id}/CHANGELOG.md'
2929

3030
MODELERFOUR_ARGUMENTS = '--pipeline.modelerfour.additional-checks=false --pipeline.modelerfour.lenient-model-deduplication=true'
31-
FLUENTLITE_ARGUMENTS = '--java {0} --azure-arm --verbose --sdk-integration --generate-samples --fluent=lite --java.fluent=lite --java.license-header=MICROSOFT_MIT_SMALL'.format(
31+
FLUENTLITE_ARGUMENTS = '{0} --azure-arm --verbose --sdk-integration --generate-samples --fluent=lite --java.fluent=lite --java.license-header=MICROSOFT_MIT_SMALL'.format(
3232
MODELERFOUR_ARGUMENTS)
3333

3434
CI_HEADER = '''\

0 commit comments

Comments
 (0)