-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
manymjolnir appservice #364
Conversation
4748926
to
99c9c37
Compare
4af1e5d
to
839fe05
Compare
bd919e4
to
c6def0b
Compare
c6def0b
to
bd919e4
Compare
3057d05
to
2d40fdb
Compare
092044d
to
818e4cf
Compare
b854954
to
bd544ab
Compare
bd544ab
to
ec4cb2e
Compare
docs/appservice.md
Outdated
|
||
`docker run -rm -v /mjolnir/data/path:/data matrixdotorg/mjolnir appservice -r -u "http://$HOST:$MATRIX_PORT" -f /data/config/mjolnir-registration.yaml` | ||
|
||
5. Invite the application service bot (specified in the registration) to the access control room you made earlier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: "made" => "created"
Also, I'd rephrase:
"Step 4 created an application service bot. You now need to invite it in the access control room that you have created in Step 1."
However, don't we need to start the application service (step 6) before inviting the bot?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to start the service before inviting the bot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The appservice doesn't need to be aware of the invite, only the homeserver
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as the appservice will try joining anyways
export interface MjolnirRecord { | ||
local_part: string, | ||
owner: string, | ||
management_room: string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we clarify that it's a management_room_id
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably too late now, but we should follow up once schema management is sorted out, added to #415
} | ||
|
||
public async store(mjolnirRecord: MjolnirRecord): Promise<void> { | ||
await this.pgClient.query( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this behave if the connection to the client is lost at some point, i.e. if Postgres is upgraded while Mjölnir is on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably explodes, how are you supposed to handle that? (genuine)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, in my code, I use a connection pool. I drop the connection as soon as I stop using it and I request a connection from the pool when I need a new one. The connection pool is smart enough to reconnect if I have been disconnected. This limits the risks of exploding in flight.
Sounds like a followup issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private constructor( | ||
private readonly matrixClient: MatrixClient, | ||
/** | ||
* This will want refactoring later on since, well, for some reason our API is designed to accept the token in request body and not authorization header :( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly true, but that's not documentation :)
Is this something that can be done quickly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not #416
36671ea
to
b828501
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good! I have a few questions but I feel that we're nearly there.
try { | ||
response = JSON.parse(body); | ||
} catch (e) { | ||
reject(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see it documented?
this.user = user; | ||
const roomsInvitedTo: string[] = []; | ||
await new Promise(async resolve => { | ||
user.on('room.invite', (roomId: string) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why we're using user
to watch for a room.invite
. Aren't we expecting the bot or a new virtual user to be invited?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user gets invited to a management and policy room by the newly provisioned mjolnir
user.on('room.invite', (roomId: string) => { | ||
roomsInvitedTo.push(roomId) | ||
// the appservice should invite it to a policy room and a management room. | ||
if (roomsInvitedTo.length === 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're only checking the length of roomsInvitedTo
? Not the actual rooms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We check those later, it would be nice to describe the rooms we are looking for upfront, but I'm not sure matrix is introspective enough for that.
const mjolnirDetails: CreateMjolnirResponse = await new Promise(async resolve => { | ||
const mjolnirDetailsPromise = apiClient.createMjolnir(roomToProtectId); | ||
user.on('room.invite', (roomId: string) => { | ||
roomsInvitedTo.push(roomId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically, same questions as in the previous test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, seems they are almost the same
55a4b7f
to
f6b8f45
Compare
matrix-bot-sdk imporved the types for this
still needs hooking up when mjolnir restarts, and when the access control changes
It's much harder to forget to initialize the components now that you have to in order to construct them in the first place.
this means that the appsrvice bot is now called 'mjolnir-bot' by default which was easier than going through old code base and renaming
We could have used another Dockerfile for the appservice, extending the exising one but we decided not to because there would have been lots of fiddling around the entrypoint and logistics involved around adding a tag for it via github actions. Not to mention that this would be duplicating the image just to run it with a different binary. This solution is much simpler, backwards compatible, and conscious about the future.
f6b8f45
to
4d07b1b
Compare
No description provided.