Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(512)

Side by Side Diff: scripts/slave/recipe_modules/service_account/api.py

Issue 1954753003: Service account module (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/build.git@master
Patch Set: Added proper logging, removed pragma no cover. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 from recipe_engine import recipe_api
12
13
14 class ServiceAccountApi(recipe_api.RecipeApi):
15
16 def _config_defaults(self):
17 if self.m.platform.is_win:
18 self.set_config('service_account_windows')
19 else:
20 self.set_config('service_account_default')
21
22 def get_token(self, account):
23 if self.c is None:
24 self._config_defaults()
25 account_file = self.m.path.join(self.c.accounts_path,
26 'service-account-%s.json' % account)
27 try:
28 # TODO: authutil is to be deployed using cipd.
29 step_result = self.m.step('get access token',
30 [self.c.authutil_path, 'token',
31 '-service-account-json=' + account_file],
32 stdout=self.m.raw_io.output())
33 except self.m.step.StepFailure as ex:
34 if not self.m.path.exists(self.c.authutil_path):
35 ex.result.presentation.logs['Authutil not found'] = [
36 'The authutil binary was not found at the default location.',
37 '',
38 'Build the following go module: infra/go/infra/tools/authutil',
39 'and deploy it to: ' + self.c.authutil_path ]
40 raise
41
42 return step_result.stdout.strip()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698