class Google::Cloud::Gemserver::CLI::Project
# Project
Attributes
config[RW]
The Configuration
object storing the settings used by the Project
object. @return [Configuration]
Public Class Methods
new(name = nil)
click to toggle source
Initializes the project name and Configuration
object.
# File lib/google/cloud/gemserver/cli/project.rb, line 43 def initialize name = nil @proj_name = name @config = Configuration.new end
Public Instance Methods
create()
click to toggle source
Fetches a reference to the given project on Google
Cloud
Platform and prompts the user to configure it correctly.
# File lib/google/cloud/gemserver/cli/project.rb, line 51 def create raise "Project name was not provided!" unless @proj_name begin @config.update_config @proj_name, :proj_id create_gae_project enable_api enable_billing project rescue Google::Cloud::PermissionDeniedError, RuntimeError => e puts "Permission denied. You might not be authorized with " \ "gcloud. Read github.com/GoogleCloudPlatform/google-cloud`." \ "-ruby/google-cloud-gemserver/docs/authentication.md for " \ "more information on how to get authenticated." puts "If you still get this error the Cloud Resource Manager " \ "API might not be enabled." abort "More details: #{e.message}" end end
Private Instance Methods
create_gae_project()
click to toggle source
@private Checks if the current Google
Cloud
Platform project contains a Google
App Engine project. If not, one is created.
# File lib/google/cloud/gemserver/cli/project.rb, line 75 def create_gae_project return if project_exists? puts "Required Google App Engine project does not exist." system "gcloud app create --project #{@proj_name}" end
enable_api()
click to toggle source
@private Prompts the user to enable necessary APIs for the gemserver to work as intended.
@return [String]
# File lib/google/cloud/gemserver/cli/project.rb, line 112 def enable_api puts "\nEnable the Google Cloud SQL API if it is not already "\ "enabled by visiting:\n https://console.developers.google.com"\ "/apis/api/sqladmin.googleapis.com/overview?"\ "project=#{@proj_name} and clicking \"Enable\"" puts "\nEnable the Google Cloud Resource manager API if it is not"\ "already enabled by visiting:\nhttps://console.developers.google"\ ".com/apis/api/cloudresourcemanager.googleapis.com/overview?"\ "project=#{@proj_name} and clicking \"Enable\"" puts "\nEnable the Google App Engine Admin API if it is not "\ "already enabled by visiting:\nhttps://console.developers.google"\ ".com/apis/api/appengine.googleapis.com/overview?"\ "project=#{@proj_name} and clicking \"Enable\"" prompt_user end
enable_billing()
click to toggle source
@private Prompts the user to enable billing such that the gemserver work as intended.
@return [String]
# File lib/google/cloud/gemserver/cli/project.rb, line 133 def enable_billing puts "\nEnable billing for the project you just created by "\ "visiting: \nconsole.cloud.google.com/billing?project="\ "#{@proj_name}\nand setting up a billing account." prompt_user end
project()
click to toggle source
project_exists?()
click to toggle source
@private Checks if a Google
App Engine project exists.
@return [Boolean]
# File lib/google/cloud/gemserver/cli/project.rb, line 85 def project_exists? system "gcloud app describe --project #{@proj_name} >/dev/null 2>&1" end
prompt_user()
click to toggle source
@private Prompts the user to press enter.
@return [String]
# File lib/google/cloud/gemserver/cli/project.rb, line 93 def prompt_user puts "\nPress enter to continue..." STDIN.gets end