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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: scripts/slave/recipe_modules/service_account/api.py
diff --git a/scripts/slave/recipe_modules/service_account/api.py b/scripts/slave/recipe_modules/service_account/api.py
new file mode 100644
index 0000000000000000000000000000000000000000..813f9ca00b394b0831d8464aec20d8c6eb5f611b
--- /dev/null
+++ b/scripts/slave/recipe_modules/service_account/api.py
@@ -0,0 +1,45 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""API for generating oauth2 tokens from locally stored secrets.
+
+This is a thin wrapper over the authutil go executable, which itself calls
+https://github.com/luci/luci-go/blob/master/client/authcli/authcli.go
+"""
+
+import os
+
+from recipe_engine import recipe_api
+
+
+class ServiceAccountApi(recipe_api.RecipeApi):
+
+ def _config_defaults(self):
+ if self.m.platform.is_win:
+ self.set_config('service_account_windows')
+ else:
+ self.set_config('service_account_default')
+
+ def get_token(self, account):
+ if self.c is None:
+ self._config_defaults()
+ account_file = os.path.join(self.c.accounts_path,
+ 'service-account-%s.json' % account)
+ try:
+ step_result = self.m.step('get access token',
+ [self.c.authutil_path, 'token',
+ '-service-account-json=' + account_file],
+ stdout=self.m.raw_io.output())
+ except self.m.step.StepFailure: # pragma: no cover
+ if not os.path.exists(self.c.authutil_path):
+ 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.
+ 'please set the AUTHUTILPATH environment to its path.\n\n'
+ 'If running locally try: \n'
+ '$ cd infra/go \n'
+ '$ ./env.py go install infra/tools/authutil \n'
+ '$ export AUTHUTILPATH=`pwd`/bin'
+ ) % self.c.authutil_path
+ raise
+
+ return step_result.stdout.strip()

Powered by Google App Engine
This is Rietveld 408576698