blob: 2de9b404f7fbea7df8435b135578d0c00ad0ccc7 [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
73
74class RunningEnv(object):
75 """Constants related to app engine running environment."""
76
77 # Running this GAE project locally with python.
78 ENV_STANDALONE = 0
79
80 # Running this GAE project with local development server.
81 ENV_DEVELOPMENT_SERVER = 1
82
83 # Running this GAE project in app-engine production.
84 ENV_PROD = 2
85
86
87class Priorities(object):
88 """Constants related to task priority."""
89
90 # weekly task's priority
91 WEEKLY = 10
92
93 # daily task's priority
94 DAILY = 20
95
96 # postbuild task's priority
97 POSTBUILD = 30
98
99 # the default task priority
100 DEFAULT = 40
101
102
103def environment():
104 """Return proper environment settings."""
105 if os.getenv(_RUNNING_ENV, '').startswith(_ENV_DEVELOPMENT_STR):
106 return RunningEnv.ENV_DEVELOPMENT_SERVER
107 elif os.getenv(_RUNNING_ENV, '').startswith(_ENV_APP_ENGINE_STR):
108 return RunningEnv.ENV_PROD
109 else:
110 return RunningEnv.ENV_STANDALONE
111
112
113def application_id():
114 """Get current running application id.
115
116 Returns:
117 If it's a Google internal GAE whose id format is 'google.com:<name>',
118 return <name>; Otherwise, return the full id.
119 """
120 app_id = app_identity.get_application_id()
121 logging.info('app_id: %s', app_id)
122 if app_id is not None and len(app_id.split(':')) > 1:
123 return app_id.split(':')[1]
124 else:
125 return app_id