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."""
29 class ApiMapConstants(object):
30 """Enum class for API map entries."""
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.
43 (key) ApiSelector describing the API format.
44 (value) CloudApi child class that implements this API.
51 """Returns the default gsutil class map."""
53 ApiSelector
.XML
: BotoTranslation
,
54 ApiSelector
.JSON
: GcsJsonApi
57 ApiSelector
.XML
: BotoTranslation
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.
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.
90 gsutil_api_class_map_factory: Factory defining a GetClassMap() function
91 adhering to GsutilApiClassMapFactory
93 support_map: Entries for ApiMapConstants.SUPPORT_MAP as described above.
94 default_map: Entries for ApiMapConstants.DEFAULT_MAP as described above.
97 GsutilApiMap generated from the inputs.
100 ApiMapConstants
.API_MAP
: gsutil_api_class_map_factory
.GetClassMap(),
101 ApiMapConstants
.SUPPORT_MAP
: support_map
,
102 ApiMapConstants
.DEFAULT_MAP
: default_map