Skip to content

Commit e465667

Browse files
hinokaCommit bot
authored andcommitted
bot_update: add --auth-refresh-token-json passthrough for apply_issue
BUG=642150 Review-Url: https://codereview.chromium.org/2294413002
1 parent e4abcee commit e465667

File tree

6 files changed

+151
-12
lines changed

6 files changed

+151
-12
lines changed

recipe_modules/bot_update/api.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ def ensure_checkout(self, gclient_config=None, suffix=None,
6666
patch=True, update_presentation=True,
6767
patch_root=None, no_shallow=False,
6868
with_branch_heads=False, refs=None,
69-
patch_oauth2=False, use_site_config_creds=True,
69+
patch_oauth2=False, oauth2_json=False,
70+
use_site_config_creds=True,
7071
output_manifest=True, clobber=False,
7172
root_solution_revision=None, rietveld=None, issue=None,
7273
patchset=None, gerrit_no_reset=False,
@@ -91,6 +92,9 @@ def ensure_checkout(self, gclient_config=None, suffix=None,
9192
assert cfg is not None, (
9293
'missing gclient_config or forgot api.gclient.set_config(...) before?')
9394

95+
# Only one of these should exist.
96+
assert not (oauth2_json and patch_oauth2)
97+
9498
# Construct our bot_update command. This basically be inclusive of
9599
# everything required for bot_update to know:
96100
root = patch_root
@@ -123,7 +127,13 @@ def ensure_checkout(self, gclient_config=None, suffix=None,
123127

124128
# Point to the oauth2 auth files if specified.
125129
# These paths are where the bots put their credential files.
126-
if patch_oauth2:
130+
oauth2_json_file = email_file = key_file = None
131+
if oauth2_json:
132+
if self.m.platform.is_win:
133+
oauth2_json_file = 'C:\\creds\\refresh_tokens\\rietveld.json'
134+
else:
135+
oauth2_json_file = '/creds/refresh_tokens/rietveld.json'
136+
elif patch_oauth2:
127137
# TODO(martiniss): remove this hack :(. crbug.com/624212
128138
if use_site_config_creds:
129139
email_file = self.m.path['build'].join(
@@ -134,8 +144,6 @@ def ensure_checkout(self, gclient_config=None, suffix=None,
134144
#TODO(martiniss): make this use path.join, so it works on windows
135145
email_file = '/creds/rietveld/client_email'
136146
key_file = '/creds/rietveld/secret_key'
137-
else:
138-
email_file = key_file = None
139147

140148
# Allow patch_project's revision if necessary.
141149
# This is important for projects which are checked out as DEPS of the
@@ -160,6 +168,7 @@ def ensure_checkout(self, gclient_config=None, suffix=None,
160168
['--gerrit_ref', gerrit_ref],
161169
['--apply_issue_email_file', email_file],
162170
['--apply_issue_key_file', key_file],
171+
['--apply_issue_oauth2_file', oauth2_json_file],
163172

164173
# Hookups to JSON output back into recipes.
165174
['--output_json', self.m.json.output()],]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[
2+
{
3+
"cmd": [
4+
"python",
5+
"-u",
6+
"RECIPE_MODULE[depot_tools::bot_update]/resources/bot_update.py",
7+
"--spec",
8+
"cache_dir = '[GIT_CACHE]'\nsolutions = [{'deps_file': '.DEPS.git', 'managed': True, 'name': 'src', 'url': 'https://chromium.googlesource.com/chromium/src.git'}]",
9+
"--patch_root",
10+
"src",
11+
"--revision_mapping_file",
12+
"{\"src\": \"got_cr_revision\"}",
13+
"--git-cache-dir",
14+
"[GIT_CACHE]",
15+
"--apply_issue_oauth2_file",
16+
"/creds/refresh_tokens/rietveld.json",
17+
"--output_json",
18+
"/path/to/tmp/json",
19+
"--revision",
20+
"src@HEAD"
21+
],
22+
"env": {
23+
"PATH": "%(PATH)s:RECIPE_PACKAGE_REPO[depot_tools]"
24+
},
25+
"name": "bot_update",
26+
"~followup_annotations": [
27+
"@@@STEP_TEXT@Some step text@@@",
28+
"@@@[email protected]@{@@@",
29+
"@@@[email protected]@ \"did_run\": true, @@@",
30+
"@@@[email protected]@ \"fixed_revisions\": {@@@",
31+
"@@@[email protected]@ \"src\": \"HEAD\"@@@",
32+
"@@@[email protected]@ }, @@@",
33+
"@@@[email protected]@ \"patch_failure\": false, @@@",
34+
"@@@[email protected]@ \"patch_root\": \"src\", @@@",
35+
"@@@[email protected]@ \"properties\": {@@@",
36+
"@@@[email protected]@ \"got_cr_revision\": \"f27fede2220bcd326aee3e86ddfd4ebd0fe58cb9\", @@@",
37+
"@@@[email protected]@ \"got_cr_revision_cp\": \"refs/heads/master@{#170242}\"@@@",
38+
"@@@[email protected]@ }, @@@",
39+
"@@@[email protected]@ \"root\": \"src\", @@@",
40+
"@@@[email protected]@ \"step_text\": \"Some step text\"@@@",
41+
"@@@[email protected]@}@@@",
42+
43+
"@@@SET_BUILD_PROPERTY@got_cr_revision@\"f27fede2220bcd326aee3e86ddfd4ebd0fe58cb9\"@@@",
44+
"@@@SET_BUILD_PROPERTY@got_cr_revision_cp@\"refs/heads/master@{#170242}\"@@@"
45+
]
46+
},
47+
{
48+
"name": "$result",
49+
"recipe_result": null,
50+
"status_code": 0
51+
}
52+
]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[
2+
{
3+
"cmd": [
4+
"python",
5+
"-u",
6+
"RECIPE_MODULE[depot_tools::bot_update]\\resources\\bot_update.py",
7+
"--spec",
8+
"cache_dir = '[GIT_CACHE]'\nsolutions = [{'deps_file': '.DEPS.git', 'managed': True, 'name': 'src', 'url': 'https://chromium.googlesource.com/chromium/src.git'}]",
9+
"--patch_root",
10+
"src",
11+
"--revision_mapping_file",
12+
"{\"src\": \"got_cr_revision\"}",
13+
"--git-cache-dir",
14+
"[GIT_CACHE]",
15+
"--apply_issue_oauth2_file",
16+
"C:\\creds\\refresh_tokens\\rietveld.json",
17+
"--output_json",
18+
"/path/to/tmp/json",
19+
"--revision",
20+
"src@HEAD"
21+
],
22+
"env": {
23+
"PATH": "%(PATH)s;RECIPE_PACKAGE_REPO[depot_tools]"
24+
},
25+
"name": "bot_update",
26+
"~followup_annotations": [
27+
"@@@STEP_TEXT@Some step text@@@",
28+
"@@@[email protected]@{@@@",
29+
"@@@[email protected]@ \"did_run\": true, @@@",
30+
"@@@[email protected]@ \"fixed_revisions\": {@@@",
31+
"@@@[email protected]@ \"src\": \"HEAD\"@@@",
32+
"@@@[email protected]@ }, @@@",
33+
"@@@[email protected]@ \"patch_failure\": false, @@@",
34+
"@@@[email protected]@ \"patch_root\": \"src\", @@@",
35+
"@@@[email protected]@ \"properties\": {@@@",
36+
"@@@[email protected]@ \"got_cr_revision\": \"f27fede2220bcd326aee3e86ddfd4ebd0fe58cb9\", @@@",
37+
"@@@[email protected]@ \"got_cr_revision_cp\": \"refs/heads/master@{#170242}\"@@@",
38+
"@@@[email protected]@ }, @@@",
39+
"@@@[email protected]@ \"root\": \"src\", @@@",
40+
"@@@[email protected]@ \"step_text\": \"Some step text\"@@@",
41+
"@@@[email protected]@}@@@",
42+
43+
"@@@SET_BUILD_PROPERTY@got_cr_revision@\"f27fede2220bcd326aee3e86ddfd4ebd0fe58cb9\"@@@",
44+
"@@@SET_BUILD_PROPERTY@got_cr_revision_cp@\"refs/heads/master@{#170242}\"@@@"
45+
]
46+
},
47+
{
48+
"name": "$result",
49+
"recipe_result": null,
50+
"status_code": 0
51+
}
52+
]

recipe_modules/bot_update/example.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
DEPS = [
66
'bot_update',
77
'gclient',
8+
'recipe_engine/platform',
89
'recipe_engine/path',
910
'recipe_engine/properties',
1011
]
@@ -30,6 +31,7 @@ def RunSteps(api):
3031
with_branch_heads = api.properties.get('with_branch_heads', False)
3132
refs = api.properties.get('refs', [])
3233
oauth2 = api.properties.get('oauth2', False)
34+
oauth2_json = api.properties.get('oauth2_json', False)
3335
root_solution_revision = api.properties.get('root_solution_revision')
3436
suffix = api.properties.get('suffix')
3537
gerrit_no_reset = True if api.properties.get('gerrit_no_reset') else False
@@ -48,6 +50,7 @@ def RunSteps(api):
4850
with_branch_heads=with_branch_heads,
4951
output_manifest=output_manifest,
5052
refs=refs, patch_oauth2=oauth2,
53+
oauth2_json=oauth2_json,
5154
clobber=clobber,
5255
root_solution_revision=root_solution_revision,
5356
suffix=suffix,
@@ -78,6 +81,18 @@ def GenTests(api):
7881
yield api.test('trychange_oauth2') + api.properties(
7982
oauth2=True,
8083
)
84+
yield api.test('trychange_oauth2_json') + api.properties(
85+
mastername='tryserver.chromium.linux',
86+
buildername='linux_rel',
87+
slavename='totallyaslave-c4',
88+
oauth2_json=True,
89+
)
90+
yield api.test('trychange_oauth2_json_win') + api.properties(
91+
mastername='tryserver.chromium.win',
92+
buildername='win_rel',
93+
slavename='totallyaslave-c4',
94+
oauth2_json=True,
95+
) + api.platform('win', 64)
8196
yield api.test('tryjob_fail') + api.properties(
8297
issue=12345,
8398
patchset=654321,

recipe_modules/bot_update/resources/bot_update.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,8 @@ def _download(url):
555555

556556

557557
def apply_rietveld_issue(issue, patchset, root, server, _rev_map, _revision,
558-
email_file, key_file, whitelist=None, blacklist=None):
558+
email_file, key_file, oauth2_file,
559+
whitelist=None, blacklist=None):
559560
apply_issue_bin = ('apply_issue.bat' if sys.platform.startswith('win')
560561
else 'apply_issue')
561562
cmd = [apply_issue_bin,
@@ -570,8 +571,10 @@ def apply_rietveld_issue(issue, patchset, root, server, _rev_map, _revision,
570571
# Don't run gclient sync when it sees a DEPS change.
571572
'--ignore_deps',
572573
]
573-
# Use an oauth key file if specified.
574-
if email_file and key_file:
574+
# Use an oauth key or json file if specified.
575+
if oauth2_file:
576+
cmd.extend(['--auth-refresh-token-json', oauth2_file])
577+
elif email_file and key_file:
575578
cmd.extend(['--email-file', email_file, '--private-key-file', key_file])
576579
else:
577580
cmd.append('--no-auth')
@@ -714,8 +717,9 @@ def ensure_deps_revisions(deps_url_mapping, solutions, revisions):
714717
def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only,
715718
patch_root, issue, patchset, rietveld_server, gerrit_repo,
716719
gerrit_ref, gerrit_rebase_patch_ref, revision_mapping,
717-
apply_issue_email_file, apply_issue_key_file, shallow, refs,
718-
git_cache_dir, gerrit_reset):
720+
apply_issue_email_file, apply_issue_key_file,
721+
apply_issue_oauth2_file, shallow, refs, git_cache_dir,
722+
gerrit_reset):
719723
# Get a checkout of each solution, without DEPS or hooks.
720724
# Calling git directly because there is no way to run Gclient without
721725
# invoking DEPS.
@@ -738,7 +742,8 @@ def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only,
738742
if issue:
739743
apply_rietveld_issue(issue, patchset, patch_root, rietveld_server,
740744
revision_mapping, git_ref, apply_issue_email_file,
741-
apply_issue_key_file, whitelist=[target])
745+
apply_issue_key_file, apply_issue_oauth2_file,
746+
whitelist=[target])
742747
already_patched.append(target)
743748
elif gerrit_ref:
744749
apply_gerrit_ref(gerrit_repo, gerrit_ref, patch_root, gerrit_reset,
@@ -765,8 +770,9 @@ def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only,
765770
# Apply the rest of the patch here (sans DEPS)
766771
if issue:
767772
apply_rietveld_issue(issue, patchset, patch_root, rietveld_server,
768-
revision_mapping, git_ref, apply_issue_email_file,
769-
apply_issue_key_file, blacklist=already_patched)
773+
revision_mapping, apply_issue_oauth2_file, git_ref,
774+
apply_issue_email_file, apply_issue_key_file,
775+
blacklist=already_patched)
770776
elif gerrit_ref and not applied_gerrit_patch:
771777
# If gerrit_ref was for solution's main repository, it has already been
772778
# applied above. This chunk is executed only for patches to DEPS-ed in
@@ -835,6 +841,9 @@ def parse_args():
835841
parse.add_option('--apply_issue_key_file',
836842
help='--private-key-file option passthrough for '
837843
'apply_patch.py.')
844+
parse.add_option('--apply_issue_oauth2_file',
845+
help='--auth-refresh-token-json option passthrough for '
846+
'apply_patch.py.')
838847
parse.add_option('--root', dest='patch_root',
839848
help='DEPRECATED: Use --patch_root.')
840849
parse.add_option('--patch_root', help='Directory to patch on top of.')
@@ -972,6 +981,7 @@ def checkout(options, git_slns, specs, revisions, step_text, shallow):
972981
revision_mapping=options.revision_mapping,
973982
apply_issue_email_file=options.apply_issue_email_file,
974983
apply_issue_key_file=options.apply_issue_key_file,
984+
apply_issue_oauth2_file=options.apply_issue_oauth2_file,
975985

976986
# Finally, extra configurations such as shallowness of the clone.
977987
shallow=shallow,

tests/bot_update_coverage_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
'revision_mapping': {},
3838
'apply_issue_email_file': None,
3939
'apply_issue_key_file': None,
40+
'apply_issue_oauth2_file': None,
4041
'shallow': False,
4142
'refs': [],
4243
'git_cache_dir': '',

0 commit comments

Comments
 (0)