Module: GClouder::Resources::Compute::BGPVPNs

Includes:
Config::CLIArgs, Config::Project, GCloud, Logging, GClouder::Resource::Cleaner, Shell
Defined in:
lib/gclouder/resources/compute/bgp-vpns.rb

Defined Under Namespace

Modules: BGPVPN, Cleaner, Local, Remote

Class Method Summary collapse

Methods included from GClouder::Resource::Cleaner

#clean, #cleaner, included, #undefined

Methods included from Config::CLIArgs

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

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

Methods included from GCloud

#gcloud, included, #verify

Class Method Details

.dirObject



48
49
50
# File 'lib/gclouder/resources/compute/bgp-vpns.rb', line 48

def self.dir
  cli_args[:keys_dir] || File.join(ENV["HOME"], "keys")
end

.ensureObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gclouder/resources/compute/bgp-vpns.rb', line 32

def self.ensure
  return if Local.list.empty?

  header

  Local.list.each do |region, instances|
    info region, indent: 2, heading: true

    instances.each do |vpn|
      set_shared_secret(region, vpn)
      info
      BGPVPN.create(region, vpn)
    end
  end
end

.header(stage = :ensure) ⇒ Object



22
23
24
# File 'lib/gclouder/resources/compute/bgp-vpns.rb', line 22

def self.header(stage = :ensure)
  info "[#{stage}] compute / bgp-vpns", indent: 1, title: true
end

.set_shared_secret(region, vpn) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/gclouder/resources/compute/bgp-vpns.rb', line 52

def self.set_shared_secret(region, vpn)
  # if 'shared_secret' key is set, use it
  # if not, fall back to trying to read the secret from an environment variable, the name
  # of which is provided by the 'shared_secret_env_var' key
  unless vpn.key?("shared_secret") || vpn.key?("shared_secret_env_var") || vpn.key?("shared_secret_file")
    if cli_args[:dry_run]
      warning "no shared secret found for VPN"
    else
      fatal "shared_secret_env_var or shared_secret must be set for region/vpn: #{region}/#{vpn["name"]}"
      return false
    end
  end

  vpn["shared_secret"] = if vpn.key?("shared_secret") && !vpn["shared_secret"].empty? && !vpn["shared_secret"].nil?
    vpn["shared_secret"]
  else
    ENV[vpn["shared_secret_env_var"]] if vpn["shared_secret_env_var"]
  end

  # this overrides the above for now..
  if vpn.key?("shared_secret_file")
    config_file = File.join(dir, vpn["shared_secret_file"])

    if !File.exists?(config_file)
      fatal "shared_secret_file specified for vpn but no file found for region/vpn: #{region}/#{vpn["name"]}"
    end

    vpn["shared_secret"] = File.read(config_file)
  end
end

.validateObject



26
27
28
29
30
# File 'lib/gclouder/resources/compute/bgp-vpns.rb', line 26

def self.validate
  return if Local.list.empty?
  header :validate
  Local.validate
end