pre-commit-gpg 0.9.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -2
- data/lib/plugins/pre_commit/checks/gpg.rb +71 -4
- data/lib/pre-commit/gpg/version.rb +10 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c5c56b6665ce9b4b2ae8acf1fac1e81e7d4758c
|
4
|
+
data.tar.gz: 200bb9f2b7770741063ab01c82f8be06b0486a4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac550686a21360ca1f331b0f43b7f290ab45e930fe44f3d3e8f4f4651cd273300743f7573f5e510c9d2e73b0d15fa6937bd5b328993fb4d65d30057c36bf03cd
|
7
|
+
data.tar.gz: 5dff4bbdc4e214c78d250951296f933d5b5340681c8b90f3d5af0b270878a2e81602a403baaa89b750dd34e4c1317b399127083786468b11ee19638e6fb30a9a
|
data/README.md
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# GPG verification for pre-commit gem
|
2
|
-
|
3
1
|
[![Gem Version](https://badge.fury.io/rb/pre-commit-gpg.png)](https://rubygems.org/gems/pre-commit-gpg)
|
4
2
|
[![Build Status](https://secure.travis-ci.org/pre-commit-plugins/pre-commit-gpg.png?branch=master)](https://travis-ci.org/pre-commit-plugins/pre-commit-gpg)
|
5
3
|
[![Dependency Status](https://gemnasium.com/pre-commit-plugins/pre-commit-gpg.png)](https://gemnasium.com/pre-commit-plugins/pre-commit-gpg)
|
@@ -8,3 +6,13 @@
|
|
8
6
|
[![Inline docs](http://inch-ci.org/github/pre-commit-plugins/pre-commit-gpg.png)](http://inch-ci.org/github/pre-commit-plugins/pre-commit-gpg)
|
9
7
|
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/pre-commit-plugins/pre-commit-gpg/master/frames)
|
10
8
|
[![Github Code](http://img.shields.io/badge/github-code-blue.svg)](https://github.com/pre-commit-plugins/pre-commit-gpg)
|
9
|
+
|
10
|
+
# GPG verification for pre-commit gem
|
11
|
+
|
12
|
+
### Installation
|
13
|
+
|
14
|
+
gem install pre-commit-gpg
|
15
|
+
|
16
|
+
### Usage
|
17
|
+
|
18
|
+
pre-commit enable yaml checks gpg
|
@@ -1,13 +1,37 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright 2014 Michal Papis <mpapis@gmail.com>
|
3
|
+
|
4
|
+
See the file LICENSE for copying permission.
|
5
|
+
=end
|
6
|
+
|
1
7
|
require 'pre-commit/checks/shell'
|
8
|
+
require 'pre-commit/error_list'
|
2
9
|
|
10
|
+
# :nodoc:
|
3
11
|
module PreCommit
|
12
|
+
# :nodoc:
|
4
13
|
module Checks
|
14
|
+
|
15
|
+
#
|
16
|
+
# pre-commit gem plugin to verify GPG signatures
|
17
|
+
# when either the file or signature changes
|
18
|
+
#
|
5
19
|
class Gpg < Shell
|
6
20
|
|
21
|
+
#
|
22
|
+
# description of the plugin
|
23
|
+
#
|
7
24
|
def self.description
|
8
25
|
"Finds GPG verification problems"
|
9
26
|
end
|
10
27
|
|
28
|
+
#
|
29
|
+
# Finds files with signature and verifies them
|
30
|
+
#
|
31
|
+
# @param staged_files [Array<String>] list of files to check
|
32
|
+
#
|
33
|
+
# @return [nil|Array<PreCommit::ErrorList>] nil when no errors,
|
34
|
+
# list of errors otherwise
|
11
35
|
def call(staged_files)
|
12
36
|
signature_files = staged_files.map { |file| get_signature(file) }.compact.uniq
|
13
37
|
return if signature_files.empty?
|
@@ -15,11 +39,18 @@ module PreCommit
|
|
15
39
|
errors = signature_files.map { |file| run_check(file) }.compact
|
16
40
|
return if errors.empty?
|
17
41
|
|
18
|
-
errors
|
42
|
+
errors
|
19
43
|
end
|
20
44
|
|
21
45
|
private
|
22
46
|
|
47
|
+
#
|
48
|
+
# Checks if the given file is a signature or has one
|
49
|
+
#
|
50
|
+
# @param file [String] the file to check
|
51
|
+
#
|
52
|
+
# @return [nil|String] signature file when found, nil otherwise
|
53
|
+
#
|
23
54
|
def get_signature(file)
|
24
55
|
if
|
25
56
|
File.exist?(file + ".asc")
|
@@ -33,20 +64,55 @@ module PreCommit
|
|
33
64
|
end
|
34
65
|
end
|
35
66
|
|
67
|
+
#
|
68
|
+
# Verify given file GPG signature
|
69
|
+
#
|
70
|
+
# @param file [String] path to file to verify
|
71
|
+
#
|
72
|
+
# @return [nil|PreCommit::ErrorList] nil when file verified,
|
73
|
+
# ErrorList when no GPG found to verify
|
74
|
+
# ErrorList when verification failed
|
75
|
+
#
|
36
76
|
def run_check(file)
|
37
77
|
if
|
38
78
|
gpg_program
|
39
79
|
then
|
40
|
-
execute(gpg_program, "--verify", file)
|
80
|
+
parse_error( execute(gpg_program, "--verify", file), file )
|
41
81
|
else
|
42
|
-
|
82
|
+
PreCommit::ErrorList.new(PreCommit::Line.new("No GPG program found to run verification", file))
|
43
83
|
end
|
44
84
|
end
|
45
85
|
|
86
|
+
#
|
87
|
+
# convert verification failure string into ErrorList
|
88
|
+
#
|
89
|
+
# @param errors [String] Output of failed GPG verification to parse
|
90
|
+
# @param file [String] File that versification failed
|
91
|
+
#
|
92
|
+
# @return [nil|PreCommit::ErrorList] nil when file verified,
|
93
|
+
# ErrorList when verification failed
|
94
|
+
#
|
95
|
+
def parse_error(errors, file)
|
96
|
+
return if errors.nil?
|
97
|
+
PreCommit::ErrorList.new(
|
98
|
+
errors.split(/\n/).map do |error|
|
99
|
+
PreCommit::Line.new(error, file)
|
100
|
+
end
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
#
|
105
|
+
# @return [nil|String] path to the GPG binary or +nil+
|
106
|
+
#
|
46
107
|
def gpg_program
|
47
108
|
@gpg_program ||= find_binary(:gpg2) || find_binary(:gpg)
|
48
109
|
end
|
49
110
|
|
111
|
+
#
|
112
|
+
# @param binary [String] the name of binary to find on +PATH+
|
113
|
+
#
|
114
|
+
# @return [nil|String] path to the searched binary or +nil+
|
115
|
+
#
|
50
116
|
def find_binary(binary)
|
51
117
|
result = execute_raw(
|
52
118
|
"which #{binary}",
|
@@ -54,6 +120,7 @@ module PreCommit
|
|
54
120
|
) and result.strip
|
55
121
|
end
|
56
122
|
|
57
|
-
end
|
123
|
+
end # class Gpg < Shell
|
124
|
+
|
58
125
|
end
|
59
126
|
end
|
@@ -1,5 +1,14 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright 2014 Michal Papis <mpapis@gmail.com>
|
3
|
+
|
4
|
+
See the file LICENSE for copying permission.
|
5
|
+
=end
|
6
|
+
|
7
|
+
# :nodoc:
|
1
8
|
module PreCommit
|
9
|
+
# placeholder for gem VERSION
|
2
10
|
module Gpg
|
3
|
-
|
11
|
+
# the gem version
|
12
|
+
VERSION = "1.0.0"
|
4
13
|
end
|
5
14
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pre-commit-gpg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michal Papis
|
@@ -120,7 +120,7 @@ files:
|
|
120
120
|
- lib/pre-commit/gpg/version.rb
|
121
121
|
homepage: http://github.com/pre-commit-plugins/pre-commit-gpg
|
122
122
|
licenses:
|
123
|
-
-
|
123
|
+
- MIT
|
124
124
|
metadata: {}
|
125
125
|
post_install_message:
|
126
126
|
rdoc_options: []
|