Module: GClouder::Resources::Storage::Notifications::Notification

Includes:
Config::CLIArgs, GSUtil
Defined in:
lib/gclouder/resources/storage/notifications.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

.ensure(notification) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/gclouder/resources/storage/notifications.rb', line 74

def self.ensure(notification)
  if notification_exists?(notification)
    good "notification topic: projects/#{notification["project"]}/topics/#{notification["name"]}; bucket: #{notification["bucket"]}", indent: 4
    return
  end

  event_type_args = ""
  if notification.has_key?("events")
    event_type_args = "-e #{notification["events"].join(",")}"
  end
  prefix_arg = ""
  if notification.has_key?("prefix")
    prefix_arg = "-p #{notification["prefix"]}"
  end

  args = "-t projects/#{notification["project"]}/topics/#{notification["name"]} #{prefix_arg} #{event_type_args} -f json gs://#{notification["bucket"]}"

  add "notification topic: #{notification["name"]}; bucket: #{notification["bucket"]}", indent: 4
  gsutil "notification create", args
end

.notification_exists?(notification) ⇒ Boolean

Returns:



63
64
65
66
67
68
69
70
71
72
# File 'lib/gclouder/resources/storage/notifications.rb', line 63

def self.notification_exists?(notification)
  notifications_exist = gsutil_exec("notification list", " gs://#{notification["bucket"]} > /dev/null 2>&1 && echo 0 || echo 1").to_i == 0
  if not notifications_exist
    return false
  end

  return gsutil("notification list", "gs://#{notification["bucket"]}", force: true)
    .include?("projects/#{notification["project"]}/topics/#{notification["name"]}")

end