Skip to content

Commit 72430d9

Browse files
authored
feat(adding_signature_validation): Adding Validation for signatures.
1 parent 3a91783 commit 72430d9

File tree

6 files changed

+37
-2
lines changed

6 files changed

+37
-2
lines changed

.github/workflows/python-package.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ jobs:
2020

2121
steps:
2222
- uses: actions/checkout@v2
23+
with:
24+
fetch-depth: 0
25+
ref: ${{ github.event.pull_request.head.sha }}
2326
- name: Set up Python ${{ matrix.python-version }}
2427
uses: actions/setup-python@v2
2528
with:
@@ -42,6 +45,14 @@ jobs:
4245
- name: integration tests
4346
run: |
4447
pytest tests/integration
48+
- name: Setup ruby env
49+
uses: actions/setup-ruby@v1
50+
with:
51+
ruby-version: 2.7
52+
- run: |
53+
gem install pre-commit-sign
54+
export COMMIT_MESSAGE=$(git log -1)
55+
ruby validate-signature.rb "${COMMIT_MESSAGE}"
4556
4657
deploy:
4758
strategy:

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
repos:
2+
- repo: https://github.com/pre-commit/mirrors-autopep8
3+
rev: v1.5.6 # Use the sha / tag you want to point at
4+
hooks:
5+
- id: autopep8
26
- repo: https://github.com/pre-commit/pre-commit-hooks
37
rev: v1.3.0
48
hooks:

validate-signature.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/ruby
2+
require 'pre-commit-sign'
3+
if ARGV.length >= 1
4+
puts 'Validating signature'
5+
commit_message = ARGV[0]
6+
message_body = commit_message.split("\n").select { |l| l.start_with?(' ') }.join("\n").gsub(/^ /, '')
7+
pcs = PrecommitSign.from_message(message_body)
8+
pcs.date = DateTime.strptime(/^Date:\s+(.*)$/.match(commit_message).captures.first, '%a %b %d %T %Y %z').to_time
9+
puts "Commit Message: #{message_body}"
10+
if pcs.valid_signature?
11+
puts 'Perfect'
12+
else
13+
puts 'Not valid'
14+
exit 1
15+
end
16+
else
17+
puts "Need a commit message to validate signature from. Try pre-commit install -f && pre-commit install --install-hooks -t commit-msg -f before commiting your code."
18+
exit 1
19+
end

vmware_exporter/defer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'''
22
Helpers for writing efficient twisted code, optimized for coroutine scheduling efficiency
33
'''
4+
# autopep8'd
45

56
from twisted.internet import defer
67
from twisted.python import failure

vmware_exporter/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
# autopep8'd
12
import os
2-
33
from pyVmomi import vmodl
44

55

vmware_exporter/vmware_exporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
# -*- python -*-
33
# -*- coding: utf-8 -*-
4+
# autopep8'd
45
"""
56
Handles collection of metrics for vmware.
67
"""
@@ -795,7 +796,6 @@ def vm_inventory(self):
795796

796797
@defer.inlineCallbacks
797798
def customAttributesLabelNames(self, metric_type):
798-
799799
"""
800800
vm perf, vms, vmguestes and snapshots metrics share the same custom attributes
801801
as they re related to virtual machine objects

0 commit comments

Comments
 (0)