blob: 5b43226f1494422cb9c6753e9755c28eb6237458 [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
Xixuan Wu27a61f82017-09-14 11:42:37 -070023class AppID(object):
24 """Constants refer to app id."""
25
26 PROD_APP = 'suite-scheduler'
27 STAGING_APP = 'suite-scheduler-staging'
28
29
30class CalendarID(object):
31 """Constants refer to calendar id."""
32
33 PROD_NEW_BUILD = (
34 'google.com_8n9gndgp0o642d7ta7dakbiiso@group.calendar.google.com')
35 PROD_NIGHTLY = (
36 'google.com_e8p3i4pk80lt6snfb57fdgff3g@group.calendar.google.com')
37 PROD_WEEKLY = (
38 'google.com_9es5a7m1r9til9uf5qc8mpr6p4@group.calendar.google.com')
39 STAGING_NEW_BUILD = (
40 'google.com_pjlsd9371ic158vdgcacspu0m4@group.calendar.google.com')
41 STAGING_NIGHTLY = (
42 'google.com_lu3v13kr4if93l9embsvb5llj4@group.calendar.google.com')
43 STAGING_WEEKLY = (
44 'google.com_9l29i5ncfk24e5aktjr6gaerp8@group.calendar.google.com')
45
46
Xixuan Wu5d6063e2017-09-05 16:15:07 -070047class RestClient(object):
48 """Constants related to rest clients to google service."""
49
50 # client info for connecting to android build API.
51 ANDROID_BUILD_CLIENT = RestClientInfo._make(
52 ['https://www.googleapis.com/auth/androidbuild.internal',
53 'androidbuildinternal',
54 'v2beta1'])
55
56 # client info for connecting to google storage API.
57 STORAGE_CLIENT = RestClientInfo._make(
58 ['https://www.googleapis.com/auth/devstorage.full_control',
59 'storage',
60 'v1'])
61
62 # client info for connecting to google calendar API.
63 CALENDAR_CLIENT = RestClientInfo._make(
64 ['https://www.googleapis.com/auth/calendar',
65 'calendar',
66 'v3'])
67
68 SWARMING_CLIENT = RestClientInfo._make(
69 ['https://www.googleapis.com/auth/userinfo.email',
70 'swarming',
71 'v1'])
72
Xixuan Wu6f117e92017-10-27 10:51:58 -070073 STACKDRIVER_CLIENT = RestClientInfo._make(
74 ['https://www.googleapis.com/auth/logging.read',
75 'logging',
76 'v2'])
77
Xixuan Wu5d6063e2017-09-05 16:15:07 -070078
79class RunningEnv(object):
80 """Constants related to app engine running environment."""
81
82 # Running this GAE project locally with python.
83 ENV_STANDALONE = 0
84
85 # Running this GAE project with local development server.
86 ENV_DEVELOPMENT_SERVER = 1
87
88 # Running this GAE project in app-engine production.
89 ENV_PROD = 2
90
91
92class Priorities(object):
93 """Constants related to task priority."""
94
95 # weekly task's priority
96 WEEKLY = 10
97
98 # daily task's priority
99 DAILY = 20
100
101 # postbuild task's priority
102 POSTBUILD = 30
103
104 # the default task priority
105 DEFAULT = 40
106
107
108def environment():
109 """Return proper environment settings."""
110 if os.getenv(_RUNNING_ENV, '').startswith(_ENV_DEVELOPMENT_STR):
111 return RunningEnv.ENV_DEVELOPMENT_SERVER
112 elif os.getenv(_RUNNING_ENV, '').startswith(_ENV_APP_ENGINE_STR):
113 return RunningEnv.ENV_PROD
114 else:
115 return RunningEnv.ENV_STANDALONE
116
117
118def application_id():
119 """Get current running application id.
120
121 Returns:
122 If it's a Google internal GAE whose id format is 'google.com:<name>',
123 return <name>; Otherwise, return the full id.
124 """
125 app_id = app_identity.get_application_id()
126 logging.info('app_id: %s', app_id)
127 if app_id is not None and len(app_id.split(':')) > 1:
128 return app_id.split(':')[1]
129 else:
130 return app_id