Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Dec 4, 2023
1 parent 42f1399 commit 730ebb6
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 53 deletions.
3 changes: 2 additions & 1 deletion .github/linters/.markdown-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ MD007:
MD010:
ignore_code_languages: [caddyfile]
MD013:
line_length: false
line_length: 500
code_block_line_length: false
tables: false
MD026:
punctuation: ".,;:!。,;:" # List of not allowed
Expand Down
2 changes: 1 addition & 1 deletion .github/linters/.textlintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"rules": {
"terminology": {
"defaultTerms": true,
"exclude": [
"terms": [
"Internet-Draft"
]
}
Expand Down
4 changes: 0 additions & 4 deletions .github/super-linter.env

This file was deleted.

5 changes: 5 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ jobs:
- name: Lint Code Base
uses: super-linter/super-linter/slim@v4
env:
VALIDATE_ALL_CODEBASE: true
VALIDATE_GO: false
VALIDATE_KUBERNETES_CONFORM: false
VALIDATE_TYPESCRIPT_STANDARD: false
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57 changes: 36 additions & 21 deletions examples/chat/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,62 @@
from flask import Flask, make_response, request, render_template, abort
import jwt
import os
import json
from uritemplate import expand

HUB_URL = os.environ.get(
'HUB_URL', 'https://localhost/.well-known/mercure')
JWT_KEY = os.environ.get('JWT_KEY', '!ChangeThisMercureHubJWTSecretKey!')
HUB_URL = os.environ.get("HUB_URL", "https://localhost/.well-known/mercure")
JWT_KEY = os.environ.get("JWT_KEY", "!ChangeThisMercureHubJWTSecretKey!")
MESSAGE_URI_TEMPLATE = os.environ.get(
'MESSAGE_URI_TEMPLATE', 'https://chat.example.com/messages/{id}')
"MESSAGE_URI_TEMPLATE", "https://chat.example.com/messages/{id}"
)

SUBSCRIPTIONS_TEMPLATE = '/.well-known/mercure/subscriptions/{topic}{/subscriber}'
SUBSCRIPTIONS_TEMPLATE = "/.well-known/mercure/subscriptions/{topic}{/subscriber}"
SUBSCRIPTIONS_TOPIC = expand(SUBSCRIPTIONS_TEMPLATE, topic=MESSAGE_URI_TEMPLATE)

app = Flask(__name__)


@app.route('/', methods=['GET'])
@app.route("/", methods=["GET"])
def join():
return render_template('join.html')
return render_template("join.html")


@app.route('/', methods=['POST'])
@app.route("/", methods=["POST"])
def chat():
username = request.form['username']
username = request.form["username"]
if not username:
abort(400)

token = jwt.encode(
{'mercure':
{
'subscribe': [MESSAGE_URI_TEMPLATE, SUBSCRIPTIONS_TEMPLATE],
'publish': [MESSAGE_URI_TEMPLATE],
'payload': {'username': username}
{
"mercure": {
"subscribe": [MESSAGE_URI_TEMPLATE, SUBSCRIPTIONS_TEMPLATE],
"publish": [MESSAGE_URI_TEMPLATE],
"payload": {"username": username},
}
},
},
JWT_KEY,
algorithm='HS256',
algorithm="HS256",
)

resp = make_response(render_template('chat.html', config={
'hubURL': HUB_URL, 'messageURITemplate': MESSAGE_URI_TEMPLATE, 'subscriptionsTopic': SUBSCRIPTIONS_TOPIC, 'username': username}))
resp.set_cookie('mercureAuthorization', token, httponly=True, path='/.well-known/mercure',
samesite="strict", domain=os.environ.get('COOKIE_DOMAIN', None), secure=request.is_secure) # Force secure to True for real apps
resp = make_response(
render_template(
"chat.html",
config={
"hubURL": HUB_URL,
"messageURITemplate": MESSAGE_URI_TEMPLATE,
"subscriptionsTopic": SUBSCRIPTIONS_TOPIC,
"username": username,
},
)
)
resp.set_cookie(
"mercureAuthorization",
token,
httponly=True,
path="/.well-known/mercure",
samesite="strict",
domain=os.environ.get("COOKIE_DOMAIN", None),
secure=request.is_secure,
) # Force secure to True for real apps

return resp
19 changes: 10 additions & 9 deletions examples/chat/static/app.css
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
.hero img {
width: 40%;
width: 40%;
}

#chat #messages, #chat .panel {
height: 100%;
overflow-y: scroll;
#chat #messages,
#chat .panel {
height: 100%;
overflow-y: scroll;
}

#chat .columns {
height: 70vh;
height: 70vh;
}

#chat .box {
display: flex;
flex-direction: column;
justify-content: space-between;
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
height: 100%;
}
2 changes: 1 addition & 1 deletion examples/publish/php.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

echo file_get_contents('https://localhost/.well-known/mercure', false, stream_context_create(['http' => [
'method' => 'POST',
'header' => "Content-type: application/x-www-form-urlencoded\r\nAuthorization: Bearer ".DEMO_JWT,
'header' => "Content-type: application/x-www-form-urlencoded\r\nAuthorization: Bearer " . DEMO_JWT,
'content' => $postData,
]]));
4 changes: 4 additions & 0 deletions examples/publish/ruby.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# frozen_string_literal: true

require 'json'
require 'net/http'

