Class: Google::Cloud::Gemserver::CLI::CloudSQL

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/gemserver/cli/cloud_sql.rb

Overview

CloudSQL

CloudSQL manages the creation of a Cloud SQL instance as well as the necessary database and user creation.

Constant Summary collapse

SCOPES =

Permits SQL admin operations with the Cloud SQL API.

["https://www.googleapis.com/auth/sqlservice.admin"]
.freeze
SQL =

An alias for the SqladminV1beta4 module.

Google::Apis::SqladminV1beta4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inst = nil) ⇒ CloudSQL

Creates a CloudSQL object and loads the necessary configuration settings.

Parameters:

  • inst (String) (defaults to: nil)

    Name of the instance to be used. Optional.



76
77
78
79
80
81
82
83
84
# File 'lib/google/cloud/gemserver/cli/cloud_sql.rb', line 76

def initialize inst = nil
  auth = Google::Auth.get_application_default SCOPES
  Google::Apis::RequestOptions.default.authorization = auth
  @config = Configuration.new
  @service     = SQL::SQLAdminService.new
  @inst        = inst || "instance-#{SecureRandom.uuid}".freeze
  @custom      = inst ? true : false
  load_config
end

Instance Attribute Details

#dbString (readonly)

The name of the database used to store gemserver data.

Returns:

  • (String)


44
45
46
# File 'lib/google/cloud/gemserver/cli/cloud_sql.rb', line 44

def db
  @db
end

#instString (readonly)

The name of the Cloud SQL instance.

Returns:

  • (String)


64
65
66
# File 'lib/google/cloud/gemserver/cli/cloud_sql.rb', line 64

def inst
  @inst
end

#proj_idString (readonly)

The project ID of the project the gemserver will be deployed to.

Returns:

  • (String)


59
60
61
# File 'lib/google/cloud/gemserver/cli/cloud_sql.rb', line 59

def proj_id
  @proj_id
end

#pwdString (readonly)

The password of the default user created to access the database.

Returns:

  • (String)


54
55
56
# File 'lib/google/cloud/gemserver/cli/cloud_sql.rb', line 54

def pwd
  @pwd
end

#serviceGoogle::Apis::SqladminV1beta4::SQLAdminService (readonly)

The Cloud SQL API used to manage Cloud SQL instances.

Returns:

  • (Google::Apis::SqladminV1beta4::SQLAdminService)


69
70
71
# File 'lib/google/cloud/gemserver/cli/cloud_sql.rb', line 69

def service
  @service
end

#userString (readonly)

The name of the default user created to access the database.

Returns:

  • (String)


49
50
51
# File 'lib/google/cloud/gemserver/cli/cloud_sql.rb', line 49

def user
  @user
end

Instance Method Details

#runObject

Prepares a Cloud SQL instance with a database and user. Also saves the database settings in the appropriate configuration file.



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/google/cloud/gemserver/cli/cloud_sql.rb', line 89

def run
  create_instance do |instance_op|
    run_sql_task instance_op if instance_op.class == SQL::Operation
    update_root_user
    create_db do |db_op|
      run_sql_task db_op
      create_user
    end
  end
  update_config
end