forked from cncf/gitdm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_forbidden_data.rb
executable file
·93 lines (85 loc) · 2.17 KB
/
add_forbidden_data.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env ruby
require 'csv'
require 'digest'
def add_forbidden_data1(args)
# Read currently forbidden list
config_file = 'cncf-config/forbidden-sha1.csv'
shas = {}
begin
CSV.foreach(config_file, headers: true) do |row|
h = row.to_h
sha = h['sha']
shas[sha] = true
puts "Already forbidden SHA1: '#{sha}'"
end
rescue Errno::ENOENT => e
puts "No forbidden config yet, ok"
end
# Process new forbidden list
sha1 = Digest::SHA1.new
added = false
args.each do |argo|
arg = argo.strip
sha = sha1.hexdigest arg
if shas.key? sha
puts "This is already forbidden value: '#{arg}' --> SHA1: '#{sha}', skipping"
next
end
puts "Adding value '#{arg}' --> SHA1: '#{sha}' to forbidden list"
shas[sha] = true
added = true
end
return unless added
# Save new forbidden file (we added something)
hdr = %w(sha)
CSV.open(config_file, 'w', headers: hdr) do |csv|
csv << hdr
shas.keys.sort.each do |sha|
csv << [sha]
end
end
end
def add_forbidden_data256(args)
# Read currently forbidden list
config_file = 'cncf-config/forbidden-sha256.csv'
shas = {}
begin
CSV.foreach(config_file, headers: true) do |row|
h = row.to_h
sha = h['sha']
shas[sha] = true
puts "Already forbidden SHA256: '#{sha}'"
end
rescue Errno::ENOENT => e
puts "No forbidden config yet, ok"
end
# Process new forbidden list
sha256 = Digest::SHA256.new
added = false
args.each do |argo|
arg = argo.strip
sha = sha256.hexdigest arg
if shas.key? sha
puts "This is already forbidden value: '#{arg}' --> SHA256: '#{sha}', skipping"
next
end
puts "Adding value '#{arg}' --> SHA256: '#{sha}' to forbidden list"
shas[sha] = true
added = true
end
return unless added
# Save new forbidden file (we added something)
hdr = %w(sha)
CSV.open(config_file, 'w', headers: hdr) do |csv|
csv << hdr
shas.keys.sort.each do |sha|
csv << [sha]
end
end
end
if ARGV.size < 1
puts "Missing arguments: [email protected] 'Hidden Name' anything_that_should_not_appear_in_repo"
exit(1)
end
add_forbidden_data1(ARGV)
add_forbidden_data256(ARGV)