Compare commits
77 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d8d35889d | ||
|
|
ef2b9f9e1b | ||
|
|
d83e436bbb | ||
|
|
00ebf584ff | ||
|
|
38dd4b1898 | ||
|
|
ece40e90d6 | ||
|
|
5e2a080d2a | ||
|
|
07decbb976 | ||
|
|
9a7fa88d60 | ||
|
|
a32520bcba | ||
|
|
39b542952b | ||
|
|
b0aafdcc54 | ||
|
|
565e4316ca | ||
|
|
961192eb9b | ||
|
|
1bd1c094f2 | ||
|
|
380fa0efda | ||
|
|
059bfd27eb | ||
|
|
45954b02ca | ||
|
|
e1b924f614 | ||
|
|
865dceddf9 | ||
|
|
172bd870c6 | ||
|
|
ee3231c879 | ||
|
|
d18ae5e249 | ||
|
|
48166b4990 | ||
|
|
ec006d3466 | ||
|
|
754051fcb4 | ||
|
|
a4f74712d8 | ||
|
|
4f9ee0b2aa | ||
|
|
06a6f04be9 | ||
|
|
094a429688 | ||
|
|
520caaf67f | ||
|
|
cffec51d48 | ||
|
|
8ccd28a009 | ||
|
|
5ecc336d73 | ||
|
|
8fb6765066 | ||
|
|
3e8a362a1b | ||
|
|
7a3d5d053b | ||
|
|
6cd6e89652 | ||
|
|
22beab49f0 | ||
|
|
72a6e2e8e4 | ||
|
|
588ece1608 | ||
|
|
cbe95869b0 | ||
|
|
21c8f5fa9c | ||
|
|
2d6d95b809 | ||
|
|
09413952ec | ||
|
|
3e89131ae2 | ||
|
|
381e90d319 | ||
|
|
b70afe012b | ||
|
|
a437576753 | ||
|
|
8c96f62349 | ||
|
|
f0b114e8d8 | ||
|
|
7b2c71435e | ||
|
|
20d34c6c0a | ||
|
|
b1ebb09184 | ||
|
|
756e93fbbb | ||
|
|
40e28f9677 | ||
|
|
9d10b07e10 | ||
|
|
1ad5a1eb42 | ||
|
|
d60c333193 | ||
|
|
a9d5a3da9d | ||
|
|
c11dd6630f | ||
|
|
78234b674c | ||
|
|
7b9a0b72d6 | ||
|
|
a645d164e0 | ||
|
|
f58a7a9b06 | ||
|
|
cd16576a1f | ||
|
|
b02023370b | ||
|
|
3acdd86c88 | ||
|
|
52a46ce079 | ||
|
|
c30cddfa06 | ||
|
|
3b7bdfc16e | ||
|
|
cc9161d223 | ||
|
|
1de505f615 | ||
|
|
32293934dd | ||
|
|
740891ff39 | ||
|
|
1b91299899 | ||
|
|
372fb3c434 |
3
.github/FUNDING.yml
vendored
3
.github/FUNDING.yml
vendored
@ -1 +1,4 @@
|
|||||||
github: ldez
|
github: ldez
|
||||||
|
ko_fi: ldez_oss
|
||||||
|
liberapay: ldez
|
||||||
|
thanks_dev: u/gh/ldez
|
||||||
|
|||||||
38
.github/workflows/go-cross.yml
vendored
38
.github/workflows/go-cross.yml
vendored
@ -1,5 +1,12 @@
|
|||||||
name: Go Matrix
|
name: Go Matrix
|
||||||
on: [push, pull_request]
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
@ -11,37 +18,20 @@ jobs:
|
|||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
go-version: [ 1.17, 1.x ]
|
go-version: [ stable ]
|
||||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
# https://github.com/marketplace/actions/setup-go-environment
|
|
||||||
- name: Set up Go ${{ matrix.go-version }}
|
|
||||||
uses: actions/setup-go@v2
|
|
||||||
with:
|
|
||||||
go-version: ${{ matrix.go-version }}
|
|
||||||
|
|
||||||
# https://github.com/marketplace/actions/checkout
|
# https://github.com/marketplace/actions/checkout
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# https://github.com/marketplace/actions/cache
|
# https://github.com/marketplace/actions/setup-go-environment
|
||||||
- name: Cache Go modules
|
- name: Set up Go ${{ matrix.go-version }}
|
||||||
uses: actions/cache@v2
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
# In order:
|
go-version: ${{ matrix.go-version }}
|
||||||
# * Module download cache
|
|
||||||
# * Build cache (Linux)
|
|
||||||
# * Build cache (Mac)
|
|
||||||
# * Build cache (Windows)
|
|
||||||
path: |
|
|
||||||
~/go/pkg/mod
|
|
||||||
~/.cache/go-build
|
|
||||||
~/Library/Caches/go-build
|
|
||||||
%LocalAppData%\go-build
|
|
||||||
key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-${{ matrix.go-version }}-go-
|
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: go test -v -cover ./...
|
run: go test -v -cover ./...
|
||||||
|
|||||||
63
.github/workflows/main.yml
vendored
63
.github/workflows/main.yml
vendored
@ -3,10 +3,10 @@ name: Main
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- main
|
||||||
tags:
|
|
||||||
- v*
|
|
||||||
pull_request:
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
@ -14,34 +14,16 @@ jobs:
|
|||||||
name: Main Process
|
name: Main Process
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
GO_VERSION: 1.17
|
GO_VERSION: stable
|
||||||
GOLANGCI_LINT_VERSION: v1.43.0
|
GOLANGCI_LINT_VERSION: v2.0.1
|
||||||
SEIHON_VERSION: v0.9.0
|
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
# https://github.com/marketplace/actions/setup-go-environment
|
- uses: actions/setup-go@v5
|
||||||
- name: Set up Go ${{ env.GO_VERSION }}
|
|
||||||
uses: actions/setup-go@v2
|
|
||||||
with:
|
with:
|
||||||
go-version: ${{ env.GO_VERSION }}
|
go-version: ${{ env.GO_VERSION }}
|
||||||
|
|
||||||
# https://github.com/marketplace/actions/checkout
|
|
||||||
- name: Check out code
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
# https://github.com/marketplace/actions/cache
|
|
||||||
- name: Cache Go modules
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: ~/go/pkg/mod
|
|
||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-go-
|
|
||||||
|
|
||||||
- name: Check and get dependencies
|
- name: Check and get dependencies
|
||||||
run: |
|
run: |
|
||||||
go mod download
|
go mod download
|
||||||
@ -52,37 +34,8 @@ jobs:
|
|||||||
# https://golangci-lint.run/usage/install#other-ci
|
# https://golangci-lint.run/usage/install#other-ci
|
||||||
- name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }}
|
- name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }}
|
||||||
run: |
|
run: |
|
||||||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}
|
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}
|
||||||
golangci-lint --version
|
golangci-lint --version
|
||||||
|
|
||||||
- name: Make
|
- name: Make
|
||||||
run: make
|
run: make
|
||||||
|
|
||||||
# https://goreleaser.com/ci/actions/
|
|
||||||
- name: Run GoReleaser
|
|
||||||
uses: goreleaser/goreleaser-action@v2
|
|
||||||
if: startsWith(github.ref, 'refs/tags/v')
|
|
||||||
with:
|
|
||||||
version: latest
|
|
||||||
args: release --rm-dist
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
# Install Docker image multi-arch builder
|
|
||||||
- name: Install seihon ${{ env.SEIHON_VERSION }}
|
|
||||||
if: startsWith(github.ref, 'refs/tags/v')
|
|
||||||
run: |
|
|
||||||
curl -sSfL https://raw.githubusercontent.com/ldez/seihon/master/godownloader.sh | sh -s -- -b $(go env GOPATH)/bin ${SEIHON_VERSION}
|
|
||||||
seihon --version
|
|
||||||
|
|
||||||
- name: Docker Login
|
|
||||||
if: startsWith(github.ref, 'refs/tags/v')
|
|
||||||
env:
|
|
||||||
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
|
||||||
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
|
||||||
run: |
|
|
||||||
echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin
|
|
||||||
|
|
||||||
- name: Deploy Docker Images (seihon)
|
|
||||||
if: startsWith(github.ref, 'refs/tags/v')
|
|
||||||
run: make publish-images
|
|
||||||
|
|||||||
70
.github/workflows/release.yml
vendored
Normal file
70
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
name: "Release a tag"
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- v*
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
name: Release Process
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
GO_VERSION: stable
|
||||||
|
CGO_ENABLED: 0
|
||||||
|
|
||||||
|
steps:
|
||||||
|
# temporary workaround for an error in free disk space action
|
||||||
|
# https://github.com/jlumbroso/free-disk-space/issues/14
|
||||||
|
- name: Update Package List and Remove Dotnet
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get remove -y '^dotnet-.*'
|
||||||
|
|
||||||
|
# https://github.com/marketplace/actions/free-disk-space-ubuntu
|
||||||
|
- name: Free Disk Space
|
||||||
|
uses: jlumbroso/free-disk-space@main
|
||||||
|
with:
|
||||||
|
# this might remove tools that are actually needed
|
||||||
|
tool-cache: false
|
||||||
|
|
||||||
|
# all of these default to true
|
||||||
|
android: true
|
||||||
|
dotnet: true
|
||||||
|
haskell: true
|
||||||
|
large-packages: true
|
||||||
|
docker-images: true
|
||||||
|
swap-storage: false
|
||||||
|
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: ${{ env.GO_VERSION }}
|
||||||
|
|
||||||
|
- name: dockerhub-login
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
|
- name: ghcr-login
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.repository_owner }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
|
||||||
|
- name: Run GoReleaser
|
||||||
|
uses: goreleaser/goreleaser-action@v6
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
args: release -p 1 --clean --timeout=90m
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
179
.golangci.yml
179
.golangci.yml
@ -1,93 +1,108 @@
|
|||||||
run:
|
version: "2"
|
||||||
timeout: 5m
|
|
||||||
skip-files: []
|
|
||||||
|
|
||||||
linters-settings:
|
formatters:
|
||||||
govet:
|
enable:
|
||||||
check-shadowing: true
|
- gci
|
||||||
gocyclo:
|
- gofumpt
|
||||||
min-complexity: 12
|
settings:
|
||||||
maligned:
|
gofumpt:
|
||||||
suggest-new: true
|
extra-rules: true
|
||||||
goconst:
|
|
||||||
min-len: 3
|
|
||||||
min-occurrences: 3
|
|
||||||
misspell:
|
|
||||||
locale: US
|
|
||||||
gofumpt:
|
|
||||||
extra-rules: true
|
|
||||||
depguard:
|
|
||||||
list-type: blacklist
|
|
||||||
include-go-root: false
|
|
||||||
packages:
|
|
||||||
- github.com/pkg/errors
|
|
||||||
godox:
|
|
||||||
keywords:
|
|
||||||
- FIXME
|
|
||||||
gocritic:
|
|
||||||
enabled-tags:
|
|
||||||
- diagnostic
|
|
||||||
- style
|
|
||||||
- performance
|
|
||||||
disabled-checks:
|
|
||||||
- sloppyReassign
|
|
||||||
- rangeValCopy
|
|
||||||
- octalLiteral
|
|
||||||
- paramTypeCombine # already handle by gofumpt.extra-rules
|
|
||||||
settings:
|
|
||||||
hugeParam:
|
|
||||||
sizeThreshold: 100
|
|
||||||
forbidigo:
|
|
||||||
forbid:
|
|
||||||
- '^print(ln)?$'
|
|
||||||
- '^spew\.Print(f|ln)?$'
|
|
||||||
- '^spew\.Dump$'
|
|
||||||
gomoddirectives:
|
|
||||||
replace-allow-list:
|
|
||||||
- github.com/abbot/go-http-auth
|
|
||||||
- github.com/go-check/check
|
|
||||||
- github.com/gorilla/mux
|
|
||||||
- github.com/mailgun/minheap
|
|
||||||
- github.com/mailgun/multibuf
|
|
||||||
- github.com/jaguilar/vt100
|
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
enable-all: true
|
default: all
|
||||||
disable:
|
disable:
|
||||||
- golint # deprecated
|
|
||||||
- scopelint # deprecated
|
|
||||||
- interfacer # deprecated
|
|
||||||
- maligned # deprecated
|
|
||||||
- sqlclosecheck # not relevant (SQL)
|
|
||||||
- rowserrcheck # not relevant (SQL)
|
|
||||||
- cyclop # duplicate of gocyclo
|
- cyclop # duplicate of gocyclo
|
||||||
- lll
|
|
||||||
- gas
|
|
||||||
- dupl
|
- dupl
|
||||||
- prealloc
|
- err113
|
||||||
- scopelint
|
|
||||||
- wsl
|
|
||||||
- nlreturn
|
|
||||||
- gomnd
|
|
||||||
- testpackage
|
|
||||||
- paralleltest
|
|
||||||
- tparallel
|
|
||||||
- goerr113
|
|
||||||
- wrapcheck
|
|
||||||
- exhaustive
|
- exhaustive
|
||||||
- exhaustivestruct
|
- exhaustruct
|
||||||
- ifshort
|
- lll
|
||||||
- varnamelen
|
- mnd
|
||||||
- nilnil
|
- nilnil
|
||||||
|
- nlreturn
|
||||||
|
- paralleltest
|
||||||
|
- prealloc
|
||||||
|
- rowserrcheck # not relevant (SQL)
|
||||||
|
- sqlclosecheck # not relevant (SQL)
|
||||||
|
- testpackage
|
||||||
|
- tparallel
|
||||||
|
- varnamelen
|
||||||
|
- wrapcheck
|
||||||
|
- wsl
|
||||||
|
settings:
|
||||||
|
depguard:
|
||||||
|
rules:
|
||||||
|
main:
|
||||||
|
deny:
|
||||||
|
- pkg: github.com/instana/testify
|
||||||
|
desc: not allowed
|
||||||
|
- pkg: github.com/pkg/errors
|
||||||
|
desc: Should be replaced by standard lib errors package
|
||||||
|
forbidigo:
|
||||||
|
forbid:
|
||||||
|
- pattern: ^print(ln)?$
|
||||||
|
- pattern: ^spew\.Print(f|ln)?$
|
||||||
|
- pattern: ^spew\.Dump$
|
||||||
|
funlen:
|
||||||
|
lines: -1
|
||||||
|
statements: 40
|
||||||
|
goconst:
|
||||||
|
min-len: 3
|
||||||
|
min-occurrences: 3
|
||||||
|
gocritic:
|
||||||
|
disabled-checks:
|
||||||
|
- sloppyReassign
|
||||||
|
- rangeValCopy
|
||||||
|
- octalLiteral
|
||||||
|
- paramTypeCombine # already handle by gofumpt.extra-rules
|
||||||
|
enabled-tags:
|
||||||
|
- diagnostic
|
||||||
|
- style
|
||||||
|
- performance
|
||||||
|
settings:
|
||||||
|
hugeParam:
|
||||||
|
sizeThreshold: 100
|
||||||
|
gocyclo:
|
||||||
|
min-complexity: 12
|
||||||
|
godox:
|
||||||
|
keywords:
|
||||||
|
- FIXME
|
||||||
|
gomoddirectives:
|
||||||
|
replace-allow-list:
|
||||||
|
- github.com/abbot/go-http-auth
|
||||||
|
- github.com/go-check/check
|
||||||
|
- github.com/gorilla/mux
|
||||||
|
- github.com/mailgun/minheap
|
||||||
|
- github.com/mailgun/multibuf
|
||||||
|
- github.com/jaguilar/vt100
|
||||||
|
gosec:
|
||||||
|
excludes:
|
||||||
|
- G204 # Subprocess launched with a potential tainted input or cmd arguments
|
||||||
|
- G301 # Expect directory permissions to be 0750 or less
|
||||||
|
- G306 # Expect WriteFile permissions to be 0600 or less
|
||||||
|
govet:
|
||||||
|
disable:
|
||||||
|
- fieldalignment
|
||||||
|
enable-all: true
|
||||||
|
misspell:
|
||||||
|
locale: US
|
||||||
|
|
||||||
|
exclusions:
|
||||||
|
presets:
|
||||||
|
- comments
|
||||||
|
rules:
|
||||||
|
- linters:
|
||||||
|
- gochecknoglobals
|
||||||
|
- gochecknoinits
|
||||||
|
path: cmd/
|
||||||
|
- linters:
|
||||||
|
- tagalign
|
||||||
|
path: internal/traefikv[1-3]/
|
||||||
|
- path: (.+)\.go$
|
||||||
|
text: 'ST1000: at least one file in a package should have a package comment'
|
||||||
|
- path: (.+)\.go$
|
||||||
|
text: 'package-comments: should have a package comment'
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
exclude-use-default: false
|
max-issues-per-linter: 0
|
||||||
max-per-linter: 0
|
|
||||||
max-same-issues: 0
|
max-same-issues: 0
|
||||||
exclude:
|
|
||||||
- 'ST1000: at least one file in a package should have a package comment'
|
|
||||||
exclude-rules:
|
|
||||||
- path: cmd/
|
|
||||||
linters:
|
|
||||||
- gochecknoglobals
|
|
||||||
- gochecknoinits
|
|
||||||
|
|||||||
180
.goreleaser.yml
180
.goreleaser.yml
@ -1,3 +1,4 @@
|
|||||||
|
version: 2
|
||||||
project_name: traefik-certs-dumper
|
project_name: traefik-certs-dumper
|
||||||
|
|
||||||
builds:
|
builds:
|
||||||
@ -5,7 +6,7 @@ builds:
|
|||||||
ldflags:
|
ldflags:
|
||||||
- -s -w -X github.com/ldez/traefik-certs-dumper/cmd.version={{.Version}} -X github.com/ldez/traefik-certs-dumper/cmd.commit={{.ShortCommit}} -X github.com/ldez/traefik-certs-dumper/cmd.date={{.Date}}
|
- -s -w -X github.com/ldez/traefik-certs-dumper/cmd.version={{.Version}} -X github.com/ldez/traefik-certs-dumper/cmd.commit={{.ShortCommit}} -X github.com/ldez/traefik-certs-dumper/cmd.date={{.Date}}
|
||||||
env:
|
env:
|
||||||
- GO111MODULE=on
|
- CGO_ENABLED=0
|
||||||
goos:
|
goos:
|
||||||
- linux
|
- linux
|
||||||
- darwin
|
- darwin
|
||||||
@ -40,9 +41,182 @@ changelog:
|
|||||||
archives:
|
archives:
|
||||||
- id: tcd
|
- id: tcd
|
||||||
name_template: '{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
|
name_template: '{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
|
||||||
format: tar.gz
|
formats: [ 'tar.gz' ]
|
||||||
format_overrides:
|
format_overrides:
|
||||||
- goos: windows
|
- goos: windows
|
||||||
format: zip
|
formats: [ 'zip' ]
|
||||||
files:
|
files:
|
||||||
- LICENSE
|
- LICENSE
|
||||||
|
|
||||||
|
docker_manifests:
|
||||||
|
- name_template: 'ldez/traefik-certs-dumper:{{ .Tag }}'
|
||||||
|
image_templates:
|
||||||
|
- 'ldez/traefik-certs-dumper:{{ .Tag }}-amd64'
|
||||||
|
- 'ldez/traefik-certs-dumper:{{ .Tag }}-arm64'
|
||||||
|
- 'ldez/traefik-certs-dumper:{{ .Tag }}-armv7'
|
||||||
|
- 'ldez/traefik-certs-dumper:{{ .Tag }}-armv6'
|
||||||
|
- 'ldez/traefik-certs-dumper:{{ .Tag }}-386'
|
||||||
|
- name_template: 'ldez/traefik-certs-dumper:latest'
|
||||||
|
image_templates:
|
||||||
|
- 'ldez/traefik-certs-dumper:{{ .Tag }}-amd64'
|
||||||
|
- 'ldez/traefik-certs-dumper:{{ .Tag }}-arm64'
|
||||||
|
- 'ldez/traefik-certs-dumper:{{ .Tag }}-armv7'
|
||||||
|
- 'ldez/traefik-certs-dumper:{{ .Tag }}-armv6'
|
||||||
|
- 'ldez/traefik-certs-dumper:{{ .Tag }}-386'
|
||||||
|
- name_template: 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}'
|
||||||
|
image_templates:
|
||||||
|
- 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-amd64'
|
||||||
|
- 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-arm64'
|
||||||
|
- 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-armv7'
|
||||||
|
- 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-armv6'
|
||||||
|
- 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-386'
|
||||||
|
- name_template: 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}'
|
||||||
|
image_templates:
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-amd64'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-arm64'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-armv7'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-armv6'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-386'
|
||||||
|
- name_template: 'ghcr.io/ldez/traefik-certs-dumper:latest'
|
||||||
|
image_templates:
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-amd64'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-arm64'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-armv7'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-armv6'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-386'
|
||||||
|
- name_template: 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}'
|
||||||
|
image_templates:
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-amd64'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-arm64'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-armv7'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-armv6'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-386'
|
||||||
|
|
||||||
|
dockers:
|
||||||
|
- use: buildx
|
||||||
|
goos: linux
|
||||||
|
goarch: amd64
|
||||||
|
dockerfile: buildx.Dockerfile
|
||||||
|
image_templates:
|
||||||
|
- 'ldez/traefik-certs-dumper:latest-amd64'
|
||||||
|
- 'ldez/traefik-certs-dumper:{{ .Tag }}-amd64'
|
||||||
|
- 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-amd64'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:latest-amd64'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-amd64'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-amd64'
|
||||||
|
build_flag_templates:
|
||||||
|
- '--pull'
|
||||||
|
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
|
||||||
|
- '--label=org.opencontainers.image.title={{.ProjectName}}'
|
||||||
|
- '--label=org.opencontainers.image.description=Dump ACME data from Traefik to certificates'
|
||||||
|
- '--label=org.opencontainers.image.source={{.GitURL}}'
|
||||||
|
- '--label=org.opencontainers.image.url={{.GitURL}}'
|
||||||
|
- '--label=org.opencontainers.image.documentation=https://github.com/ldez/traefik-certs-dumper'
|
||||||
|
- '--label=org.opencontainers.image.created={{.Date}}'
|
||||||
|
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
|
||||||
|
- '--label=org.opencontainers.image.version={{.Version}}'
|
||||||
|
- '--platform=linux/amd64'
|
||||||
|
|
||||||
|
- use: buildx
|
||||||
|
goos: linux
|
||||||
|
goarch: arm64
|
||||||
|
dockerfile: buildx.Dockerfile
|
||||||
|
image_templates:
|
||||||
|
- 'ldez/traefik-certs-dumper:latest-arm64'
|
||||||
|
- 'ldez/traefik-certs-dumper:latest-arm.v8' # only for compatibility with Seihon
|
||||||
|
- 'ldez/traefik-certs-dumper:{{ .Tag }}-arm64'
|
||||||
|
- 'ldez/traefik-certs-dumper:{{ .Tag }}-arm.v8' # only for compatibility with Seihon
|
||||||
|
- 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-arm64'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:latest-arm64'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-arm64'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-arm64'
|
||||||
|
build_flag_templates:
|
||||||
|
- '--pull'
|
||||||
|
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
|
||||||
|
- '--label=org.opencontainers.image.title={{.ProjectName}}'
|
||||||
|
- '--label=org.opencontainers.image.description=Dump ACME data from Traefik to certificates'
|
||||||
|
- '--label=org.opencontainers.image.source={{.GitURL}}'
|
||||||
|
- '--label=org.opencontainers.image.url={{.GitURL}}'
|
||||||
|
- '--label=org.opencontainers.image.documentation=https://github.com/ldez/traefik-certs-dumper'
|
||||||
|
- '--label=org.opencontainers.image.created={{.Date}}'
|
||||||
|
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
|
||||||
|
- '--label=org.opencontainers.image.version={{.Version}}'
|
||||||
|
- '--platform=linux/arm64'
|
||||||
|
|
||||||
|
- use: buildx
|
||||||
|
goos: linux
|
||||||
|
goarch: arm
|
||||||
|
goarm: '7'
|
||||||
|
dockerfile: buildx.Dockerfile
|
||||||
|
image_templates:
|
||||||
|
- 'ldez/traefik-certs-dumper:latest-armv7'
|
||||||
|
- 'ldez/traefik-certs-dumper:latest-arm.v7' # only for compatibility with Seihon
|
||||||
|
- 'ldez/traefik-certs-dumper:{{ .Tag }}-armv7'
|
||||||
|
- 'ldez/traefik-certs-dumper:{{ .Tag }}-arm.v7' # only for compatibility with Seihon
|
||||||
|
- 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-armv7'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:latest-armv7'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-armv7'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-armv7'
|
||||||
|
build_flag_templates:
|
||||||
|
- '--pull'
|
||||||
|
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
|
||||||
|
- '--label=org.opencontainers.image.title={{.ProjectName}}'
|
||||||
|
- '--label=org.opencontainers.image.description=Dump ACME data from Traefik to certificates'
|
||||||
|
- '--label=org.opencontainers.image.source={{.GitURL}}'
|
||||||
|
- '--label=org.opencontainers.image.url={{.GitURL}}'
|
||||||
|
- '--label=org.opencontainers.image.documentation=https://github.com/ldez/traefik-certs-dumper'
|
||||||
|
- '--label=org.opencontainers.image.created={{.Date}}'
|
||||||
|
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
|
||||||
|
- '--label=org.opencontainers.image.version={{.Version}}'
|
||||||
|
- '--platform=linux/arm/v7'
|
||||||
|
|
||||||
|
- use: buildx
|
||||||
|
goos: linux
|
||||||
|
goarch: arm
|
||||||
|
goarm: '6'
|
||||||
|
dockerfile: buildx.Dockerfile
|
||||||
|
image_templates:
|
||||||
|
- 'ldez/traefik-certs-dumper:latest-armv6'
|
||||||
|
- 'ldez/traefik-certs-dumper:latest-arm.v6' # only for compatibility with Seihon
|
||||||
|
- 'ldez/traefik-certs-dumper:{{ .Tag }}-armv6'
|
||||||
|
- 'ldez/traefik-certs-dumper:{{ .Tag }}-arm.v6' # only for compatibility with Seihon
|
||||||
|
- 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-armv6'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:latest-armv6'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-armv6'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-armv6'
|
||||||
|
build_flag_templates:
|
||||||
|
- '--pull'
|
||||||
|
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
|
||||||
|
- '--label=org.opencontainers.image.title={{.ProjectName}}'
|
||||||
|
- '--label=org.opencontainers.image.description=Dump ACME data from Traefik to certificates'
|
||||||
|
- '--label=org.opencontainers.image.source={{.GitURL}}'
|
||||||
|
- '--label=org.opencontainers.image.url={{.GitURL}}'
|
||||||
|
- '--label=org.opencontainers.image.documentation=https://github.com/ldez/traefik-certs-dumper'
|
||||||
|
- '--label=org.opencontainers.image.created={{.Date}}'
|
||||||
|
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
|
||||||
|
- '--label=org.opencontainers.image.version={{.Version}}'
|
||||||
|
- '--platform=linux/arm/v6'
|
||||||
|
|
||||||
|
- use: buildx
|
||||||
|
goos: linux
|
||||||
|
goarch: '386'
|
||||||
|
dockerfile: buildx.Dockerfile
|
||||||
|
image_templates:
|
||||||
|
- 'ldez/traefik-certs-dumper:latest-386'
|
||||||
|
- 'ldez/traefik-certs-dumper:{{ .Tag }}-386'
|
||||||
|
- 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-386'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:latest-386'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-386'
|
||||||
|
- 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-386'
|
||||||
|
build_flag_templates:
|
||||||
|
- '--pull'
|
||||||
|
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
|
||||||
|
- '--label=org.opencontainers.image.title={{.ProjectName}}'
|
||||||
|
- '--label=org.opencontainers.image.description=Dump ACME data from Traefik to certificates'
|
||||||
|
- '--label=org.opencontainers.image.source={{.GitURL}}'
|
||||||
|
- '--label=org.opencontainers.image.url={{.GitURL}}'
|
||||||
|
- '--label=org.opencontainers.image.documentation=https://github.com/ldez/traefik-certs-dumper'
|
||||||
|
- '--label=org.opencontainers.image.created={{.Date}}'
|
||||||
|
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
|
||||||
|
- '--label=org.opencontainers.image.version={{.Version}}'
|
||||||
|
- '--platform=linux/386'
|
||||||
|
|||||||
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
|||||||
Copyright 2019 Fernandez Ludovic
|
Copyright 2019-2024 Fernandez Ludovic
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
3
Makefile
3
Makefile
@ -25,6 +25,3 @@ checks:
|
|||||||
|
|
||||||
doc:
|
doc:
|
||||||
go run . doc
|
go run . doc
|
||||||
|
|
||||||
publish-images:
|
|
||||||
seihon publish -v "$(TAG_NAME)" -v "latest" --image-name ldez/traefik-certs-dumper --dry-run=false
|
|
||||||
|
|||||||
9
buildx.Dockerfile
Normal file
9
buildx.Dockerfile
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# syntax=docker/dockerfile:1.4
|
||||||
|
FROM alpine:3
|
||||||
|
|
||||||
|
RUN apk --no-cache --no-progress add git ca-certificates tzdata jq \
|
||||||
|
&& rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
|
COPY traefik-certs-dumper /usr/bin/traefik-certs-dumper
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/bin/traefik-certs-dumper"]
|
||||||
@ -1,8 +1,10 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/abronan/valkeyrie/store"
|
"context"
|
||||||
"github.com/abronan/valkeyrie/store/boltdb"
|
"time"
|
||||||
|
|
||||||
|
"github.com/kvtools/boltdb"
|
||||||
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
||||||
"github.com/ldez/traefik-certs-dumper/v2/dumper/kv"
|
"github.com/ldez/traefik-certs-dumper/v2/dumper/kv"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -29,11 +31,20 @@ func boltdbRun(baseConfig *dumper.BaseConfig, cmd *cobra.Command) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
config.Options.Bucket = cmd.Flag("bucket").Value.String()
|
connectionTimeout, err := cmd.Flags().GetInt("connection-timeout")
|
||||||
config.Options.PersistConnection, _ = cmd.Flags().GetBool("persist-connection")
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
config.Backend = store.BOLTDB
|
persistConnection, _ := cmd.Flags().GetBool("persist-connection")
|
||||||
boltdb.Register()
|
|
||||||
|
|
||||||
return kv.Dump(config, baseConfig)
|
config.Options = &boltdb.Config{
|
||||||
|
Bucket: cmd.Flag("bucket").Value.String(),
|
||||||
|
PersistConnection: persistConnection,
|
||||||
|
ConnectionTimeout: time.Duration(connectionTimeout) * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
|
config.StoreName = boltdb.StoreName
|
||||||
|
|
||||||
|
return kv.Dump(context.Background(), config, baseConfig)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/abronan/valkeyrie/store"
|
"context"
|
||||||
"github.com/abronan/valkeyrie/store/consul"
|
"time"
|
||||||
|
|
||||||
|
"github.com/kvtools/consul"
|
||||||
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
||||||
"github.com/ldez/traefik-certs-dumper/v2/dumper/kv"
|
"github.com/ldez/traefik-certs-dumper/v2/dumper/kv"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -28,10 +30,24 @@ func consulRun(baseConfig *dumper.BaseConfig, cmd *cobra.Command) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
config.Options.Token = cmd.Flag("token").Value.String()
|
tlsConfig, err := createTLSConfig(cmd)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
config.Backend = store.CONSUL
|
connectionTimeout, err := cmd.Flags().GetInt("connection-timeout")
|
||||||
consul.Register()
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return kv.Dump(config, baseConfig)
|
config.Options = &consul.Config{
|
||||||
|
TLS: tlsConfig,
|
||||||
|
ConnectionTimeout: time.Duration(connectionTimeout) * time.Second,
|
||||||
|
Token: cmd.Flag("token").Value.String(),
|
||||||
|
Namespace: "",
|
||||||
|
}
|
||||||
|
|
||||||
|
config.StoreName = consul.StoreName
|
||||||
|
|
||||||
|
return kv.Dump(context.Background(), config, baseConfig)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ var docCmd = &cobra.Command{
|
|||||||
Use: "doc",
|
Use: "doc",
|
||||||
Short: "Generate documentation",
|
Short: "Generate documentation",
|
||||||
Hidden: true,
|
Hidden: true,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(_ *cobra.Command, _ []string) error {
|
||||||
return doc.GenMarkdownTree(rootCmd, "./docs")
|
return doc.GenMarkdownTree(rootCmd, "./docs")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
42
cmd/etcd.go
42
cmd/etcd.go
@ -1,11 +1,11 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/abronan/valkeyrie/store"
|
"github.com/kvtools/etcdv2"
|
||||||
etcdv2 "github.com/abronan/valkeyrie/store/etcd/v2"
|
"github.com/kvtools/etcdv3"
|
||||||
etcdv3 "github.com/abronan/valkeyrie/store/etcd/v3"
|
|
||||||
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
||||||
"github.com/ldez/traefik-certs-dumper/v2/dumper/kv"
|
"github.com/ldez/traefik-certs-dumper/v2/dumper/kv"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -32,25 +32,47 @@ func etcdRun(baseConfig *dumper.BaseConfig, cmd *cobra.Command) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
backend, err := cmd.Flags().GetString("etcd-version")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
tlsConfig, err := createTLSConfig(cmd)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
synPeriod, err := cmd.Flags().GetInt("sync-period")
|
synPeriod, err := cmd.Flags().GetInt("sync-period")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
config.Options.SyncPeriod = time.Duration(synPeriod) * time.Second
|
|
||||||
|
|
||||||
backend, err := cmd.Flags().GetString("etcd-version")
|
connectionTimeout, err := cmd.Flags().GetInt("connection-timeout")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch backend {
|
switch backend {
|
||||||
case "etcdv3":
|
case "etcdv3":
|
||||||
config.Backend = store.ETCDV3
|
config.Options = &etcdv3.Config{
|
||||||
etcdv3.Register()
|
TLS: tlsConfig,
|
||||||
|
ConnectionTimeout: time.Duration(connectionTimeout) * time.Second,
|
||||||
|
SyncPeriod: time.Duration(synPeriod) * time.Second,
|
||||||
|
Username: cmd.Flag("password").Value.String(),
|
||||||
|
Password: cmd.Flag("username").Value.String(),
|
||||||
|
}
|
||||||
|
config.StoreName = etcdv3.StoreName
|
||||||
default:
|
default:
|
||||||
config.Backend = store.ETCD
|
config.Options = &etcdv2.Config{
|
||||||
etcdv2.Register()
|
TLS: tlsConfig,
|
||||||
|
ConnectionTimeout: time.Duration(connectionTimeout) * time.Second,
|
||||||
|
SyncPeriod: time.Duration(synPeriod) * time.Second,
|
||||||
|
Username: cmd.Flag("password").Value.String(),
|
||||||
|
Password: cmd.Flag("username").Value.String(),
|
||||||
|
}
|
||||||
|
|
||||||
|
config.StoreName = etcdv2.StoreName
|
||||||
}
|
}
|
||||||
|
|
||||||
return kv.Dump(config, baseConfig)
|
return kv.Dump(context.Background(), config, baseConfig)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
||||||
"github.com/ldez/traefik-certs-dumper/v2/dumper/file"
|
"github.com/ldez/traefik-certs-dumper/v2/dumper/file"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// fileCmd represents the file command.
|
|
||||||
var fileCmd = &cobra.Command{
|
var fileCmd = &cobra.Command{
|
||||||
Use: "file",
|
Use: "file",
|
||||||
Short: `Dump the content of the "acme.json" file.`,
|
Short: `Dump the content of the "acme.json" file.`,
|
||||||
@ -16,7 +17,7 @@ var fileCmd = &cobra.Command{
|
|||||||
|
|
||||||
baseConfig.Version = cmd.Flag("version").Value.String()
|
baseConfig.Version = cmd.Flag("version").Value.String()
|
||||||
|
|
||||||
return file.Dump(acmeFile, baseConfig)
|
return file.Dump(context.Background(), acmeFile, baseConfig)
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,5 +25,5 @@ func init() {
|
|||||||
rootCmd.AddCommand(fileCmd)
|
rootCmd.AddCommand(fileCmd)
|
||||||
|
|
||||||
fileCmd.Flags().String("source", "./acme.json", "Path to 'acme.json' file.")
|
fileCmd.Flags().String("source", "./acme.json", "Path to 'acme.json' file.")
|
||||||
fileCmd.Flags().String("version", "", "Traefik version. If empty use v1. Possible values: 'v2'.")
|
fileCmd.Flags().String("version", "", "Traefik version. If empty use v1. Possible values: 'v2', 'v3'.")
|
||||||
}
|
}
|
||||||
|
|||||||
29
cmd/kv.go
29
cmd/kv.go
@ -3,12 +3,11 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/abronan/valkeyrie/store"
|
|
||||||
"github.com/ldez/traefik-certs-dumper/v2/dumper/kv"
|
"github.com/ldez/traefik-certs-dumper/v2/dumper/kv"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@ -44,26 +43,10 @@ func getKvConfig(cmd *cobra.Command) (*kv.Config, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
connectionTimeout, err := cmd.Flags().GetInt("connection-timeout")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
tlsConfig, err := createTLSConfig(cmd)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &kv.Config{
|
return &kv.Config{
|
||||||
Endpoints: endpoints,
|
Endpoints: endpoints,
|
||||||
Prefix: cmd.Flag("prefix").Value.String(),
|
Prefix: cmd.Flag("prefix").Value.String(),
|
||||||
Suffix: cmd.Flag("suffix").Value.String(),
|
Suffix: cmd.Flag("suffix").Value.String(),
|
||||||
Options: &store.Config{
|
|
||||||
ConnectionTimeout: time.Duration(connectionTimeout) * time.Second,
|
|
||||||
Username: cmd.Flag("password").Value.String(),
|
|
||||||
Password: cmd.Flag("username").Value.String(),
|
|
||||||
TLS: tlsConfig,
|
|
||||||
},
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +70,7 @@ func createTLSConfig(cmd *cobra.Command) (*tls.Config, error) {
|
|||||||
certContent := cmd.Flag("tls.cert").Value.String()
|
certContent := cmd.Flag("tls.cert").Value.String()
|
||||||
|
|
||||||
if !insecureSkipVerify && (certContent == "" || privateKey == "") {
|
if !insecureSkipVerify && (certContent == "" || privateKey == "") {
|
||||||
return nil, fmt.Errorf("TLS Certificate or Key file must be set when TLS configuration is created")
|
return nil, errors.New("TLS Certificate or Key file must be set when TLS configuration is created")
|
||||||
}
|
}
|
||||||
|
|
||||||
cert, err := getCertificate(privateKey, certContent)
|
cert, err := getCertificate(privateKey, certContent)
|
||||||
@ -98,7 +81,7 @@ func createTLSConfig(cmd *cobra.Command) (*tls.Config, error) {
|
|||||||
return &tls.Config{
|
return &tls.Config{
|
||||||
Certificates: []tls.Certificate{cert},
|
Certificates: []tls.Certificate{cert},
|
||||||
RootCAs: caPool,
|
RootCAs: caPool,
|
||||||
InsecureSkipVerify: insecureSkipVerify,
|
InsecureSkipVerify: insecureSkipVerify, //nolint:gosec // it's a CLI option.
|
||||||
ClientAuth: clientAuth,
|
ClientAuth: clientAuth,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@ -113,7 +96,7 @@ func getCertPool(ca string) (*x509.CertPool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !caPool.AppendCertsFromPEM(caContent) {
|
if !caPool.AppendCertsFromPEM(caContent) {
|
||||||
return nil, fmt.Errorf("failed to parse CA")
|
return nil, errors.New("failed to parse CA")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,11 +138,11 @@ func getCertificate(privateKey, certContent string) (tls.Certificate, error) {
|
|||||||
_, errCertIsFile := os.Stat(certContent)
|
_, errCertIsFile := os.Stat(certContent)
|
||||||
|
|
||||||
if errCertIsFile == nil && os.IsNotExist(errKeyIsFile) {
|
if errCertIsFile == nil && os.IsNotExist(errKeyIsFile) {
|
||||||
return tls.Certificate{}, fmt.Errorf("tls cert is a file, but tls key is not")
|
return tls.Certificate{}, errors.New("tls cert is a file, but tls key is not")
|
||||||
}
|
}
|
||||||
|
|
||||||
if os.IsNotExist(errCertIsFile) && errKeyIsFile == nil {
|
if os.IsNotExist(errCertIsFile) && errKeyIsFile == nil {
|
||||||
return tls.Certificate{}, fmt.Errorf("TLS key is a file, but tls cert is not")
|
return tls.Certificate{}, errors.New("TLS key is a file, but tls cert is not")
|
||||||
}
|
}
|
||||||
|
|
||||||
// string
|
// string
|
||||||
|
|||||||
44
cmd/root.go
44
cmd/root.go
@ -1,12 +1,16 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
||||||
"github.com/mitchellh/go-homedir"
|
"github.com/mitchellh/go-homedir"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -20,7 +24,7 @@ var rootCmd = &cobra.Command{
|
|||||||
Use: "traefik-certs-dumper",
|
Use: "traefik-certs-dumper",
|
||||||
Short: "Dump Let's Encrypt certificates from Traefik.",
|
Short: "Dump Let's Encrypt certificates from Traefik.",
|
||||||
Long: `Dump Let's Encrypt certificates from Traefik.`,
|
Long: `Dump Let's Encrypt certificates from Traefik.`,
|
||||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
|
||||||
if cmd.Name() == "version" {
|
if cmd.Name() == "version" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -34,6 +38,7 @@ var rootCmd = &cobra.Command{
|
|||||||
return fmt.Errorf("--crt-ext (%q) and --key-ext (%q) are identical, in this case --domain-subdir is required", crtExt, keyExt)
|
return fmt.Errorf("--crt-ext (%q) and --key-ext (%q) are identical, in this case --domain-subdir is required", crtExt, keyExt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -45,6 +50,8 @@ func Execute() {
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
help()
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -131,10 +138,10 @@ func tree(root, indent string) error {
|
|||||||
for i, name := range names {
|
for i, name := range names {
|
||||||
add := "│ "
|
add := "│ "
|
||||||
if i == len(names)-1 {
|
if i == len(names)-1 {
|
||||||
fmt.Printf(indent + "└──")
|
fmt.Print(indent + "└──")
|
||||||
add = " "
|
add = " "
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf(indent + "├──")
|
fmt.Print(indent + "├──")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := tree(filepath.Join(root, name), indent+add); err != nil {
|
if err := tree(filepath.Join(root, name), indent+add); err != nil {
|
||||||
@ -177,3 +184,34 @@ func getBaseConfig(cmd *cobra.Command) (*dumper.BaseConfig, error) {
|
|||||||
Hook: cmd.Flag("post-hook").Value.String(),
|
Hook: cmd.Flag("post-hook").Value.String(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func help() {
|
||||||
|
var maxInt int64 = 2 // -> 50%
|
||||||
|
if time.Now().Month() == time.December {
|
||||||
|
maxInt = 1 // -> 100%
|
||||||
|
}
|
||||||
|
|
||||||
|
n, _ := rand.Int(rand.Reader, big.NewInt(maxInt))
|
||||||
|
if n.Cmp(big.NewInt(0)) != 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.SetFlags(0)
|
||||||
|
|
||||||
|
pStyle := lipgloss.NewStyle().
|
||||||
|
Padding(1).
|
||||||
|
BorderStyle(lipgloss.RoundedBorder()).
|
||||||
|
BorderForeground(lipgloss.Color("161")).
|
||||||
|
Align(lipgloss.Center)
|
||||||
|
|
||||||
|
hStyle := lipgloss.NewStyle().Bold(true)
|
||||||
|
|
||||||
|
s := fmt.Sprintln(hStyle.Render("Request for Donation."))
|
||||||
|
s += `
|
||||||
|
I need your help!
|
||||||
|
Donations fund the maintenance and development of traefik-certs-dumper.
|
||||||
|
Click on this link to donate: https://donate.ldez.dev`
|
||||||
|
|
||||||
|
log.Println(pStyle.Render(s))
|
||||||
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||||
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ var (
|
|||||||
var versionCmd = &cobra.Command{
|
var versionCmd = &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "Display version",
|
Short: "Display version",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(_ *cobra.Command, _ []string) {
|
||||||
displayVersion(rootCmd.Name())
|
displayVersion(rootCmd.Name())
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/abronan/valkeyrie/store"
|
"context"
|
||||||
"github.com/abronan/valkeyrie/store/zookeeper"
|
"time"
|
||||||
|
|
||||||
|
"github.com/kvtools/zookeeper"
|
||||||
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
||||||
"github.com/ldez/traefik-certs-dumper/v2/dumper/kv"
|
"github.com/ldez/traefik-certs-dumper/v2/dumper/kv"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -26,8 +28,19 @@ func zookeeperRun(baseConfig *dumper.BaseConfig, cmd *cobra.Command) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
config.Backend = store.ZK
|
connectionTimeout, err := cmd.Flags().GetInt("connection-timeout")
|
||||||
zookeeper.Register()
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return kv.Dump(config, baseConfig)
|
config.Options = &zookeeper.Config{
|
||||||
|
ConnectionTimeout: time.Duration(connectionTimeout) * time.Second,
|
||||||
|
Username: cmd.Flag("password").Value.String(),
|
||||||
|
Password: cmd.Flag("username").Value.String(),
|
||||||
|
MaxBufferSize: 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
config.StoreName = zookeeper.StoreName
|
||||||
|
|
||||||
|
return kv.Dump(context.Background(), config, baseConfig)
|
||||||
}
|
}
|
||||||
|
|||||||
1
contrib/readme.md
Normal file
1
contrib/readme.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
This directory content external contributions that are not maintain by @ldez.
|
||||||
40
contrib/traefik-certs-dumper.service
Normal file
40
contrib/traefik-certs-dumper.service
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=traefik certs dumper
|
||||||
|
; If you do not start traefik via systemd, choose network.target or docker.target
|
||||||
|
After=traefik.target
|
||||||
|
Wants=network-online.target systemd-networkd-wait-online.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Restart=on-abnormal
|
||||||
|
User=root
|
||||||
|
ExecStart=/usr/local/bin/traefik-certs-dumper file --version v2 --source /etc/traefik/acme/acme.json --dest /etc/ssl --watch
|
||||||
|
RestartSec=30
|
||||||
|
TimeoutSec=30
|
||||||
|
;WatchdogSec=30
|
||||||
|
|
||||||
|
; Limit the number of file descriptors; see `man systemd.exec` for more limit settings.
|
||||||
|
; LimitNOFILE=1048576
|
||||||
|
; Limit number of processes in this unit
|
||||||
|
LimitNPROC=1
|
||||||
|
|
||||||
|
; Use private /tmp and /var/tmp, which are discarded after traefik stops.
|
||||||
|
PrivateTmp=true
|
||||||
|
; Use a minimal /dev (May bring additional security if switched to 'true', but it may not work on Raspberry Pis or other devices)
|
||||||
|
PrivateDevices=true
|
||||||
|
; Hide /home, /root, and /run/user. Nobody will steal your SSH-keys.
|
||||||
|
ProtectHome=true
|
||||||
|
; Make cgroups /sys/fs/cgroup read-only
|
||||||
|
ProtectControlGroups=true
|
||||||
|
; Make kernel settings (procfs and sysfs) read-only
|
||||||
|
ProtectKernelTunables=true
|
||||||
|
; Make /usr, /boot, /etc and possibly some more folders read-only.
|
||||||
|
ProtectSystem=full
|
||||||
|
; This merely retains r/w access rights, it does not add any new. Must still be writable on the host!
|
||||||
|
ReadWriteDirectories=/etc/ssl
|
||||||
|
ReadOnlyPaths=/etc/traefik/acme/acme.json
|
||||||
|
|
||||||
|
; The following additional security directives only work with systemd v229 or later.
|
||||||
|
NoNewPrivileges=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@ -1,5 +1,3 @@
|
|||||||
version: '3.7'
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
traefik:
|
traefik:
|
||||||
image: traefik:v1.7
|
image: traefik:v1.7
|
||||||
@ -25,10 +23,9 @@ services:
|
|||||||
- ./letsencrypt:/letsencrypt
|
- ./letsencrypt:/letsencrypt
|
||||||
|
|
||||||
traefik-certs-dumper:
|
traefik-certs-dumper:
|
||||||
image: ldez/traefik-certs-dumper:v2.7.4
|
image: ldez/traefik-certs-dumper:v2.9.3
|
||||||
entrypoint: sh -c '
|
entrypoint: sh -c '
|
||||||
apk add jq
|
while ! [ -e /data/acme.json ]
|
||||||
; while ! [ -e /data/acme.json ]
|
|
||||||
|| ! [ `jq ".Certificates | length" /data/acme.json` != 0 ]; do
|
|| ! [ `jq ".Certificates | length" /data/acme.json` != 0 ]; do
|
||||||
sleep 1
|
sleep 1
|
||||||
; done
|
; done
|
||||||
@ -36,9 +33,10 @@ services:
|
|||||||
--source /data/acme.json --dest /data/certs'
|
--source /data/acme.json --dest /data/certs'
|
||||||
volumes:
|
volumes:
|
||||||
- ./letsencrypt:/data
|
- ./letsencrypt:/data
|
||||||
|
network_mode: "none"
|
||||||
|
|
||||||
whoami:
|
whoami:
|
||||||
image: traefik/whoami:v1.6.0
|
image: traefik/whoami:v1.8.1
|
||||||
labels:
|
labels:
|
||||||
traefik.enable: true
|
traefik.enable: true
|
||||||
traefik.frontend.rule: Host:example.com
|
traefik.frontend.rule: Host:example.com
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
version: '3.7'
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
|
||||||
traefik:
|
traefik:
|
||||||
image: traefik:v2.3
|
image: traefik:v2.11.3
|
||||||
command:
|
command:
|
||||||
- --log.level=INFO
|
- --log.level=INFO
|
||||||
- --entrypoints.web.address=:80
|
- --entrypoints.web.address=:80
|
||||||
@ -18,27 +16,27 @@ services:
|
|||||||
- --certificatesresolvers.le.acme.storage=/letsencrypt/acme.json
|
- --certificatesresolvers.le.acme.storage=/letsencrypt/acme.json
|
||||||
- --certificatesresolvers.le.acme.tlsChallenge=true
|
- --certificatesresolvers.le.acme.tlsChallenge=true
|
||||||
ports:
|
ports:
|
||||||
- 80:80
|
- "80:80"
|
||||||
- 443:443
|
- "443:443"
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||||
- ./letsencrypt/:/letsencrypt
|
- ./letsencrypt/:/letsencrypt
|
||||||
|
|
||||||
traefik-certs-dumper:
|
traefik-certs-dumper:
|
||||||
image: ldez/traefik-certs-dumper:v2.7.4
|
image: ldez/traefik-certs-dumper:v2.9.3
|
||||||
entrypoint: sh -c '
|
entrypoint: sh -c '
|
||||||
apk add jq
|
while ! [ -e /data/acme.json ]
|
||||||
; while ! [ -e /data/acme.json ]
|
|| ! [ `jq ".[] | .Certificates | length" /data/acme.json | jq -s "add" ` != 0 ]; do
|
||||||
|| ! [ `jq ".[] | .Certificates | length" /data/acme.json` != 0 ]; do
|
|
||||||
sleep 1
|
sleep 1
|
||||||
; done
|
; done
|
||||||
&& traefik-certs-dumper file --version v2 --watch
|
&& traefik-certs-dumper file --version v2 --watch
|
||||||
--source /data/acme.json --dest /data/certs'
|
--source /data/acme.json --dest /data/certs'
|
||||||
volumes:
|
volumes:
|
||||||
- ./letsencrypt:/data
|
- ./letsencrypt:/data
|
||||||
|
network_mode: "none"
|
||||||
|
|
||||||
whoami:
|
whoami:
|
||||||
image: traefik/whoami:v1.6.0
|
image: traefik/whoami:v1.8.1
|
||||||
labels:
|
labels:
|
||||||
traefik.enable: 'true'
|
traefik.enable: 'true'
|
||||||
|
|
||||||
|
|||||||
@ -24,8 +24,9 @@ Dump Let's Encrypt certificates from Traefik.
|
|||||||
|
|
||||||
### SEE ALSO
|
### SEE ALSO
|
||||||
|
|
||||||
|
* [traefik-certs-dumper completion](traefik-certs-dumper_completion.md) - Generate the autocompletion script for the specified shell
|
||||||
* [traefik-certs-dumper file](traefik-certs-dumper_file.md) - Dump the content of the "acme.json" file.
|
* [traefik-certs-dumper file](traefik-certs-dumper_file.md) - Dump the content of the "acme.json" file.
|
||||||
* [traefik-certs-dumper kv](traefik-certs-dumper_kv.md) - Dump the content of a KV store.
|
* [traefik-certs-dumper kv](traefik-certs-dumper_kv.md) - Dump the content of a KV store.
|
||||||
* [traefik-certs-dumper version](traefik-certs-dumper_version.md) - Display version
|
* [traefik-certs-dumper version](traefik-certs-dumper_version.md) - Display version
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 9-Oct-2019
|
###### Auto generated by spf13/cobra on 21-Feb-2025
|
||||||
|
|||||||
40
docs/traefik-certs-dumper_completion.md
Normal file
40
docs/traefik-certs-dumper_completion.md
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
## traefik-certs-dumper completion
|
||||||
|
|
||||||
|
Generate the autocompletion script for the specified shell
|
||||||
|
|
||||||
|
### Synopsis
|
||||||
|
|
||||||
|
Generate the autocompletion script for traefik-certs-dumper for the specified shell.
|
||||||
|
See each sub-command's help for details on how to use the generated script.
|
||||||
|
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
```
|
||||||
|
-h, --help help for completion
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options inherited from parent commands
|
||||||
|
|
||||||
|
```
|
||||||
|
--clean Clean destination folder before dumping content. (default true)
|
||||||
|
--config string config file (default is $HOME/.traefik-certs-dumper.yaml)
|
||||||
|
--crt-ext string The file extension of the generated certificates. (default ".crt")
|
||||||
|
--crt-name string The file name (without extension) of the generated certificates. (default "certificate")
|
||||||
|
--dest string Path to store the dump content. (default "./dump")
|
||||||
|
--domain-subdir Use domain as sub-directory.
|
||||||
|
--key-ext string The file extension of the generated private keys. (default ".key")
|
||||||
|
--key-name string The file name (without extension) of the generated private keys. (default "privatekey")
|
||||||
|
--post-hook string Execute a command only if changes occurs on the data source. (works only with the watch mode)
|
||||||
|
--watch Enable watching changes.
|
||||||
|
```
|
||||||
|
|
||||||
|
### SEE ALSO
|
||||||
|
|
||||||
|
* [traefik-certs-dumper](traefik-certs-dumper.md) - Dump Let's Encrypt certificates from Traefik.
|
||||||
|
* [traefik-certs-dumper completion bash](traefik-certs-dumper_completion_bash.md) - Generate the autocompletion script for bash
|
||||||
|
* [traefik-certs-dumper completion fish](traefik-certs-dumper_completion_fish.md) - Generate the autocompletion script for fish
|
||||||
|
* [traefik-certs-dumper completion powershell](traefik-certs-dumper_completion_powershell.md) - Generate the autocompletion script for powershell
|
||||||
|
* [traefik-certs-dumper completion zsh](traefik-certs-dumper_completion_zsh.md) - Generate the autocompletion script for zsh
|
||||||
|
|
||||||
|
###### Auto generated by spf13/cobra on 21-Feb-2025
|
||||||
59
docs/traefik-certs-dumper_completion_bash.md
Normal file
59
docs/traefik-certs-dumper_completion_bash.md
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
## traefik-certs-dumper completion bash
|
||||||
|
|
||||||
|
Generate the autocompletion script for bash
|
||||||
|
|
||||||
|
### Synopsis
|
||||||
|
|
||||||
|
Generate the autocompletion script for the bash shell.
|
||||||
|
|
||||||
|
This script depends on the 'bash-completion' package.
|
||||||
|
If it is not installed already, you can install it via your OS's package manager.
|
||||||
|
|
||||||
|
To load completions in your current shell session:
|
||||||
|
|
||||||
|
source <(traefik-certs-dumper completion bash)
|
||||||
|
|
||||||
|
To load completions for every new session, execute once:
|
||||||
|
|
||||||
|
#### Linux:
|
||||||
|
|
||||||
|
traefik-certs-dumper completion bash > /etc/bash_completion.d/traefik-certs-dumper
|
||||||
|
|
||||||
|
#### macOS:
|
||||||
|
|
||||||
|
traefik-certs-dumper completion bash > $(brew --prefix)/etc/bash_completion.d/traefik-certs-dumper
|
||||||
|
|
||||||
|
You will need to start a new shell for this setup to take effect.
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
traefik-certs-dumper completion bash
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
```
|
||||||
|
-h, --help help for bash
|
||||||
|
--no-descriptions disable completion descriptions
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options inherited from parent commands
|
||||||
|
|
||||||
|
```
|
||||||
|
--clean Clean destination folder before dumping content. (default true)
|
||||||
|
--config string config file (default is $HOME/.traefik-certs-dumper.yaml)
|
||||||
|
--crt-ext string The file extension of the generated certificates. (default ".crt")
|
||||||
|
--crt-name string The file name (without extension) of the generated certificates. (default "certificate")
|
||||||
|
--dest string Path to store the dump content. (default "./dump")
|
||||||
|
--domain-subdir Use domain as sub-directory.
|
||||||
|
--key-ext string The file extension of the generated private keys. (default ".key")
|
||||||
|
--key-name string The file name (without extension) of the generated private keys. (default "privatekey")
|
||||||
|
--post-hook string Execute a command only if changes occurs on the data source. (works only with the watch mode)
|
||||||
|
--watch Enable watching changes.
|
||||||
|
```
|
||||||
|
|
||||||
|
### SEE ALSO
|
||||||
|
|
||||||
|
* [traefik-certs-dumper completion](traefik-certs-dumper_completion.md) - Generate the autocompletion script for the specified shell
|
||||||
|
|
||||||
|
###### Auto generated by spf13/cobra on 21-Feb-2025
|
||||||
50
docs/traefik-certs-dumper_completion_fish.md
Normal file
50
docs/traefik-certs-dumper_completion_fish.md
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
## traefik-certs-dumper completion fish
|
||||||
|
|
||||||
|
Generate the autocompletion script for fish
|
||||||
|
|
||||||
|
### Synopsis
|
||||||
|
|
||||||
|
Generate the autocompletion script for the fish shell.
|
||||||
|
|
||||||
|
To load completions in your current shell session:
|
||||||
|
|
||||||
|
traefik-certs-dumper completion fish | source
|
||||||
|
|
||||||
|
To load completions for every new session, execute once:
|
||||||
|
|
||||||
|
traefik-certs-dumper completion fish > ~/.config/fish/completions/traefik-certs-dumper.fish
|
||||||
|
|
||||||
|
You will need to start a new shell for this setup to take effect.
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
traefik-certs-dumper completion fish [flags]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
```
|
||||||
|
-h, --help help for fish
|
||||||
|
--no-descriptions disable completion descriptions
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options inherited from parent commands
|
||||||
|
|
||||||
|
```
|
||||||
|
--clean Clean destination folder before dumping content. (default true)
|
||||||
|
--config string config file (default is $HOME/.traefik-certs-dumper.yaml)
|
||||||
|
--crt-ext string The file extension of the generated certificates. (default ".crt")
|
||||||
|
--crt-name string The file name (without extension) of the generated certificates. (default "certificate")
|
||||||
|
--dest string Path to store the dump content. (default "./dump")
|
||||||
|
--domain-subdir Use domain as sub-directory.
|
||||||
|
--key-ext string The file extension of the generated private keys. (default ".key")
|
||||||
|
--key-name string The file name (without extension) of the generated private keys. (default "privatekey")
|
||||||
|
--post-hook string Execute a command only if changes occurs on the data source. (works only with the watch mode)
|
||||||
|
--watch Enable watching changes.
|
||||||
|
```
|
||||||
|
|
||||||
|
### SEE ALSO
|
||||||
|
|
||||||
|
* [traefik-certs-dumper completion](traefik-certs-dumper_completion.md) - Generate the autocompletion script for the specified shell
|
||||||
|
|
||||||
|
###### Auto generated by spf13/cobra on 21-Feb-2025
|
||||||
47
docs/traefik-certs-dumper_completion_powershell.md
Normal file
47
docs/traefik-certs-dumper_completion_powershell.md
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
## traefik-certs-dumper completion powershell
|
||||||
|
|
||||||
|
Generate the autocompletion script for powershell
|
||||||
|
|
||||||
|
### Synopsis
|
||||||
|
|
||||||
|
Generate the autocompletion script for powershell.
|
||||||
|
|
||||||
|
To load completions in your current shell session:
|
||||||
|
|
||||||
|
traefik-certs-dumper completion powershell | Out-String | Invoke-Expression
|
||||||
|
|
||||||
|
To load completions for every new session, add the output of the above command
|
||||||
|
to your powershell profile.
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
traefik-certs-dumper completion powershell [flags]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
```
|
||||||
|
-h, --help help for powershell
|
||||||
|
--no-descriptions disable completion descriptions
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options inherited from parent commands
|
||||||
|
|
||||||
|
```
|
||||||
|
--clean Clean destination folder before dumping content. (default true)
|
||||||
|
--config string config file (default is $HOME/.traefik-certs-dumper.yaml)
|
||||||
|
--crt-ext string The file extension of the generated certificates. (default ".crt")
|
||||||
|
--crt-name string The file name (without extension) of the generated certificates. (default "certificate")
|
||||||
|
--dest string Path to store the dump content. (default "./dump")
|
||||||
|
--domain-subdir Use domain as sub-directory.
|
||||||
|
--key-ext string The file extension of the generated private keys. (default ".key")
|
||||||
|
--key-name string The file name (without extension) of the generated private keys. (default "privatekey")
|
||||||
|
--post-hook string Execute a command only if changes occurs on the data source. (works only with the watch mode)
|
||||||
|
--watch Enable watching changes.
|
||||||
|
```
|
||||||
|
|
||||||
|
### SEE ALSO
|
||||||
|
|
||||||
|
* [traefik-certs-dumper completion](traefik-certs-dumper_completion.md) - Generate the autocompletion script for the specified shell
|
||||||
|
|
||||||
|
###### Auto generated by spf13/cobra on 21-Feb-2025
|
||||||
61
docs/traefik-certs-dumper_completion_zsh.md
Normal file
61
docs/traefik-certs-dumper_completion_zsh.md
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
## traefik-certs-dumper completion zsh
|
||||||
|
|
||||||
|
Generate the autocompletion script for zsh
|
||||||
|
|
||||||
|
### Synopsis
|
||||||
|
|
||||||
|
Generate the autocompletion script for the zsh shell.
|
||||||
|
|
||||||
|
If shell completion is not already enabled in your environment you will need
|
||||||
|
to enable it. You can execute the following once:
|
||||||
|
|
||||||
|
echo "autoload -U compinit; compinit" >> ~/.zshrc
|
||||||
|
|
||||||
|
To load completions in your current shell session:
|
||||||
|
|
||||||
|
source <(traefik-certs-dumper completion zsh)
|
||||||
|
|
||||||
|
To load completions for every new session, execute once:
|
||||||
|
|
||||||
|
#### Linux:
|
||||||
|
|
||||||
|
traefik-certs-dumper completion zsh > "${fpath[1]}/_traefik-certs-dumper"
|
||||||
|
|
||||||
|
#### macOS:
|
||||||
|
|
||||||
|
traefik-certs-dumper completion zsh > $(brew --prefix)/share/zsh/site-functions/_traefik-certs-dumper
|
||||||
|
|
||||||
|
You will need to start a new shell for this setup to take effect.
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
traefik-certs-dumper completion zsh [flags]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
```
|
||||||
|
-h, --help help for zsh
|
||||||
|
--no-descriptions disable completion descriptions
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options inherited from parent commands
|
||||||
|
|
||||||
|
```
|
||||||
|
--clean Clean destination folder before dumping content. (default true)
|
||||||
|
--config string config file (default is $HOME/.traefik-certs-dumper.yaml)
|
||||||
|
--crt-ext string The file extension of the generated certificates. (default ".crt")
|
||||||
|
--crt-name string The file name (without extension) of the generated certificates. (default "certificate")
|
||||||
|
--dest string Path to store the dump content. (default "./dump")
|
||||||
|
--domain-subdir Use domain as sub-directory.
|
||||||
|
--key-ext string The file extension of the generated private keys. (default ".key")
|
||||||
|
--key-name string The file name (without extension) of the generated private keys. (default "privatekey")
|
||||||
|
--post-hook string Execute a command only if changes occurs on the data source. (works only with the watch mode)
|
||||||
|
--watch Enable watching changes.
|
||||||
|
```
|
||||||
|
|
||||||
|
### SEE ALSO
|
||||||
|
|
||||||
|
* [traefik-certs-dumper completion](traefik-certs-dumper_completion.md) - Generate the autocompletion script for the specified shell
|
||||||
|
|
||||||
|
###### Auto generated by spf13/cobra on 21-Feb-2025
|
||||||
@ -15,7 +15,7 @@ traefik-certs-dumper file [flags]
|
|||||||
```
|
```
|
||||||
-h, --help help for file
|
-h, --help help for file
|
||||||
--source string Path to 'acme.json' file. (default "./acme.json")
|
--source string Path to 'acme.json' file. (default "./acme.json")
|
||||||
--version string Traefik version. If empty use v1. Possible values: 'v2'.
|
--version string Traefik version. If empty use v1. Possible values: 'v2', 'v3'.
|
||||||
```
|
```
|
||||||
|
|
||||||
### Options inherited from parent commands
|
### Options inherited from parent commands
|
||||||
@ -37,4 +37,4 @@ traefik-certs-dumper file [flags]
|
|||||||
|
|
||||||
* [traefik-certs-dumper](traefik-certs-dumper.md) - Dump Let's Encrypt certificates from Traefik.
|
* [traefik-certs-dumper](traefik-certs-dumper.md) - Dump Let's Encrypt certificates from Traefik.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 9-Oct-2019
|
###### Auto generated by spf13/cobra on 21-Feb-2025
|
||||||
|
|||||||
@ -47,4 +47,4 @@ Dump the content of a KV store.
|
|||||||
* [traefik-certs-dumper kv etcd](traefik-certs-dumper_kv_etcd.md) - Dump the content of etcd.
|
* [traefik-certs-dumper kv etcd](traefik-certs-dumper_kv_etcd.md) - Dump the content of etcd.
|
||||||
* [traefik-certs-dumper kv zookeeper](traefik-certs-dumper_kv_zookeeper.md) - Dump the content of zookeeper.
|
* [traefik-certs-dumper kv zookeeper](traefik-certs-dumper_kv_zookeeper.md) - Dump the content of zookeeper.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 9-Oct-2019
|
###### Auto generated by spf13/cobra on 21-Feb-2025
|
||||||
|
|||||||
@ -49,4 +49,4 @@ traefik-certs-dumper kv boltdb [flags]
|
|||||||
|
|
||||||
* [traefik-certs-dumper kv](traefik-certs-dumper_kv.md) - Dump the content of a KV store.
|
* [traefik-certs-dumper kv](traefik-certs-dumper_kv.md) - Dump the content of a KV store.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 9-Oct-2019
|
###### Auto generated by spf13/cobra on 21-Feb-2025
|
||||||
|
|||||||
@ -48,4 +48,4 @@ traefik-certs-dumper kv consul [flags]
|
|||||||
|
|
||||||
* [traefik-certs-dumper kv](traefik-certs-dumper_kv.md) - Dump the content of a KV store.
|
* [traefik-certs-dumper kv](traefik-certs-dumper_kv.md) - Dump the content of a KV store.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 9-Oct-2019
|
###### Auto generated by spf13/cobra on 21-Feb-2025
|
||||||
|
|||||||
@ -49,4 +49,4 @@ traefik-certs-dumper kv etcd [flags]
|
|||||||
|
|
||||||
* [traefik-certs-dumper kv](traefik-certs-dumper_kv.md) - Dump the content of a KV store.
|
* [traefik-certs-dumper kv](traefik-certs-dumper_kv.md) - Dump the content of a KV store.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 9-Oct-2019
|
###### Auto generated by spf13/cobra on 21-Feb-2025
|
||||||
|
|||||||
@ -47,4 +47,4 @@ traefik-certs-dumper kv zookeeper [flags]
|
|||||||
|
|
||||||
* [traefik-certs-dumper kv](traefik-certs-dumper_kv.md) - Dump the content of a KV store.
|
* [traefik-certs-dumper kv](traefik-certs-dumper_kv.md) - Dump the content of a KV store.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 9-Oct-2019
|
###### Auto generated by spf13/cobra on 21-Feb-2025
|
||||||
|
|||||||
@ -2,10 +2,6 @@
|
|||||||
|
|
||||||
Display version
|
Display version
|
||||||
|
|
||||||
### Synopsis
|
|
||||||
|
|
||||||
Display version
|
|
||||||
|
|
||||||
```
|
```
|
||||||
traefik-certs-dumper version [flags]
|
traefik-certs-dumper version [flags]
|
||||||
```
|
```
|
||||||
@ -35,4 +31,4 @@ traefik-certs-dumper version [flags]
|
|||||||
|
|
||||||
* [traefik-certs-dumper](traefik-certs-dumper.md) - Dump Let's Encrypt certificates from Traefik.
|
* [traefik-certs-dumper](traefik-certs-dumper.md) - Dump Let's Encrypt certificates from Traefik.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 9-Oct-2019
|
###### Auto generated by spf13/cobra on 21-Feb-2025
|
||||||
|
|||||||
@ -2,7 +2,8 @@ package file
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/md5"
|
"context"
|
||||||
|
"crypto/sha256"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -14,61 +15,95 @@ import (
|
|||||||
|
|
||||||
"github.com/fsnotify/fsnotify"
|
"github.com/fsnotify/fsnotify"
|
||||||
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
||||||
v1 "github.com/ldez/traefik-certs-dumper/v2/dumper/v1"
|
dumperv1 "github.com/ldez/traefik-certs-dumper/v2/dumper/v1"
|
||||||
v2 "github.com/ldez/traefik-certs-dumper/v2/dumper/v2"
|
dumperv2 "github.com/ldez/traefik-certs-dumper/v2/dumper/v2"
|
||||||
|
dumperv3 "github.com/ldez/traefik-certs-dumper/v2/dumper/v3"
|
||||||
"github.com/ldez/traefik-certs-dumper/v2/hook"
|
"github.com/ldez/traefik-certs-dumper/v2/hook"
|
||||||
"github.com/traefik/traefik/v2/pkg/provider/acme"
|
"github.com/ldez/traefik-certs-dumper/v2/internal/traefikv1"
|
||||||
|
"github.com/ldez/traefik-certs-dumper/v2/internal/traefikv2"
|
||||||
|
"github.com/ldez/traefik-certs-dumper/v2/internal/traefikv3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Dump Dumps "acme.json" file to certificates.
|
// Dump Dumps "acme.json" file to certificates.
|
||||||
func Dump(acmeFile string, baseConfig *dumper.BaseConfig) error {
|
func Dump(ctx context.Context, acmeFile string, baseConfig *dumper.BaseConfig) error {
|
||||||
err := dump(acmeFile, baseConfig)
|
err := dump(acmeFile, baseConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if baseConfig.Watch {
|
if baseConfig.Watch {
|
||||||
hook.Exec(baseConfig.Hook)
|
hook.Exec(ctx, baseConfig.Hook)
|
||||||
|
|
||||||
return watch(acmeFile, baseConfig)
|
return watch(ctx, acmeFile, baseConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func dump(acmeFile string, baseConfig *dumper.BaseConfig) error {
|
func dump(acmeFile string, baseConfig *dumper.BaseConfig) error {
|
||||||
if baseConfig.Version == "v2" {
|
switch baseConfig.Version {
|
||||||
|
case "v3":
|
||||||
|
err := dumpV3(acmeFile, baseConfig)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("v3: dump failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
|
||||||
|
case "v2":
|
||||||
err := dumpV2(acmeFile, baseConfig)
|
err := dumpV2(acmeFile, baseConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("v2: dump failed: %w", err)
|
return fmt.Errorf("v2: dump failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
|
||||||
|
case "v1":
|
||||||
|
err := dumpV1(acmeFile, baseConfig)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("v1: dump failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
|
||||||
|
default:
|
||||||
|
err := dumpV1(acmeFile, baseConfig)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("v1: dump failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := dumpV1(acmeFile, baseConfig)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("v1: dump failed: %w", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func dumpV1(acmeFile string, baseConfig *dumper.BaseConfig) error {
|
func dumpV1(acmeFile string, baseConfig *dumper.BaseConfig) error {
|
||||||
data := &v1.StoredData{}
|
data := &traefikv1.StoredData{}
|
||||||
err := readJSONFile(acmeFile, data)
|
err := readJSONFile(acmeFile, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return v1.Dump(data, baseConfig)
|
return dumperv1.Dump(data, baseConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func dumpV2(acmeFile string, baseConfig *dumper.BaseConfig) error {
|
func dumpV2(acmeFile string, baseConfig *dumper.BaseConfig) error {
|
||||||
data := map[string]*acme.StoredData{}
|
data := map[string]*traefikv2.StoredData{}
|
||||||
err := readJSONFile(acmeFile, &data)
|
err := readJSONFile(acmeFile, &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return v2.Dump(data, baseConfig)
|
return dumperv2.Dump(data, baseConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dumpV3(acmeFile string, baseConfig *dumper.BaseConfig) error {
|
||||||
|
data := map[string]*traefikv3.StoredData{}
|
||||||
|
err := readJSONFile(acmeFile, &data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return dumperv3.Dump(data, baseConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func readJSONFile(acmeFile string, data interface{}) error {
|
func readJSONFile(acmeFile string, data interface{}) error {
|
||||||
@ -90,7 +125,7 @@ func readJSONFile(acmeFile string, data interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func watch(acmeFile string, baseConfig *dumper.BaseConfig) error {
|
func watch(ctx context.Context, acmeFile string, baseConfig *dumper.BaseConfig) error {
|
||||||
watcher, err := fsnotify.NewWatcher()
|
watcher, err := fsnotify.NewWatcher()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create new watcher: %w", err)
|
return fmt.Errorf("failed to create new watcher: %w", err)
|
||||||
@ -113,7 +148,7 @@ func watch(acmeFile string, baseConfig *dumper.BaseConfig) error {
|
|||||||
log.Println("event:", event)
|
log.Println("event:", event)
|
||||||
}
|
}
|
||||||
|
|
||||||
hash, errW := manageEvent(watcher, event, acmeFile, previousHash, baseConfig)
|
hash, errW := manageEvent(ctx, watcher, event, acmeFile, previousHash, baseConfig)
|
||||||
if errW != nil {
|
if errW != nil {
|
||||||
log.Println("error:", errW)
|
log.Println("error:", errW)
|
||||||
done <- true
|
done <- true
|
||||||
@ -144,7 +179,7 @@ func watch(acmeFile string, baseConfig *dumper.BaseConfig) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func manageEvent(watcher *fsnotify.Watcher, event fsnotify.Event, acmeFile string, previousHash []byte, baseConfig *dumper.BaseConfig) ([]byte, error) {
|
func manageEvent(ctx context.Context, watcher *fsnotify.Watcher, event fsnotify.Event, acmeFile string, previousHash []byte, baseConfig *dumper.BaseConfig) ([]byte, error) {
|
||||||
err := manageRename(watcher, event, acmeFile)
|
err := manageRename(watcher, event, acmeFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("watcher renewal failed: %w", err)
|
return nil, fmt.Errorf("watcher renewal failed: %w", err)
|
||||||
@ -168,7 +203,7 @@ func manageEvent(watcher *fsnotify.Watcher, event fsnotify.Event, acmeFile strin
|
|||||||
log.Println("Dumped new certificate data.")
|
log.Println("Dumped new certificate data.")
|
||||||
}
|
}
|
||||||
|
|
||||||
hook.Exec(baseConfig.Hook)
|
hook.Exec(ctx, baseConfig.Hook)
|
||||||
}
|
}
|
||||||
|
|
||||||
return hash, nil
|
return hash, nil
|
||||||
@ -193,7 +228,7 @@ func calculateHash(acmeFile string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
defer func() { _ = file.Close() }()
|
defer func() { _ = file.Close() }()
|
||||||
|
|
||||||
h := md5.New()
|
h := sha256.New()
|
||||||
_, err = io.Copy(h, file)
|
_, err = io.Copy(h, file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@ -26,10 +26,14 @@ func TestDump(t *testing.T) {
|
|||||||
acmeFile: "./fixtures/acme-v2.json",
|
acmeFile: "./fixtures/acme-v2.json",
|
||||||
version: "v2",
|
version: "v2",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "should dump traefik v3 file content",
|
||||||
|
acmeFile: "./fixtures/acme-v3.json",
|
||||||
|
version: "v3",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
test := test
|
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@ -49,7 +53,7 @@ func TestDump(t *testing.T) {
|
|||||||
Version: test.version,
|
Version: test.version,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := Dump(test.acmeFile, cfg)
|
err := Dump(t.Context(), test.acmeFile, cfg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
36
dumper/file/fixtures/acme-v3.json
Normal file
36
dumper/file/fixtures/acme-v3.json
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
"default": {
|
||||||
|
"Account": {
|
||||||
|
"Email": "test@email.com",
|
||||||
|
"Registration": {
|
||||||
|
"body": {
|
||||||
|
"status": "valid",
|
||||||
|
"contact": [
|
||||||
|
"mailto:test@email.com"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"uri": "https://acme-v02.api.letsencrypt.org/acme/acct/12345678"
|
||||||
|
},
|
||||||
|
"PrivateKey": "Q2VydGlmaWNhdGUgS2V5",
|
||||||
|
"KeyType": "4096"
|
||||||
|
},
|
||||||
|
"Certificates": [
|
||||||
|
{
|
||||||
|
"domain": {
|
||||||
|
"main": "my.domain.com"
|
||||||
|
},
|
||||||
|
"certificate": "Q2VydGlmaWNhdGU=",
|
||||||
|
"key": "Q2VydGlmaWNhdGUgS2V5",
|
||||||
|
"Store": "default"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"domain": {
|
||||||
|
"main": "my.domain2.com"
|
||||||
|
},
|
||||||
|
"certificate": "Q2VydGlmaWNhdGU=",
|
||||||
|
"key": "Q2VydGlmaWNhdGUgS2V5",
|
||||||
|
"Store": "default"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,12 +1,14 @@
|
|||||||
package kv
|
package kv
|
||||||
|
|
||||||
import "github.com/abronan/valkeyrie/store"
|
import (
|
||||||
|
"github.com/kvtools/valkeyrie"
|
||||||
|
)
|
||||||
|
|
||||||
// Config KV configuration.
|
// Config KV configuration.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Backend store.Backend
|
StoreName string
|
||||||
Prefix string
|
Prefix string
|
||||||
Suffix string
|
Suffix string
|
||||||
Endpoints []string
|
Endpoints []string
|
||||||
Options *store.Config
|
Options valkeyrie.Config
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package kv
|
|||||||
import (
|
import (
|
||||||
"github.com/go-acme/lego/v4/certcrypto"
|
"github.com/go-acme/lego/v4/certcrypto"
|
||||||
"github.com/go-acme/lego/v4/registration"
|
"github.com/go-acme/lego/v4/registration"
|
||||||
v1 "github.com/ldez/traefik-certs-dumper/v2/dumper/v1"
|
"github.com/ldez/traefik-certs-dumper/v2/internal/traefikv1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CertificateOld is used to store certificate info.
|
// CertificateOld is used to store certificate info.
|
||||||
@ -39,14 +39,14 @@ type ChallengeCert struct {
|
|||||||
|
|
||||||
// DomainsCertificate contains a certificate for multiple domains.
|
// DomainsCertificate contains a certificate for multiple domains.
|
||||||
type DomainsCertificate struct {
|
type DomainsCertificate struct {
|
||||||
Domains v1.Domain
|
Domains traefikv1.Domain
|
||||||
Certificate *CertificateOld
|
Certificate *CertificateOld
|
||||||
}
|
}
|
||||||
|
|
||||||
// convertOldAccount converts account information from old account format.
|
// convertOldAccount converts account information from old account format.
|
||||||
func convertOldAccount(account *AccountOld) *v1.StoredData {
|
func convertOldAccount(account *AccountOld) *traefikv1.StoredData {
|
||||||
storedData := &v1.StoredData{
|
storedData := &traefikv1.StoredData{
|
||||||
Account: &v1.Account{
|
Account: &traefikv1.Account{
|
||||||
PrivateKey: account.PrivateKey,
|
PrivateKey: account.PrivateKey,
|
||||||
Registration: account.Registration,
|
Registration: account.Registration,
|
||||||
Email: account.Email,
|
Email: account.Email,
|
||||||
@ -54,9 +54,9 @@ func convertOldAccount(account *AccountOld) *v1.StoredData {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var certs []*v1.Certificate
|
var certs []*traefikv1.Certificate
|
||||||
for _, oldCert := range account.DomainsCertificate.Certs {
|
for _, oldCert := range account.DomainsCertificate.Certs {
|
||||||
certs = append(certs, &v1.Certificate{
|
certs = append(certs, &traefikv1.Certificate{
|
||||||
Certificate: oldCert.Certificate.Certificate,
|
Certificate: oldCert.Certificate.Certificate,
|
||||||
Domain: oldCert.Domains,
|
Domain: oldCert.Domains,
|
||||||
Key: oldCert.Certificate.PrivateKey,
|
Key: oldCert.Certificate.PrivateKey,
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package kv
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -10,19 +11,20 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/abronan/valkeyrie"
|
"github.com/kvtools/valkeyrie"
|
||||||
"github.com/abronan/valkeyrie/store"
|
"github.com/kvtools/valkeyrie/store"
|
||||||
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
||||||
v1 "github.com/ldez/traefik-certs-dumper/v2/dumper/v1"
|
v1 "github.com/ldez/traefik-certs-dumper/v2/dumper/v1"
|
||||||
"github.com/ldez/traefik-certs-dumper/v2/hook"
|
"github.com/ldez/traefik-certs-dumper/v2/hook"
|
||||||
|
"github.com/ldez/traefik-certs-dumper/v2/internal/traefikv1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultStoreKeySuffix is the default suffix/storage.
|
// DefaultStoreKeySuffix is the default suffix/storage.
|
||||||
const DefaultStoreKeySuffix = "/acme/account/object"
|
const DefaultStoreKeySuffix = "/acme/account/object"
|
||||||
|
|
||||||
// Dump Dumps KV content to certificates.
|
// Dump Dumps KV content to certificates.
|
||||||
func Dump(config *Config, baseConfig *dumper.BaseConfig) error {
|
func Dump(ctx context.Context, config *Config, baseConfig *dumper.BaseConfig) error {
|
||||||
kvStore, err := valkeyrie.NewStore(config.Backend, config.Endpoints, config.Options)
|
kvStore, err := valkeyrie.NewStore(ctx, config.StoreName, config.Endpoints, config.Options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to create client of the store: %w", err)
|
return fmt.Errorf("unable to create client of the store: %w", err)
|
||||||
}
|
}
|
||||||
@ -30,10 +32,10 @@ func Dump(config *Config, baseConfig *dumper.BaseConfig) error {
|
|||||||
storeKey := config.Prefix + config.Suffix
|
storeKey := config.Prefix + config.Suffix
|
||||||
|
|
||||||
if baseConfig.Watch {
|
if baseConfig.Watch {
|
||||||
return watch(kvStore, storeKey, baseConfig)
|
return watch(ctx, kvStore, storeKey, baseConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
pair, err := kvStore.Get(storeKey, nil)
|
pair, err := kvStore.Get(ctx, storeKey, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to retrieve %s value: %w", storeKey, err)
|
return fmt.Errorf("unable to retrieve %s value: %w", storeKey, err)
|
||||||
}
|
}
|
||||||
@ -41,10 +43,8 @@ func Dump(config *Config, baseConfig *dumper.BaseConfig) error {
|
|||||||
return dumpPair(pair, baseConfig)
|
return dumpPair(pair, baseConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func watch(kvStore store.Store, storeKey string, baseConfig *dumper.BaseConfig) error {
|
func watch(ctx context.Context, kvStore store.Store, storeKey string, baseConfig *dumper.BaseConfig) error {
|
||||||
stopCh := make(<-chan struct{})
|
pairs, err := kvStore.Watch(ctx, storeKey, nil)
|
||||||
|
|
||||||
pairs, err := kvStore.Watch(storeKey, stopCh, nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ func watch(kvStore store.Store, storeKey string, baseConfig *dumper.BaseConfig)
|
|||||||
log.Println("Dumped new certificate data.")
|
log.Println("Dumped new certificate data.")
|
||||||
}
|
}
|
||||||
|
|
||||||
hook.Exec(baseConfig.Hook)
|
hook.Exec(ctx, baseConfig.Hook)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ func dumpPair(pair *store.KVPair, baseConfig *dumper.BaseConfig) error {
|
|||||||
return v1.Dump(data, baseConfig)
|
return v1.Dump(data, baseConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStoredDataFromGzip(pair *store.KVPair) (*v1.StoredData, error) {
|
func getStoredDataFromGzip(pair *store.KVPair) (*traefikv1.StoredData, error) {
|
||||||
reader, err := gzip.NewReader(bytes.NewBuffer(pair.Value))
|
reader, err := gzip.NewReader(bytes.NewBuffer(pair.Value))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("fail to create GZip reader: %w", err)
|
return nil, fmt.Errorf("fail to create GZip reader: %w", err)
|
||||||
@ -89,6 +89,7 @@ func getStoredDataFromGzip(pair *store.KVPair) (*v1.StoredData, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
account := &AccountOld{}
|
account := &AccountOld{}
|
||||||
|
//nolint:musttag // old format
|
||||||
if err := json.Unmarshal(acmeData, &account); err != nil {
|
if err := json.Unmarshal(acmeData, &account); err != nil {
|
||||||
return nil, fmt.Errorf("unable marshal AccountOld: %w", err)
|
return nil, fmt.Errorf("unable marshal AccountOld: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/go-acme/lego/v4/certcrypto"
|
"github.com/go-acme/lego/v4/certcrypto"
|
||||||
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
||||||
|
"github.com/ldez/traefik-certs-dumper/v2/internal/traefikv1"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -16,7 +17,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Dump Dumps data to certificates.
|
// Dump Dumps data to certificates.
|
||||||
func Dump(data *StoredData, baseConfig *dumper.BaseConfig) error {
|
func Dump(data *traefikv1.StoredData, baseConfig *dumper.BaseConfig) error {
|
||||||
if baseConfig.Clean {
|
if baseConfig.Clean {
|
||||||
err := cleanDir(baseConfig.DumpPath)
|
err := cleanDir(baseConfig.DumpPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -54,7 +55,7 @@ func Dump(data *StoredData, baseConfig *dumper.BaseConfig) error {
|
|||||||
return os.WriteFile(filepath.Join(baseConfig.DumpPath, keysSubDir, "letsencrypt"+baseConfig.KeyInfo.Ext), privateKeyPem, 0o600)
|
return os.WriteFile(filepath.Join(baseConfig.DumpPath, keysSubDir, "letsencrypt"+baseConfig.KeyInfo.Ext), privateKeyPem, 0o600)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeCert(dumpPath string, cert *Certificate, info dumper.FileInfo, domainSubDir bool) error {
|
func writeCert(dumpPath string, cert *traefikv1.Certificate, info dumper.FileInfo, domainSubDir bool) error {
|
||||||
certPath := filepath.Join(dumpPath, certsSubDir, safeName(cert.Domain.Main+info.Ext))
|
certPath := filepath.Join(dumpPath, certsSubDir, safeName(cert.Domain.Main+info.Ext))
|
||||||
if domainSubDir {
|
if domainSubDir {
|
||||||
certPath = filepath.Join(dumpPath, safeName(cert.Domain.Main), info.Name+info.Ext)
|
certPath = filepath.Join(dumpPath, safeName(cert.Domain.Main), info.Name+info.Ext)
|
||||||
@ -66,7 +67,7 @@ func writeCert(dumpPath string, cert *Certificate, info dumper.FileInfo, domainS
|
|||||||
return os.WriteFile(certPath, cert.Certificate, 0o666)
|
return os.WriteFile(certPath, cert.Certificate, 0o666)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeKey(dumpPath string, cert *Certificate, info dumper.FileInfo, domainSubDir bool) error {
|
func writeKey(dumpPath string, cert *traefikv1.Certificate, info dumper.FileInfo, domainSubDir bool) error {
|
||||||
keyPath := filepath.Join(dumpPath, keysSubDir, safeName(cert.Domain.Main+info.Ext))
|
keyPath := filepath.Join(dumpPath, keysSubDir, safeName(cert.Domain.Main+info.Ext))
|
||||||
if domainSubDir {
|
if domainSubDir {
|
||||||
keyPath = filepath.Join(dumpPath, safeName(cert.Domain.Main), info.Name+info.Ext)
|
keyPath = filepath.Join(dumpPath, safeName(cert.Domain.Main), info.Name+info.Ext)
|
||||||
@ -78,7 +79,7 @@ func writeKey(dumpPath string, cert *Certificate, info dumper.FileInfo, domainSu
|
|||||||
return os.WriteFile(keyPath, cert.Key, 0o600)
|
return os.WriteFile(keyPath, cert.Key, 0o600)
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractPEMPrivateKey(account *Account) []byte {
|
func extractPEMPrivateKey(account *traefikv1.Account) []byte {
|
||||||
var block *pem.Block
|
var block *pem.Block
|
||||||
switch account.KeyType {
|
switch account.KeyType {
|
||||||
case certcrypto.RSA2048, certcrypto.RSA4096, certcrypto.RSA8192:
|
case certcrypto.RSA2048, certcrypto.RSA4096, certcrypto.RSA8192:
|
||||||
@ -92,7 +93,7 @@ func extractPEMPrivateKey(account *Account) []byte {
|
|||||||
Bytes: account.PrivateKey,
|
Bytes: account.PrivateKey,
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
panic("unsupported key type")
|
panic(fmt.Sprintf("unsupported key type: '%v'", account.KeyType))
|
||||||
}
|
}
|
||||||
|
|
||||||
return pem.EncodeToMemory(block)
|
return pem.EncodeToMemory(block)
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/go-acme/lego/v4/certcrypto"
|
"github.com/go-acme/lego/v4/certcrypto"
|
||||||
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
||||||
"github.com/traefik/traefik/v2/pkg/provider/acme"
|
"github.com/ldez/traefik-certs-dumper/v2/internal/traefikv2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -17,7 +17,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Dump Dumps data to certificates.
|
// Dump Dumps data to certificates.
|
||||||
func Dump(data map[string]*acme.StoredData, baseConfig *dumper.BaseConfig) error {
|
func Dump(data map[string]*traefikv2.StoredData, baseConfig *dumper.BaseConfig) error {
|
||||||
if baseConfig.Clean {
|
if baseConfig.Clean {
|
||||||
err := cleanDir(baseConfig.DumpPath)
|
err := cleanDir(baseConfig.DumpPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -63,7 +63,7 @@ func Dump(data map[string]*acme.StoredData, baseConfig *dumper.BaseConfig) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeCert(dumpPath string, cert acme.Certificate, info dumper.FileInfo, domainSubDir bool) error {
|
func writeCert(dumpPath string, cert traefikv2.Certificate, info dumper.FileInfo, domainSubDir bool) error {
|
||||||
certPath := filepath.Join(dumpPath, certsSubDir, safeName(cert.Domain.Main+info.Ext))
|
certPath := filepath.Join(dumpPath, certsSubDir, safeName(cert.Domain.Main+info.Ext))
|
||||||
if domainSubDir {
|
if domainSubDir {
|
||||||
certPath = filepath.Join(dumpPath, safeName(cert.Domain.Main), info.Name+info.Ext)
|
certPath = filepath.Join(dumpPath, safeName(cert.Domain.Main), info.Name+info.Ext)
|
||||||
@ -75,7 +75,7 @@ func writeCert(dumpPath string, cert acme.Certificate, info dumper.FileInfo, dom
|
|||||||
return os.WriteFile(certPath, cert.Certificate, 0o666)
|
return os.WriteFile(certPath, cert.Certificate, 0o666)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeKey(dumpPath string, cert acme.Certificate, info dumper.FileInfo, domainSubDir bool) error {
|
func writeKey(dumpPath string, cert traefikv2.Certificate, info dumper.FileInfo, domainSubDir bool) error {
|
||||||
keyPath := filepath.Join(dumpPath, keysSubDir, safeName(cert.Domain.Main+info.Ext))
|
keyPath := filepath.Join(dumpPath, keysSubDir, safeName(cert.Domain.Main+info.Ext))
|
||||||
if domainSubDir {
|
if domainSubDir {
|
||||||
keyPath = filepath.Join(dumpPath, safeName(cert.Domain.Main), info.Name+info.Ext)
|
keyPath = filepath.Join(dumpPath, safeName(cert.Domain.Main), info.Name+info.Ext)
|
||||||
@ -87,7 +87,7 @@ func writeKey(dumpPath string, cert acme.Certificate, info dumper.FileInfo, doma
|
|||||||
return os.WriteFile(keyPath, cert.Key, 0o600)
|
return os.WriteFile(keyPath, cert.Key, 0o600)
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractPEMPrivateKey(account *acme.Account) []byte {
|
func extractPEMPrivateKey(account *traefikv2.Account) []byte {
|
||||||
var block *pem.Block
|
var block *pem.Block
|
||||||
switch account.KeyType {
|
switch account.KeyType {
|
||||||
case certcrypto.RSA2048, certcrypto.RSA4096, certcrypto.RSA8192:
|
case certcrypto.RSA2048, certcrypto.RSA4096, certcrypto.RSA8192:
|
||||||
@ -101,7 +101,7 @@ func extractPEMPrivateKey(account *acme.Account) []byte {
|
|||||||
Bytes: account.PrivateKey,
|
Bytes: account.PrivateKey,
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
panic("unsupported key type")
|
panic(fmt.Sprintf("unsupported key type: '%v'", account.KeyType))
|
||||||
}
|
}
|
||||||
|
|
||||||
return pem.EncodeToMemory(block)
|
return pem.EncodeToMemory(block)
|
||||||
|
|||||||
132
dumper/v3/dumper.go
Normal file
132
dumper/v3/dumper.go
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
package v3
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/pem"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/go-acme/lego/v4/certcrypto"
|
||||||
|
"github.com/ldez/traefik-certs-dumper/v2/dumper"
|
||||||
|
"github.com/ldez/traefik-certs-dumper/v2/internal/traefikv3"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
certsSubDir = "certs"
|
||||||
|
keysSubDir = "private"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Dump Dumps data to certificates.
|
||||||
|
func Dump(data map[string]*traefikv3.StoredData, baseConfig *dumper.BaseConfig) error {
|
||||||
|
if baseConfig.Clean {
|
||||||
|
err := cleanDir(baseConfig.DumpPath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("folder cleaning failed: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !baseConfig.DomainSubDir {
|
||||||
|
if err := os.MkdirAll(filepath.Join(baseConfig.DumpPath, certsSubDir), 0o755); err != nil {
|
||||||
|
return fmt.Errorf("certs folder creation failure: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.MkdirAll(filepath.Join(baseConfig.DumpPath, keysSubDir), 0o755); err != nil {
|
||||||
|
return fmt.Errorf("keys folder creation failure: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, store := range data {
|
||||||
|
for _, cert := range store.Certificates {
|
||||||
|
err := writeCert(baseConfig.DumpPath, cert.Certificate, baseConfig.CrtInfo, baseConfig.DomainSubDir)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to write certificates: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = writeKey(baseConfig.DumpPath, cert.Certificate, baseConfig.KeyInfo, baseConfig.DomainSubDir)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to write certificate keys: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if store.Account == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
privateKeyPem := extractPEMPrivateKey(store.Account)
|
||||||
|
|
||||||
|
err := os.WriteFile(filepath.Join(baseConfig.DumpPath, keysSubDir, "letsencrypt"+baseConfig.KeyInfo.Ext), privateKeyPem, 0o600)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to write private key: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeCert(dumpPath string, cert traefikv3.Certificate, info dumper.FileInfo, domainSubDir bool) error {
|
||||||
|
certPath := filepath.Join(dumpPath, certsSubDir, safeName(cert.Domain.Main+info.Ext))
|
||||||
|
if domainSubDir {
|
||||||
|
certPath = filepath.Join(dumpPath, safeName(cert.Domain.Main), info.Name+info.Ext)
|
||||||
|
if err := os.MkdirAll(filepath.Join(dumpPath, safeName(cert.Domain.Main)), 0o755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return os.WriteFile(certPath, cert.Certificate, 0o666)
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeKey(dumpPath string, cert traefikv3.Certificate, info dumper.FileInfo, domainSubDir bool) error {
|
||||||
|
keyPath := filepath.Join(dumpPath, keysSubDir, safeName(cert.Domain.Main+info.Ext))
|
||||||
|
if domainSubDir {
|
||||||
|
keyPath = filepath.Join(dumpPath, safeName(cert.Domain.Main), info.Name+info.Ext)
|
||||||
|
if err := os.MkdirAll(filepath.Join(dumpPath, safeName(cert.Domain.Main)), 0o755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return os.WriteFile(keyPath, cert.Key, 0o600)
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractPEMPrivateKey(account *traefikv3.Account) []byte {
|
||||||
|
var block *pem.Block
|
||||||
|
switch account.KeyType {
|
||||||
|
case certcrypto.RSA2048, certcrypto.RSA4096, certcrypto.RSA8192:
|
||||||
|
block = &pem.Block{
|
||||||
|
Type: "RSA PRIVATE KEY",
|
||||||
|
Bytes: account.PrivateKey,
|
||||||
|
}
|
||||||
|
case certcrypto.EC256, certcrypto.EC384:
|
||||||
|
block = &pem.Block{
|
||||||
|
Type: "EC PRIVATE KEY",
|
||||||
|
Bytes: account.PrivateKey,
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("unsupported key type: '%v'", account.KeyType))
|
||||||
|
}
|
||||||
|
|
||||||
|
return pem.EncodeToMemory(block)
|
||||||
|
}
|
||||||
|
|
||||||
|
func cleanDir(dumpPath string) error {
|
||||||
|
_, errExists := os.Stat(dumpPath)
|
||||||
|
if os.IsNotExist(errExists) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if errExists != nil {
|
||||||
|
return errExists
|
||||||
|
}
|
||||||
|
|
||||||
|
dir, err := os.ReadDir(dumpPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, f := range dir {
|
||||||
|
if err := os.RemoveAll(filepath.Join(dumpPath, f.Name())); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
8
dumper/v3/filename.go
Normal file
8
dumper/v3/filename.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
//go:build !windows
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package v3
|
||||||
|
|
||||||
|
func safeName(filename string) string {
|
||||||
|
return filename
|
||||||
|
}
|
||||||
10
dumper/v3/filename_windows.go
Normal file
10
dumper/v3/filename_windows.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
//go:build windows
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package v3
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
func safeName(filename string) string {
|
||||||
|
return strings.ReplaceAll(filename, "*", "_")
|
||||||
|
}
|
||||||
237
go.mod
237
go.mod
@ -1,175 +1,90 @@
|
|||||||
module github.com/ldez/traefik-certs-dumper/v2
|
module github.com/ldez/traefik-certs-dumper/v2
|
||||||
|
|
||||||
go 1.17
|
go 1.24.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/abronan/valkeyrie v0.2.0
|
github.com/charmbracelet/lipgloss v1.0.0
|
||||||
github.com/fsnotify/fsnotify v1.5.1
|
github.com/fsnotify/fsnotify v1.9.0
|
||||||
github.com/go-acme/lego/v4 v4.5.3
|
github.com/go-acme/lego/v4 v4.25.2
|
||||||
|
github.com/kvtools/boltdb v1.0.2
|
||||||
|
github.com/kvtools/consul v1.0.2
|
||||||
|
github.com/kvtools/etcdv2 v1.0.2
|
||||||
|
github.com/kvtools/etcdv3 v1.0.2
|
||||||
|
github.com/kvtools/valkeyrie v1.0.0
|
||||||
|
github.com/kvtools/zookeeper v1.0.2
|
||||||
github.com/mitchellh/go-homedir v1.1.0
|
github.com/mitchellh/go-homedir v1.1.0
|
||||||
github.com/spf13/cobra v1.2.1
|
github.com/spf13/cobra v1.9.1
|
||||||
github.com/spf13/viper v1.9.0
|
github.com/spf13/viper v1.19.0
|
||||||
github.com/stretchr/testify v1.7.0
|
github.com/stretchr/testify v1.10.0
|
||||||
github.com/traefik/traefik/v2 v2.5.5
|
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
cloud.google.com/go v0.93.3 // indirect
|
github.com/armon/go-metrics v0.4.1 // indirect
|
||||||
github.com/Azure/azure-sdk-for-go v40.3.0+incompatible // indirect
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||||
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
|
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||||
github.com/Azure/go-autorest/autorest v0.11.19 // indirect
|
github.com/charmbracelet/x/ansi v0.4.2 // indirect
|
||||||
github.com/Azure/go-autorest/autorest/adal v0.9.13 // indirect
|
github.com/coreos/go-semver v0.3.1 // indirect
|
||||||
github.com/Azure/go-autorest/autorest/azure/auth v0.5.8 // indirect
|
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
|
||||||
github.com/Azure/go-autorest/autorest/azure/cli v0.4.2 // indirect
|
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
|
||||||
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||||
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
|
github.com/fatih/color v1.18.0 // indirect
|
||||||
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
|
github.com/go-jose/go-jose/v4 v4.1.1 // indirect
|
||||||
github.com/Azure/go-autorest/logger v0.2.1 // indirect
|
github.com/go-zookeeper/zk v1.0.4 // indirect
|
||||||
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
|
|
||||||
github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87 // indirect
|
|
||||||
github.com/akamai/AkamaiOPEN-edgegrid-golang v1.1.1 // indirect
|
|
||||||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1183 // indirect
|
|
||||||
github.com/armon/go-metrics v0.3.8 // indirect
|
|
||||||
github.com/aws/aws-sdk-go v1.39.0 // indirect
|
|
||||||
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
|
|
||||||
github.com/cenkalti/backoff/v4 v4.1.1 // indirect
|
|
||||||
github.com/cloudflare/cloudflare-go v0.20.0 // indirect
|
|
||||||
github.com/containous/alice v0.0.0-20181107144136-d83ebdd94cbd // indirect
|
|
||||||
github.com/coreos/go-semver v0.3.0 // indirect
|
|
||||||
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
|
|
||||||
github.com/cpu/goacmedns v0.1.1 // indirect
|
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
|
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
|
||||||
github.com/deepmap/oapi-codegen v1.6.1 // indirect
|
|
||||||
github.com/dimchansky/utfbom v1.1.1 // indirect
|
|
||||||
github.com/dnsimple/dnsimple-go v0.70.1 // indirect
|
|
||||||
github.com/exoscale/egoscale v0.67.0 // indirect
|
|
||||||
github.com/fatih/color v1.9.0 // indirect
|
|
||||||
github.com/fatih/structs v1.1.0 // indirect
|
|
||||||
github.com/form3tech-oss/jwt-go v3.2.2+incompatible // indirect
|
|
||||||
github.com/go-errors/errors v1.0.1 // indirect
|
|
||||||
github.com/go-logr/logr v0.4.0 // indirect
|
|
||||||
github.com/go-resty/resty/v2 v2.1.1-0.20191201195748-d7b97669fe48 // indirect
|
|
||||||
github.com/gofrs/uuid v3.3.0+incompatible // indirect
|
|
||||||
github.com/gogo/protobuf v1.3.2 // indirect
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
|
github.com/golang/protobuf v1.5.4 // indirect
|
||||||
github.com/golang/protobuf v1.5.2 // indirect
|
github.com/hashicorp/consul/api v1.28.2 // indirect
|
||||||
github.com/google/go-github/v28 v28.1.1 // indirect
|
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||||
github.com/google/go-querystring v1.1.0 // indirect
|
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||||
github.com/google/uuid v1.2.0 // indirect
|
github.com/hashicorp/go-hclog v1.6.3 // indirect
|
||||||
github.com/googleapis/gax-go/v2 v2.1.0 // indirect
|
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
|
||||||
github.com/gophercloud/gophercloud v0.16.0 // indirect
|
github.com/hashicorp/go-metrics v0.5.4 // indirect
|
||||||
github.com/gophercloud/utils v0.0.0-20210216074907-f6de111f2eae // indirect
|
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||||
github.com/gorilla/context v1.1.1 // indirect
|
|
||||||
github.com/gorilla/mux v1.8.0 // indirect
|
|
||||||
github.com/gravitational/trace v0.0.0-20190726142706-a535a178675f // indirect
|
|
||||||
github.com/hashicorp/consul/api v1.10.1 // indirect
|
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
|
|
||||||
github.com/hashicorp/go-hclog v0.16.1 // indirect
|
|
||||||
github.com/hashicorp/go-immutable-radix v1.3.0 // indirect
|
|
||||||
github.com/hashicorp/go-retryablehttp v0.7.0 // indirect
|
|
||||||
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
|
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
|
||||||
github.com/hashicorp/go-version v1.3.0 // indirect
|
github.com/hashicorp/golang-lru v1.0.2 // indirect
|
||||||
github.com/hashicorp/golang-lru v0.5.4 // indirect
|
github.com/hashicorp/hcl v1.0.1-vault-5 // indirect
|
||||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
github.com/hashicorp/serf v0.10.2 // indirect
|
||||||
github.com/hashicorp/serf v0.9.5 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||||
github.com/infobloxopen/infoblox-go-client v1.1.1 // indirect
|
github.com/magiconair/properties v1.8.9 // indirect
|
||||||
github.com/jarcoal/httpmock v1.0.6 // indirect
|
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||||
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/jonboulle/clockwork v0.1.0 // indirect
|
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||||
github.com/json-iterator/go v1.1.11 // indirect
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213 // indirect
|
|
||||||
github.com/kolo/xmlrpc v0.0.0-20200310150728-e0350524596b // indirect
|
|
||||||
github.com/labbsr0x/bindman-dns-webhook v1.0.2 // indirect
|
|
||||||
github.com/labbsr0x/goh v1.0.1 // indirect
|
|
||||||
github.com/linode/linodego v0.31.1 // indirect
|
|
||||||
github.com/liquidweb/go-lwApi v0.0.5 // indirect
|
|
||||||
github.com/liquidweb/liquidweb-cli v0.6.9 // indirect
|
|
||||||
github.com/liquidweb/liquidweb-go v1.6.3 // indirect
|
|
||||||
github.com/magiconair/properties v1.8.5 // indirect
|
|
||||||
github.com/mattn/go-colorable v0.1.8 // indirect
|
|
||||||
github.com/mattn/go-isatty v0.0.12 // indirect
|
|
||||||
github.com/miekg/dns v1.1.43 // indirect
|
|
||||||
github.com/mitchellh/mapstructure v1.4.2 // indirect
|
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.1 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04 // indirect
|
github.com/muesli/termenv v0.15.2 // indirect
|
||||||
github.com/nrdcg/auroradns v1.0.1 // indirect
|
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
|
||||||
github.com/nrdcg/desec v0.6.0 // indirect
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||||
github.com/nrdcg/dnspod-go v0.4.0 // indirect
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
github.com/nrdcg/freemyip v0.2.0 // indirect
|
github.com/rogpeppe/go-internal v1.12.0 // indirect
|
||||||
github.com/nrdcg/goinwx v0.8.1 // indirect
|
|
||||||
github.com/nrdcg/namesilo v0.2.1 // indirect
|
|
||||||
github.com/nrdcg/porkbun v0.1.1 // indirect
|
|
||||||
github.com/oracle/oci-go-sdk v24.3.0+incompatible // indirect
|
|
||||||
github.com/ovh/go-ovh v1.1.0 // indirect
|
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
|
|
||||||
github.com/pelletier/go-toml v1.9.4 // indirect
|
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
|
||||||
github.com/pquerna/otp v1.3.0 // indirect
|
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||||
github.com/sacloud/libsacloud v1.36.2 // indirect
|
github.com/sagikazarmark/locafero v0.4.0 // indirect
|
||||||
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da // indirect
|
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
||||||
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20210127161313-bd30bebeac4f // indirect
|
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||||
github.com/sirupsen/logrus v1.8.1 // indirect
|
github.com/spf13/afero v1.11.0 // indirect
|
||||||
github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9 // indirect
|
github.com/spf13/cast v1.7.1 // indirect
|
||||||
github.com/softlayer/softlayer-go v1.0.3 // indirect
|
github.com/spf13/pflag v1.0.6 // indirect
|
||||||
github.com/softlayer/xmlrpc v0.0.0-20200409220501-5f089df7cb7e // indirect
|
github.com/subosito/gotenv v1.6.0 // indirect
|
||||||
github.com/spf13/afero v1.6.0 // indirect
|
go.etcd.io/bbolt v1.3.6 // indirect
|
||||||
github.com/spf13/cast v1.4.1 // indirect
|
go.etcd.io/etcd/api/v3 v3.5.14 // indirect
|
||||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
go.etcd.io/etcd/client/pkg/v3 v3.5.14 // indirect
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
go.etcd.io/etcd/client/v2 v2.305.12 // indirect
|
||||||
github.com/stretchr/objx v0.3.0 // indirect
|
go.etcd.io/etcd/client/v3 v3.5.14 // indirect
|
||||||
github.com/subosito/gotenv v1.2.0 // indirect
|
go.uber.org/multierr v1.11.0 // indirect
|
||||||
github.com/traefik/paerser v0.1.4 // indirect
|
go.uber.org/zap v1.27.0 // indirect
|
||||||
github.com/transip/gotransip/v6 v6.6.1 // indirect
|
golang.org/x/crypto v0.40.0 // indirect
|
||||||
github.com/unrolled/render v1.0.2 // indirect
|
golang.org/x/exp v0.0.0-20241210194714-1829a127f884 // indirect
|
||||||
github.com/vinyldns/go-vinyldns v0.0.0-20200917153823-148a5f6b8f14 // indirect
|
golang.org/x/net v0.42.0 // indirect
|
||||||
github.com/vulcand/predicate v1.1.0 // indirect
|
golang.org/x/sys v0.34.0 // indirect
|
||||||
github.com/vultr/govultr/v2 v2.7.1 // indirect
|
golang.org/x/text v0.27.0 // indirect
|
||||||
go.etcd.io/bbolt v1.3.5 // indirect
|
google.golang.org/genproto/googleapis/api v0.0.0-20250707201910-8d1bb00bc6a7 // indirect
|
||||||
go.etcd.io/etcd/api/v3 v3.5.0 // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7 // indirect
|
||||||
go.etcd.io/etcd/client/pkg/v3 v3.5.0 // indirect
|
google.golang.org/grpc v1.73.0 // indirect
|
||||||
go.etcd.io/etcd/client/v2 v2.305.0 // indirect
|
google.golang.org/protobuf v1.36.6 // indirect
|
||||||
go.etcd.io/etcd/client/v3 v3.5.0 // indirect
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||||
go.opencensus.io v0.23.0 // indirect
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
go.uber.org/atomic v1.7.0 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
go.uber.org/multierr v1.6.0 // indirect
|
|
||||||
go.uber.org/ratelimit v0.0.0-20180316092928-c15da0234277 // indirect
|
|
||||||
go.uber.org/zap v1.17.0 // indirect
|
|
||||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
|
|
||||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
|
|
||||||
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
|
|
||||||
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
|
|
||||||
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
|
|
||||||
golang.org/x/text v0.3.6 // indirect
|
|
||||||
golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6 // indirect
|
|
||||||
google.golang.org/api v0.56.0 // indirect
|
|
||||||
google.golang.org/appengine v1.6.7 // indirect
|
|
||||||
google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71 // indirect
|
|
||||||
google.golang.org/grpc v1.40.0 // indirect
|
|
||||||
google.golang.org/protobuf v1.27.1 // indirect
|
|
||||||
gopkg.in/ini.v1 v1.63.2 // indirect
|
|
||||||
gopkg.in/ns1/ns1-go.v2 v2.6.2 // indirect
|
|
||||||
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
|
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
|
||||||
k8s.io/apimachinery v0.21.0 // indirect
|
|
||||||
k8s.io/klog/v2 v2.8.0 // indirect
|
|
||||||
sigs.k8s.io/structured-merge-diff/v4 v4.1.0 // indirect
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Containous forks
|
exclude github.com/tencentcloud/tencentcloud-sdk-go v3.0.83+incompatible
|
||||||
replace (
|
|
||||||
github.com/abbot/go-http-auth => github.com/containous/go-http-auth v0.4.1-0.20200324110947-a37a7636d23e
|
|
||||||
github.com/go-check/check => github.com/containous/check v0.0.0-20170915194414-ca0bf163426a
|
|
||||||
github.com/gorilla/mux => github.com/containous/mux v0.0.0-20181024131434-c33f32e26898
|
|
||||||
github.com/mailgun/minheap => github.com/containous/minheap v0.0.0-20190809180810-6e71eb837595
|
|
||||||
github.com/mailgun/multibuf => github.com/containous/multibuf v0.0.0-20190809014333-8b6c9a7e6bba
|
|
||||||
)
|
|
||||||
|
|
||||||
// https://github.com/docker/compose/blob/e44222664abd07ce1d1fe6796d84d93cbc7468c3/go.mod#L131
|
|
||||||
replace github.com/jaguilar/vt100 => github.com/tonistiigi/vt100 v0.0.0-20190402012908-ad4c4a574305
|
|
||||||
|
|||||||
@ -11,21 +11,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Exec Execute a command on a go routine.
|
// Exec Execute a command on a go routine.
|
||||||
func Exec(command string) {
|
func Exec(ctx context.Context, command string) {
|
||||||
if command == "" {
|
if command == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
errH := execute(command)
|
errH := execute(ctx, command)
|
||||||
if errH != nil {
|
if errH != nil {
|
||||||
panic(errH)
|
panic(errH)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func execute(command string) error {
|
func execute(ctx context.Context, command string) error {
|
||||||
ctxCmd, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
ctxCmd, cancel := context.WithTimeout(ctx, 30*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
parts := strings.Fields(os.ExpandEnv(command))
|
parts := strings.Fields(os.ExpandEnv(command))
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
package hook
|
package hook
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func Test_execute(t *testing.T) {
|
func Test_execute(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
@ -19,7 +21,7 @@ func Test_execute(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
err := execute(test.command)
|
err := execute(t.Context(), test.command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,17 +3,17 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/abronan/valkeyrie"
|
"github.com/kvtools/boltdb"
|
||||||
"github.com/abronan/valkeyrie/store"
|
"github.com/kvtools/consul"
|
||||||
"github.com/abronan/valkeyrie/store/boltdb"
|
"github.com/kvtools/etcdv3"
|
||||||
"github.com/abronan/valkeyrie/store/consul"
|
"github.com/kvtools/valkeyrie"
|
||||||
etcdv3 "github.com/abronan/valkeyrie/store/etcd/v3"
|
"github.com/kvtools/zookeeper"
|
||||||
"github.com/abronan/valkeyrie/store/zookeeper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const storeKey = "traefik/acme/account/object"
|
const storeKey = "traefik/acme/account/object"
|
||||||
@ -22,38 +22,43 @@ func main() {
|
|||||||
log.SetFlags(log.Lshortfile)
|
log.SetFlags(log.Lshortfile)
|
||||||
|
|
||||||
source := "./acme.json"
|
source := "./acme.json"
|
||||||
err := loadData(source)
|
err := loadData(context.Background(), source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadData(source string) error {
|
func loadData(ctx context.Context, source string) error {
|
||||||
content, err := readFile(source)
|
content, err := readFile(source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Consul
|
// Consul
|
||||||
err = putData(store.CONSUL, []string{"localhost:8500"}, content)
|
|
||||||
|
err = putData(ctx, consul.StoreName, []string{"localhost:8500"},
|
||||||
|
&consul.Config{ConnectionTimeout: 3 * time.Second}, content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ETCD v3
|
// ETCD v3
|
||||||
err = putData(store.ETCDV3, []string{"localhost:2379"}, content)
|
err = putData(ctx, etcdv3.StoreName, []string{"localhost:2379"},
|
||||||
|
&etcdv3.Config{ConnectionTimeout: 3 * time.Second}, content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zookeeper
|
// Zookeeper
|
||||||
err = putData(store.ZK, []string{"localhost:2181"}, content)
|
err = putData(ctx, zookeeper.StoreName, []string{"localhost:2181"},
|
||||||
|
&zookeeper.Config{ConnectionTimeout: 3 * time.Second}, content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// BoltDB
|
// BoltDB
|
||||||
err = putData(store.BOLTDB, []string{"/tmp/test-traefik-certs-dumper.db"}, content)
|
err = putData(ctx, boltdb.StoreName, []string{"/tmp/test-traefik-certs-dumper.db"},
|
||||||
|
&boltdb.Config{ConnectionTimeout: 3 * time.Second, Bucket: "traefik"}, content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -61,29 +66,13 @@ func loadData(source string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func putData(backend store.Backend, addrs []string, content []byte) error {
|
func putData(ctx context.Context, backend string, addrs []string, options valkeyrie.Config, content []byte) error {
|
||||||
storeConfig := &store.Config{
|
kvStore, err := valkeyrie.NewStore(ctx, backend, addrs, options)
|
||||||
ConnectionTimeout: 3 * time.Second,
|
|
||||||
Bucket: "traefik",
|
|
||||||
}
|
|
||||||
|
|
||||||
switch backend {
|
|
||||||
case store.CONSUL:
|
|
||||||
consul.Register()
|
|
||||||
case store.ETCDV3:
|
|
||||||
etcdv3.Register()
|
|
||||||
case store.ZK:
|
|
||||||
zookeeper.Register()
|
|
||||||
case store.BOLTDB:
|
|
||||||
boltdb.Register()
|
|
||||||
}
|
|
||||||
|
|
||||||
kvStore, err := valkeyrie.NewStore(backend, addrs, storeConfig)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := kvStore.Put(storeKey, content, nil); err != nil {
|
if err := kvStore.Put(ctx, storeKey, content, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
package v1
|
package traefikv1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-acme/lego/v4/certcrypto"
|
"github.com/go-acme/lego/v4/certcrypto"
|
||||||
101
internal/traefikv2/acme.go
Normal file
101
internal/traefikv2/acme.go
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
package traefikv2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto"
|
||||||
|
"crypto/x509"
|
||||||
|
|
||||||
|
"github.com/go-acme/lego/v4/certcrypto"
|
||||||
|
"github.com/go-acme/lego/v4/registration"
|
||||||
|
)
|
||||||
|
|
||||||
|
// StoredData represents the data managed by Store.
|
||||||
|
type StoredData struct {
|
||||||
|
Account *Account
|
||||||
|
Certificates []*CertAndStore
|
||||||
|
}
|
||||||
|
|
||||||
|
// Account is used to store lets encrypt registration info.
|
||||||
|
type Account struct {
|
||||||
|
Email string
|
||||||
|
Registration *registration.Resource
|
||||||
|
PrivateKey []byte
|
||||||
|
KeyType certcrypto.KeyType
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetEmail returns email.
|
||||||
|
func (a *Account) GetEmail() string {
|
||||||
|
return a.Email
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRegistration returns lets encrypt registration resource.
|
||||||
|
func (a *Account) GetRegistration() *registration.Resource {
|
||||||
|
return a.Registration
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPrivateKey returns private key.
|
||||||
|
func (a *Account) GetPrivateKey() crypto.PrivateKey {
|
||||||
|
privateKey, err := x509.ParsePKCS1PrivateKey(a.PrivateKey)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return privateKey
|
||||||
|
}
|
||||||
|
|
||||||
|
// CertAndStore allows mapping a TLS certificate to a TLS store.
|
||||||
|
type CertAndStore struct {
|
||||||
|
Certificate
|
||||||
|
Store string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Certificate is a struct which contains all data needed from an ACME certificate.
|
||||||
|
type Certificate struct {
|
||||||
|
Domain Domain `json:"domain,omitempty" toml:"domain,omitempty" yaml:"domain,omitempty"`
|
||||||
|
Certificate []byte `json:"certificate,omitempty" toml:"certificate,omitempty" yaml:"certificate,omitempty"`
|
||||||
|
Key []byte `json:"key,omitempty" toml:"key,omitempty" yaml:"key,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Domain holds a domain name with SANs.
|
||||||
|
type Domain struct {
|
||||||
|
// Main defines the main domain name.
|
||||||
|
Main string `description:"Default subject name." json:"main,omitempty" toml:"main,omitempty" yaml:"main,omitempty"`
|
||||||
|
// SANs defines the subject alternative domain names.
|
||||||
|
SANs []string `description:"Subject alternative names." json:"sans,omitempty" toml:"sans,omitempty" yaml:"sans,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToStrArray convert a domain into an array of strings.
|
||||||
|
func (d *Domain) ToStrArray() []string {
|
||||||
|
var domains []string
|
||||||
|
if d.Main != "" {
|
||||||
|
domains = []string{d.Main}
|
||||||
|
}
|
||||||
|
return append(domains, d.SANs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set sets a domains from an array of strings.
|
||||||
|
func (d *Domain) Set(domains []string) {
|
||||||
|
if len(domains) > 0 {
|
||||||
|
d.Main = domains[0]
|
||||||
|
d.SANs = domains[1:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (d *Domain) DeepCopyInto(out *Domain) {
|
||||||
|
*out = *d
|
||||||
|
if d.SANs != nil {
|
||||||
|
in, out := &d.SANs, &out.SANs
|
||||||
|
*out = make([]string, len(*in))
|
||||||
|
copy(*out, *in)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Domain.
|
||||||
|
func (d *Domain) DeepCopy() *Domain {
|
||||||
|
if d == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(Domain)
|
||||||
|
d.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
101
internal/traefikv3/acme.go
Normal file
101
internal/traefikv3/acme.go
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
package traefikv3
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto"
|
||||||
|
"crypto/x509"
|
||||||
|
|
||||||
|
"github.com/go-acme/lego/v4/certcrypto"
|
||||||
|
"github.com/go-acme/lego/v4/registration"
|
||||||
|
)
|
||||||
|
|
||||||
|
// StoredData represents the data managed by Store.
|
||||||
|
type StoredData struct {
|
||||||
|
Account *Account
|
||||||
|
Certificates []*CertAndStore
|
||||||
|
}
|
||||||
|
|
||||||
|
// Account is used to store lets encrypt registration info.
|
||||||
|
type Account struct {
|
||||||
|
Email string
|
||||||
|
Registration *registration.Resource
|
||||||
|
PrivateKey []byte
|
||||||
|
KeyType certcrypto.KeyType
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetEmail returns email.
|
||||||
|
func (a *Account) GetEmail() string {
|
||||||
|
return a.Email
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRegistration returns lets encrypt registration resource.
|
||||||
|
func (a *Account) GetRegistration() *registration.Resource {
|
||||||
|
return a.Registration
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPrivateKey returns private key.
|
||||||
|
func (a *Account) GetPrivateKey() crypto.PrivateKey {
|
||||||
|
privateKey, err := x509.ParsePKCS1PrivateKey(a.PrivateKey)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return privateKey
|
||||||
|
}
|
||||||
|
|
||||||
|
// CertAndStore allows mapping a TLS certificate to a TLS store.
|
||||||
|
type CertAndStore struct {
|
||||||
|
Certificate
|
||||||
|
Store string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Certificate is a struct which contains all data needed from an ACME certificate.
|
||||||
|
type Certificate struct {
|
||||||
|
Domain Domain `json:"domain,omitempty" toml:"domain,omitempty" yaml:"domain,omitempty"`
|
||||||
|
Certificate []byte `json:"certificate,omitempty" toml:"certificate,omitempty" yaml:"certificate,omitempty"`
|
||||||
|
Key []byte `json:"key,omitempty" toml:"key,omitempty" yaml:"key,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Domain holds a domain name with SANs.
|
||||||
|
type Domain struct {
|
||||||
|
// Main defines the main domain name.
|
||||||
|
Main string `description:"Default subject name." json:"main,omitempty" toml:"main,omitempty" yaml:"main,omitempty"`
|
||||||
|
// SANs defines the subject alternative domain names.
|
||||||
|
SANs []string `description:"Subject alternative names." json:"sans,omitempty" toml:"sans,omitempty" yaml:"sans,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToStrArray convert a domain into an array of strings.
|
||||||
|
func (d *Domain) ToStrArray() []string {
|
||||||
|
var domains []string
|
||||||
|
if d.Main != "" {
|
||||||
|
domains = []string{d.Main}
|
||||||
|
}
|
||||||
|
return append(domains, d.SANs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set sets a domains from an array of strings.
|
||||||
|
func (d *Domain) Set(domains []string) {
|
||||||
|
if len(domains) > 0 {
|
||||||
|
d.Main = domains[0]
|
||||||
|
d.SANs = domains[1:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (d *Domain) DeepCopyInto(out *Domain) {
|
||||||
|
*out = *d
|
||||||
|
if d.SANs != nil {
|
||||||
|
in, out := &d.SANs, &out.SANs
|
||||||
|
*out = make([]string, len(*in))
|
||||||
|
copy(*out, *in)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Domain.
|
||||||
|
func (d *Domain) DeepCopy() *Domain {
|
||||||
|
if d == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(Domain)
|
||||||
|
d.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
29
readme.md
29
readme.md
@ -18,16 +18,17 @@ If you appreciate this project:
|
|||||||
- from file ("acme.json")
|
- from file ("acme.json")
|
||||||
- from KV stores (Consul, Etcd, Zookeeper)
|
- from KV stores (Consul, Etcd, Zookeeper)
|
||||||
- Output formats:
|
- Output formats:
|
||||||
- use domain as sub-directory (allow custom names and extensions)
|
- use domain as subdirectory (allow custom names and extensions)
|
||||||
- flat (domain as filename)
|
- flat (domain as filename)
|
||||||
- Hook (only with watch mode and if the data source changes)
|
- Hook (only with watch mode and if the data source changes)
|
||||||
|
- Support Traefik v1, v2, and v3.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### Download / CI Integration
|
### Download / CI Integration
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -sfL https://raw.githubusercontent.com/ldez/traefik-certs-dumper/master/godownloader.sh | bash -s -- -b $(go env GOPATH)/bin v2.7.4
|
curl -sfL https://raw.githubusercontent.com/ldez/traefik-certs-dumper/master/godownloader.sh | bash -s -- -b $(go env GOPATH)/bin v2.9.3
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
@ -60,6 +61,7 @@ Examples:
|
|||||||
|
|
||||||
- Traefik v1: [docker-compose](docs/docker-compose-traefik-v1.yml)
|
- Traefik v1: [docker-compose](docs/docker-compose-traefik-v1.yml)
|
||||||
- Traefik v2: [docker-compose](docs/docker-compose-traefik-v2.yml)
|
- Traefik v2: [docker-compose](docs/docker-compose-traefik-v2.yml)
|
||||||
|
- Traefik v3: TODO
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -69,12 +71,10 @@ Examples:
|
|||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
**Note:** to dump data from Traefik v2, the CLI flag `--version v2` must be added.
|
|
||||||
|
|
||||||
### Simple Dump
|
### Simple Dump
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ traefik-certs-dumper file
|
$ traefik-certs-dumper file --version v3
|
||||||
dump
|
dump
|
||||||
├──certs
|
├──certs
|
||||||
│ └──my.domain.com.key
|
│ └──my.domain.com.key
|
||||||
@ -86,7 +86,7 @@ dump
|
|||||||
### Change source and destination
|
### Change source and destination
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ traefik-certs-dumper file --source ./acme.json --dest ./dump/test
|
$ traefik-certs-dumper file --version v3 --source ./acme.json --dest ./dump/test
|
||||||
test
|
test
|
||||||
├──certs
|
├──certs
|
||||||
│ └──my.domain.com.key
|
│ └──my.domain.com.key
|
||||||
@ -98,7 +98,7 @@ test
|
|||||||
### Use domain as sub-directory
|
### Use domain as sub-directory
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ traefik-certs-dumper file --domain-subdir=true
|
$ traefik-certs-dumper file --version v3 --domain-subdir=true
|
||||||
dump
|
dump
|
||||||
├──my.domain.com
|
├──my.domain.com
|
||||||
│ ├──certificate.crt
|
│ ├──certificate.crt
|
||||||
@ -110,7 +110,7 @@ dump
|
|||||||
#### Change file extension
|
#### Change file extension
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ traefik-certs-dumper file --domain-subdir --crt-ext=.pem --key-ext=.pem
|
$ traefik-certs-dumper file --version v3 --domain-subdir --crt-ext=.pem --key-ext=.pem
|
||||||
dump
|
dump
|
||||||
├──my.domain.com
|
├──my.domain.com
|
||||||
│ ├──certificate.pem
|
│ ├──certificate.pem
|
||||||
@ -122,7 +122,7 @@ dump
|
|||||||
#### Change file name
|
#### Change file name
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ traefik-certs-dumper file --domain-subdir --crt-name=fullchain --key-name=privkey
|
$ traefik-certs-dumper file --version v3 --domain-subdir --crt-name=fullchain --key-name=privkey
|
||||||
dump
|
dump
|
||||||
├──my.domain.com
|
├──my.domain.com
|
||||||
│ ├──fullchain.crt
|
│ ├──fullchain.crt
|
||||||
@ -133,24 +133,21 @@ dump
|
|||||||
|
|
||||||
## Hook
|
## Hook
|
||||||
|
|
||||||
Hook can be a one liner passed as a string, or a file for more complex post-hook scenarios.
|
Hook can be a one-liner passed as a string, or a file for more complex post-hook scenarios.
|
||||||
For the former, create a file (ex: `hook.sh`) and mount it, then pass `sh hooksh` as a parameter to `--post-hook`.
|
For the former, create a file (ex: `hook.sh`) and mount it, then pass `sh hooksh` as a parameter to `--post-hook`.
|
||||||
|
|
||||||
Here is a docker-compose example:
|
Here is a docker-compose example:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
version: '3.7'
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
# ...
|
# ...
|
||||||
|
|
||||||
traefik-certs-dumper:
|
traefik-certs-dumper:
|
||||||
image: ldez/traefik-certs-dumper:v2.7.4
|
image: ldez/traefik-certs-dumper:v2.9.3
|
||||||
container_name: traefik-certs-dumper
|
container_name: traefik-certs-dumper
|
||||||
entrypoint: sh -c '
|
entrypoint: sh -c '
|
||||||
apk add jq
|
while ! [ -e /data/acme.json ]
|
||||||
; while ! [ -e /data/acme.json ]
|
|| ! [ `jq ".[] | .Certificates | length" /data/acme.json | jq -s "add" ` != 0 ]; do
|
||||||
|| ! [ `jq ".[] | .Certificates | length" /data/acme.json` != 0 ]; do
|
|
||||||
sleep 1
|
sleep 1
|
||||||
; done
|
; done
|
||||||
&& traefik-certs-dumper file --version v2 --watch
|
&& traefik-certs-dumper file --version v2 --watch
|
||||||
|
|||||||
@ -1,24 +0,0 @@
|
|||||||
FROM golang:1-alpine as builder
|
|
||||||
|
|
||||||
RUN apk --update upgrade \
|
|
||||||
&& apk --no-cache --no-progress add git make gcc musl-dev ca-certificates tzdata
|
|
||||||
|
|
||||||
WORKDIR /go/src/github.com/ldez/traefik-certs-dumper
|
|
||||||
|
|
||||||
ENV GO111MODULE on
|
|
||||||
COPY go.mod go.sum ./
|
|
||||||
RUN go mod download
|
|
||||||
|
|
||||||
COPY . .
|
|
||||||
RUN GOARCH={{ .GoARCH }} GOARM={{ .GoARM }} make build
|
|
||||||
|
|
||||||
FROM {{ .RuntimeImage }}
|
|
||||||
|
|
||||||
# Not supported for multi-arch without Buildkit or QEMU
|
|
||||||
#RUN apk --update upgrade \
|
|
||||||
# && apk --no-cache --no-progress add ca-certificates
|
|
||||||
|
|
||||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
|
||||||
COPY --from=builder /go/src/github.com/ldez/traefik-certs-dumper/traefik-certs-dumper /usr/bin/traefik-certs-dumper
|
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/bin/traefik-certs-dumper"]
|
|
||||||
Loading…
Reference in New Issue
Block a user