Skip to content

Commit

Permalink
fix: Exception on initial key imports
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelWaldvogel committed May 12, 2019
1 parent c8b0147 commit 4c89f14
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

# 0.9.4 - 2019-05-12
## Added

## Fixed
- Handling of HTTP errors
- Domain names in tests

## Changed


# 0.9.3 - 2019-05-12
## Added
- Default server set to `https://gitta.enotar.ch`; can be changed with
Expand Down
12 changes: 6 additions & 6 deletions git_timestamp/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import pygit2 as git
import requests

VERSION = '0.9.3'
VERSION = '0.9.4'


class GitArgumentParser(argparse.ArgumentParser):
Expand Down Expand Up @@ -179,7 +179,7 @@ def get_keyid(server):
# Obtain key in TOFU fashion and remember keyid
r = requests.get(server, params={'request': 'get-public-key-v1'},
timeout=30)
quit_if_http_error(args, r)
quit_if_http_error(server, r)
(keyid, name) = validate_key_and_import(r.text)
gcfg = git.Config.get_global_config()
gcfg['timestamper.%s.keyid' % key] = keyid
Expand Down Expand Up @@ -270,12 +270,12 @@ def validate_tag(text, commit, keyid, name, args):
else:
sys.exit("No OpenPGP signature found")

def quit_if_http_error(args, r):
def quit_if_http_error(server, r):
if r.status_code == 301:
sys.exit("Timestamping server URL changed from %s to %s\n"
"Please change this on the command line(s) or run\n"
" git config [--global] timestamp.server %s"
% (args.server, r.headers['Location'], r.headers['Location']))
% (server, r.headers['Location'], r.headers['Location']))
if r.status_code != 200:
sys.exit("Timestamping request failed; server responded with %d %s"
% (r.status_code, r.reason))
Expand All @@ -297,7 +297,7 @@ def timestamp_tag(repo, commit, keyid, name, args):
'commit': commit.id,
'tagname': args.tag
}, allow_redirects=False)
quit_if_http_error(args, r)
quit_if_http_error(args.server, r)
validate_tag(r.text, commit, keyid, name, args)
tagid = repo.write(git.GIT_OBJ_TAG, r.text)
repo.create_reference('refs/tags/%s' % args.tag, tagid)
Expand Down Expand Up @@ -363,7 +363,7 @@ def timestamp_branch(repo, commit, keyid, name, args):
pass
try:
r = requests.post(args.server, data=data, allow_redirects=False)
quit_if_http_error(args, r)
quit_if_http_error(args.server, r)
validate_branch(r.text, keyid, name, data, args)
commitid = repo.write(git.GIT_OBJ_COMMIT, r.text)
repo.create_reference('refs/heads/' + args.branch, commitid, force=True)
Expand Down

0 comments on commit 4c89f14

Please sign in to comment.