Module: GClouder::Resources::Storage::Buckets::Bucket

Includes:
Config::CLIArgs, GSUtil
Defined in:
lib/gclouder/resources/storage/buckets.rb

Class Method Summary collapse

Methods included from Config::CLIArgs

check, #cli_args, cli_args, included, load, valid_resources

Methods included from GSUtil

#gsutil, #gsutil_exec, included

Methods included from Config::Project

load, #project, project

Methods included from Helpers

#hash_to_args, included, #module_exists?, #to_arg, #to_deep_merge_hash, #valid_json?

Methods included from Logging

#add, #bad, #change, #debug, #error, #fatal, #good, included, #info, log, loggers, #remove, report, #resource_state, setup, #warn, #warning

Methods included from Shell

included, #shell

Class Method Details

.check_exists?(region, bucket_name) ⇒ Boolean

Returns:



85
86
87
# File 'lib/gclouder/resources/storage/buckets.rb', line 85

def self.check_exists?(region, bucket_name)
  gsutil_exec("ls", "-p #{project['project_id']} gs://#{bucket_name} > /dev/null 2>&1 && echo 0 || echo 1").to_i == 0
end

.ensure(region, bucket) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/gclouder/resources/storage/buckets.rb', line 89

def self.ensure(region, bucket)
  if check_exists?(region, bucket["name"])
    good bucket["name"]
    return
  end

  add "#{bucket["name"]} [#{bucket["default_access"]}]"
  gsutil "mb", "-p #{project['project_id']} -l #{region} gs://#{bucket["name"]}"

  setDefaultAccess bucket["name"], bucket["default_access"] if bucket.key?("default_access")
end

.setDefaultAccess(bucket_name, default_access) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/gclouder/resources/storage/buckets.rb', line 77

def self.setDefaultAccess(bucket_name, default_access)
  info "# gsutil defacl ch -u #{default_access} gs://#{bucket_name}" if cli_args[:debug]

  return if cli_args[:dry_run]

  gsutil "defacl ch", "-u #{default_access} gs://#{bucket_name}"
end