1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Merge branch 'master' into gce_l7

This commit is contained in:
snyquist2 2014-08-13 18:14:12 +00:00
commit 20a31a5da7
52 changed files with 2794 additions and 4 deletions

View file

@ -35,7 +35,7 @@ module Fog
def get(key, &block)
requires :directory
data = service.get_namespace(directory.key + key, :parse => false)#, &block)
data = service.get_namespace(directory.key + key, :parse => false, &block)
file_data = data.headers.merge({
:body => data.body,
:key => key

View file

@ -2,8 +2,13 @@ module Fog
module Storage
class Atmos
class Real
def get_namespace(namespace = '', options = {})
def get_namespace(namespace = '', options = {}, &block)
options = options.reject {|key, value| value.nil?}
if block_given?
options[:response_block] = Proc.new
end
request({
:expects => 200,
:method => 'GET',

View file

@ -6,7 +6,7 @@ module Fog
def reset
@block_device_mapping = {}
@context = []
@contexts = ['blockDeviceMapping', 'groupSet', 'iamInstanceProfile']
@contexts = ['blockDeviceMapping', 'groupSet', 'iamInstanceProfile', 'networkInterfaceSet']
@spot_instance_request = { 'launchSpecification' => { 'iamInstanceProfile' => {}, 'blockDeviceMapping' => [], 'groupSet' => [] } }
@response = { 'spotInstanceRequestSet' => [] }
end
@ -34,7 +34,9 @@ module Fog
when 'deviceName', 'status', 'volumeId'
@block_device_mapping[name] = value
when 'groupId'
@spot_instance_request['launchSpecification']['groupSet'] << value
if !@context.include?('networkInterfaceSet')
@spot_instance_request['launchSpecification']['groupSet'] << value
end
when 'arn', 'name'
@spot_instance_request['launchSpecification']['iamInstanceProfile'][name] = value
when 'instanceId', 'launchedAvailabilityZone', 'productDescription', 'spotInstanceRequestId', 'state', 'type'

View file

@ -146,6 +146,9 @@ module Fog
elsif state_reason_key = filter_key.split('state-reason-')[1]
aliased_key = state_reason_aliases[state_reason_key]
instance_set = instance_set.reject{|instance| ![*filter_value].include?(instance['stateReason'][aliased_key])}
elsif filter_key == "availability-zone"
aliased_key = aliases[filter_key]
instance_set = instance_set.reject{|instance| ![*filter_value].include?(instance['placement'][aliased_key])}
elsif filter_key == "group-name"
instance_set = instance_set.reject {|instance| !instance['groupSet'].include?(filter_value)}
elsif filter_key == "group-id"

View file

@ -0,0 +1,7 @@
def test
connection = Fog::Google::SQL.new
puts 'Listing all Flags...'
puts '--------------------'
connection.flags
end

View file

@ -0,0 +1,38 @@
def test
connection = Fog::Google::SQL.new
puts 'Create a Instance...'
puts '--------------------'
instance = connection.instances.create(:instance => Fog::Mock.random_letters(16), :tier => 'D1')
instance.wait_for { ready? }
puts 'Get the Instance...'
puts '----------------------'
connection.instances.get(instance.instance)
puts 'List all Instances...'
puts '---------------------'
connection.instances.all
puts 'Update the Instance...'
puts '----------------------'
instance.activation_policy = 'ALWAYS'
instance.update
instance.wait_for { ready? }
puts 'Reset the Instance SSL configuration...'
puts '---------------------------------------'
instance.reset_ssl_config
puts 'Restart the Instance...'
puts '-----------------------'
instance.restart
puts 'Set the Instance root password...'
puts '---------------------------------'
instance.set_root_password(Fog::Mock.random_letters_and_numbers(8))
puts 'Delete the Instance...'
puts '----------------------'
instance.destroy
end

View file

@ -0,0 +1,20 @@
def test
connection = Fog::Google::SQL.new
puts 'Create a Instance...'
puts '--------------------'
instance = connection.instances.create(:instance => Fog::Mock.random_letters(16), :tier => 'D1')
instance.wait_for { ready? }
puts 'Delete the Instance...'
puts '----------------------'
operation = instance.destroy
puts 'Get the Operation...'
puts '--------------------'
connection.operations.get(instance.identity, operation.identity)
puts 'Listing all Operations...'
puts '-------------------------'
connection.operations.all(instance.identity)
end

View file

@ -0,0 +1,28 @@
def test
connection = Fog::Google::SQL.new
puts 'Create a Instance...'
puts '--------------------'
instance = connection.instances.create(:instance => Fog::Mock.random_letters(16), :tier => 'D1')
instance.wait_for { ready? }
puts 'Create a SSL certificate...'
puts '---------------------------'
ssl_cert = connection.ssl_certs.create(:instance => instance.instance, :common_name => Fog::Mock.random_letters(16))
puts 'Get the SSL certificate...'
puts '--------------------------'
connection.ssl_certs.get(instance.instance, ssl_cert.sha1_fingerprint)
puts 'List all SSL certificate...'
puts '---------------------------'
connection.ssl_certs.all(instance.instance)
puts 'Delete the SSL certificate...'
puts '-----------------------------'
ssl_cert.destroy
puts 'Delete the Instance...'
puts '----------------------'
instance.destroy
end

View file

@ -0,0 +1,7 @@
def test
connection = Fog::Google::SQL.new
puts 'Listing all Tiers...'
puts '--------------------'
connection.tiers
end

View file

@ -0,0 +1,34 @@
require 'fog/core/model'
module Fog
module Google
class SQL
##
# A database instance backup run resource
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/backupRuns
class BackupRun < Fog::Model
identity :backup_configuration, :aliases => 'backupConfiguration'
attribute :due_time, :aliases => 'dueTime'
attribute :end_time, :aliases => 'endTime'
attribute :enqueued_time, :aliases => 'enqueuedTime'
attribute :error
attribute :instance
attribute :kind
attribute :start_time, :aliases => 'startTime'
attribute :status
DONE_STATE = 'DONE'
##
# Checks if the instance backup run is done
#
# @return [Boolean] True if the backup run is done; False otherwise
def ready?
self.state == DONE_STATE
end
end
end
end
end

View file

@ -0,0 +1,38 @@
require 'fog/core/collection'
require 'fog/google/models/sql/backup_run'
module Fog
module Google
class SQL
class BackupRuns < Fog::Collection
model Fog::Google::SQL::BackupRun
##
# Lists all backup runs associated with a given instance and configuration
#
# @param [String] instance_id Instance ID
# @param [String] backup_configuration_id Backup Configuration ID
# @return [Array<Fog::Google::SQL::BackupRun>] List of Backup run resources
def all(instance_id, backup_configuration_id)
data = service.list_backup_runs(instance_id, backup_configuration_id).body['items'] || []
load(data)
end
##
# Retrieves a resource containing information about a backup run
#
# @param [String] instance_id Instance ID
# @param [String] backup_configuration_id Backup Configuration ID
# @param [String] due_time The time when this run is due to start in RFC 3339 format
# @return [Fog::Google::SQL::BackupRun] Backup run resource
def get(instance_id, backup_configuration_id, due_time)
if backup_run = service.get_backup_run(instance_id, backup_configuration_id, due_time).body
new(backup_run)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,22 @@
require 'fog/core/model'
module Fog
module Google
class SQL
##
# A Google Cloud SQL service flag resource
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/flags
class Flag < Fog::Model
identity :name
attribute :allowed_string_values, :aliases => 'allowedStringValues'
attribute :applies_to, :aliases => 'appliesTo'
attribute :kind
attribute :max_value, :aliases => 'maxValue'
attribute :min_value, :aliases => 'minValue'
attribute :type
end
end
end
end

View file

@ -0,0 +1,21 @@
require 'fog/core/collection'
require 'fog/google/models/sql/flag'
module Fog
module Google
class SQL
class Flags < Fog::Collection
model Fog::Google::SQL::Flag
##
# List all available database flags
#
# @return [Array<Fog::Google::SQL::Flag>] List of flags
def all
data = service.list_flags.body['items'] || []
load(data)
end
end
end
end
end

View file

@ -0,0 +1,353 @@
require 'fog/core/model'
module Fog
module Google
class SQL
class Instance < Fog::Model
identity :instance
attribute :current_disk_size, :aliases => 'currentDiskSize'
attribute :database_version, :aliases => 'databaseVersion'
attribute :etag
attribute :ip_addresses, :aliases => 'ipAddresses'
attribute :kind
attribute :max_disk_size, :aliases => 'maxDiskSize'
attribute :project
attribute :region
attribute :server_ca_cert, :aliases => 'serverCaCert'
attribute :settings
attribute :state
# These attributes are not available in the representation of an 'Instance' returned by the Google SQL API.
attribute :activation_policy
attribute :autorized_gae_applications
attribute :backup_configuration
attribute :database_flags
attribute :ip_configuration_authorized_networks
attribute :ip_configuration_enabled
attribute :ip_configuration_require_ssl
attribute :location_preference_zone_follow_gae_application
attribute :location_preference_zone
attribute :pricing_plan
attribute :replication_type
attribute :settings_version
attribute :tier
MAINTENANCE_STATE = 'MAINTENANCE'
PENDING_CREATE_STATE = 'PENDING_CREATE'
RUNNABLE_STATE = 'RUNNABLE'
SUSPENDED_STATE = 'SUSPENDED'
UNKNOWN_STATE = 'UNKNOWN_STATE'
##
# Returns the activation policy for this instance
#
# @return [String] The activation policy for this instance
def activation_policy
self.settings['activationPolicy']
end
##
# Returns the AppEngine app ids that can access this instance
#
# @return [Array<String>] The AppEngine app ids that can access this instance
def autorized_gae_applications
self.settings['authorizedGaeApplications']
end
##
# Returns the daily backup configuration for the instance
#
# @return [Array<Hash>] The daily backup configuration for the instance
def backup_configuration
self.settings['backupConfiguration']
end
##
# Creates a Cloud SQL instance as a clone of the source instance
#
# @param [String] destination_name Name of the Cloud SQL instance to be created as a clone
# @param [Hash] options Method options
# @option options [String] :log_filename Name of the binary log file for a Cloud SQL instance
# @option options [Integer] :log_position Position (offset) within the binary log file
# @option options [Boolean] :async If the operation must be performed asynchronously (true by default)
# @return [Fog::Google::SQL::Operation] A Operation resource
def clone(destination_name, options = {})
requires :identity
data = service.clone_instance(self.identity, destination_name, options)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
unless options.fetch(:async, true)
operation.wait_for { ready? }
end
operation
end
##
# Creates a Cloud SQL instance
#
# @return [Fog::Google::SQL::Instance] Instance resource
def create
requires :identity
data = service.insert_instance(self.identity, self.attributes[:tier], self.attributes)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
operation.wait_for { !pending? }
reload
end
##
# Returns the database flags passed to the instance at startup
#
# @return [Array<Hash>] The database flags passed to the instance at startup
def database_flags
self.settings['databaseFlags']
end
##
# Deletes a Cloud SQL instance
#
# @param [Hash] options Method options
# @option options [Boolean] :async If the operation must be performed asynchronously (true by default)
# @return [Fog::Google::SQL::Operation] A Operation resource
def destroy(options = {})
requires :identity
data = service.delete_instance(self.identity)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
unless options.fetch(:async, true)
# DISABLED: A delete instance operation never reachs a 'DONE' state (bug?)
# operation.wait_for { ready? }
end
operation
end
##
# Exports data from a Cloud SQL instance to a Google Cloud Storage bucket as a MySQL dump file
#
# @param [String] uri The path to the file in Google Cloud Storage where the export will be stored,
# or where it was already stored
# @param [Hash] options Method options
# @option options [Array<String>] :databases Databases (for example, guestbook) from which the export is made.
# If unspecified, all databases are exported.
# @option options [Array<String>] :tables Tables to export, or that were exported, from the specified database.
# If you specify tables, specify one and only one database.
# @option options [Boolean] :async If the operation must be performed asynchronously (true by default)
# @return [Fog::Google::SQL::Operation] A Operation resource
def export(uri, options = {})
requires :identity
data = service.export_instance(self.identity, uri, options)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
unless options.fetch(:async, true)
operation.wait_for { ready? }
end
operation
end
##
# Imports data into a Cloud SQL instance from a MySQL dump file in Google Cloud Storage
#
# @param [Array<String>] uri A path to the MySQL dump file in Google Cloud Storage from which the import is
# made
# @param [Hash] options Method options
# @option options [String] :database The database (for example, guestbook) to which the import is made.
# If not set, it is assumed that the database is specified in the file to be imported.
# @option options [Boolean] :async If the operation must be performed asynchronously (true by default)
# @return [Fog::Google::SQL::Operation] A Operation resource
def import(uri, options = {})
requires :identity
data = service.import_instance(self.identity, uri, options)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
unless options.fetch(:async, true)
operation.wait_for { ready? }
end
operation
end
##
# Returns the list of external networks that are allowed to connect to the instance using the IP
#
# @return [Array<String>] The list of external networks that are allowed to connect to the instance using the IP
def ip_configuration_authorized_networks
self.settings.fetch('ipConfiguration', {})['authorizedNetworks']
end
##
# Returns whether the instance should be assigned an IP address or not
#
# @return [Boolean] Whether the instance should be assigned an IP address or not
def ip_configuration_enabled
self.settings.fetch('ipConfiguration', {})['enabled']
end
##
# Returns whether the mysqld should default to 'REQUIRE X509' for users connecting over IP
#
# @return [Boolean] Whether the mysqld should default to 'REQUIRE X509' for users connecting over IP
def ip_configuration_require_ssl
self.settings.fetch('ipConfiguration', {})['requireSsl']
end
##
# Returns the AppEngine application to follow
#
# @return [String] The AppEngine application to follow
def location_preference_zone_follow_gae_application
self.settings.fetch('locationPreference', {})['followGaeApplication']
end
##
# Returns the preferred Compute Engine zone
#
# @return [String] The preferred Compute Engine zone
def location_preference_zone
self.settings.fetch('locationPreference', {})['zone']
end
##
# Returns the pricing plan for this instance
#
# @return [String] The pricing plan for this instance
def pricing_plan
self.settings['pricingPlan']
end
##
# Checks if the instance is running
#
# @return [Boolean] True if the instance is running; False otherwise
def ready?
self.state == RUNNABLE_STATE
end
##
# Returns the type of replication this instance uses
#
# @return [String] The type of replication this instance uses
def replication_type
self.settings['replicationType']
end
##
# Deletes all client certificates and generates a new server SSL certificate for the instance
#
# @param [Hash] options Method options
# @option options [Boolean] :async If the operation must be performed asynchronously (true by default)
# @return [Fog::Google::SQL::Operation] A Operation resource
def reset_ssl_config(options = {})
requires :identity
data = service.reset_instance_ssl_config(self.identity)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
unless options.fetch(:async, true)
operation.wait_for { ready? }
end
operation
end
##
# Restarts a Cloud SQL instance
#
# @param [Hash] options Method options
# @option options [Boolean] :async If the operation must be performed asynchronously (true by default)
# @return [Fog::Google::SQL::Operation] A Operation resource
def restart(options = {})
requires :identity
data = service.restart_instance(self.identity)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
unless options.fetch(:async, true)
operation.wait_for { ready? }
end
operation
end
##
# Restores a backup of a Cloud SQL instance
#
# @param [String] backup_configuration The identifier of the backup configuration
# @param [String] due_time The time when this run is due to start in RFC 3339 format
# @param [Hash] options Method options
# @option options [Boolean] :async If the operation must be performed asynchronously (true by default)
# @return [Fog::Google::SQL::Operation] A Operation resource
def restore_backup(backup_configuration, due_time, options = {})
requires :identity
data = service.restore_instance_backup(self.identity, backup_configuration, due_time)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
unless options.fetch(:async, true)
operation.wait_for { ready? }
end
operation
end
##
# Saves a Cloud SQL instance
#
# @return [Fog::Google::SQL::Instance] Instance resource
def save
self.etag ? update : create
end
##
# Sets the password for the root user
#
# @param [String] password The password for the root user
# @param [Hash] options Method options
# @option options [Boolean] :async If the operation must be performed asynchronously (true by default)
# @return [Fog::Google::SQL::Operation] A Operation resource
def set_root_password(password, options = {})
requires :identity
data = service.set_instance_root_password(self.identity, password)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
unless options.fetch(:async, true)
operation.wait_for { ready? }
end
operation
end
##
# Returns the version of instance settings
#
# @return [String] The version of instance settings
def settings_version
self.settings['settingsVersion']
end
##
# Lists all of the current SSL certificates for the instance
#
# @return [Array<Fog::Google::SQL::SslCert>] List of SSL certificate resources
def ssl_certs
requires :identity
service.ssl_certs.all(self.identity)
end
##
# Returns the tier of service for this instance
#
# @return [String] The tier of service for this instance
def tier
self.settings['tier']
end
##
# Updates settings of a Cloud SQL instance
#
# @return [Fog::Google::SQL::Instance] Instance resource
def update
requires :identity
data = service.update_instance(self.identity, self.settings_version, self.tier, self.attributes)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
operation.wait_for { !pending? }
reload
end
end
end
end
end

View file

@ -0,0 +1,39 @@
require 'fog/core/collection'
require 'fog/google/models/sql/instance'
module Fog
module Google
class SQL
class Instances < Fog::Collection
model Fog::Google::SQL::Instance
##
# Lists all instance
#
# @return [Array<Fog::Google::SQL::Instance>] List of instance resources
def all
data = service.list_instances.body['items'] || []
load(data)
end
##
# Retrieves an instance
#
# @param [String] instance_id Instance ID
# @return [Fog::Google::SQL::Instance] Instance resource
def get(instance_id)
if instance = service.get_instance(instance_id).body
new(instance)
end
rescue Fog::Errors::NotFound
nil
rescue Fog::Errors::Error => e
# Google SQL returns a 403 if we try to access a non-existing resource
# The default behaviour in Fog is to return a nil
return nil if e.message == 'The client is not authorized to make this request.'
raise e
end
end
end
end
end

View file

@ -0,0 +1,61 @@
require 'fog/core/model'
module Fog
module Google
class SQL
##
# An Operation resource contains information about database instance operations
# such as create, delete, and restart
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/operations
class Operation < Fog::Model
identity :operation
attribute :end_time, :aliases => 'endTime'
attribute :enqueued_time, :aliases => 'enqueuedTime'
attribute :error
attribute :export_context, :aliases => 'exportContext'
attribute :import_context, :aliases => 'importContext'
attribute :instance
attribute :kind
attribute :operation_type, :aliases => 'operationType'
attribute :start_time, :aliases => 'startTime'
attribute :state
attribute :user_email_address, :aliases => 'userEmailAddress'
DONE_STATE = 'DONE'
PENDING_STATE = 'PENDING'
RUNNING_STATE = 'RUNNING'
UNKNOWN_STATE = 'UNKNOWN'
##
# Checks if the instance operation is pending
#
# @return [Boolean] True if the operation is pending; False otherwise
def pending?
self.state == PENDING_STATE
end
##
# Checks if the instance operation is done
#
# @return [Boolean] True if the operation is done; False otherwise
def ready?
self.state == DONE_STATE
end
##
# Reloads an instance operation
#
# @return [Fog::Google::SQL::Operation] Instance operation resource
def reload
requires :identity
data = collection.get(self.instance, self.identity)
merge_attributes(data.attributes)
self
end
end
end
end
end

View file

@ -0,0 +1,49 @@
require 'fog/core/collection'
require 'fog/google/models/sql/operation'
module Fog
module Google
class SQL
class Operations < Fog::Collection
model Fog::Google::SQL::Operation
##
# Lists all instance operations that have been performed on the given instance
#
# @param [String] instance_id Instance ID
# @return [Array<Fog::Google::SQL::Operation>] List of instance operation resources
def all(instance_id)
data = []
begin
data = service.list_operations(instance_id).body['items'] || []
rescue Fog::Errors::Error => e
# Google SQL returns a 403 if we try to access a non-existing resource
# The default behaviour in Fog is to return an empty Array
raise e unless e.message == 'The client is not authorized to make this request.'
end
load(data)
end
##
# Retrieves an instance operation that has been performed on an instance
#
# @param [String] instance_id Instance ID
# @param [String] operation_id Instance operation ID
# @return [Fog::Google::SQL::Operation] Instance operation resource
def get(instance_id, operation_id)
if operation = service.get_operation(instance_id, operation_id).body
new(operation)
end
rescue Fog::Errors::NotFound
nil
rescue Fog::Errors::Error => e
# Google SQL returns a 403 if we try to access a non-existing resource
# The default behaviour in Fog is to return a nil
return nil if e.message == 'The client is not authorized to make this request.'
raise e
end
end
end
end
end

View file

@ -0,0 +1,73 @@
require 'fog/core/model'
module Fog
module Google
class SQL
##
# A SSL certificate resource
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/sslCerts
class SslCert < Fog::Model
identity :sha1_fingerprint, :aliases => 'sha1Fingerprint'
attribute :cert
attribute :cert_serial_number, :aliases => 'certSerialNumber'
attribute :common_name, :aliases => 'commonName'
attribute :create_time, :aliases => 'createTime'
attribute :expiration_time, :aliases => 'expirationTime'
attribute :instance
attribute :kind
# These attributes are not available in the representation of a 'SSL Certificate' returned by the SQL API.
# These attributes are only available as a reponse to a create operation
attribute :server_ca_cert, :aliases => 'serverCaCert'
attribute :cert_private_key, :aliases => 'certPrivateKey'
##
# Deletes a SSL certificate. The change will not take effect until the instance is restarted.
#
# @param [Hash] options Method options
# @option options [Boolean] :async If the operation must be performed asynchronously (true by default)
# @return [Fog::Google::SQL::Operation] A Operation resource
def destroy(options = {})
requires :instance, :identity
data = service.delete_ssl_cert(self.instance, self.identity)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
unless options.fetch(:async, true)
operation.wait_for { ready? }
end
operation
end
##
# Reloads a SSL certificate
#
# @return [Fog::Google::SQL::SslCert] SSL certificate resource
def reload
requires :instance, :identity
data = collection.get(self.instance, self.identity)
merge_attributes(data.attributes)
self
end
##
# Creates a SSL certificate. The new certificate will not be usable until the instance is restarted.
#
# @raise [Fog::Errors::Error] If SSL certificate already exists
def save
requires :instance, :common_name
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
data = service.insert_ssl_cert(self.instance, self.common_name).body
merge_attributes(data['clientCert']['certInfo'])
self.server_ca_cert = Fog::Google::SQL::SslCert.new(data['serverCaCert'])
self.cert_private_key = data['clientCert']['certPrivateKey']
self
end
end
end
end
end

View file

@ -0,0 +1,49 @@
require 'fog/core/collection'
require 'fog/google/models/sql/ssl_cert'
module Fog
module Google
class SQL
class SslCerts < Fog::Collection
model Fog::Google::SQL::SslCert
##
# Lists all of the current SSL certificates for the instance
#
# @param [String] instance_id Instance ID
# @return [Array<Fog::Google::SQL::SslCert>] List of SSL certificate resources
def all(instance_id)
data = []
begin
data = service.list_ssl_certs(instance_id).body['items'] || []
rescue Fog::Errors::Error => e
# Google SQL returns a 403 if we try to access a non-existing resource
# The default behaviour in Fog is to return an empty Array
raise e unless e.message == 'The client is not authorized to make this request.'
end
load(data)
end
##
# Retrieves a particular SSL certificate (does not include the private key)
#
# @param [String] instance_id Instance ID
# @param [String] sha1_fingerprint Sha1 FingerPrint
# @return [Fog::Google::SQL::SslCert] SSL certificate resource
def get(instance_id, sha1_fingerprint)
if ssl_cert = service.get_ssl_cert(instance_id, sha1_fingerprint).body
new(ssl_cert)
end
rescue Fog::Errors::NotFound
nil
rescue Fog::Errors::Error => e
# Google SQL returns a 403 if we try to access a non-existing resource
# The default behaviour in Fog is to return a nil
return nil if e.message == 'The client is not authorized to make this request.'
raise e
end
end
end
end
end

View file

@ -0,0 +1,84 @@
module Fog
module Google
class SQL
##
# Creates a Cloud SQL instance as a clone of the source instance
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/instances/clone
class Real
def clone_instance(instance_id, destination_name, options = {})
# The @sql.instances.clone method is overrided by the standard Ruby clone method
# so we cannot call it because it will just clone the @sql.instances instance.
# Instead we need to find the proper method trough the discovered_methods.
api_method = @sql.instances.discovered_methods.find { |x| x.id == 'sql.instances.clone' }
parameters = {
'project' => @project,
}
body = {
'cloneContext' => {
'kind' => 'sql#cloneContext',
'sourceInstanceName' => instance_id,
'destinationInstanceName' => destination_name,
}
}
if options[:log_position]
body['cloneContext']['binLogCoordinates'] = {
'kind' => 'sql#binLogCoordinates',
'binLogFileName' => options[:log_filename],
'binLogPosition' => options[:log_position],
}
end
request(api_method, parameters, body)
end
end
class Mock
def clone_instance(instance_id, destination_name, options = {})
self.data[:instances][destination_name] = self.data[:instances][instance_id]
self.data[:instances][destination_name]['instance'] = destination_name
self.data[:ssl_certs][destination_name] = {}
self.data[:backup_runs][destination_name] = {}
operation = self.random_operation
self.data[:operations][destination_name] ||= {}
self.data[:operations][destination_name][operation] = {
'kind' => 'sql#instanceOperation',
'instance' => destination_name,
'operation' => operation,
'operationType' => 'CREATE',
'state' => Fog::Google::SQL::Operation::DONE_STATE,
'userEmailAddress' => 'google_client_email@developer.gserviceaccount.com',
'enqueuedTime' => Time.now.iso8601,
'startTime' => Time.now.iso8601,
'endTime' => Time.now.iso8601,
}
operation = self.random_operation
self.data[:operations][instance_id] ||= {}
self.data[:operations][instance_id][operation] = {
'kind' => 'sql#instanceOperation',
'instance' => instance_id,
'operation' => operation,
'operationType' => 'CLONE',
'state' => Fog::Google::SQL::Operation::DONE_STATE,
'userEmailAddress' => 'google_client_email@developer.gserviceaccount.com',
'enqueuedTime' => Time.now.iso8601,
'startTime' => Time.now.iso8601,
'endTime' => Time.now.iso8601,
}
body = {
'kind' => 'sql#instancesClone',
'operation' => operation,
}
build_excon_response(body)
end
end
end
end
end

View file

@ -0,0 +1,67 @@
module Fog
module Google
class SQL
##
# Deletes a Cloud SQL instance
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/instances/delete
class Real
def delete_instance(instance_id)
api_method = @sql.instances.delete
parameters = {
'project' => @project,
'instance' => instance_id,
}
request(api_method, parameters)
end
end
class Mock
def delete_instance(instance_id)
if self.data[:instances].has_key?(instance_id)
self.data[:instances].delete(instance_id)
self.data[:ssl_certs].delete(instance_id)
self.data[:backup_runs].delete(instance_id)
operation = self.random_operation
self.data[:operations][instance_id] ||= {}
self.data[:operations][instance_id][operation] = {
'kind' => 'sql#instanceOperation',
'instance' => instance_id,
'operation' => operation,
'operationType' => 'DELETE',
'state' => Fog::Google::SQL::Operation::PENDING_STATE,
'userEmailAddress' => 'google_client_email@developer.gserviceaccount.com',
'enqueuedTime' => Time.now.iso8601,
}
body = {
'kind' => 'sql#instancesDelete',
'operation' => operation,
}
status = 200
else
body = {
'error' => {
'errors' => [
{
'domain' => 'global',
'reason' => 'notAuthorized',
'message' => 'The client is not authorized to make this request.',
}
],
'code' => 403,
'message' => 'The client is not authorized to make this request.',
}
}
status = 403
end
build_excon_response(body, status)
end
end
end
end
end

View file

@ -0,0 +1,68 @@
module Fog
module Google
class SQL
##
# Deletes a SSL certificate. The change will not take effect until the instance is restarted.
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/sslCerts/delete
class Real
def delete_ssl_cert(instance_id, sha1_fingerprint)
api_method = @sql.ssl_certs.delete
parameters = {
'project' => @project,
'instance' => instance_id,
'sha1Fingerprint' => sha1_fingerprint,
}
request(api_method, parameters)
end
end
class Mock
def delete_ssl_cert(instance_id, sha1_fingerprint)
if self.data[:ssl_certs].has_key?(instance_id)
self.data[:ssl_certs][instance_id].delete(sha1_fingerprint)
operation = self.random_operation
self.data[:operations][instance_id] ||= {}
self.data[:operations][instance_id][operation] = {
'kind' => 'sql#instanceOperation',
'instance' => instance_id,
'operation' => operation,
'operationType' => 'UPDATE',
'state' => Fog::Google::SQL::Operation::DONE_STATE,
'userEmailAddress' => 'google_client_email@developer.gserviceaccount.com',
'enqueuedTime' => Time.now.iso8601,
'startTime' => Time.now.iso8601,
'endTime' => Time.now.iso8601,
}
body = {
'kind' => 'sql#sslCertsDelete',
'operation' => operation,
}
status = 200
else
body = {
'error' => {
'errors' => [
{
'domain' => 'global',
'reason' => 'notAuthorized',
'message' => 'The client is not authorized to make this request.',
}
],
'code' => 403,
'message' => 'The client is not authorized to make this request.',
}
}
status = 403
end
build_excon_response(body, status)
end
end
end
end
end

View file

@ -0,0 +1,56 @@
module Fog
module Google
class SQL
##
# Exports data from a Cloud SQL instance to a Google Cloud Storage bucket as a MySQL dump file
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/instances/export
class Real
def export_instance(instance_id, uri, options = {})
api_method = @sql.instances.export
parameters = {
'project' => @project,
'instance' => instance_id,
}
body = {
'exportContext' => {
'kind' => 'sql#exportContext',
'uri' => uri,
'database' => Array(options[:databases]),
'table' => Array(options[:tables]),
}
}
request(api_method, parameters, body)
end
end
class Mock
def export_instance(instance_id, uri, options = {})
operation = self.random_operation
self.data[:operations][instance_id] ||= {}
self.data[:operations][instance_id][operation] = {
'kind' => 'sql#instanceOperation',
'instance' => instance_id,
'operation' => operation,
'operationType' => 'EXPORT',
'state' => Fog::Google::SQL::Operation::DONE_STATE,
'userEmailAddress' => 'google_client_email@developer.gserviceaccount.com',
'enqueuedTime' => Time.now.iso8601,
'startTime' => Time.now.iso8601,
'endTime' => Time.now.iso8601,
}
body = {
'kind' => 'sql#instancesExport',
'operation' => operation,
}
build_excon_response(body)
end
end
end
end
end

View file

@ -0,0 +1,30 @@
module Fog
module Google
class SQL
##
# Retrieves a resource containing information about a backup run
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/backupRuns/get
class Real
def get_backup_run(instance_id, backup_configuration_id, due_time)
api_method = @sql.backup_runs.get
parameters = {
'project' => @project,
'instance' => instance_id,
'backupConfiguration' => backup_configuration_id,
'dueTime' => due_time,
}
request(api_method, parameters)
end
end
class Mock
def get_backup_run(instance_id, backup_configuration_id, due_time)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,48 @@
module Fog
module Google
class SQL
##
# Retrieves a resource containing information about a Cloud SQL instance
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/instances/get
class Real
def get_instance(instance_id)
api_method = @sql.instances.get
parameters = {
'project' => @project,
'instance' => instance_id,
}
request(api_method, parameters)
end
end
class Mock
def get_instance(instance_id)
if self.data[:instances].has_key?(instance_id)
body = self.data[:instances][instance_id]
status = 200
else
body = {
'error' => {
'errors' => [
{
'domain' => 'global',
'reason' => 'notAuthorized',
'message' => 'The client is not authorized to make this request.',
}
],
'code' => 403,
'message' => 'The client is not authorized to make this request.',
}
}
status = 403
end
build_excon_response(body, status)
end
end
end
end
end

View file

@ -0,0 +1,66 @@
module Fog
module Google
class SQL
##
# Retrieves an instance operation that has been performed on an instance
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/operations/get
class Real
def get_operation(instance_id, operation_id)
api_method = @sql.operations.get
parameters = {
'project' => @project,
'instance' => instance_id,
'operation' => operation_id,
}
request(api_method, parameters)
end
end
class Mock
def get_operation(instance_id, operation_id)
if self.data[:operations].has_key?(instance_id)
if self.data[:operations][instance_id].has_key?(operation_id)
body = self.data[:operations][instance_id][operation_id]
status = 200
else
body = {
'error' => {
'errors' => [
{
'domain' => 'global',
'reason' => 'operationDoesNotExist',
'message' => 'The Cloud SQL instance operation does not exist.',
}
],
'code' => 404,
'message' => 'The Cloud SQL instance operation does not exist.',
}
}
status = 404
end
else
body = {
'error' => {
'errors' => [
{
'domain' => 'global',
'reason' => 'notAuthorized',
'message' => 'The client is not authorized to make this request.',
}
],
'code' => 403,
'message' => 'The client is not authorized to make this request.',
}
}
status = 403
end
build_excon_response(body, status)
end
end
end
end
end

View file

@ -0,0 +1,66 @@
module Fog
module Google
class SQL
##
# Retrieves a particular SSL certificate (does not include the private key)
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/sslCerts/get
class Real
def get_ssl_cert(instance_id, sha1_fingerprint)
api_method = @sql.ssl_certs.get
parameters = {
'project' => @project,
'instance' => instance_id,
'sha1Fingerprint' => sha1_fingerprint,
}
request(api_method, parameters)
end
end
class Mock
def get_ssl_cert(instance_id, sha1_fingerprint)
if self.data[:ssl_certs].has_key?(instance_id)
if self.data[:ssl_certs][instance_id].has_key?(sha1_fingerprint)
body = self.data[:ssl_certs][instance_id][sha1_fingerprint]
status = 200
else
body = {
'error' => {
'errors' => [
{
'domain' => 'global',
'reason' => 'sslCertificateDoesNotExist',
'message' => 'The SSL certificate does not exist.',
}
],
'code' => 404,
'message' => 'The SSL certificate does not exist.',
}
}
status = 404
end
else
body = {
'error' => {
'errors' => [
{
'domain' => 'global',
'reason' => 'notAuthorized',
'message' => 'The client is not authorized to make this request.',
}
],
'code' => 403,
'message' => 'The client is not authorized to make this request.',
}
}
status = 403
end
build_excon_response(body, status)
end
end
end
end
end

View file

@ -0,0 +1,55 @@
module Fog
module Google
class SQL
##
# Imports data into a Cloud SQL instance from a MySQL dump file in Google Cloud Storage
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/instances/import
class Real
def import_instance(instance_id, uri, options = {})
api_method = @sql.instances.import
parameters = {
'project' => @project,
'instance' => instance_id,
}
body = {
'importContext' => {
'kind' => 'sql#importContext',
'uri' => Array(uri),
'database' => options[:database],
}
}
request(api_method, parameters, body)
end
end
class Mock
def import_instance(instance_id, uri, options = {})
operation = self.random_operation
self.data[:operations][instance_id] ||= {}
self.data[:operations][instance_id][operation] = {
'kind' => 'sql#instanceOperation',
'instance' => instance_id,
'operation' => operation,
'operationType' => 'IMPORT',
'state' => Fog::Google::SQL::Operation::DONE_STATE,
'userEmailAddress' => 'google_client_email@developer.gserviceaccount.com',
'enqueuedTime' => Time.now.iso8601,
'startTime' => Time.now.iso8601,
'endTime' => Time.now.iso8601,
}
body = {
'kind' => 'sql#instancesImport',
'operation' => operation,
}
build_excon_response(body)
end
end
end
end
end

View file

@ -0,0 +1,165 @@
module Fog
module Google
class SQL
##
# Creates a new Cloud SQL instance
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/instances/insert
class Real
def insert_instance(name, tier, options = {})
api_method = @sql.instances.insert
parameters = {
'project' => @project,
}
body = {
'project' => @project,
'instance' => name,
'settings' => {
'tier' => tier,
}
}
if options[:region]
body['region'] = options[:region]
end
if options[:activation_policy]
body['settings']['activationPolicy'] = options[:activation_policy]
end
if options[:autorized_gae_applications]
body['settings']['authorizedGaeApplications'] = Array(options[:autorized_gae_applications])
end
if options[:backup_configuration]
body['settings']['backupConfiguration'] = options[:backup_configuration]
end
if options[:ip_configuration_authorized_networks]
body['settings']['ipConfiguration'] ||= {}
body['settings']['ipConfiguration']['authorizedNetworks'] = Array(options[:ip_configuration_authorized_networks])
end
if options[:ip_configuration_enabled]
body['settings']['ipConfiguration'] ||= {}
body['settings']['ipConfiguration']['enabled'] = options[:ip_configuration_enabled]
end
if options[:ip_configuration_require_ssl]
body['settings']['ipConfiguration'] ||= {}
body['settings']['ipConfiguration']['requireSsl'] = options[:ip_configuration_require_ssl]
end
if options[:location_preference_zone_follow_gae_application]
body['settings']['locationPreference'] ||= {}
body['settings']['locationPreference']['followGaeApplication'] = options[:location_preference_zone_follow_gae_application]
end
if options[:location_preference_zone]
body['settings']['locationPreference'] ||= {}
body['settings']['locationPreference']['zone'] = options[:location_preference_zone]
end
if options[:pricing_plan]
body['settings']['pricingPlan'] = options[:pricing_plan]
end
if options[:replication_type]
body['settings']['replicationType'] = options[:replication_type]
end
request(api_method, parameters, body)
end
end
class Mock
def insert_instance(name, tier, options = {})
data = {
'kind' => 'sql#instance',
'instance' => name,
'etag' => Fog::Mock.random_base64(32),
'project' => @project,
'state' => Fog::Google::SQL::Instance::RUNNABLE_STATE ,
'databaseVersion' => 'MYSQL_5_5',
'region' => options[:region] || 'us-central',
'currentDiskSize' => '86245269',
'maxDiskSize' => '268435456000',
'settings' => {
'kind' => 'sql#settings',
'settingsVersion' => '1',
'tier' => tier,
'backupConfiguration' => [
{
'kind' => 'sql#backupConfiguration',
'startTime' => '04:00',
'enabled' => false,
'id' => Fog::Mock.random_hex(32),
'binaryLogEnabled' => false
}
],
'pricingPlan' => options[:pricing_plan] || 'PER_USE',
'replicationType' => options[:replication_type] || 'SYNCHRONOUS',
'activationPolicy' => options[:activation_policy] || 'ON_DEMAND',
'ipConfiguration' => {
'enabled' => false,
},
'locationPreference' => {
'kind' => 'sql#locationPreference',
}
},
'serverCaCert' => {
'kind' => 'sql#sslCert',
'instance' => name,
'sha1Fingerprint' => Fog::Mock.random_hex(40),
'commonName' => 'C=US,O=Google\\, Inc,CN=Google Cloud SQL Server CA',
'certSerialNumber' => '0',
'cert' => "-----BEGIN CERTIFICATE-----\nMIIDITCCAgmgAwIBAgIBADANBgkqhkiG9w0BAQUFADBIMSMwIQYDVQQDExpHb29n\nbGUgQ2xvdWQgU1FMIFNlcnZlciBDQTEUMBIGA1UEChMLR29vZ2xlLCBJbmMxCzAJ\nBgNVBAYTAlVTMB4XDTE0MDYwNDA1MjkxMVoXDTI0MDYwMTA1MjkxMVowSDEjMCEG\nA1UEAxMaR29vZ2xlIENsb3VkIFNRTCBTZXJ2ZXIgQ0ExFDASBgNVBAoTC0dvb2ds\nZSwgSW5jMQswCQYDVQQGEwJVUzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC\nggEBALlRjq3zccH5ed6NMfCFcTYd9XxYXyvLurxxjDIA6A7/ymVM9qdQC0uckf7C\nsi4uMi2yfK+PHZ0jXC+g0uPx5RTm+nbKl4I++VOh2g6oZHeNdFt4rVJpr+jzGUMf\nr67SymUr70TQOTEVpx2Ud3rBB2szulxWUSXEy2AGA3uNUGe/IgENh7p56s00Sr97\nTRP1S5/JVMalncgNVLH2nNqBQJZTx9t9qvGatoUfmHUU0+M//J5sXLbgdzeEeeot\nHJUyoXjA2sRkH1+F/d6PpFrcr1I8dVmCBEbTAnm7HpKh5Mx2nRYi+t/y9D2Mblwx\n9dBRfr3WIJ1JDxzt3L8CtBGZbvUCAwEAAaMWMBQwEgYDVR0TAQH/BAgwBgEB/wIB\nADANBgkqhkiG9w0BAQUFAAOCAQEAmHuBecPc265sbd26B1HXUAD6FHdzoZLrAZVW\n+1eIK4E669P4y6LkLuoCkLd64/YwA4K2FioksqgHOahbYWJJYPymy4ae+IPXzXcY\nPv3gmBsKk++sHb64D9Cj/k5n8BEiVmmrsUCUiL75nJAzK+El3hvKKWWl76XX/qHP\nk8ZAxIrn8bCiVOaj6NR4+p1OmcZSPNWxz7j/EwQxoABRxgPgt+B/YRseevww7an2\n/rGs0sk7RE0QDjLfZblYGh+xVPBBLuLmf4L5JNJkFEoeGSWrxTzvXnS+2LZeHdM/\nJ9nsiKu5JKPhMUS0vOcTymOkh8tJ6Np8gwg6ca4g6dT3llE6uQ==\n-----END CERTIFICATE-----",
'createTime' => Time.now.iso8601,
'expirationTime' => Time.now.iso8601,
}
}
if options[:autorized_gae_applications]
data['settings']['authorizedGaeApplications'] = Array(options[:autorized_gae_applications])
end
if options[:backup_configuration]
data['settings']['backupConfiguration'] = options[:backup_configuration]
end
if options[:ip_configuration_authorized_networks]
data['settings']['ipConfiguration']['authorizedNetworks'] = Array(options[:ip_configuration_authorized_networks])
end
if options[:ip_configuration_enabled]
data['settings']['ipConfiguration']['enabled'] = options[:ip_configuration_enabled]
end
if options[:ip_configuration_require_ssl]
data['settings']['ipConfiguration']['requireSsl'] = options[:ip_configuration_require_ssl]
end
if options[:location_preference_zone_follow_gae_application]
data['settings']['locationPreference']['followGaeApplication'] = options[:location_preference_zone_follow_gae_application]
end
if options[:location_preference_zone]
data['settings']['locationPreference']['zone'] = options[:location_preference_zone]
end
self.data[:instances][name] = data
self.data[:ssl_certs][name] = {}
self.data[:backup_runs][name] = {}
operation = self.random_operation
self.data[:operations][name] ||= {}
self.data[:operations][name][operation] = {
'kind' => 'sql#instanceOperation',
'instance' => name,
'operation' => operation,
'operationType' => 'CREATE',
'state' => Fog::Google::SQL::Operation::DONE_STATE,
'userEmailAddress' => 'google_client_email@developer.gserviceaccount.com',
'enqueuedTime' => Time.now.iso8601,
'startTime' => Time.now.iso8601,
'endTime' => Time.now.iso8601,
}
body = {
'kind' => 'sql#instancesInsert',
'operation' => operation,
}
status = 200
build_excon_response(body, status)
end
end
end
end
end

View file

@ -0,0 +1,80 @@
module Fog
module Google
class SQL
##
# Creates an SSL certificate. The new certificate will not be usable until the instance is restarted.
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/sslCerts/insert
class Real
def insert_ssl_cert(instance_id, common_name)
api_method = @sql.ssl_certs.insert
parameters = {
'project' => @project,
'instance' => instance_id,
}
body = {
'commonName' => common_name
}
request(api_method, parameters, body)
end
end
class Mock
def insert_ssl_cert(instance_id, common_name)
if self.data[:ssl_certs].has_key?(instance_id)
sha1_fingerprint = Fog::Mock.random_hex(40)
data = {
'kind' => 'sql#sslCert',
'instance' => instance_id,
'sha1Fingerprint' => sha1_fingerprint,
'commonName' => common_name,
'certSerialNumber' => Fog::Mock.random_numbers(9),
'cert' => "-----BEGIN CERTIFICATE-----\nMIIC/zCCAeegAwIBAgIELAk5vzANBgkqhkiG9w0BAQUFADBNMSgwJgYDVQQDEx9H\nb29nbGUgQ2xvdWQgU1FMIENsaWVudCBDQSB0ZXN0MRQwEgYDVQQKEwtHb29nbGUs\nIEluYzELMAkGA1UEBhMCVVMwHhcNMTQwNjA0MDY1MjAwWhcNMjQwNjAxMDY1MjAw\nWjAyMQ0wCwYDVQQDEwR0ZXN0MRQwEgYDVQQKEwtHb29nbGUsIEluYzELMAkGA1UE\nBhMCVVMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC9G9ZG19n978EW\n5bQ/TM1Fnb4fd/FRT8XMs2D5C7+dKLEgbeUOvZQt4EsQ6cC+UVhoK7N6DvnXAZ1M\ng+B159Xlqjv8Mh5RihfGjPCdlw2pF7Pu68LyYghvQLhi7yhuNeaN+FBeKvjcW9k0\ni54AM8Ub2a/kxAwMtXm1kGtgc1+qkUlyBxfn1UoKI5Dhvw/InxgI1kS/VUkkk9kv\n0q/oyPrboE/vuSitDq+pHjRFwrIQcS6Pz9DYHhZVyDDkTIh7vLXM0JEQRT1SiA8k\n+4hwXI3WBqPRZRI4H1KmYSSIKvZtci63SbM/rHitXkGipFF1lw0gSqfpM8gG36fl\naITBPI97AgMBAAGjAjAAMA0GCSqGSIb3DQEBBQUAA4IBAQCOvRWYdcaYl/qHgif8\nvD4QEQLiy3+Hn5zSLQEcqP/BymhUw4LSGhu8NJxJ26PvlHzAnWa2/OkTCkgSpM4k\nkebO2vyuU8XY/7FeRO3uNktEAp2Aw1RYJ/IqSDvjpg5/hJTHKADrAkiu2SyCJvoO\nqblzBO7TvLj5BBdvcr1/hfWRuAt5NykOww9AMEAzrfLzrF7f98RntOZzIwwX+UvF\nLXQZwc/b55d97Y249pLRQCBnHdaEtZLQTEQulj1zMx2lkH5CrQWGwDCVFuIyt/rN\nzFJGN09McKrWkBZuwPtkkyb+sBVXZX6cEFgHHA+7D91QRH4lbEjjO8OjQgaA6qWN\n5iGN\n-----END CERTIFICATE-----",
'createTime' => Time.now.iso8601,
'expirationTime' => Time.now.iso8601,
}
self.data[:ssl_certs][instance_id][sha1_fingerprint] = data
body = {
'kind' => 'sql#sslCertsInsert',
'serverCaCert' => {
'kind' => 'sql#sslCert',
'instance' => instance_id,
'sha1Fingerprint' => Fog::Mock.random_hex(40),
'commonName' => 'C=US,O=Google\\, Inc,CN=Google Cloud SQL Server CA',
'certSerialNumber' => '0',
'cert' => "-----BEGIN CERTIFICATE-----\nMIIDITCCAgmgAwIBAgIBADANBgkqhkiG9w0BAQUFADBIMSMwIQYDVQQDExpHb29n\nbGUgQ2xvdWQgU1FMIFNlcnZlciBDQTEUMBIGA1UEChMLR29vZ2xlLCBJbmMxCzAJ\nBgNVBAYTAlVTMB4XDTE0MDYwNDA1MjkxMVoXDTI0MDYwMTA1MjkxMVowSDEjMCEG\nA1UEAxMaR29vZ2xlIENsb3VkIFNRTCBTZXJ2ZXIgQ0ExFDASBgNVBAoTC0dvb2ds\nZSwgSW5jMQswCQYDVQQGEwJVUzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC\nggEBALlRjq3zccH5ed6NMfCFcTYd9XxYXyvLurxxjDIA6A7/ymVM9qdQC0uckf7C\nsi4uMi2yfK+PHZ0jXC+g0uPx5RTm+nbKl4I++VOh2g6oZHeNdFt4rVJpr+jzGUMf\nr67SymUr70TQOTEVpx2Ud3rBB2szulxWUSXEy2AGA3uNUGe/IgENh7p56s00Sr97\nTRP1S5/JVMalncgNVLH2nNqBQJZTx9t9qvGatoUfmHUU0+M//J5sXLbgdzeEeeot\nHJUyoXjA2sRkH1+F/d6PpFrcr1I8dVmCBEbTAnm7HpKh5Mx2nRYi+t/y9D2Mblwx\n9dBRfr3WIJ1JDxzt3L8CtBGZbvUCAwEAAaMWMBQwEgYDVR0TAQH/BAgwBgEB/wIB\nADANBgkqhkiG9w0BAQUFAAOCAQEAmHuBecPc265sbd26B1HXUAD6FHdzoZLrAZVW\n+1eIK4E669P4y6LkLuoCkLd64/YwA4K2FioksqgHOahbYWJJYPymy4ae+IPXzXcY\nPv3gmBsKk++sHb64D9Cj/k5n8BEiVmmrsUCUiL75nJAzK+El3hvKKWWl76XX/qHP\nk8ZAxIrn8bCiVOaj6NR4+p1OmcZSPNWxz7j/EwQxoABRxgPgt+B/YRseevww7an2\n/rGs0sk7RE0QDjLfZblYGh+xVPBBLuLmf4L5JNJkFEoeGSWrxTzvXnS+2LZeHdM/\nJ9nsiKu5JKPhMUS0vOcTymOkh8tJ6Np8gwg6ca4g6dT3llE6uQ==\n-----END CERTIFICATE-----",
'createTime' => Time.now.iso8601,
'expirationTime' => Time.now.iso8601,
},
'clientCert' => {
'certInfo' => data,
'certPrivateKey' => "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAvRvWRtfZ/e/BFuW0P0zNRZ2+H3fxUU/FzLNg+Qu/nSixIG3l\nDr2ULeBLEOnAvlFYaCuzeg751wGdTIPgdefV5ao7/DIeUYoXxozwnZcNqRez7uvC\n8mIIb0C4Yu8objXmjfhQXir43FvZNIueADPFG9mv5MQMDLV5tZBrYHNfqpFJcgcX\n59VKCiOQ4b8PyJ8YCNZEv1VJJJPZL9Kv6Mj626BP77korQ6vqR40RcKyEHEuj8/Q\n2B4WVcgw5EyIe7y1zNCREEU9UogPJPuIcFyN1gaj0WUSOB9SpmEkiCr2bXIut0mz\nP6x4rV5BoqRRdZcNIEqn6TPIBt+n5WiEwTyPewIDAQABAoIBAH89e6+vDL4P05vU\ncrMkufldac9CpNxREIXrLBRmE0drWcK4Lqb8Z/d2MwvuPAHSOendfaVi7jf8nhod\noamzk/gz0qieEEhM4jJ2Im/mcwqTKD5Z45Gy5Hn20hm/UTTWj4p2yZySzV93bW4t\nguIf80AJ+I+0WWczs/C2e4kqF/RrIf4ff7UF/2TPS+sEmkTA74APWIMqjkr0cjTP\nrIJCp8jFn/639dVLeHcw2abduZSV8PkQSNdqPeH2P+GpqkYLREPMAw/jPGZYoVli\npQ57cB1THj/juYFYMS7dlJ3hr0pDo6Vw30L6EcE63dvXzJvhOfPXtFufdfanPiey\nUSICtAECgYEA/qP7ZJ9ohqg4D5v9TM4fVlUpo68/jMaWlPPoLQwNXZ81rTN4yOxm\nUJLhDvQCWYZie1jwn9+UA1bdp4PceSbEWh4iM0h4TcxmhHmos6pxGYb/uw6jGLw4\nqjCqDP69/Jgmkfobs4u/h9xtZEHo6u5rrbDZIu0EezL7ArMrSOYVRsMCgYEAvh5K\n4H5EVMhiHnjvbpToOzGjMpqoBr0XSq63Cx45U5on5Bp8oc/iQPnCzpwcrJb4vwRV\nVYYtD/PWpdjzhTVy6SgVnkTKoo6N/Y9vFAYCf67eb4Yu4L8MonlYU2IY7bA3SChw\nesHlwsVZdlNqieWmOuacA8IbgXW4ftbtZDzBuOkCgYEArA8rn+simtJxxwJVHp+s\nhw5Wa3bQDxRkzVMdz8p0AY3BnD3KYKFz5P/KOOth5xIp20TWmoBdKAB7F2S/BdHP\nHUF9RH+0YoU5xEvcVUJW17PjeobCZ8VO2Ji3Xr6Gq3Y3oa2JKEHGckvcUsFCW/Qs\nKBn2LmZO/9wLxeBA4CovuDcCgYAVGTWEDl807Xv+F7uykPHox8xtrD4jaU6xagxE\nPplsDrqIlOvp5TEdttoIpciE2shGIov5zscncw8KHrZ/vPvApkMn6kh2m81kK0vP\ndA9I7jYfOEvxgyI60a6cqlFL53drGZnJ9cSyxcX03LMBFKxK8xazUBJPXqoX4XA8\n5IU3KQKBgQDCPVBZbZcwcfI+fGRZX8DLE61tscK1uy0ySQPmz/tm3ixDAdQNgGvD\nXjyPvMCEtHx7+ZbykLS7SJZG4924LKyGxF9bw5AYTPyxietOUfoqaS8v3kJ03Ebu\nkVDmZkAiMk5E+oGchYsD613QRFjF4nlmrHfxtRqTPqa/OpNDimdG+w==\n-----END RSA PRIVATE KEY-----",
}
}
status = 200
else
body = {
'error' => {
'errors' => [
{
'domain' => 'global',
'reason' => 'notAuthorized',
'message' => 'The client is not authorized to make this request.',
}
],
'code' => 403,
'message' => 'The client is not authorized to make this request.',
}
}
status = 403
end
build_excon_response(body, status)
end
end
end
end
end

View file

@ -0,0 +1,30 @@
module Fog
module Google
class SQL
##
# Lists all backup runs associated with a given instance and configuration in the
# reverse chronological order of the enqueued time
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/backupRuns/list
class Real
def list_backup_runs(instance_id, backup_configuration_id)
api_method = @sql.backup_runs.list
parameters = {
'project' => @project,
'instance' => instance_id,
'backupConfiguration' => backup_configuration_id,
}
request(api_method, parameters)
end
end
class Mock
def list_backup_runs(instance_id, backup_configuration_id)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,143 @@
module Fog
module Google
class SQL
##
# List all available database flags for Google Cloud SQL instances
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/flags/list
class Real
def list_flags
api_method = @sql.flags.list
parameters = {}
request(api_method, parameters)
end
end
class Mock
def list_flags
body = {
'kind' => 'sql#flagsList',
'items' => [
{
'kind' => 'sql#flag',
'name' => 'log_output',
'type' => 'STRING',
'appliesTo' => ['MYSQL_5_5', 'MYSQL_5_6'],
'allowedStringValues' => ['TABLE', 'NONE'],
},
{
'kind' => 'sql#flag',
'name' => 'general_log',
'type' => 'BOOLEAN',
'appliesTo' => ['MYSQL_5_5', 'MYSQL_5_6'],
},
{
'kind' => 'sql#flag',
'name' => 'log_queries_not_using_indexes',
'type' => 'BOOLEAN',
'appliesTo' => ['MYSQL_5_5', 'MYSQL_5_6'],
},
{
'kind' => 'sql#flag',
'name' => 'log_bin_trust_function_creators',
'type' => 'BOOLEAN',
'appliesTo' => ['MYSQL_5_5', 'MYSQL_5_6'],
},
{
'kind' => 'sql#flag',
'name' => 'slow_query_log',
'type' => 'BOOLEAN',
'appliesTo' => ['MYSQL_5_5', 'MYSQL_5_6'],
},
{
'kind' => 'sql#flag',
'name' => 'read_only',
'type' => 'BOOLEAN',
'appliesTo' => ['MYSQL_5_5', 'MYSQL_5_6'],
},
{
'kind' => 'sql#flag',
'name' => 'max_allowed_packet',
'type' => 'INTEGER',
'appliesTo' => ['MYSQL_5_5', 'MYSQL_5_6'],
'minValue' => '16384',
'maxValue' => '1073741824',
},
{
'kind' => 'sql#flag',
'name' => 'long_query_time',
'type' => 'INTEGER',
'appliesTo' => ['MYSQL_5_5', 'MYSQL_5_6'],
'minValue' => '0',
'maxValue' => '30000000',
},
{
'kind' => 'sql#flag',
'name' => 'group_concat_max_len',
'type' => 'INTEGER',
'appliesTo' => ['MYSQL_5_5', 'MYSQL_5_6'],
'minValue' => '4',
'maxValue' => '17179869184',
},
{
'kind' => 'sql#flag',
'name' => 'wait_timeout',
'type' => 'INTEGER',
'appliesTo' => ['MYSQL_5_5', 'MYSQL_5_6'],
'minValue' => '1',
'maxValue' => '31536000',
},
{
'kind' => 'sql#flag',
'name' => 'innodb_lock_wait_timeout',
'type' => 'INTEGER',
'appliesTo' => ['MYSQL_5_5', 'MYSQL_5_6'],
'minValue' => '1',
'maxValue' => '1073741824',
},
{
'kind' => 'sql#flag',
'name' => 'lower_case_table_names',
'type' => 'INTEGER',
'appliesTo' => ['MYSQL_5_5', 'MYSQL_5_6'],
'minValue' => '0',
'maxValue' => '2',
},
{
'kind' => 'sql#flag',
'name' => 'innodb_flush_log_at_trx_commit',
'type' => 'INTEGER',
'appliesTo' => ['MYSQL_5_5', 'MYSQL_5_6'],
'minValue' => '0',
'maxValue' => '2',
},
{
'kind' => 'sql#flag',
'name' => 'skip_show_database',
'type' => 'NONE',
'appliesTo' => ['MYSQL_5_5', 'MYSQL_5_6'],
},
{
'kind' => 'sql#flag',
'name' => 'event_scheduler',
'type' => 'BOOLEAN',
'appliesTo' => ['MYSQL_5_5', 'MYSQL_5_6'],
},
{
'kind' => 'sql#flag',
'name' => 'character_set_server',
'type' => 'STRING',
'appliesTo' => ['MYSQL_5_5', 'MYSQL_5_6'],
'allowedStringValues' => ['utf8', 'utf8mb4'],
},
]
}
build_excon_response(body)
end
end
end
end
end

View file

@ -0,0 +1,32 @@
module Fog
module Google
class SQL
##
# Lists instances under a given project in the alphabetical order of the instance name
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/instances/list
class Real
def list_instances
api_method = @sql.instances.list
parameters = {
'project' => @project,
}
request(api_method, parameters)
end
end
class Mock
def list_instances
body = {
'kind' => 'sql#instancesList',
'items' => self.data[:instances].values,
}
build_excon_response(body)
end
end
end
end
end

View file

@ -0,0 +1,52 @@
module Fog
module Google
class SQL
##
# Lists all instance operations that have been performed on the given Cloud SQL instance
# in the reverse chronological order of the start time
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/operations/list
class Real
def list_operations(instance_id)
api_method = @sql.operations.list
parameters = {
'project' => @project,
'instance' => instance_id,
}
request(api_method, parameters)
end
end
class Mock
def list_operations(instance_id)
if self.data[:operations].has_key?(instance_id)
body = {
'kind' => 'sql#operationsList',
'items' => self.data[:operations][instance_id].values,
}
status = 200
else
body = {
'error' => {
'errors' => [
{
'domain' => 'global',
'reason' => 'notAuthorized',
'message' => 'The client is not authorized to make this request.',
}
],
'code' => 403,
'message' => 'The client is not authorized to make this request.',
}
}
status = 403
end
build_excon_response(body, status)
end
end
end
end
end

View file

@ -0,0 +1,51 @@
module Fog
module Google
class SQL
##
# Lists all of the current SSL certificates for the instance
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/sslCerts/list
class Real
def list_ssl_certs(instance_id)
api_method = @sql.ssl_certs.list
parameters = {
'project' => @project,
'instance' => instance_id,
}
request(api_method, parameters)
end
end
class Mock
def list_ssl_certs(instance_id)
if self.data[:ssl_certs].has_key?(instance_id)
body = {
'kind' => 'sql#sslCertsList',
'items' => self.data[:ssl_certs][instance_id].values,
}
status = 200
else
body = {
'error' => {
'errors' => [
{
'domain' => 'global',
'reason' => 'notAuthorized',
'message' => 'The client is not authorized to make this request.',
}
],
'code' => 403,
'message' => 'The client is not authorized to make this request.',
}
}
status = 403
end
build_excon_response(body, status)
end
end
end
end
end

View file

@ -0,0 +1,49 @@
module Fog
module Google
class SQL
##
# Deletes all client certificates and generates a new server SSL certificate for the instance.
# The changes will not take effect until the instance is restarted. Existing instances without
# a server certificate will need to call this once to set a server certificate
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/instances/resetSslConfig
class Real
def reset_instance_ssl_config(instance_id)
api_method = @sql.instances.reset_ssl_config
parameters = {
'project' => @project,
'instance' => instance_id,
}
request(api_method, parameters)
end
end
class Mock
def reset_instance_ssl_config(instance_id)
operation = self.random_operation
self.data[:operations][instance_id] ||= {}
self.data[:operations][instance_id][operation] = {
'kind' => 'sql#instanceOperation',
'instance' => instance_id,
'operation' => operation,
'operationType' => 'UPDATE',
'state' => Fog::Google::SQL::Operation::DONE_STATE,
'userEmailAddress' => 'google_client_email@developer.gserviceaccount.com',
'enqueuedTime' => Time.now.iso8601,
'startTime' => Time.now.iso8601,
'endTime' => Time.now.iso8601,
}
body = {
'kind' => 'sql#instancesResetSslConfig',
'operation' => operation,
}
build_excon_response(body)
end
end
end
end
end

View file

@ -0,0 +1,47 @@
module Fog
module Google
class SQL
##
# Restarts a Cloud SQL instance
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/instances/restart
class Real
def restart_instance(instance_id)
api_method = @sql.instances.restart
parameters = {
'project' => @project,
'instance' => instance_id,
}
request(api_method, parameters)
end
end
class Mock
def restart_instance(instance_id)
operation = self.random_operation
self.data[:operations][instance_id] ||= {}
self.data[:operations][instance_id][operation] = {
'kind' => 'sql#instanceOperation',
'instance' => instance_id,
'operation' => operation,
'operationType' => 'RESTART',
'state' => Fog::Google::SQL::Operation::DONE_STATE,
'userEmailAddress' => 'google_client_email@developer.gserviceaccount.com',
'enqueuedTime' => Time.now.iso8601,
'startTime' => Time.now.iso8601,
'endTime' => Time.now.iso8601,
}
body = {
'kind' => 'sql#instancesRestart',
'operation' => operation,
}
build_excon_response(body)
end
end
end
end
end

View file

@ -0,0 +1,30 @@
module Fog
module Google
class SQL
##
# Restores a backup of a Cloud SQL instance
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/instances/restoreBackup
class Real
def restore_instance_backup(identity, backup_configuration, due_time)
api_method = @sql.instances.reset_ssl_config
parameters = {
'project' => @project,
'instance' => identity,
'backupConfiguration' => backup_configuration,
'dueTime' => due_time,
}
request(api_method, parameters)
end
end
class Mock
def restore_instance_backup(identity, backup_configuration, due_time)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,54 @@
module Fog
module Google
class SQL
##
# Sets the password for the root user
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/instances/setRootPassword
class Real
def set_instance_root_password(instance_id, password)
api_method = @sql.instances.set_root_password
parameters = {
'project' => @project,
'instance' => instance_id,
}
body = {
'setRootPasswordContext' => {
'kind' => 'sql#setRootUserContext',
'password' => password,
}
}
request(api_method, parameters, body)
end
end
class Mock
def set_instance_root_password(instance_id, password)
operation = self.random_operation
self.data[:operations][instance_id] ||= {}
self.data[:operations][instance_id][operation] = {
'kind' => 'sql#instanceOperation',
'instance' => instance_id,
'operation' => operation,
'operationType' => 'INJECT_USER',
'state' => Fog::Google::SQL::Operation::DONE_STATE,
'userEmailAddress' => 'google_client_email@developer.gserviceaccount.com',
'enqueuedTime' => Time.now.iso8601,
'startTime' => Time.now.iso8601,
'endTime' => Time.now.iso8601,
}
body = {
'kind' => 'sql#instancesSetRootPassword',
'operation' => operation,
}
build_excon_response(body)
end
end
end
end
end

View file

@ -0,0 +1,132 @@
module Fog
module Google
class SQL
##
# Updates settings of a Cloud SQL instance
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/instances/update
class Real
def update_instance(instance_id, settings_version, tier, options = {})
api_method = @sql.instances.update
parameters = {
'project' => @project,
'instance' => instance_id,
}
body = {
'project' => @project,
'instance' => instance_id,
'settings' => {
'settingsVersion' => settings_version,
'tier' => tier,
}
}
if options[:activation_policy]
body['settings']['activationPolicy'] = options[:activation_policy]
end
if options[:autorized_gae_applications]
body['settings']['authorizedGaeApplications'] = Array(options[:autorized_gae_applications])
end
if options[:backup_configuration]
body['settings']['backupConfiguration'] = options[:backup_configuration]
end
if options[:ip_configuration_authorized_networks]
body['settings']['ipConfiguration'] ||= {}
body['settings']['ipConfiguration']['authorizedNetworks'] = Array(options[:ip_configuration_authorized_networks])
end
if options[:ip_configuration_enabled]
body['settings']['ipConfiguration'] ||= {}
body['settings']['ipConfiguration']['enabled'] = options[:ip_configuration_enabled]
end
if options[:ip_configuration_require_ssl]
body['settings']['ipConfiguration'] ||= {}
body['settings']['ipConfiguration']['requireSsl'] = options[:ip_configuration_require_ssl]
end
if options[:location_preference_zone_follow_gae_application]
body['settings']['locationPreference'] ||= {}
body['settings']['locationPreference']['followGaeApplication'] = options[:location_preference_zone_follow_gae_application]
end
if options[:location_preference_zone]
body['settings']['locationPreference'] ||= {}
body['settings']['locationPreference']['zone'] = options[:location_preference_zone]
end
if options[:pricing_plan]
body['settings']['pricingPlan'] = options[:pricing_plan]
end
if options[:replication_type]
body['settings']['replicationType'] = options[:replication_type]
end
request(api_method, parameters, body)
end
end
class Mock
def update_instance(instance_id, settings_version, tier, options = {})
data = self.data[:instances][instance_id]
data['tier'] = tier
if options[:activation_policy]
data['settings']['activationPolicy'] = options[:activation_policy]
end
if options[:autorized_gae_applications]
data['settings']['authorizedGaeApplications'] = Array(options[:autorized_gae_applications])
end
if options[:backup_configuration]
data['settings']['backupConfiguration'] = options[:backup_configuration]
end
if options[:ip_configuration_authorized_networks]
data['settings']['ipConfiguration'] ||= {}
data['settings']['ipConfiguration']['authorizedNetworks'] = Array(options[:ip_configuration_authorized_networks])
end
if options[:ip_configuration_enabled]
data['settings']['ipConfiguration'] ||= {}
data['settings']['ipConfiguration']['enabled'] = options[:ip_configuration_enabled]
end
if options[:ip_configuration_require_ssl]
data['settings']['ipConfiguration'] ||= {}
data['settings']['ipConfiguration']['requireSsl'] = options[:ip_configuration_require_ssl]
end
if options[:location_preference_zone_follow_gae_application]
data['settings']['locationPreference'] ||= {}
data['settings']['locationPreference']['followGaeApplication'] = options[:location_preference_zone_follow_gae_application]
end
if options[:location_preference_zone]
data['settings']['locationPreference'] ||= {}
data['settings']['locationPreference']['zone'] = options[:location_preference_zone]
end
if options[:pricing_plan]
data['settings']['pricingPlan'] = options[:pricing_plan]
end
if options[:replication_type]
data['settings']['replicationType'] = options[:replication_type]
end
self.data[:instances][instance_id] = data
operation = self.random_operation
self.data[:operations][instance_id] ||= {}
self.data[:operations][instance_id][operation] = {
'kind' => 'sql#instanceOperation',
'instance' => instance_id,
'operation' => operation,
'operationType' => 'UPDATE',
'state' => Fog::Google::SQL::Operation::DONE_STATE,
'userEmailAddress' => 'google_client_email@developer.gserviceaccount.com',
'enqueuedTime' => Time.now.iso8601,
'startTime' => Time.now.iso8601,
'endTime' => Time.now.iso8601,
}
body = {
'kind' => 'sql#instancesUpdate',
'operation' => operation,
}
status = 200
build_excon_response(body, status)
end
end
end
end
end

View file

@ -16,6 +16,26 @@ module Fog
# MODELS
model_path 'fog/google/models/sql'
# Backup Run
model :backup_run
collection :backup_runs
# Flag
model :flag
collection :flags
# Instance
model :instance
collection :instances
# Operation
model :operation
collection :operations
# SSL Certificate
model :ssl_cert
collection :ssl_certs
# Tier
model :tier
collection :tiers
@ -24,6 +44,37 @@ module Fog
# REQUESTS
request_path 'fog/google/requests/sql'
# Backup Run
request :get_backup_run
request :list_backup_runs
# Flag
request :list_flags
# Instance
request :clone_instance
request :delete_instance
request :export_instance
request :get_instance
request :import_instance
request :insert_instance
request :list_instances
request :reset_instance_ssl_config
request :restart_instance
request :restore_instance_backup
request :set_instance_root_password
request :update_instance
# Operation
request :get_operation
request :list_operations
# SSL Certificate
request :delete_ssl_cert
request :get_ssl_cert
request :insert_ssl_cert
request :list_ssl_certs
# Tier
request :list_tiers

View file

@ -0,0 +1,12 @@
Shindo.tests('Fog::Google[:sql] | flags model', ['google']) do
@flags = Fog::Google[:sql].tiers
tests('success') do
tests('#all').succeeds do
@flags.all
end
end
end

View file

@ -0,0 +1,56 @@
Shindo.tests('Fog::Google[:sql] | instance model', ['google']) do
@instances = Fog::Google[:sql].instances
tests('success') do
tests('#create').succeeds do
@instance = @instances.create(:instance => Fog::Mock.random_letters(16), :tier => 'D1')
@instance.wait_for { ready? }
end
tests('#update').succeeds do
@instance.activation_policy = 'ALWAYS'
@instance.update
@instance.wait_for { ready? }
end
tests('#clone').succeeds do
pending unless Fog.mocking? # Binary log must be activated
instance_cloned_id = Fog::Mock.random_letters(16)
@instance.clone(instance_cloned_id, :async => false)
@instances.get(instance_cloned_id).destroy
end
tests('#export').succeeds do
pending unless Fog.mocking? # We don't have access to a Google Cloud Storage bucket
@instance.export("gs://#{Fog::Mock.random_letters_and_numbers(16)}/mysql-export", :async => false)
end
tests('#import').succeeds do
pending unless Fog.mocking? # We don't have access to a Google Cloud Storage bucket
@instance.import("gs://#{Fog::Mock.random_letters_and_numbers(16)}/mysql-export", :async => false)
end
tests('#ready?').succeeds do
@instance.ready? == true
end
tests('#reset_ssl_config').succeeds do
@instance.reset_ssl_config(:async => false)
end
tests('#restart').succeeds do
@instance.restart(:async => false)
end
tests('#set_root_password').succeeds do
@instance.set_root_password(Fog::Mock.random_letters_and_numbers(8), :async => false)
end
tests('#destroy').succeeds do
@instance.destroy
end
end
end

View file

@ -0,0 +1,32 @@
Shindo.tests('Fog::Google[:sql] | instances model', ['google']) do
@instance = Fog::Google[:sql].instances.create(:instance => Fog::Mock.random_letters(16), :tier => 'D1')
@instance.wait_for { ready? }
@instances = Fog::Google[:sql].instances
tests('success') do
tests('#all').succeeds do
@instances.all
end
tests('#get').succeeds do
@instances.get(@instance.instance)
end
end
@instance.destroy(:async => false)
tests('failure') do
tests('#all').returns([]) do
@instances.all
end
tests('#get').returns(nil) do
@instances.get(Fog::Mock.random_letters_and_numbers(16))
end
end
end

View file

@ -0,0 +1,25 @@
Shindo.tests('Fog::Google[:sql] | operation model', ['google']) do
@instance = Fog::Google[:sql].instances.create(:instance => Fog::Mock.random_letters(16), :tier => 'D1')
@instance.wait_for { ready? }
@operations = Fog::Google[:sql].operations
@operation = @operations.all(@instance.instance).first
tests('success') do
tests('#pending?').succeeds do
@operation.pending? == false
end
tests('#ready?').succeeds do
@operation.ready? == true
end
tests('#reload').succeeds do
@operation.reload
end
end
@instance.destroy
end

View file

@ -0,0 +1,38 @@
Shindo.tests('Fog::Google[:sql] | operations model', ['google']) do
@instance = Fog::Google[:sql].instances.create(:instance => Fog::Mock.random_letters(16), :tier => 'D1')
@instance.wait_for { ready? }
@operations = Fog::Google[:sql].operations
tests('success') do
tests('#all').succeeds do
@operations.all(@instance.instance)
end
tests('#get').succeeds do
@operations.get(@instance.instance, @operations.all(@instance.instance).first.operation)
end
end
tests('failure') do
tests('#all').returns([]) do
@operations.all(Fog::Mock.random_letters_and_numbers(16))
end
tests('#get').returns(nil) do
pending unless Fog.mocking? # Real test fails on google-api-client (mismatch between catalog and real response)
@operations.get(@instance.instance, Fog::Mock.random_letters_and_numbers(16))
end
tests('#get').returns(nil) do
pending unless Fog.mocking? # Real test fails on google-api-client (mismatch between catalog and real response)
@operations.get(Fog::Mock.random_letters_and_numbers(16), Fog::Mock.random_letters_and_numbers(16))
end
end
@instance.destroy
end

View file

@ -0,0 +1,24 @@
Shindo.tests('Fog::Google[:sql] | ssl_cert model', ['google']) do
@instance = Fog::Google[:sql].instances.create(:instance => Fog::Mock.random_letters(16), :tier => 'D1')
@instance.wait_for { ready? }
@ssl_certs = Fog::Google[:sql].ssl_certs
tests('success') do
tests('#create').succeeds do
@ssl_cert = @ssl_certs.create(:instance => @instance.instance, :common_name => Fog::Mock.random_letters(16))
end
tests('#reload').succeeds do
@ssl_cert.reload
end
tests('#destroy').succeeds do
@ssl_cert.destroy
end
end
@instance.destroy
end

View file

@ -0,0 +1,39 @@
Shindo.tests('Fog::Google[:sql] | ssl_certs model', ['google']) do
@instance = Fog::Google[:sql].instances.create(:instance => Fog::Mock.random_letters(16), :tier => 'D1')
@instance.wait_for { ready? }
@ssl_cert = Fog::Google[:sql].ssl_certs.create(:instance => @instance.instance,
:common_name => Fog::Mock.random_letters(16))
@ssl_certs = Fog::Google[:sql].ssl_certs
tests('success') do
tests('#all').succeeds do
@ssl_certs.all(@instance.instance)
end
tests('#get').succeeds do
@ssl_certs.get(@instance.instance, @ssl_cert.sha1_fingerprint)
end
end
tests('failure') do
tests('#all').returns([]) do
@ssl_certs.all(Fog::Mock.random_letters_and_numbers(16))
end
tests('#get').returns(nil) do
@ssl_certs.get(@instance.instance, Fog::Mock.random_letters_and_numbers(16))
end
tests('#get').returns(nil) do
@ssl_certs.get(Fog::Mock.random_letters_and_numbers(16), Fog::Mock.random_letters_and_numbers(16))
end
end
@ssl_cert.destroy
@instance.destroy
end

View file

@ -0,0 +1,27 @@
Shindo.tests('Fog::Google[:sql] | flag requests', ['google']) do
@sql = Fog::Google[:sql]
@get_flag_format = {
'name' => String,
'allowedStringValues' => Fog::Nullable::Array,
'appliesTo' => Array,
'kind' => String,
'maxValue' => Fog::Nullable::String,
'minValue' => Fog::Nullable::String,
'type' => String,
}
@list_flags_format = {
'kind' => String,
'items' => [@get_flag_format],
}
tests('success') do
tests('#list_flags').formats(@list_flags_format) do
@sql.list_flags.body
end
end
end

View file

@ -0,0 +1,129 @@
Shindo.tests('Fog::Google[:sql] | instance requests', ['google']) do
@sql = Fog::Google[:sql]
@instance_id = Fog::Mock.random_letters(16)
@insert_instance_format = {
'kind' => String,
'operation' => String,
}
@get_instance_format = {
'instance' => String,
'currentDiskSize' => Fog::Nullable::String,
'databaseVersion' => String,
'etag' => String,
'ipAddresses' => Fog::Nullable::String,
'kind' => String,
'maxDiskSize' => String,
'project' => String,
'region' => String,
'serverCaCert' => Hash,
'settings' => Hash,
'state' => String,
}
@list_instances_format = {
'kind' => String,
'items' => [@get_instance_format],
}
@clone_instance_format = {
'kind' => String,
'operation' => String,
}
@export_instance_format = {
'kind' => String,
'operation' => String,
}
@import_instance_format = {
'kind' => String,
'operation' => String,
}
@reset_instance_ssl_config_format = {
'kind' => String,
'operation' => String,
}
@restart_instance_format = {
'kind' => String,
'operation' => String,
}
@set_instance_root_password_format = {
'kind' => String,
'operation' => String,
}
@update_instance_format = {
'kind' => String,
'operation' => String,
}
@delete_instance_format = {
'kind' => String,
'operation' => String,
}
tests('success') do
tests('#insert_instance').formats(@insert_instance_format) do
result = @sql.insert_instance(@instance_id, 'D1').body
@sql.instances.get(@instance_id).wait_for { ready? }
result
end
tests('#list_instances').formats(@list_instances_format) do
@sql.list_instances.body
end
tests('#get_instance').formats(@get_instance_format) do
@sql.get_instance(@instance_id).body
end
tests('#update_instance').formats(@update_instance_format) do
instance = @sql.instances.get(@instance_id)
@sql.update_instance(instance.instance, instance.settings_version, instance.tier, instance.attributes).body
end
tests('#clone_instance').formats(@clone_instance_format) do
pending unless Fog.mocking? # Binary log must be activated
instance_cloned_id = Fog::Mock.random_letters(16)
clone_instance_format = @sql.clone_instance(@instance_id, instance_cloned_id).body
@sql.delete_instance(instance_cloned_id)
clone_instance_format
end
tests('#export_instance').formats(@export_instance_format) do
pending unless Fog.mocking? # We don't have access to a Google Cloud Storage bucket
@sql.export_instance(@instance_id, "gs://#{Fog::Mock.random_letters_and_numbers(16)}/mysql-export").body
end
tests('#import_instance').formats(@import_instance_format) do
pending unless Fog.mocking? # We don't have access to a Google Cloud Storage bucket
@sql.import_instance(@instance_id, "gs://#{Fog::Mock.random_letters_and_numbers(16)}/mysql-export").body
end
tests('#reset_instance_ssl_config').formats(@reset_instance_ssl_config_format) do
@sql.reset_instance_ssl_config(@instance_id).body
end
tests('#set_instance_root_password').formats(@set_instance_root_password_format) do
@sql.set_instance_root_password(@instance_id, Fog::Mock.random_letters_and_numbers(8)).body
end
tests('#restart_instance').formats(@restart_instance_format) do
result = @sql.restart_instance(@instance_id).body
@sql.operations.get(@instance_id, result['operation']).wait_for { ready? }
result
end
tests('#delete_instance').formats(@delete_instance_format) do
@sql.delete_instance(@instance_id).body
end
end
end

View file

@ -0,0 +1,42 @@
Shindo.tests('Fog::Google[:sql] | operation requests', ['google']) do
@sql = Fog::Google[:sql]
@instance_id = Fog::Mock.random_letters(16)
@instance = @sql.instances.create(:instance => @instance_id, :tier => 'D1')
@instance.wait_for { ready? }
@get_operation_format = {
'operation' => String,
'endTime' => Fog::Nullable::String,
'enqueuedTime' => String,
'error' => Fog::Nullable::Array,
'exportContext' => Fog::Nullable::Array,
'importContext' => Fog::Nullable::Array,
'instance' => String,
'kind' => String,
'operationType' => String,
'startTime' => Fog::Nullable::String,
'state' => String,
'userEmailAddress' => String,
}
@list_operations_format = {
'kind' => String,
'items' => [@get_operation_format],
}
tests('success') do
tests('#list_operations').formats(@list_operations_format) do
@sql.list_operations(@instance_id).body
end
tests('#get_operation').formats(@get_operation_format) do
operation_id = @sql.operations.all(@instance_id).first.operation
@sql.get_operation(@instance_id, operation_id).body
end
end
@instance.destroy
end

View file

@ -0,0 +1,61 @@
Shindo.tests('Fog::Google[:sql] | ssl_cert requests', ['google']) do
@sql = Fog::Google[:sql]
@instance_id = Fog::Mock.random_letters(16)
@instance = @sql.instances.create(:instance => @instance_id, :tier => 'D1')
@instance.wait_for { ready? }
@get_ssl_cert_format = {
'sha1Fingerprint' => String,
'cert' => String,
'certSerialNumber' => String,
'commonName' => String,
'createTime' => String,
'expirationTime' => Fog::Nullable::String,
'instance' => String,
'kind' => String,
}
@insert_ssl_cert_format = {
'kind' => String,
'serverCaCert' => @get_ssl_cert_format,
'clientCert' => {
'certInfo' => @get_ssl_cert_format,
'certPrivateKey' => String,
},
}
@list_ssl_certs_format = {
'kind' => String,
'items' => [@get_ssl_cert_format],
}
@delete_ssl_cert_format = {
'kind' => String,
'operation' => String,
}
tests('success') do
tests('#insert_ssl_cert').formats(@insert_ssl_cert_format) do
@sql.insert_ssl_cert(@instance_id, Fog::Mock.random_letters(16)).body
end
tests('#list_ssl_certs').formats(@list_ssl_certs_format) do
@sql.list_ssl_certs(@instance_id).body
end
tests('#get_ssl_cert').formats(@get_ssl_cert_format) do
sha1_fingerprint = @sql.ssl_certs.all(@instance_id).first.sha1_fingerprint
@sql.get_ssl_cert(@instance_id, sha1_fingerprint).body
end
tests('#delete_ssl_cert').formats(@delete_ssl_cert_format) do
sha1_fingerprint = @sql.ssl_certs.all(@instance_id).first.sha1_fingerprint
@sql.delete_ssl_cert(@instance_id, sha1_fingerprint).body
end
end
@instance.destroy
end