Module: GClouder::Resources::Compute::ProjectInfo::SSHKeys

Includes:
Config::CLIArgs, Config::Project, Logging
Defined in:
lib/gclouder/resources/compute/project_info/ssh_keys.rb

Defined Under Namespace

Modules: Local, Remote

Class Method Summary collapse

Methods included from Config::CLIArgs

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

Class Method Details

.checkObject



21
22
# File 'lib/gclouder/resources/compute/project_info/ssh_keys.rb', line 21

def self.check
end

.cleanObject



16
17
18
19
# File 'lib/gclouder/resources/compute/project_info/ssh_keys.rb', line 16

def self.clean
  return unless project.key?("users")
  header :clean
end

.ensureObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/gclouder/resources/compute/project_info/ssh_keys.rb', line 30

def self.ensure
  return unless project.key?("users")
  header :ensure

  info "global", heading: true, indent: 2
  info

  Local.data.each do |user_data|
    description = user_data[:description]

    user = Remote.data.find { |entry| entry[:description] == description }

    # user doesn't exist, add it..
    if user.nil?
      add description
      next
    end

    # user exists but has been modified
    if user_data[:key] != user[:key]
      change description
      next
    end

    # user exists and is the same
    good description
  end

  Remote.data.each do |user_data|
    description = user_data[:description]

    next if Local.data.find { |entry| entry[:description] == description }

    # user isn't defined locally, remove it
    remove description, indent: 3
  end

  return if Local.list == Remote.list
  return if cli_args[:dry_run]

  Key.ensure(Local.list)
end

.header(stage = :ensure) ⇒ Object



12
13
14
# File 'lib/gclouder/resources/compute/project_info/ssh_keys.rb', line 12

def self.header(stage = :ensure)
  info "[#{stage}] compute / metadata / ssh_keys", title: true
end

.validateObject



24
25
26
27
28
# File 'lib/gclouder/resources/compute/project_info/ssh_keys.rb', line 24

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