7 Commits

12 changed files with 147 additions and 46 deletions

72
.github/ISSUE_TEMPLATE/bug_report.yml vendored Normal file
View File

@ -0,0 +1,72 @@
name: Bug Report
description: Create a report to help us improve.
body:
- type: checkboxes
id: terms
attributes:
label: Welcome!
description: |
The issue tracker is for reporting bugs and feature requests only.
All new/updated issues are triaged regularly by the maintainers.
All issues closed by a bot are subsequently double-checked by the maintainers.
DO NOT FILE ISSUES FOR GENERAL SUPPORT QUESTIONS.
options:
- label: Yes, I've searched similar issues on [GitHub](https://github.com/traefik/whoami/issues) and didn't find any.
required: true
- type: textarea
attributes:
label: What did you do?
description: |
How to write a good bug report?
- Respect the issue template as much as possible.
- The title should be short and descriptive.
- Explain the conditions which led you to report this issue: the context.
- The context should lead to something, an idea or a problem that youre facing.
- Remain clear and concise.
- Format your messages to help the reader focus on what matters and understand the structure of your message, use [Markdown syntax](https://help.github.com/articles/github-flavored-markdown)
placeholder: What did you do?
validations:
required: true
- type: textarea
attributes:
label: What were you expecting?
placeholder: What were you expecting?
validations:
required: true
- type: textarea
attributes:
label: What version are you using?
description: |
`latest` is not considered as a valid version.
placeholder: Paste your output here.
validations:
required: true
- type: textarea
attributes:
label: What is your environment & configuration?
description: arguments, toml, provider, platform, ...
placeholder: Add information here.
value: |
```yaml
# (paste your configuration here)
```
Add more configuration information here.
validations:
required: true
- type: textarea
attributes:
label: If applicable, please paste the log output in DEBUG level
description: "`--log.level=DEBUG` switch."
placeholder: Paste your output here.
validations:
required: false

5
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Traefik Community Support
url: https://community.traefik.io/
about: If you have a question, or are looking for advice, please post on our Discuss forum! The community loves to chime in to help. Happy Coding!

View File

@ -0,0 +1,30 @@
name: Feature Request
description: Suggest an idea for this project.
body:
- type: checkboxes
id: terms
attributes:
label: Welcome!
description: |
The issue tracker is for reporting bugs and feature requests only.
DO NOT FILE ISSUES FOR GENERAL SUPPORT QUESTIONS.
options:
- label: Yes, I've searched similar issues on [GitHub](https://github.com/traefik/whoami/issues) and didn't find any.
required: true
- type: textarea
attributes:
label: What did you expect to see?
description: |
How to write a good issue?
- Respect the issue template as much as possible.
- The title should be short and descriptive.
- Explain the conditions which led you to report this issue: the context.
- The context should lead to something, an idea or a problem that youre facing.
- Remain clear and concise.
- Format your messages to help the reader focus on what matters and understand the structure of your message, use [Markdown syntax](https://help.github.com/articles/github-flavored-markdown)
placeholder: What did you expect to see?
validations:
required: true

View File

@ -12,21 +12,21 @@ jobs:
name: Main Process name: Main Process
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
GO_VERSION: '1.20' GO_VERSION: stable
GOLANGCI_LINT_VERSION: v1.53.3 GOLANGCI_LINT_VERSION: v1.63.4
CGO_ENABLED: 0 CGO_ENABLED: 0
steps: steps:
# https://github.com/marketplace/actions/checkout # https://github.com/marketplace/actions/checkout
- name: Check out code - name: Check out code
uses: actions/checkout@v3 uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
# https://github.com/marketplace/actions/setup-go-environment # https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ env.GO_VERSION }} - name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v4 uses: actions/setup-go@v5
with: with:
go-version: ${{ env.GO_VERSION }} go-version: ${{ env.GO_VERSION }}

View File

@ -15,17 +15,17 @@ jobs:
strategy: strategy:
matrix: matrix:
go-version: [ 1.19, 1.x ] go-version: [ stable, oldstable ]
os: [ubuntu-latest, macos-latest, windows-latest] os: [ubuntu-latest, macos-latest, windows-latest]
steps: steps:
# https://github.com/marketplace/actions/checkout # https://github.com/marketplace/actions/checkout
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v4
# https://github.com/marketplace/actions/setup-go-environment # https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ matrix.go-version }} - name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v4 uses: actions/setup-go@v5
with: with:
go-version: ${{ matrix.go-version }} go-version: ${{ matrix.go-version }}

View File

@ -9,47 +9,47 @@ jobs:
name: Release Process name: Release Process
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
GO_VERSION: '1.20' GO_VERSION: stable
CGO_ENABLED: 0 CGO_ENABLED: 0
steps: steps:
# https://github.com/marketplace/actions/checkout # https://github.com/marketplace/actions/checkout
- name: Check out code - name: Check out code
uses: actions/checkout@v3 uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
# https://github.com/marketplace/actions/setup-go-environment # https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ env.GO_VERSION }} - name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v4 uses: actions/setup-go@v5
with: with:
go-version: ${{ env.GO_VERSION }} go-version: ${{ env.GO_VERSION }}
- name: dockerhub-login - name: dockerhub-login
uses: docker/login-action@v1 uses: docker/login-action@v3
with: with:
username: ${{ secrets.DOCKER_USERNAME }} username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }} password: ${{ secrets.DOCKER_PASSWORD }}
- name: ghcr-login - name: ghcr-login
uses: docker/login-action@v1 uses: docker/login-action@v3
with: with:
registry: ghcr.io registry: ghcr.io
username: traefiker username: traefiker
password: ${{ secrets.GHCR_TOKEN }} password: ${{ secrets.GHCR_TOKEN }}
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@v2 uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2 uses: docker/setup-buildx-action@v3
# https://goreleaser.com/ci/actions/ # https://goreleaser.com/ci/actions/
- name: Run GoReleaser - name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2 uses: goreleaser/goreleaser-action@v5
with: with:
version: latest version: latest
args: release --rm-dist args: release --clean
env: env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_REPO }} GITHUB_TOKEN: ${{ secrets.GH_TOKEN_REPO }}

