# Copyright 2015 Google LLC## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## https://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.require"google/cloud/config"require"google/cloud/core/version"### # Google Cloud## The google-cloud library is the official library for interacting with Google# Cloud Platform. Google Cloud Platform is a set of modular cloud-based services# that allow you to create anything from simple websites to complex# applications.## The goal of google-cloud is to provide an API that is comfortable to# Rubyists. Your authentication credentials are detected automatically in# Google Cloud Platform environments such as Google Compute Engine, Google# App Engine and Google Kubernetes Engine. In other environments you can# configure authentication easily, either directly in your code or via# environment variables. Read more about the options for connecting in the# [Authentication# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).## You can learn more about various options for connection on the [Authentication# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).#moduleGooglemoduleCloud### Creates a new object for connecting to Google Cloud.## For more information on connecting to Google Cloud see the [Authentication# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).## @param [String] project_id Project identifier for the service you are# connecting to.# @param [String, Hash, Google::Auth::Credentials] credentials The path to# the keyfile as a String, the contents of the keyfile as a Hash, or a# Google::Auth::Credentials object.# @param [Integer] retries Number of times to retry requests on server# error. The default value is `3`. Optional.# @param [Integer] timeout Default timeout to use in requests. Optional.## @return [Google::Cloud]## @example# require "google/cloud"## gcloud = Google::Cloud.new# datastore = gcloud.datastore# pubsub = gcloud.pubsub# storage = gcloud.storage#defself.newproject_id=nil,credentials=nil,retries: nil,timeout: nilgcloud=Object.newgcloud.instance_variable_set:@project,project_idgcloud.instance_variable_set:@keyfile,credentialsgcloud.instance_variable_set:@retries,retriesgcloud.instance_variable_set:@timeout,timeoutgcloud.extendGoogle::Cloudgcloudend### Configure the default parameter for Google::Cloud. The values defined on# this top level will be shared across all Google::Cloud libraries, which# may also add fields to this object or add sub configuration options under# this object.## Possible configuration parameters:## * `project_id`: The Google Cloud Project ID. Automatically discovered# when running from GCP environments.# * `credentials`: The service account JSON file path. Automatically# discovered when running from GCP environments.## @return [Google::Cloud::Config] The top-level configuration object for# Google::Cloud libraries.#defself.configure@config||=Config.createyield@configifblock_given?@configend### Initialize toplevel configuration# @private#defself.init_configurationconfiguredo|config|default_project=Google::Cloud::Config.deferreddoENV["GOOGLE_CLOUD_PROJECT"]||ENV["GCLOUD_PROJECT"]enddefault_creds=Google::Cloud::Config.deferreddoGoogle::Cloud::Config.credentials_from_env\"GOOGLE_CLOUD_CREDENTIALS","GOOGLE_CLOUD_CREDENTIALS_JSON","GOOGLE_CLOUD_KEYFILE","GOOGLE_CLOUD_KEYFILE_JSON","GCLOUD_KEYFILE","GCLOUD_KEYFILE_JSON"endconfig.add_field!:project_id,default_project,match: String,allow_nil: trueconfig.add_alias!:project,:project_idconfig.add_field!:credentials,default_creds,match: Objectconfig.add_alias!:keyfile,:credentialsendend# In June, 2018, set supported version to 2.3 and recommended to 2.4.# Thereafter, follow the MRI support schedule: supported means non-EOL,# and recommended means in normal (rather than security) maintenance.# See https://www.ruby-lang.org/en/downloads/branches/### Minimum "supported" Ruby version (non-EOL)# @private#SUPPORTED_VERSION_THRESHOLD="2.0".freeze### Minimum "recommended" Ruby version (normal maintenance)# @private#RECOMMENDED_VERSION_THRESHOLD="2.3".freeze### Check Ruby version and emit a warning if it is old# @private#defself.warn_on_old_ruby_version\supported_version: SUPPORTED_VERSION_THRESHOLD,recommended_version: RECOMMENDED_VERSION_THRESHOLDreturnifENV["GOOGLE_CLOUD_SUPPRESS_RUBY_WARNINGS"]cur_version=Gem::Version.newRUBY_VERSIONifcur_version<Gem::Version.new(supported_version)warn_unsupported_rubycur_version,recommended_versionelsifcur_version<Gem::Version.new(recommended_version)warn_nonrecommended_rubycur_version,recommended_versionendrescueArgumentErrorwarn"Unable to determine current Ruby version."end### Print a warning for an EOL version of Ruby# @private#defself.warn_unsupported_rubycur_version,recommended_versionwarn"WARNING: You are running Ruby #{cur_version}, which has reached"\" end-of-life and is no longer supported by Ruby Core."warn"The Google Cloud API clients work best on supported versions of"\" Ruby. It is strongly recommended that you upgrade to Ruby"\" #{recommended_version} or later."warn"See https://www.ruby-lang.org/en/downloads/branches/ for more"\" info on the Ruby maintenance schedule."warn"To suppress this message, set the"\" GOOGLE_CLOUD_SUPPRESS_RUBY_WARNINGS environment variable."end### Print a warning for a supported but nearing EOL version of Ruby# @private#defself.warn_nonrecommended_rubycur_version,recommended_versionwarn"WARNING: You are running Ruby #{cur_version}, which is nearing"\" end-of-life."warn"The Google Cloud API clients work best on supported versions of"\" Ruby. Consider upgrading to Ruby #{recommended_version} or later."warn"See https://www.ruby-lang.org/en/downloads/branches/ for more"\" info on the Ruby maintenance schedule."warn"To suppress this message, set the"\" GOOGLE_CLOUD_SUPPRESS_RUBY_WARNINGS environment variable."endendend# Set the default top-level configurationGoogle::Cloud.init_configuration# Emit a warning if current Ruby is at or nearing end-of-lifeGoogle::Cloud.warn_on_old_ruby_version# Auto-load all Google Cloud service gems.auto_load_files=ifGem.respond_to?:find_latest_filesGem.find_latest_files"google-cloud-*.rb"else# Ruby 2.0 does not have Gem.find_latest_filesGem.find_files"google-cloud-*.rb"endauto_load_files.eachdo|google_cloud_service|requiregoogle_cloud_serviceend