Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / tools / telemetry / third_party / gsutilz / gslib / cs_api_map.py
blob24d28014a2d6f3aa02a987297792483c561e2558
1 # -*- coding: utf-8 -*-
2 # Copyright 2013 Google Inc. All Rights Reserved.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 """API map classes used with the CloudApiDelegator class."""
17 from __future__ import absolute_import
19 from gslib.boto_translation import BotoTranslation
20 from gslib.gcs_json_api import GcsJsonApi
23 class ApiSelector(object):
24 """Enum class for API."""
25 XML = 'XML'
26 JSON = 'JSON'
29 class ApiMapConstants(object):
30 """Enum class for API map entries."""
31 API_MAP = 'apiclass'
32 SUPPORT_MAP = 'supported'
33 DEFAULT_MAP = 'default'
36 class GsutilApiClassMapFactory(object):
37 """Factory for generating gsutil API class maps.
39 A valid class map is defined as:
41 (key) Provider prefix used in URI strings.
42 (value) {
43 (key) ApiSelector describing the API format.
44 (value) CloudApi child class that implements this API.
47 """
49 @classmethod
50 def GetClassMap(cls):
51 """Returns the default gsutil class map."""
52 gs_class_map = {
53 ApiSelector.XML: BotoTranslation,
54 ApiSelector.JSON: GcsJsonApi
56 s3_class_map = {
57 ApiSelector.XML: BotoTranslation
59 class_map = {
60 'gs': gs_class_map,
61 's3': s3_class_map
63 return class_map
66 class GsutilApiMapFactory(object):
67 """Factory the generates the default gsutil API map.
69 The API map determines which Cloud API implementation is used for a given
70 command. A valid API map is defined as:
72 (key) ApiMapConstants.API_MAP : (value) Gsutil API class map (as
73 described in GsutilApiClassMapFactory comments).
74 (key) ApiMapConstants.SUPPORT_MAP : (value) {
75 (key) Provider prefix used in URI strings.
76 (value) list of ApiSelectors supported by the command for this provider.
78 (key) ApiMapConstants.DEFAULT_MAP : (value) {
79 (key) Provider prefix used in URI strings.
80 (value) Default ApiSelector for this command and provider.
83 """
85 @classmethod
86 def GetApiMap(cls, gsutil_api_class_map_factory, support_map, default_map):
87 """Creates a GsutilApiMap for use by the command from the inputs.
89 Args:
90 gsutil_api_class_map_factory: Factory defining a GetClassMap() function
91 adhering to GsutilApiClassMapFactory
92 semantics.
93 support_map: Entries for ApiMapConstants.SUPPORT_MAP as described above.
94 default_map: Entries for ApiMapConstants.DEFAULT_MAP as described above.
96 Returns:
97 GsutilApiMap generated from the inputs.
98 """
99 return {
100 ApiMapConstants.API_MAP: gsutil_api_class_map_factory.GetClassMap(),
101 ApiMapConstants.SUPPORT_MAP: support_map,
102 ApiMapConstants.DEFAULT_MAP: default_map