Module: GClouder::Resources::Project::IAMPolicyBinding::Remote

Includes:
Config::Project, GCloud, Logging
Defined in:
lib/gclouder/resources/project/iam_policy_binding.rb

Class Method Summary collapse

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 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 GCloud

#gcloud, included, #verify

Methods included from Config::CLIArgs

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

Methods included from Shell

included, #shell

Class Method Details

.listObject



259
260
261
262
263
264
265
# File 'lib/gclouder/resources/project/iam_policy_binding.rb', line 259

def self.list
  resources.each_with_object({ "global" => [] }) do |data, collection|
    data["name"] = data["role"].gsub("roles/", "")
    data.delete("role")
    collection["global"] << data
  end
end

.policy_member?(project, role, member) ⇒ Boolean

Returns:



271
272
273
274
275
276
# File 'lib/gclouder/resources/project/iam_policy_binding.rb', line 271

def self.policy_member?(project, role, member)
  bindings = gcloud("--format json projects get-iam-policy #{project} | jq '.bindings[] | select(.role == \"roles/#{role}\")'", force: true)
  return false if bindings.empty?
  fatal "could not get policy bindings for project: #{project}" unless bindings.key?("members")
  bindings["members"].include?(member["name"])
end

.project_idObject



278
279
280
# File 'lib/gclouder/resources/project/iam_policy_binding.rb', line 278

def self.project_id
  project["project_id"]
end

.resourcesObject



267
268
269
# File 'lib/gclouder/resources/project/iam_policy_binding.rb', line 267

def self.resources
  gcloud("--format json projects get-iam-policy #{project_id} | jq .bindings", force: true)
end