# rubocop:disable Layout/LineLength
token = 'eyJhbGciOiJIUzI1NiJ9.eyJtZXJjdXJlIjp7InB1Ymxpc2giOlsiKiJdLCJzdWJzY3JpYmUiOlsiaHR0cHM6Ly9leGFtcGxlLmNvbS9teS1wcml2YXRlLXRvcGljIiwie3NjaGVtZX06Ly97K2hvc3R9L2RlbW8vYm9va3Mve2lkfS5qc29ubGQiLCIvLndlbGwta25vd24vbWVyY3VyZS9zdWJzY3JpcHRpb25zey90b3BpY317L3N1YnNjcmliZXJ9Il0sInBheWxvYWQiOnsidXNlciI6Imh0dHBzOi8vZXhhbXBsZS5jb20vdXNlcnMvZHVuZ2xhcyIsInJlbW90ZUFkZHIiOiIxMjcuMC4wLjEifX19.KKPIikwUzRuB3DTpVw6ajzwSChwFw5omBMmMcWKiDcM'
# rubocop:enable Layout/LineLength

Net::HTTP.start('localhost', 3000) do |http|
req = Net::HTTP::Post.new('/.well-known/mercure')
Expand Down
12 changes: 6 additions & 6 deletions examples/subscribe/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import os

token = jwt.encode(
{'mercure': {'subscribe': ['*']}},
os.environ.get('JWT_KEY', '!ChangeThisMercureHubJWTSecretKey!'),
algorithm='HS256',
{"mercure": {"subscribe": ["*"]}},
os.environ.get("JWT_KEY", "!ChangeThisMercureHubJWTSecretKey!"),
algorithm="HS256",
)

updates = SSEClient(
os.environ.get('HUB_URL', 'https://localhost/.well-known/mercure'),
params={'topic': ['*']},
headers={'Authorization': b'Bearer '+token},
os.environ.get("HUB_URL", "https://localhost/.well-known/mercure"),
params={"topic": ["*"]},
headers={"Authorization": b"Bearer " + token},
)
for update in updates:
print("Update received: ", update)
30 changes: 20 additions & 10 deletions gatling/LoadTest.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
/** Load test for Mercure.
*
* 1. Grab Gatling 3 on https://gatling.io
* 2. Run path/to/gatling/bin/gatling.sh --simulations-folder .
* 1. Grab Gatling 3 on https://gatling.io 2. Run
* path/to/gatling/bin/gatling.sh --simulations-folder .
*
* Available environment variables (all optional):
* - HUB_URL: the URL of the hub to test
* - JWT: the JWT to use for authenticating the publisher, fallbacks to JWT if not set and PRIVATE_UPDATES set
* - INITIAL_SUBSCRIBERS: the number of concurrent subscribers initially connected
* - SUBSCRIBERS_RATE_FROM: minimum rate (per second) of additional subscribers to connect
* - SUBSCRIBERS_RATE_TO: maximum rate (per second) of additional subscribers to connect
* - JWT: the JWT to use for authenticating the publisher, fallbacks to JWT
* if not set and PRIVATE_UPDATES set
* - INITIAL_SUBSCRIBERS: the number of concurrent subscribers initially
* connected
* - SUBSCRIBERS_RATE_FROM: minimum rate (per second) of additional
* subscribers to connect
* - SUBSCRIBERS_RATE_TO: maximum rate (per second) of additional subscribers
* to connect
* - PUBLISHERS_RATE_FROM: minimum rate (per second) of publications
* - PUBLISHERS_RATE_TO: maximum rate (per second) of publications
* - INJECTION_DURATION: duration of the publishers injection
* - CONNECTION_DURATION: duration of subscribers' connection
* - RANDOM_CONNECTION_DURATION: to randomize the connection duration (will longs CONNECTION_DURATION at max)
* - RANDOM_CONNECTION_DURATION: to randomize the connection duration (will
* longs CONNECTION_DURATION at max)
*/

package mercure
Expand All @@ -35,7 +40,9 @@ class LoadTest extends Simulation {
"eyJhbGciOiJIUzI1NiJ9.eyJtZXJjdXJlIjp7InB1Ymxpc2giOlsiKiJdLCJzdWJzY3JpYmUiOlsiaHR0cHM6Ly9leGFtcGxlLmNvbS9teS1wcml2YXRlLXRvcGljIiwie3NjaGVtZX06Ly97K2hvc3R9L2RlbW8vYm9va3Mve2lkfS5qc29ubGQiLCIvLndlbGwta25vd24vbWVyY3VyZS9zdWJzY3JpcHRpb25zey90b3BpY317L3N1YnNjcmliZXJ9Il0sInBheWxvYWQiOnsidXNlciI6Imh0dHBzOi8vZXhhbXBsZS5jb20vdXNlcnMvZHVuZ2xhcyIsInJlbW90ZUFkZHIiOiIxMjcuMC4wLjEifX19.KKPIikwUzRuB3DTpVw6ajzwSChwFw5omBMmMcWKiDcM"
)

/** JWT to use to subscribe, fallbacks to JWT if not set and PRIVATE_UPDATES set */
/** JWT to use to subscribe, fallbacks to JWT if not set and PRIVATE_UPDATES
* set
*/
val SubscriberJwt = Properties.envOrElse("SUBSCRIBER_JWT", null)

/** Number of concurrent subscribers initially connected */
Expand Down Expand Up @@ -65,13 +72,16 @@ class LoadTest extends Simulation {
val RandomConnectionDuration =
Properties.envOrElse("RANDOM_CONNECTION_DURATION", "true").toBoolean

/** Send private updates with random topics instead of public ones always with the same topic */
/** Send private updates with random topics instead of public ones always with
* the same topic
*/
var PrivateUpdates =
Properties.envOrElse("PRIVATE_UPDATES", "false").toBoolean

val rnd = new scala.util.Random

/** Subscriber test as a function to handle conditional Authorization header */
/** Subscriber test as a function to handle conditional Authorization header
*/
def subscriberTest() = {
var topic = "https://example.com"
if (PrivateUpdates) {
Expand Down

0 comments on commit 730ebb6

Please sign in to comment.