class CatalogCapacityModificationRequest(messages.Message): """Represents a request to modify machine capacity in the catalog.""" # Dimensions instance specifying what sort of machine this is. dimensions = messages.MessageField(Dimensions, 1, required=True) # Amount of available capacity matching the specified dimensions. count = messages.IntegerField(2, required=True)
class TaskProperties(messages.Message): """Important metadata about a particular task.""" # Specifies named caches to map into the working directory. These caches # outlives the task, which can then be reused by tasks later used on this bot # that request the same named cache. caches = messages.MessageField(CacheEntry, 11, repeated=True) # CIPD packages to install. These packages are meant to be software that is # needed (a dependency) to the task being run. Unlike isolated files, the CIPD # packages do not expire from the server. cipd_input = messages.MessageField(CipdInput, 10) # Command to run. This has priority over a command specified in the isolated # files. Only one of 'command' or 'extra_args' can be specified. command = messages.StringField(1, repeated=True) # Relative working directory to start the 'command' in, defaults to the root # mapped directory or what is provided in the isolated file, if any. relative_cwd = messages.StringField(15) # Dimensions are what is used to determine which bot can run the task. The # bot must have all the matching dimensions, even for repeated keys with # multiple different values. It is a logical AND, all values must match. # # It should have been a StringListPair but this would be a breaking change. dimensions = messages.MessageField(StringPair, 2, repeated=True) # Environment variables to set when running the task. env = messages.MessageField(StringPair, 3, repeated=True) # Swarming-root relative paths to prepend to a given environment variable. # # These allow you to put certain subdirectories of the task into PATH, # PYTHONPATH, or other PATH-like environment variables. The order of # operations is: # * Turn slashes into native-platform slashes. # * Make the path absolute # * Prepend it to the current value of the envvar using the os-native list # separator (i.e. `;` on windows, `:` on POSIX). # # Each envvar can have multiple paths to prepend. They will be prepended in # the order seen here. # # For example, if env_prefixes was: # [("PATH", ["foo", "bar"]), # ("CUSTOMPATH", ["custom"])] # # The task would see: # PATH=/path/to/swarming/rundir/foo:/path/to/swarming/rundir/bar:$PATH # CUSTOMPATH=/path/to/swarming/rundir/custom # # The path should always be specified here with forward-slashes, and it must # not attempt to escape the swarming root (i.e. must not contain `..`). # # These are applied AFTER evaluating `env` entries. env_prefixes = messages.MessageField(StringListPair, 14, repeated=True) # Maximum number of seconds the task can run before its process is forcibly # terminated and the task results in TIMED_OUT. execution_timeout_secs = messages.IntegerField(4) # Extraneous arguments to append to the command specified in the isolated # file. Can only be used when an isolated file specifies a command. Only one # of 'command' or 'extra_args' can be specified. extra_args = messages.StringField(5, repeated=True) # Number of second to give the child process after a SIGTERM before sending a # SIGKILL. See doc/Bot.md#timeout-handling grace_period_secs = messages.IntegerField(6) # True if the task does not access any service through the network and is # believed to be 100% reproducible with the same outcome. In the case of a # successful task, previous results will be reused if possible. idempotent = messages.BooleanField(7) # Isolated inputs to map in the working directory. The isolated file may # optionally specify a command to run. Otherwise, 'command' must be specified. inputs_ref = messages.MessageField(FilesRef, 8) # Maximum number of seconds the task may be silent (no output to stdout nor # stderr) before it is considered hung and it forcibly terminated early and # the task results in TIMED_OUT. io_timeout_secs = messages.IntegerField(9) # Paths in the working directory to archive back. outputs = messages.StringField(12, repeated=True) # Secret bytes to provide to the task. Cannot be retrieved back. secret_bytes = messages.BytesField(13)
class TasksCancelRequest(messages.Message): """Request to cancel some subset of pending/running tasks.""" tags = messages.StringField(1, repeated=True) cursor = messages.StringField(2) limit = messages.IntegerField(3, default=100) kill_running = messages.BooleanField(4)
class UserRank(messages.Message): username = messages.StringField(1) wins = messages.IntegerField(2)
class UserGamesRequestForm(messages.Message): jwt_token = messages.StringField(1, required=True) offset = messages.IntegerField(2, default=0)
class PackageRef(messages.Message): """Information about some ref belonging to a package.""" instance_id = messages.StringField(1, required=True) modified_by = messages.StringField(2, required=True) modified_ts = messages.IntegerField(3, required=True)
class InstanceTag(messages.Message): """Some single package instance tag.""" tag = messages.StringField(1, required=True) registered_by = messages.StringField(2, required=True) registered_ts = messages.IntegerField(3, required=True)
class Problem(messages.Message): code = messages.MessageField(Code, 1) status = messages.StringField(2) age = messages.IntegerField(3) date_range = messages.MessageField(DateRange, 4)
class VitalResult(messages.Message): code = messages.MessageField(Code, 1) value = messages.IntegerField(2) unit = messages.StringField(3)
class PreuploadStatus(messages.Message): """Endpoints response type for a single URL or pair of URLs.""" gs_upload_url = messages.StringField(1) upload_ticket = messages.StringField(2) index = messages.IntegerField(3)
class HelloWorldApi(remote.Service): def _getProfileFromUser(self): """Get current user and return profile in DB""" user = endpoints.get_current_user() p_key = ndb.Key(Profile, user.email()) p = p_key.get() if not p: p = Profile(key=p_key, nickname=user.nickname(), email=user.email()) p.put() return p def _copyProfileToForm(self, profile): """Put profile from DB in to protorpc form""" pf = ProfileForm() pf.nick = profile.nickname pf.email = profile.email return pf @endpoints.method(message_types.VoidMessage, GreetingCollection, path='hellogreeting', http_method='GET', name='greetings.listGreetings') def greetings_list(self, unused_request): return STORED_GREETINGS RESOURCE_ID = endpoints.ResourceContainer( message_types.VoidMessage, id=messages.IntegerField(2, variant=messages.Variant.INT32, required=True)) @endpoints.method(RESOURCE_ID, GreetingForm, path='hellogreeting/{id}', http_method='GET', name='greetings.getGreeting') def greeting(self, request): try: return STORED_GREETINGS.items[request.id] except: return endpoints.NotFoundException('Greeting %s not found.' % request.id) @endpoints.method(GreetingForm, GreetingForm, path='hellogreeting', http_method='POST', name='greeting.addGreeting') def addGreeting(self, request): """Add greeting with user's profile as parent""" profile = self._getProfileFromUser() p_key = ndb.Key(Profile, profile.email) g = Greeting(message=request.message, parent=p_key) g.put() return request @endpoints.method(message_types.VoidMessage, ProfileForm) def returnPofile(self, unused_request): """Return a user's profile""" profile = self._getProfileFromUser() return self._copyProfileToForm(profile)
class RetrieveRequest(messages.Message): """Request to retrieve content from memcache, datastore, or GS.""" digest = messages.StringField(1, required=True) namespace = messages.MessageField(Namespace, 2) offset = messages.IntegerField(3, default=0)
class Digest(messages.Message): """ProtoRPC message containing digest information.""" digest = messages.StringField(1) is_isolated = messages.BooleanField(2, default=False) size = messages.IntegerField(3, default=0)
def get_result_entity(task_id): """Returns the entity (TaskResultSummary or TaskRunResult) for a given ID.""" key, _ = get_result_key(task_id) return get_or_raise(key) ### API swarming_api = auth.endpoints_api( name='swarming', version='v1', description='API to interact with the Swarming service. Permits to create, ' 'view and cancel tasks, query tasks and bots') VersionRequest = endpoints.ResourceContainer(message_types.VoidMessage, version=messages.IntegerField(1)) @swarming_api.api_class(resource_name='server', path='server') class SwarmingServerService(remote.Service): @auth.endpoints_method(message_types.VoidMessage, swarming_rpcs.ServerDetails, http_method='GET') @auth.require(acl.is_bot_or_user) def details(self, _request): """Returns information about the server.""" return swarming_rpcs.ServerDetails( server_version=utils.get_app_version()) @auth.endpoints_method(VersionRequest, swarming_rpcs.FileContent,
class EventListRequest(messages.Message): limit = messages.IntegerField(1, required=True) pass
class LabResult(messages.Message): date = message_types.DateTimeField(1) code = messages.MessageField(Code, 2) value = messages.IntegerField(3) unit = messages.StringField(4)
class SettingsMessage(messages.Message): timeZoneOffset = messages.IntegerField(1, required=False) logoutUrl = messages.StringField(2, required=False) nickname = messages.StringField(3, required=False)
class MatchResultForm(messages.Message): """Used to give result of a match""" card_1 = messages.MessageField(CardForm, 1, required=True) card_2 = messages.MessageField(CardForm, 2, required=True) matched_count = messages.IntegerField(3, required=True) message = messages.StringField(4, required=True)
class PackageInstance(messages.Message): """Information about some registered package instance.""" package_name = messages.StringField(1, required=True) instance_id = messages.StringField(2, required=True) registered_by = messages.StringField(3, required=True) registered_ts = messages.IntegerField(4, required=True)
class MakeMatchForm(messages.Message): """Used to make a match in an existing game""" guess_pair_1 = messages.IntegerField(1, required=True) guess_pair_2 = messages.IntegerField(2, required=True)
class Operation(messages.Message): """A Operation object. Messages: ErrorValue: A ErrorValue object. WarningsValueListEntry: A WarningsValueListEntry object. Fields: clientOperationId: A string attribute. creationTimestamp: A string attribute. endTime: A string attribute. error: A ErrorValue attribute. httpErrorMessage: A string attribute. httpErrorStatusCode: A integer attribute. id: A string attribute. insertTime: A string attribute. kind: [Output Only] Type of the resource. Always compute#Operation for Operation resources. name: A string attribute. operationType: A string attribute. progress: A integer attribute. region: A string attribute. selfLink: A string attribute. startTime: A string attribute. status: A string attribute. statusMessage: A string attribute. targetId: A string attribute. targetLink: A string attribute. user: A string attribute. warnings: A WarningsValueListEntry attribute. zone: A string attribute. """ class ErrorValue(messages.Message): """A ErrorValue object. Messages: ErrorsValueListEntry: A ErrorsValueListEntry object. Fields: errors: A ErrorsValueListEntry attribute. """ class ErrorsValueListEntry(messages.Message): """A ErrorsValueListEntry object. Fields: code: A string attribute. location: A string attribute. message: A string attribute. """ code = messages.StringField(1) location = messages.StringField(2) message = messages.StringField(3) errors = messages.MessageField('ErrorsValueListEntry', 1, repeated=True) class WarningsValueListEntry(messages.Message): """A WarningsValueListEntry object. Messages: DataValueListEntry: A DataValueListEntry object. Fields: code: A string attribute. data: A DataValueListEntry attribute. message: A string attribute. """ class DataValueListEntry(messages.Message): """A DataValueListEntry object. Fields: key: A string attribute. value: A string attribute. """ key = messages.StringField(1) value = messages.StringField(2) code = messages.StringField(1) data = messages.MessageField('DataValueListEntry', 2, repeated=True) message = messages.StringField(3) clientOperationId = messages.StringField(1) creationTimestamp = messages.StringField(2) endTime = messages.StringField(3) error = messages.MessageField('ErrorValue', 4) httpErrorMessage = messages.StringField(5) httpErrorStatusCode = messages.IntegerField(6, variant=messages.Variant.INT32) id = messages.IntegerField(7, variant=messages.Variant.UINT64) insertTime = messages.StringField(8) kind = messages.StringField(9, default=u'autoscaler#operation') name = messages.StringField(10) operationType = messages.StringField(11) progress = messages.IntegerField(12, variant=messages.Variant.INT32) region = messages.StringField(13) selfLink = messages.StringField(14) startTime = messages.StringField(15) status = messages.StringField(16) statusMessage = messages.StringField(17) targetId = messages.IntegerField(18, variant=messages.Variant.UINT64) targetLink = messages.StringField(19) user = messages.StringField(20) warnings = messages.MessageField('WarningsValueListEntry', 21, repeated=True) zone = messages.StringField(22)
class Device(messages.Message): """Device ProtoRPC message. Attributes: serial_number: str, The serial number of the Chrome device. asset_tag: str, The asset tag of the Chrome device. identifier: str, the computed identifier for a device. Serial number if asset tag is not provided. enrolled: bool, Indicates the enrollment status of the device. device_model: int, Identifies the model name of the device. due_date: datetime, The date that device is due for return. last_know_healthy: datetime, The date to indicate the last known healthy status. shelf: shelf_messages.Shelf, The message for a shelf. assigned_user: str, The email of the user who is assigned to the device. assignment_date: datetime, The date the device was assigned to a user. current_ou: str, The current organizational unit the device belongs to. ou_change_date: datetime, The date the organizational unit was changed. locked: bool, Indicates whether or not the device is locked. lost: bool, Indicates whether or not the device is lost. mark_pending_return_date: datetime, The date a user marked device returned. chrome_device_id: str, A unique device ID. last_heartbeat: datetime, The date of the last time the device checked in. damaged: bool, Indicates the if the device is damaged. damaged_reason: str, A string denoting the reason for being reported as damaged. last_reminder: Reminder, Level, time, and count of the last reminder the device had. next_reminder: Reminder, Level, time, and count of the next reminder. page_size: int, The number of results to query for and display. page_number: int, the page index to offset the results. max_extend_date: datetime, Indicates maximum extend date a device can have. guest_enabled: bool, Indicates if guest mode has been already enabled. guest_permitted: bool, Indicates if guest mode has been allowed. given_name: str, The given name for the user. query: shared_message.SearchRequest, a message containing query options to conduct a search on an index. overdue: bool, Indicates that the due date has passed. """ serial_number = messages.StringField(1) asset_tag = messages.StringField(2) identifier = messages.StringField(3) urlkey = messages.StringField(4) enrolled = messages.BooleanField(5, default=True) device_model = messages.StringField(6) due_date = message_types.DateTimeField(7) last_known_healthy = message_types.DateTimeField(8) shelf = messages.MessageField(shelf_messages.Shelf, 9) assigned_user = messages.StringField(10) assignment_date = message_types.DateTimeField(11) current_ou = messages.StringField(12) ou_changed_date = message_types.DateTimeField(13) locked = messages.BooleanField(14) lost = messages.BooleanField(15) mark_pending_return_date = message_types.DateTimeField(16) chrome_device_id = messages.StringField(17) last_heartbeat = message_types.DateTimeField(18) damaged = messages.BooleanField(19) damaged_reason = messages.StringField(20) last_reminder = messages.MessageField(Reminder, 21) next_reminder = messages.MessageField(Reminder, 22) page_size = messages.IntegerField(23, default=10) page_number = messages.IntegerField(24, default=1) max_extend_date = message_types.DateTimeField(25) guest_enabled = messages.BooleanField(26) guest_permitted = messages.BooleanField(27) given_name = messages.StringField(28) query = messages.MessageField(shared_messages.SearchRequest, 29) overdue = messages.BooleanField(30)
class UserHighScore(messages.Message): username = messages.StringField(1) score = messages.IntegerField(2)
from models import UserForms from utils import get_by_urlsafe NEW_GAME_REQUEST = endpoints.ResourceContainer(NewGameForm) GET_GAME_REQUEST = endpoints.ResourceContainer( urlsafe_game_key=messages.StringField(1), ) MAKE_MOVE_REQUEST = endpoints.ResourceContainer( MakeMoveForm, urlsafe_game_key=messages.StringField(1), ) USER_REQUEST = endpoints.ResourceContainer(user_name=messages.StringField(1), email=messages.StringField(2)) GET_ALL_GAMES_REQUEST = endpoints.ResourceContainer( user_name=messages.StringField(1), ) # NOQA HIGH_SCORES_REQUEST = endpoints.ResourceContainer( number_of_results=messages.IntegerField(1)) MEMCACHE_MOVES_REMAINING = 'MOVES_REMAINING' @endpoints.api(name='hangman', version='v1') class HangmanApi(remote.Service): """Game API""" @endpoints.method(request_message=USER_REQUEST, response_message=StringMessage, path='user', name='create_user', http_method='POST') def create_user(self, request): """Create a User. Requires a unique username""" if User.query(User.name == request.user_name).get():
class UserAllRequestForm(messages.Message): offset = messages.IntegerField(1, default=0)
class UserForm(messages.Message): user_name = messages.StringField(1, required=True) wins = messages.IntegerField(2, required=True) loses = messages.IntegerField(3, required=True) win_ratio = messages.FloatField(4, required=True)
class NewTaskRequest(messages.Message): """Description of a new task request as described by the client. This message is used to create a new task. """ # Maximum of seconds the task may stay PENDING. Must be specified with # properties. Cannot be used at the same time as task_slices. expiration_secs = messages.IntegerField(1) # Task name for display purpose. name = messages.StringField(2) # Parent Swarming task ID of the process requesting this task. This is to tell # the server about reentrancy: when a task creates children Swarming tasks, so # that the tree of tasks can be presented in the UI; the parent task will list # all the children tasks that were triggered. parent_task_id = messages.StringField(3) # Task priority, the lower the more important. priority = messages.IntegerField(4) # Task properties, which defines what to run. properties = messages.MessageField(TaskProperties, 5) # Slice of TaskSlice, along their scheduling parameters. Cannot be used at the # same time as properties and expiration_secs. # # This defines all the various possible task execution for a task request to # be run on the Swarming infrastructure. They are processed in order, and it # is guaranteed that at most one of these will be processed. task_slices = messages.MessageField(TaskSlice, 12, repeated=True) # Tags are 'key:value' strings that describes what the task is about. This can # later be leveraged to search for kinds of tasks per tag. tags = messages.StringField(6, repeated=True) # User on which behalf this task is run, if relevant. Not validated. user = messages.StringField(7) # Defines what OAuth2 credentials the task uses when calling other services. # # Possible values are: # - 'none': do not use task service accounts at all, this is default. # - 'bot': use bot's own account, works only if bots authenticate with # OAuth2. # - 'email': use this account (if token server's service_accounts.cfg rules # allow it). Not implemented yet. # # Note that the service account name is specified outside of task properties, # and thus it is possible to have two tasks with different service accounts, # but identical properties hash (so one can be deduped). If this is unsuitable # use 'idempotent=False' or include a service account name in properties # separately. # # TODO(vadimsh): Link to a doc that describes Swarming Service Accounts, when # it exists. service_account = messages.StringField(8) # Full topic name to post task state updates to, e.g. # "projects/<id>/topics/<id>". pubsub_topic = messages.StringField(9) # Secret string to put into "auth_token" attribute of PubSub message. pubsub_auth_token = messages.StringField(10) # Will be but into "userdata" fields of PubSub message. pubsub_userdata = messages.StringField(11) # Only evaluate the task, as if we were going to schedule it, but don't # actually schedule it. This will return the TaskRequest, but without # a task_id. evaluate_only = messages.BooleanField(13)
class NewGameForm(messages.Message): user_name = messages.StringField(1, required=True) attempts = messages.IntegerField(2, default=5)
class TasksCancelResponse(messages.Message): """Result of canceling some subset of pending tasks. """ cursor = messages.StringField(1) now = message_types.DateTimeField(2) matched = messages.IntegerField(3)
class CardForm(messages.Message): """CardForm for card information""" suit = messages.StringField(1, required=True) value = messages.IntegerField(2, required=True) index = messages.IntegerField(3, required=True) matched = messages.BooleanField(4, required=True)