Module: GClouder::GCloud
- Includes:
- Config::CLIArgs, Config::Project, Helpers, Logging, Shell
- Included in:
- Resource, Resource::Find, Resources::Compute::Addresses, Resources::Compute::BGPVPNs, Resources::Compute::BGPVPNs::BGPVPN, Resources::Compute::BackendBuckets, Resources::Compute::BackendBuckets::BackendBucket, Resources::Compute::FirewallRules, Resources::Compute::FirewallRules::Rule, Resources::Compute::ForwardingRules::Rule, Resources::Compute::Networks::Network, Resources::Compute::ProjectInfo::Key, Resources::Compute::ProjectInfo::SSHKeys::Remote, Resources::Compute::TargetHTTPSProxies, Resources::Compute::TargetHTTPSProxies::Rule, Resources::Compute::URLMaps, Resources::Compute::URLMaps::PathMatcher, Resources::Compute::URLMaps::URLMap, Resources::Compute::VPNs, Resources::Compute::VPNs::VPN, Resources::Container::Clusters::Cluster, Resources::Container::NodePools, Resources::Container::NodePools::NodePool, Resources::DNS, Resources::DNS::Records, Resources::Functions::Function::Function, Resources::Logging::Sinks::Sink, Resources::Project, Resources::Project::IAMPolicyBinding, Resources::Project::IAMPolicyBinding::Binding, Resources::Project::IAMPolicyBinding::Local, Resources::Project::IAMPolicyBinding::Remote, Resources::Project::Local, Resources::PubSub::Subscriptions::Subscription, Resources::PubSub::Topics::Topic, Resources::RuntimeConfig::Configs::ConfigObject, Resources::RuntimeConfig::Variables::Variable
- Defined in:
- lib/gclouder/gcloud.rb
Class Method Summary collapse
Instance Method Summary collapse
- #gcloud(command, force: false, failure: true, silent: false, project_id: nil, config_relative: false) ⇒ Object
- #verify(project_id) ⇒ Object
Methods included from Config::CLIArgs
check, #cli_args, cli_args, load, valid_resources
Methods included from Config::Project
Methods included from Helpers
#hash_to_args, #module_exists?, #to_arg, #to_deep_merge_hash, #valid_json?
Methods included from Logging
#add, #bad, #change, #debug, #error, #fatal, #good, #info, log, loggers, #remove, report, #resource_state, setup, #warn, #warning
Methods included from Shell
Class Method Details
.included(klass) ⇒ Object
11 12 13 |
# File 'lib/gclouder/gcloud.rb', line 11 def self.included(klass) klass.extend GCloud end |
Instance Method Details
#gcloud(command, force: false, failure: true, silent: false, project_id: nil, config_relative: false) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/gclouder/gcloud.rb', line 15 def gcloud(command, force: false, failure: true, silent: false, project_id: nil, config_relative: false) project_id = verify(project_id) GClouder::Project::ID.switch(project_id) if cli_args[:dry_run] && !force debug "# gcloud --quiet --format json --project=#{project_id} #{command}" if cli_args[:debug] GClouder::Project::ID.reset return end if config_relative Dir.chdir(File.dirname(GClouder::Config::CLIArgs.cli_args[:config])) do result = shell("gcloud --quiet --format json --project=#{project_id} #{command}", failure: failure, silent: silent) end else result = shell("gcloud --quiet --format json --project=#{project_id} #{command}", failure: failure, silent: silent) end GClouder::Project::ID.reset valid_json?(result) ? JSON.parse(result.to_s) : result end |
#verify(project_id) ⇒ Object
39 40 41 42 43 |
# File 'lib/gclouder/gcloud.rb', line 39 def verify(project_id) project_id ||= project["project_id"] return project_id if project_id raise StandardError, "project_id not detected" end |