forked from 2factorauth/twofactorauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify.rb
71 lines (61 loc) · 1.64 KB
/
verify.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Load Yaml
require 'yaml'
require 'fastimage'
$output=0;
begin
def error(msg)
$output=$output+1;
if($output == 1)
puts "<------------ ERROR ------------>\n"
end
puts "#{$output}. #{msg}"
end
# Load each section, check for errors such as invalid syntax
# as well as if an image is missing
main = YAML.load_file('_data/main.yml')
main["sections"].each do |section|
data = YAML.load_file('_data/' + section["id"] + '.yml')
data['websites'].each do |website|
image = "img/#{section['id']}/#{website['img']}"
unless File.exists?(image)
error("#{website['name']} image not found.")
end
image_dimensions = [32,32]
unless FastImage.size(image) == image_dimensions
error("#{image} is not #{image_dimensions.join("x")}")
end
ext = ".png"
unless File.extname(image) == ext
error("#{image} is not #{ext}")
end
end
end
# Load each provider and look for each image
providers = YAML.load_file('_data/providers.yml')
providers["providers"].each do |provider|
pimage = "img/providers/#{provider['img']}";
unless File.exists?(pimage)
error("#{provider['name']} image not found.")
end
image_dimensions = [32,32]
unless FastImage.size(pimage) == image_dimensions
error("#{pimage} is not #{image_dimensions.join("x")}")
end
ext = ".png"
unless File.extname(pimage) == ext
error("#{pimage} is not #{ext}")
end
end
if($output > 0 )
exit 1
end
rescue Psych::SyntaxError => e
puts 'Error in the YAML'
puts e
exit 1
rescue => e
puts e
exit 1
else
puts 'No errors. You\'re good to go!'
end