blob: bc6cfaa33b8ef4923ebb902cb2b7b1cbe0c5728a [file] [log] [blame]
xixuanbea010f2017-03-27 10:10:19 -07001# Copyright 2017 The Chromium OS 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"""Module containing the constants to be reused throughout suite_scheduler."""
6
xixuanbea010f2017-03-27 10:10:19 -07007from collections import namedtuple
8import logging
9import os
10
Xixuan Wu5d6063e2017-09-05 16:15:07 -070011from google.appengine.api import app_identity
12
xixuanbea010f2017-03-27 10:10:19 -070013# Namedtuple for storing rest client info.
14RestClientInfo = namedtuple(
15 'RestClientInfo', 'scopes, service_name, service_version')
16
xixuanbea010f2017-03-27 10:10:19 -070017# Constants for detecting the running environment.
18_RUNNING_ENV = 'SERVER_SOFTWARE'
19_ENV_DEVELOPMENT_STR = 'Development'
20_ENV_APP_ENGINE_STR = 'Google App Engine/'
Xixuan Wu5d6063e2017-09-05 16:15:07 -070021
22
23class RestClient(object):
24 """Constants related to rest clients to google service."""
25
26 # client info for connecting to android build API.
27 ANDROID_BUILD_CLIENT = RestClientInfo._make(
28 ['https://www.googleapis.com/auth/androidbuild.internal',
29 'androidbuildinternal',
30 'v2beta1'])
31
32 # client info for connecting to google storage API.
33 STORAGE_CLIENT = RestClientInfo._make(
34 ['https://www.googleapis.com/auth/devstorage.full_control',
35 'storage',
36 'v1'])
37
38 # client info for connecting to google calendar API.
39 CALENDAR_CLIENT = RestClientInfo._make(
40 ['https://www.googleapis.com/auth/calendar',
41 'calendar',
42 'v3'])
43
44 SWARMING_CLIENT = RestClientInfo._make(
45 ['https://www.googleapis.com/auth/userinfo.email',
46 'swarming',
47 'v1'])
48
49
50class RunningEnv(object):
51 """Constants related to app engine running environment."""
52
53 # Running this GAE project locally with python.
54 ENV_STANDALONE = 0
55
56 # Running this GAE project with local development server.
57 ENV_DEVELOPMENT_SERVER = 1
58
59 # Running this GAE project in app-engine production.
60 ENV_PROD = 2
61
62
63class Priorities(object):
64 """Constants related to task priority."""
65
66 # weekly task's priority
67 WEEKLY = 10
68
69 # daily task's priority
70 DAILY = 20
71
72 # postbuild task's priority
73 POSTBUILD = 30
74
75 # the default task priority
76 DEFAULT = 40
77
78
79def environment():
80 """Return proper environment settings."""
81 if os.getenv(_RUNNING_ENV, '').startswith(_ENV_DEVELOPMENT_STR):
82 return RunningEnv.ENV_DEVELOPMENT_SERVER
83 elif os.getenv(_RUNNING_ENV, '').startswith(_ENV_APP_ENGINE_STR):
84 return RunningEnv.ENV_PROD
85 else:
86 return RunningEnv.ENV_STANDALONE
87
88
89def application_id():
90 """Get current running application id.
91
92 Returns:
93 If it's a Google internal GAE whose id format is 'google.com:<name>',
94 return <name>; Otherwise, return the full id.
95 """
96 app_id = app_identity.get_application_id()
97 logging.info('app_id: %s', app_id)
98 if app_id is not None and len(app_id.split(':')) > 1:
99 return app_id.split(':')[1]
100 else:
101 return app_id