View File

@ -1,6 +1,5 @@
run: run:
timeout: 2m timeout: 2m
skip-files: []
linters-settings: linters-settings:
govet: govet:
@ -53,29 +52,18 @@ linters-settings:
linters: linters:
enable-all: true enable-all: true
disable: disable:
- deadcode # deprecated
- exhaustivestruct # deprecated
- golint # deprecated
- ifshort # deprecated
- interfacer # deprecated
- maligned # deprecated
- nosnakecase # deprecated
- scopelint # deprecated
- scopelint # deprecated
- structcheck # deprecated
- varcheck # deprecated
- execinquery # not relevant (SQL)
- rowserrcheck # not relevant (SQL) - rowserrcheck # not relevant (SQL)
- sqlclosecheck # not relevant (SQL) - sqlclosecheck # not relevant (SQL)
- cyclop # duplicate of gocyclo - cyclop # duplicate of gocyclo
- dupl - dupl
- exhaustive - exhaustive
- exhaustruct - exhaustruct
- exportloopref
- forbidigo - forbidigo
- gochecknoglobals - gochecknoglobals
- gochecknoinits - gochecknoinits
- goerr113 - err113
- gomnd - mnd
- gosec - gosec
- lll - lll
- nilnil - nilnil
@ -90,7 +78,7 @@ linters:
issues: issues:
exclude-use-default: false exclude-use-default: false
max-per-linter: 0 max-issues-per-linter: 0
max-same-issues: 0 max-same-issues: 0
exclude: exclude:
- 'package-comments: should have a package comment' - 'package-comments: should have a package comment'

View File

@ -20,7 +20,7 @@ The optional `env` query parameter can be set to `true` to add the environment v
#### `/api` #### `/api`
Returns the whoami information as JSON. Returns the whoami information (and some extra information) as JSON.
The optional `env` query parameter can be set to `true` to add the environment variables to the response. The optional `env` query parameter can be set to `true` to add the environment variables to the response.

