Class: Dbagger

Inherits:
Object
  • Object
show all
Defined in:
lib/dbagger.rb

Overview

The main Dbagger driver

Class Method Summary collapse

Class Method Details

.collect_data(options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dbagger.rb', line 14

def self.collect_data(options)

  begin
    response = RestClient.get("#{options[:github_api]}/users/#{options[:gh_username]}")
  rescue => e
    return false
  end
  gituser = JSON.parse(response.body)

  return false if gituser['message'] == 'Not Found'

  begin
    response = RestClient.get("#{options[:github_api]}/users/#{options[:gh_username]}/keys")
  rescue => e
    return false
  end

  keys = []

  return false if response.body == 'Not Found'

  JSON.parse(response.body).each do |key|
    keys.push(key['key'])
  end

  return false if keys.empty?

  return {
    id: options[:username],
    ssh_keys: keys,
    groups: options[:groups].split(','),
    shell: options[:shell],
    comment: gituser['name']
  }

end