Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """API for generating oauth2 tokens from locally stored secrets. | |
| 6 | |
| 7 This is a thin wrapper over the authutil go executable, which itself calls | |
| 8 https://github.com/luci/luci-go/blob/master/client/authcli/authcli.go | |
| 9 """ | |
| 10 | |
| 11 import os | |
| 12 | |
| 13 from recipe_engine import recipe_api | |
| 14 | |
| 15 | |
| 16 class ServiceAccountApi(recipe_api.RecipeApi): | |
| 17 | |
| 18 def _config_defaults(self): | |
| 19 if self.m.platform.is_win: | |
| 20 self.set_config('service_account_windows') | |
| 21 else: | |
| 22 self.set_config('service_account_default') | |
| 23 | |
| 24 def get_token(self, account): | |
| 25 if self.c is None: | |
| 26 self._config_defaults() | |
| 27 account_file = os.path.join(self.c.accounts_path, | |
| 28 'service-account-%s.json' % account) | |
| 29 try: | |
| 30 step_result = self.m.step('get access token', | |
| 31 [self.c.authutil_path, 'token', | |
| 32 '-service-account-json=' + account_file], | |
| 33 stdout=self.m.raw_io.output()) | |
| 34 except self.m.step.StepFailure: # pragma: no cover | |
| 35 if not os.path.exists(self.c.authutil_path): | |
| 36 print('The authutil binary was not found at the default locations, ' | |
|
nodir
2016/05/06 20:32:09
recipe modules and recipes should no print directl
RobertoCN
2016/05/06 21:38:10
Done.
| |
| 37 'please set the AUTHUTILPATH environment to its path.\n\n' | |
| 38 'If running locally try: \n' | |
| 39 '$ cd infra/go \n' | |
| 40 '$ ./env.py go install infra/tools/authutil \n' | |
| 41 '$ export AUTHUTILPATH=`pwd`/bin' | |
| 42 ) % self.c.authutil_path | |
| 43 raise | |
| 44 | |
| 45 return step_result.stdout.strip() | |
| OLD | NEW |