Skip to content

Commit

Permalink
chore: make linters happy (#835)
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Dec 4, 2023
1 parent f133704 commit ba79450
Show file tree
Hide file tree
Showing 52 changed files with 570 additions and 516 deletions.
76 changes: 0 additions & 76 deletions .github/CODE_OF_CONDUCT.md

This file was deleted.

1 change: 0 additions & 1 deletion .github/FUNDING.yml

This file was deleted.

9 changes: 9 additions & 0 deletions .github/dependabot.yml
@@ -0,0 +1,9 @@
version: 2
updates:
-
package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
commit-message:
prefix: ci
13 changes: 13 additions & 0 deletions .github/linters/.gitleaks.toml
@@ -0,0 +1,13 @@

title = "gitleaks config"

[extend]
# useDefault will extend the base configuration with the default gitleaks config:
# https://github.com/zricethezav/gitleaks/blob/master/config/gitleaks.toml
useDefault = true

[allowlist]
paths = [
'''authorization_test.go''',
'''(.*?)(key)'''
]
2 changes: 1 addition & 1 deletion .github/linters/.htmlhintrc
Expand Up @@ -4,7 +4,7 @@
"attr-value-double-quotes": true,
"attr-value-not-empty": false,
"attr-no-duplication": true,
"doctype-first": true,
"doctype-first": false,
"tag-pair": true,
"tag-self-close": false,
"spec-char-escape": true,
Expand Down
6 changes: 3 additions & 3 deletions .github/linters/.markdown-lint.yml
Expand Up @@ -21,9 +21,9 @@
MD004: false # Unordered list style
MD007:
indent: 2 # Unordered list indentation
MD013:
line_length: 400 # Line length 80 is far too short
tables: false
MD010:
ignore_code_languages: [caddyfile]
MD013: false
MD026:
punctuation: ".,;:!。,;:" # List of not allowed
MD029: false # Ordered list item prefix
Expand Down
13 changes: 13 additions & 0 deletions .github/linters/.textlintrc
@@ -0,0 +1,13 @@
{
"filters": {
"comments": true
},
"rules": {
"terminology": {
"defaultTerms": true,
"exclude": [
"(?<=(?:\\w+[^.?!])? )internet\\b(?! explorer)"
]
}
}
}
12 changes: 8 additions & 4 deletions .github/workflows/cd.yml
@@ -1,12 +1,16 @@
name: Release Hub

on:
pull_request:
branches:
- main
push:
tags:
- 'v*'
branches:
- '*'
pull_request:
- main
tags:
- v*.*.*
workflow_dispatch:
inputs: {}

permissions:
contents: write
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/ci-chart.yml
@@ -1,8 +1,14 @@
name: Lint and Test Chart

on:
push:
pull_request:
branches:
- main
push:
branches:
- main
tags:
- v*.*.*

jobs:
lint-test:
Expand Down
27 changes: 20 additions & 7 deletions .github/workflows/ci.yml
@@ -1,8 +1,14 @@
name: Lint and Test Hub

on:
push:
pull_request:
branches:
- main
push:
branches:
- main
tags:
- v*.*.*

env:
GO111MODULE: 'on'
Expand Down Expand Up @@ -32,7 +38,7 @@ jobs:
strategy:
matrix:
go: [ '1.20', '1.21' ]

fail-fast: false
name: Test
runs-on: ubuntu-latest
steps:
Expand All @@ -54,21 +60,20 @@ jobs:
run: go test -race -covermode atomic -coverprofile=profile.cov -coverpkg=github.com/dunglas/mercure ./...

- name: Test Caddy module
working-directory: caddy/
run: |
go test -timeout 1m -race -covermode atomic -coverprofile=profile.cov -coverpkg=github.com/dunglas/mercure ./...
sed '1d' profile.cov >> ../profile.cov
working-directory: ./caddy
- name: Upload coverage results
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: profile.cov
parallel: true

- name: Start Mercure
run: |
cd caddy/mercure
sudo MERCURE_PUBLISHER_JWT_KEY='!ChangeThisMercureHubJWTSecretKey!' MERCURE_SUBSCRIBER_JWT_KEY='!ChangeThisMercureHubJWTSecretKey!' go run main.go start --config ../../Caddyfile.dev
cd -
working-directory: caddy/mercure/
run: sudo MERCURE_PUBLISHER_JWT_KEY='!ChangeThisMercureHubJWTSecretKey!' MERCURE_SUBSCRIBER_JWT_KEY='!ChangeThisMercureHubJWTSecretKey!' go run main.go start --config ../../Caddyfile.dev

- uses: actions/setup-node@v3
with:
Expand All @@ -87,3 +92,11 @@ jobs:
- name: Run Playwright tests
working-directory: conformance-tests/
run: npx playwright test

finish:
needs: test
runs-on: ubuntu-latest
steps:
- uses: shogo82148/actions-goveralls@v1
with:
parallel-finished: true
14 changes: 12 additions & 2 deletions .github/workflows/lint.yml
@@ -1,7 +1,14 @@
name: Lint Docs and Non-Go Code

on:
push:
pull_request:
branches:
- main
push:
branches:
- main
tags:
- v*.*.*

jobs:
lint:
Expand All @@ -13,8 +20,11 @@ jobs:
- name: Lint Code Base
uses: super-linter/super-linter/slim@v4
env:
VALIDATE_ALL_CODEBASE: false
VALIDATE_ALL_CODEBASE: true
VALIDATE_GO: false
VALIDATE_PHP_PHPCS: false
VALIDATE_KUBERNETES_CONFORM: false
VALIDATE_KUBERNETES_KUBEVAL: false
VALIDATE_TYPESCRIPT_STANDARD: false
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .golangci.yml
Expand Up @@ -44,3 +44,4 @@ issues:
- godox
- noctx
- wrapcheck
- goconst
1 change: 1 addition & 0 deletions .markdownlintignore
@@ -0,0 +1 @@
spec/**
1 change: 1 addition & 0 deletions .textlintignore
@@ -0,0 +1 @@
spec/mercure.txt
1 change: 1 addition & 0 deletions Dockerfile.legacy
@@ -1,3 +1,4 @@
# hadolint ignore=DL3006
FROM gcr.io/distroless/static
COPY mercure /
CMD ["/mercure"]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -18,7 +18,7 @@ It is especially useful to publish async and real-time updates of resources serv
* [Full documentation](https://mercure.rocks/docs)
* [Demo](https://demo.mercure.rocks/)

[The protocol](https://mercure.rocks/spec) is maintained in this repository and is also available as [an Internet Draft](https://datatracker.ietf.org/doc/draft-dunglas-mercure/).
[The protocol](https://mercure.rocks/spec) is maintained in this repository and is also available as [an Internet-Draft](https://datatracker.ietf.org/doc/draft-dunglas-mercure/).

A reference, production-grade, implementation of [**a Mercure hub**](https://mercure.rocks/docs/hub/install) (the server) is also available in this repository.
It's free software (AGPL) written in Go. It is provided along with a library that can be used in any Go application to implement the Mercure protocol directly (without a hub) and [an official Docker image](https://hub.docker.com/r/dunglas/mercure).
Expand All @@ -31,7 +31,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md).

## License and Copyright

See https://mercure.rocks/docs/hub/license.
See [license information](https://mercure.rocks/docs/hub/license).

## Credits

Expand Down
3 changes: 2 additions & 1 deletion authorization.go
Expand Up @@ -28,6 +28,7 @@ type role int

const (
defaultCookieName = "mercureAuthorization"
bearerPrefix = "Bearer "
roleSubscriber role = iota
rolePublisher
)
Expand All @@ -54,7 +55,7 @@ var (
func authorize(r *http.Request, jwtConfig *jwtConfig, publishOrigins []string, cookieName string) (*claims, error) {
authorizationHeaders, headerExists := r.Header["Authorization"]
if headerExists {
if len(authorizationHeaders) != 1 || len(authorizationHeaders[0]) < 48 || authorizationHeaders[0][:7] != "Bearer " {
if len(authorizationHeaders) != 1 || len(authorizationHeaders[0]) < 48 || authorizationHeaders[0][:7] != bearerPrefix {
return nil, ErrInvalidAuthorizationHeader
}

Expand Down

0 comments on commit ba79450

Please sign in to comment.