22
app.go
View File

@ -31,7 +31,7 @@ const (
var upgrader = websocket.Upgrader{ var upgrader = websocket.Upgrader{
ReadBufferSize: 1024, ReadBufferSize: 1024,
WriteBufferSize: 1024, WriteBufferSize: 1024,
CheckOrigin: func(r *http.Request) bool { CheckOrigin: func(_ *http.Request) bool {
return true return true
}, },
} }
@ -50,7 +50,7 @@ func init() {
flag.StringVar(&cert, "cert", "", "give me a certificate") flag.StringVar(&cert, "cert", "", "give me a certificate")
flag.StringVar(&key, "key", "", "give me a key") flag.StringVar(&key, "key", "", "give me a key")
flag.StringVar(&ca, "cacert", "", "give me a CA chain, enforces mutual TLS") flag.StringVar(&ca, "cacert", "", "give me a CA chain, enforces mutual TLS")
flag.StringVar(&port, "port", getEnv("WHOAMI_PORT_NUMBER", "8080"), "give me a port number") flag.StringVar(&port, "port", getEnv("WHOAMI_PORT_NUMBER", "80"), "give me a port number")
flag.StringVar(&name, "name", os.Getenv("WHOAMI_NAME"), "give me a name") flag.StringVar(&name, "name", os.Getenv("WHOAMI_NAME"), "give me a name")
} }
@ -85,11 +85,12 @@ func main() {
} }
server := &http.Server{ server := &http.Server{
Addr: ":" + port, Addr: ":" + port,
Handler: mux, TLSConfig: &tls.Config{ClientAuth: tls.RequestClientCert},
Handler: mux,
} }
if len(ca) > 0 { if ca != "" {
server.TLSConfig = setupMutualTLS(ca) server.TLSConfig = setupMutualTLS(ca)
} }
@ -159,7 +160,7 @@ func echoHandler(w http.ResponseWriter, r *http.Request) {
func printBinary(s []byte) { func printBinary(s []byte) {
fmt.Printf("Received b:") fmt.Printf("Received b:")
for n := 0; n < len(s); n++ { for n := range s {
fmt.Printf("%d,", s[n]) fmt.Printf("%d,", s[n])
} }
fmt.Printf("\n") fmt.Printf("\n")
@ -211,7 +212,7 @@ func whoamiHandler(w http.ResponseWriter, r *http.Request) {
queryParams := r.URL.Query() queryParams := r.URL.Query()
wait := queryParams.Get("wait") wait := queryParams.Get("wait")
if len(wait) > 0 { if wait != "" {
duration, err := time.ParseDuration(wait) duration, err := time.ParseDuration(wait)
if err == nil { if err == nil {
time.Sleep(duration) time.Sleep(duration)
@ -230,6 +231,13 @@ func whoamiHandler(w http.ResponseWriter, r *http.Request) {
} }
_, _ = fmt.Fprintln(w, "RemoteAddr:", r.RemoteAddr) _, _ = fmt.Fprintln(w, "RemoteAddr:", r.RemoteAddr)
if r.TLS != nil {
for i, cert := range r.TLS.PeerCertificates {
_, _ = fmt.Fprintf(w, "Certificate[%d] Subject: %v\n", i, cert.Subject)
}
}
if err := r.Write(w); err != nil { if err := r.Write(w); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return

View File

@ -19,7 +19,6 @@ func Test_contentReader_Read(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
t.Parallel() t.Parallel()
@ -56,7 +55,6 @@ func Test_contentReader_ReadSeek(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
t.Parallel() t.Parallel()

4
go.mod
View File

@ -1,5 +1,5 @@
module github.com/traefik/whoami module github.com/traefik/whoami
go 1.20 go 1.23
require github.com/gorilla/websocket v1.4.2 require github.com/gorilla/websocket v1.5.3

4
go.sum
View File

@ -1,2 +1,2 @@
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=