Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: goreleaser
on:
# Trigger the workflow on push or pull request,
# but only if a semver tag is created.
push:
tags:
- v*.*.*
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v1
-
name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13.x
-
name: Login to DockerHub Registry
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pfxsigner
dist/
props.json
27 changes: 21 additions & 6 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,24 @@ before:
hooks:
- make build

archive:
format: tar.gz
files:
- props.json.sample
- README.md
- LICENSE
archives:
- format: tar.gz
files:
- props.json.sample
- README.md
- LICENSE

dockers:
-
goos: linux
goarch: amd64
goarm: ''
binaries:
- pfxsigner
image_templates:
- "kailashnadh/pfxsigner:latest"
- "kailashnadh/pfxsigner:{{ .Tag }}"
skip_push: false
dockerfile: Dockerfile
extra_files:
- props.json.sample
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM ubuntu:latest AS deploy
WORKDIR /app
COPY pfxsigner .
COPY props.json.sample .
ENTRYPOINT [ "./pfxsigner" ]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
.PHONY : build test clean

LAST_COMMIT := $(shell git rev-parse --short HEAD)
LAST_COMMIT_DATE := $(shell git show -s --format=%ci ${LAST_COMMIT})
VERSION := $(shell git describe --abbrev=1)
BUILDSTR := ${VERSION} (build "\\\#"${LAST_COMMIT} $(shell date '+%Y-%m-%d %H:%M:%S'))

BIN := pfxsigner

.PHONY: build
build:
go build -o ${BIN} -ldflags="-s -w -X 'main.buildString=${BUILDSTR}'"

.PHONY: test
test:
go test ./...

Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ In the server mode, pfxsigner exposes an HTTP API to which a PDF file and signat

```shell
# Start the server
./pfxsigner -pfx-file cert.pfx -props-file "props.json" server
./pfxsigner -pfx-file cert.pfx -pfx-password password -props-file "props.json" server
```

```shell
Expand All @@ -30,6 +30,18 @@ REQ=$(cat props.json.sample)
curl -F "props=$REQ" -F 'file=@./test.pdf' -o './test-signed.pdf' localhost:8000/document
```

## Docker

You can use the [official]() Docker image to run `pfxsigner`.

**NOTE**: You'll need to mount `cert.pfx` and `props.json` from a directory available on host machine to a directory inside container. You can do that by passing `-v </path/on/host>:</path/on/container>` while launching the container.

```shell
# For example `./data` contains `cert.pfx` and `props.json`.
export PFX_PASSWORD=mysecurepass
docker run -it -p 8000:8000 -v "$PWD"/data:/data kailashnadh/pfxsigner:latest -pfx-file /data/cert.pfx -pfx-password $PFX_PASSWORD -props-file /data/props.json server
```

### API
The API endpoint is `:8000/document`. It accepts a POST request (multipart/form-data) with the following fields.

Expand Down
14 changes: 14 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type httpResp struct {
// initServer initializes CLI mode.
func initServer(c *cli.Context) error {
r := chi.NewRouter()
r.Get("/", handleIndex)
r.Get("/health", handleHealthCheck)
r.Post("/document", handleDocument)

// HTTP Server.
Expand All @@ -36,6 +38,18 @@ func initServer(c *cli.Context) error {
return nil
}

// handleIndex is default index handler.
func handleIndex(w http.ResponseWriter, r *http.Request) {
sendResponse(w, "Welcome to pfxsigner. Send a request to /document for document signing.")
return
}

// handleHealthCheck handles healthcheck request to check if service is available or not.
func handleHealthCheck(w http.ResponseWriter, r *http.Request) {
sendResponse(w, "healthy")
return
}

// handleDocument handles an HTTP document signing request.
func handleDocument(w http.ResponseWriter, r *http.Request) {
// Read the JSON request payload from the 'request' field.
Expand Down