def _CheckCloudSQLApiEnablement(): if not properties.VALUES.core.should_prompt_to_enable_api.GetBool(): return project = properties.VALUES.core.project.Get(required=True) apis.PromptToEnableApi( project, _CLOUD_SQL_API_SERVICE_TOKEN, serverless_exceptions.CloudSQLError( 'Cloud SQL API could not be enabled.')) apis.PromptToEnableApi( project, _CLOUD_SQL_ADMIN_API_SERVICE_TOKEN, serverless_exceptions.CloudSQLError( 'Cloud SQL Admin API could not be enabled.'))
def BatchCheck(self, http_response, exception): """Callback for apitools batch responses. This will use self.prompted_service_tokens to cache service tokens that have already been prompted. In this way, if the same service has multiple batch requests and is enabled on the first, the user won't get a bunch of superflous messages. Note that this cannot be reused between batch uses because of the mutation. Args: http_response: Deserialized http_wrapper.Response object. exception: apiclient.errors.HttpError object if an error occurred. """ # If there is no exception, then there is not an api enablement error. # Also, if prompting to enable is disabled, then we let the batch module # fail the batch request. if (exception is None or not properties.VALUES.core. should_prompt_to_enable_api.GetBool()): return enablement_info = apis.GetApiEnablementInfo(exception) if not enablement_info: # Exception was not an api enablement error. return project, service_token, exception = enablement_info if service_token not in self.prompted_service_tokens: # Only prompt once. self.prompted_service_tokens.add(service_token) apis.PromptToEnableApi(project, service_token, exception, is_batch_request=True)