| OLD | NEW |
| 1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Rolls recipes.cfg dependencies.""" | 5 """Rolls recipes.cfg dependencies.""" |
| 6 | 6 |
| 7 DEPS = [ | 7 DEPS = [ |
| 8 'depot_tools/bot_update', | 8 'depot_tools/bot_update', |
| 9 'depot_tools/gclient', | 9 'depot_tools/gclient', |
| 10 'file', | 10 'file', |
| 11 'url', | 11 'url', |
| 12 'recipe_engine/json', | 12 'recipe_engine/json', |
| 13 'recipe_engine/path', | 13 'recipe_engine/path', |
| 14 'recipe_engine/properties', | 14 'recipe_engine/properties', |
| 15 'recipe_engine/python', | 15 'recipe_engine/python', |
| 16 'recipe_engine/raw_io', | 16 'recipe_engine/raw_io', |
| 17 'recipe_engine/step', | 17 'recipe_engine/step', |
| 18 ] | 18 ] |
| 19 | 19 |
| 20 from recipe_engine.recipe_api import Property | 20 from recipe_engine.recipe_api import Property |
| 21 | 21 |
| 22 import collections | 22 import collections |
| 23 import re | 23 import re |
| 24 import base64 | 24 import base64 |
| 25 import json | 25 import json |
| 26 | 26 |
| 27 | 27 |
| 28 def get_auth_token(api): | 28 def get_auth_token(api, service_account=None): |
| 29 """ | 29 """ |
| 30 Get an auth token; this assumes the user is logged in with the infra | 30 Get an auth token; this assumes the user is logged in with the infra |
| 31 authutil command line utility. | 31 authutil command line utility. |
| 32 |
| 33 If service_account is provided, that service account will be used when calling |
| 34 authutil. |
| 32 """ | 35 """ |
| 36 cmd = ['/opt/infra-tools/authutil', 'token'] |
| 37 if service_account: # pragma: no cover |
| 38 cmd.extend([ |
| 39 '-service-account-json=' |
| 40 '/creds/service_accounts/service-account-%s.json' % service_account]) |
| 33 | 41 |
| 34 result = api.step('Get auth token', | 42 result = api.step( |
| 35 ['/opt/infra-tools/authutil', 'token',], | 43 'Get auth token', cmd, |
| 36 stdout=api.raw_io.output(), | 44 stdout=api.raw_io.output(), |
| 37 step_test_data=lambda: api.raw_io.test_api.stream_output('ya29.foobar')) | 45 step_test_data=lambda: api.raw_io.test_api.stream_output('ya29.foobar')) |
| 38 return result.stdout.strip() | 46 return result.stdout.strip() |
| 39 | 47 |
| 40 def parse_protobuf(lines): # pragma: no cover | 48 def parse_protobuf(lines): # pragma: no cover |
| 41 """Parse the protobuf text format just well enough to understand recipes.cfg. | 49 """Parse the protobuf text format just well enough to understand recipes.cfg. |
| 42 | 50 |
| 43 We don't use the protobuf library because we want to be as self-contained | 51 We don't use the protobuf library because we want to be as self-contained |
| 44 as possible in this bootstrap, so it can be simply vendored into a client | 52 as possible in this bootstrap, so it can be simply vendored into a client |
| 45 repo. | 53 repo. |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 "issue": Property(kind=str, default=None, | 347 "issue": Property(kind=str, default=None, |
| 340 help="The Rietveld issue number to pull data from"), | 348 help="The Rietveld issue number to pull data from"), |
| 341 "patchset": Property(kind=str, default=None, | 349 "patchset": Property(kind=str, default=None, |
| 342 help="The patchset number for the supplied issue"), | 350 help="The patchset number for the supplied issue"), |
| 343 "patch_project": Property( | 351 "patch_project": Property( |
| 344 kind=str, default=None, | 352 kind=str, default=None, |
| 345 help="The luci-config name of the project this patch belongs to"), | 353 help="The luci-config name of the project this patch belongs to"), |
| 346 | 354 |
| 347 # To generate an auth token for running locally, run | 355 # To generate an auth token for running locally, run |
| 348 # infra/go/bin/authutil login | 356 # infra/go/bin/authutil login |
| 349 'auth_token': Property(default=None), | 357 'auth_token': Property( |
| 358 default=None, help="The auth_token to use to talk to luci-config. " |
| 359 "Mutually exclusive with the service_account property"), |
| 360 'service_account': Property( |
| 361 default=None, kind=str, |
| 362 help="The name of the service account to use when running on a bot. For " |
| 363 "example, if you use \"recipe-roller\", this recipe will try to use " |
| 364 "the /creds/service_accounts/service-account-recipe-roller.json " |
| 365 "service account") |
| 350 } | 366 } |
| 351 | 367 |
| 352 def RunSteps(api, patches_raw, rietveld, issue, patchset, patch_project, | 368 def RunSteps(api, patches_raw, rietveld, issue, patchset, patch_project, |
| 353 auth_token): | 369 auth_token, service_account): |
| 354 # TODO(martiniss): use real types | 370 # TODO(martiniss): use real types |
| 355 issue = int(issue) if issue else None | 371 issue = int(issue) if issue else None |
| 356 patchset = int(patchset) if patchset else None | 372 patchset = int(patchset) if patchset else None |
| 357 | 373 |
| 358 if not auth_token: | 374 if not auth_token: |
| 359 auth_token = get_auth_token(api) | 375 auth_token = get_auth_token(api, service_account) |
| 376 else: # pragma: no cover |
| 377 assert not service_account, ( |
| 378 "Only one of \"service_account\" and \"auth_token\" may be set") |
| 360 | 379 |
| 361 headers = {'Authorization': 'Bearer %s' % auth_token} | 380 headers = {'Authorization': 'Bearer %s' % auth_token} |
| 362 | 381 |
| 363 patches = parse_patches( | 382 patches = parse_patches( |
| 364 api, patches_raw, rietveld, issue, patchset, patch_project) | 383 api, patches_raw, rietveld, issue, patchset, patch_project) |
| 365 | 384 |
| 366 root_dir = api.path['slave_build'] | 385 root_dir = api.path['slave_build'] |
| 367 | 386 |
| 368 url_mapping = get_url_mapping(api, headers) | 387 url_mapping = get_url_mapping(api, headers) |
| 369 | 388 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 api.properties( | 469 api.properties( |
| 451 rietveld="https://fake.code.review", | 470 rietveld="https://fake.code.review", |
| 452 issue='12345678', | 471 issue='12345678', |
| 453 patchset='1', | 472 patchset='1', |
| 454 patch_project="build", | 473 patch_project="build", |
| 455 ) + | 474 ) + |
| 456 api.step_data("Get build deps", project('build', ['recipe_engine'])) + | 475 api.step_data("Get build deps", project('build', ['recipe_engine'])) + |
| 457 api.step_data("Get recipe_engine deps", project('recipe_engine')) | 476 api.step_data("Get recipe_engine deps", project('recipe_engine')) |
| 458 ) | 477 ) |
| 459 | 478 |
| OLD | NEW |