Skip to content

Commit

Permalink
Rename to Draupnir in Appropriate Places (#591)
Browse files Browse the repository at this point in the history
* Rename to Draupnir in Appropriate Places

* Integrate Code review feedback on CHANGELOG.md
  • Loading branch information
FSG-Cat authored Oct 4, 2024
1 parent 39eb298 commit 9cc6407
Show file tree
Hide file tree
Showing 45 changed files with 156 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ config/*
!config/default.yaml

# Draupnir test data
mjolnir-registration.yaml
draupnir-registration.yaml
test/harness/mjolnir-data/*

# Misc
Expand Down
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!--
SPDX-FileCopyrightText: 2024 Gnuxie <[email protected]>
SPDX-License-Identifier: CC-BY-SA-4.0
-->

# Changelog

All notable changes to Draupnir will be kept in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased] - 2024-10-04

### Changed

* `Dockerfile`: entry-point was renamed from `mjolnir-entrypoint.sh` to `draupnir-entrypoint.sh`.
If you have built a Dockerfile based on ours, you may need to make some changes.

* `Dockerfile`: source code was moved from `/mjolnir` to `/draupnir`. If you have built a custom
docker image based on our Dockerfile based on ours, you may need to make some changes.

* The appservice registration file generator no longer emits `mjolnir-registration.yaml`
as it has been renamed to `draupnir-registration.yaml`. This is only a concern if you have
automated tooling that generates a registration file.

## Versions v2.0.0-beta.7 and prior

Please see [Releases](https://github.com/the-draupnir-project/Draupnir/releases) for more information.

<!-- Remove me later. Currently points to releases as this is a Unreleased change.
As soon as the release is made change the note to point to the release. -->
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ COPY . /tmp/src
RUN cd /tmp/src \
&& yarn install --network-timeout 100000 \
&& yarn build \
&& mv lib/ /mjolnir/ \
&& mv lib/ /draupnir/ \
&& mv node_modules / \
&& mv mjolnir-entrypoint.sh / \
&& mv draupnir-entrypoint.sh / \
&& mv package.json / \
&& mv version.txt / \
&& cd / \
Expand All @@ -21,5 +21,5 @@ ENV NODE_ENV=production
ENV NODE_CONFIG_DIR=/data/config

CMD ["bot"]
ENTRYPOINT ["./mjolnir-entrypoint.sh"]
ENTRYPOINT ["./draupnir-entrypoint.sh"]
VOLUME ["/data"]
6 changes: 3 additions & 3 deletions mjolnir-entrypoint.sh → draupnir-entrypoint.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
#
# SPDX-License-Identifier: Apache-2.0 AND AFL-3.0

# This is used as the entrypoint in the mjolnir Dockerfile.
# This is used as the entrypoint in the draupnir Dockerfile.
# We want to transition away form people running the image without specifying `bot` or `appservice`.
# So if eventually cli arguments are provided for the bot version, we want this to be the opportunity to move to `bot`.
# Therefore using arguments without specifying `bot` (or appservice) is unsupported.
# We maintain the behaviour where if it looks like someone is providing an executable to `docker run`, then we will execute that instead.
# This aids configuration and debugging of the image if for example node needed to be started via another method.
case "$1" in
bot) shift; set -- node /mjolnir/index.js "$@";;
appservice) shift; set -- node /mjolnir/appservice/cli.js "$@";;
bot) shift; set -- node /draupnir/index.js "$@";;
appservice) shift; set -- node /draupnir/appservice/cli.js "$@";;
esac

exec "$@";
4 changes: 2 additions & 2 deletions mx-tester.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ up:
- docker run --rm --network host --name mjolnir-test-reverse-proxy -p 127.0.0.1:8081:80 -v $MX_TEST_CWD/test/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx
- corepack yarn install
- corepack npx ts-node src/appservice/cli.ts -r -u "http://host.docker.internal:9000"
- cp mjolnir-registration.yaml $MX_TEST_SYNAPSE_DIR/data/
- cp draupnir-registration.yaml $MX_TEST_SYNAPSE_DIR/data/
after:
# Wait until Synapse is ready
- until curl localhost:9999 --stderr /dev/null > /dev/null; do echo "Waiting for Synapse..."; sleep 1s; done
Expand Down Expand Up @@ -45,7 +45,7 @@ homeserver:
enable_registration_without_verification: true

app_service_config_files:
- "/data/mjolnir-registration.yaml"
- "/data/draupnir-registration.yaml"

# We remove rc_message so we can test rate limiting,
# but we keep the others because of https://github.com/matrix-org/synapse/issues/11785
Expand Down
8 changes: 4 additions & 4 deletions src/Draupnir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const log = new Logger("Draupnir");
// webAPIS should not be included on the Draupnir class.
// That should be managed elsewhere.
// It's not actually relevant to the Draupnir instance and it only was connected
// to Mjolnir because it needs to be started after Mjolnir started and not before.
// to Draupnir because it needs to be started after Draupnir started and not before.
// And giving it to the class was a dumb easy way of doing that.

export class Draupnir implements Client, MatrixAdaptorContext {
Expand All @@ -99,7 +99,7 @@ export class Draupnir implements Client, MatrixAdaptorContext {
public readonly managementRoomOutput: ManagementRoomOutput;
public readonly managementRoomID: StringRoomID;
/*
* Config-enabled polling of reports in Synapse, so Mjolnir can react to reports
* Config-enabled polling of reports in Synapse, so Draupnir can react to reports
*/
private reportPoller?: ReportPoller;
/**
Expand Down Expand Up @@ -135,7 +135,7 @@ export class Draupnir implements Client, MatrixAdaptorContext {
public readonly policyRoomManager: PolicyRoomManager,
public readonly roomMembershipManager: RoomMembershipManager,
public readonly loggableConfigTracker: LoggableConfigTracker,
/** Mjolnir has a feature where you can choose to accept invitations from a space and not just the management room. */
/** Draupnir has a feature where you can choose to accept invitations from a space and not just the management room. */
public readonly acceptInvitesFromRoom: MatrixRoomID,
public readonly acceptInvitesFromRoomIssuer: RoomMembershipRevisionIssuer,
public readonly safeModeToggle: SafeModeToggle,
Expand Down Expand Up @@ -292,7 +292,7 @@ export class Draupnir implements Client, MatrixAdaptorContext {
try {
await this.managementRoomOutput.logMessage(
LogLevel.INFO,
"Mjolnir@startup",
"Draupnir@startup",
"Startup complete. Now monitoring rooms."
);
await sendMatrixEventsFromDeadDocument(
Expand Down
2 changes: 1 addition & 1 deletion src/ManagementRoomOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const levelToFn = {
};

/**
* Allows the different componenets of mjolnir to send messages back to the management room without introducing a dependency on the entirity of a `Mjolnir` instance.
* Allows the different componenets of draupnir to send messages back to the management room without introducing a dependency on the entirity of a `Draupnir` instance.
*/
export default class ManagementRoomOutput {
constructor(
Expand Down
4 changes: 2 additions & 2 deletions src/appservice/AccessControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {

/**
* Utility to manage which users have access to the application service,
* meaning whether a user is able to provision a mjolnir or continue to use one.
* meaning whether a user is able to provision a draupnir or continue to use one.
* Internally we use a policy list within matrix to determine who has access via the `AccessControlUnit`.
*/
export class AccessControl {
Expand All @@ -41,7 +41,7 @@ export class AccessControl {

/**
* Construct and initialize access control for the `MjolnirAppService`.
* @param accessControlListId The room id of a policy list used to manage access to the appservice (who can provision & use mjolniren)
* @param accessControlListId The room id of a policy list used to manage access to the appservice (who can provision & use draupnir)
* @param bridge The matrix-appservice-bridge, used to get the appservice bot.
* @returns A new instance of `AccessControl` to be used by `MjolnirAppService`.
*/
Expand Down
28 changes: 14 additions & 14 deletions src/appservice/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ export class Api {
}

/**
* Finds the management room for a mjolnir.
* @param req.body.openId An OpenID token to verify that the sender of the request owns the mjolnir described in `req.body.mxid`.
* @param req.body.mxid The mxid of the mjolnir we want to find the management room for.
* Finds the management room for a draupnir.
* @param req.body.openId An OpenID token to verify that the sender of the request owns the draupnir described in `req.body.mxid`.
* @param req.body.mxid The mxid of the draupnir we want to find the management room for.
*/
private async pathGet(req: express.Request, response: express.Response) {
const accessToken = req.body["openId"];
Expand Down Expand Up @@ -141,16 +141,16 @@ export class Api {
userId
);
if (mjolnir === undefined) {
response.status(400).send("unknown mjolnir mxid");
response.status(400).send("unknown draupnir mxid");
return;
}

response.status(200).json({ managementRoom: mjolnir.managementRoomID });
}

/**
* Return the mxids of mjolnirs that this user has provisioned.
* @param req.body.openId An OpenID token to find the sender of the request with and find their provisioned mjolnirs.
* Return the mxids of draupnirs that this user has provisioned.
* @param req.body.openId An OpenID token to find the sender of the request with and find their provisioned draupnirs.
*/
private async pathList(req: express.Request, response: express.Response) {
const accessToken = req.body["openId"];
Expand All @@ -174,9 +174,9 @@ export class Api {
}

/**
* Creates a new mjolnir for the requesting user and protects their first room.
* @param req.body.roomId The room id that the request to create a mjolnir originates from.
* This is so that mjolnir can protect the room once the authenticity of the request has been verified.
* Creates a new draupnir for the requesting user and protects their first room.
* @param req.body.roomId The room id that the request to create a draupnir originates from.
* This is so that draupnir can protect the room once the authenticity of the request has been verified.
* @param req.body.openId An OpenID token to find the sender of the request with.
*/
private async pathCreate(req: express.Request, response: express.Response) {
Expand Down Expand Up @@ -214,10 +214,10 @@ export class Api {
}

/**
* Request a mjolnir to join and protect a room.
* @param req.body.openId An OpenID token to find the sender of the request with and that they own the mjolnir described in `req.body.mxid`.
* @param req.body.mxid The mxid of the mjolnir that should join the room.
* @param req.body.roomId The room that this mjolnir should join and protect.
* Request a draupnir to join and protect a room.
* @param req.body.openId An OpenID token to find the sender of the request with and that they own the draupnir described in `req.body.mxid`.
* @param req.body.mxid The mxid of the draupnir that should join the room.
* @param req.body.roomId The room that this draupnir should join and protect.
*/
private async pathJoin(req: express.Request, response: express.Response) {
const accessToken = req.body["openId"];
Expand Down Expand Up @@ -255,7 +255,7 @@ export class Api {
userId
);
if (mjolnir === undefined) {
response.status(400).send("unknown mjolnir mxid");
response.status(400).send("unknown draupnir mxid");
return;
}

Expand Down
23 changes: 13 additions & 10 deletions src/appservice/AppService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ export class MjolnirAppService {

/**
* Make and initialize the app service from the config, ready to be started.
* @param config The appservice's config, not mjolnir's, see `src/appservice/config`.
* @param dataStore A datastore to persist infomration about the mjolniren to.
* @param config The appservice's config, not draupnirs's, see `src/appservice/config`.
* @param dataStore A datastore to persist infomration about the draupnir to.
* @param registrationFilePath A file path to the registration file to read the namespace and tokens from.
* @returns A new `MjolnirAppService`.
*/
Expand All @@ -109,10 +109,10 @@ export class MjolnirAppService {
// to make the code base much simpler. A small hack to pay for an overall less hacky code base.
controller: {
onUserQuery: () => {
throw new Error("Mjolnir uninitialized");
throw new Error("Draupnir uninitialized");
},
onEvent: () => {
throw new Error("Mjolnir uninitialized");
throw new Error("Draupnir uninitialized");
},
},
suppressEcho: false,
Expand Down Expand Up @@ -241,11 +241,11 @@ export class MjolnirAppService {
return {}; // auto-provision users with no additonal data
}

// Provision a new mjolnir for the invitee when the appservice bot (designated by this.bridge.botUserId) is invited to a room.
// Provision a new draupnir for the invitee when the appservice bot (designated by this.bridge.botUserId) is invited to a room.
// Acts as an alternative to the web api provided for the widget.
private async handleProvisionInvite(mxEvent: WeakEvent): Promise<void> {
log.info(
`${mxEvent.sender} has sent an invitation to the appservice bot ${this.bridge.botUserId}, attempting to provision them a mjolnir`
`${mxEvent.sender} has sent an invitation to the appservice bot ${this.bridge.botUserId}, attempting to provision them a draupnir`
);
// Join the room and try to send the welcome flow
try {
Expand Down Expand Up @@ -282,7 +282,7 @@ export class MjolnirAppService {
);
} catch (e: unknown) {
log.error(
`Failed to provision a mjolnir for ${mxEvent.sender} after they invited ${this.bridge.botUserId}:`,
`Failed to provision a draupnir for ${mxEvent.sender} after they invited ${this.bridge.botUserId}:`,
e
);
// continue, we still want to reject this invitation.
Expand All @@ -296,7 +296,7 @@ export class MjolnirAppService {
);
}
try {
// reject the invite to keep the room clean and make sure the invetee doesn't get confused and think this is their mjolnir.
// reject the invite to keep the room clean and make sure the invetee doesn't get confused and think this is their draupnir.
await this.bridge.getBot().getClient().leaveRoom(mxEvent.room_id);
} catch (e: unknown) {
log.warn("Unable to reject an invite to a room", e);
Expand Down Expand Up @@ -341,7 +341,10 @@ export class MjolnirAppService {
* @param port The port that the appservice should listen on to receive transactions from the homeserver.
*/
private async start(port: number) {
log.info("Starting MjolnirAppService, Matrix-side to listen on port", port);
log.info(
"Starting DraupnirAppService, Matrix-side to listen on port",
port
);
this.api.start(this.config.webAPI.port);
await this.bridge.listen(port);
this.prometheusMetrics.addAppServicePath(this.bridge);
Expand All @@ -353,7 +356,7 @@ export class MjolnirAppService {
res.status(200).send("ok");
},
});
log.info("MjolnirAppService started successfully");
log.info("DraupnirAppService started successfully");
}

/**
Expand Down
18 changes: 9 additions & 9 deletions src/appservice/AppServiceDraupnirManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class AppServiceDraupnirManager {
* @param dataStore The data store interface that has the details for provisioned draupnirs.
* @param bridge The bridge abstraction that encapsulates details about the appservice.
* @param accessControl Who has access to the bridge.
* @returns A new mjolnir manager.
* @returns A new Draupnir manager.
*/
public static async makeDraupnirManager(
serverName: string,
Expand All @@ -113,11 +113,11 @@ export class AppServiceDraupnirManager {
}

/**
* Creates a new mjolnir for a user.
* @param requestingUserID The user that is requesting this mjolnir and who will own it.
* Creates a new draupnir for a user.
* @param requestingUserID The user that is requesting this draupnir and who will own it.
* @param managementRoomId An existing matrix room to act as the management room.
* @param client A client for the appservice virtual user that the new mjolnir should use.
* @returns A new managed mjolnir.
* @param client A client for the appservice virtual user that the new draupnir should use.
* @returns A new managed draupnir.
*/
public async makeInstance(
localPart: string,
Expand Down Expand Up @@ -202,7 +202,7 @@ export class AppServiceDraupnirManager {
power_level_content_override: {
users: {
[requestingUserID]: 100,
// Give the mjolnir a higher PL so that can avoid issues with managing the management room.
// Give the draupnir a higher PL so that can avoid issues with managing the management room.
[await mjIntent.matrixClient.getUserId()]: 101,
},
},
Expand Down Expand Up @@ -279,9 +279,9 @@ export class AppServiceDraupnirManager {
}

/**
* Attempt to start a mjolnir, and notify its management room of any failure to start.
* Attempt to start a draupnir, and notify its management room of any failure to start.
* Will be added to `this.unstartedMjolnirs` if we fail to start it AND it is not already running.
* @param mjolnirRecord The record for the mjolnir that we want to start.
* @param mjolnirRecord The record for the draupnir that we want to start.
*/
public async startDraupnirFromRecord(
mjolnirRecord: MjolnirRecord
Expand Down Expand Up @@ -330,7 +330,7 @@ export class AppServiceDraupnirManager {
mjIntent.matrixClient
).catch((e: unknown) => {
log.error(
`Could not start mjolnir ${mjolnirRecord.local_part} for ${mjolnirRecord.owner}:`,
`Could not start draupnir ${mjolnirRecord.local_part} for ${mjolnirRecord.owner}:`,
e
);
this.baseManager.reportUnstartedDraupnir(
Expand Down
4 changes: 2 additions & 2 deletions src/appservice/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import { IConfig } from "./config/config";
import { Task } from "matrix-protection-suite";

/**
* This file provides the entrypoint for the appservice mode for mjolnir.
* This file provides the entrypoint for the appservice mode for draupnir.
* A registration file can be generated `ts-node src/appservice/cli.ts -r -u "http://host.docker.internal:9000"`
* and the appservice can be started with `ts-node src/appservice/cli -p 9000 -c your-confg.yaml`.
*/
const cli = new Cli({
registrationPath: "mjolnir-registration.yaml",
registrationPath: "draupnir-registration.yaml",
bridgeConfig: {
schema: {},
affectsRegistration: false,
Expand Down
2 changes: 1 addition & 1 deletion src/appservice/config/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ homeserver:
# The url for the appservice to call the client server API from.
url: http://localhost:8081

# Database configuration for storing which Mjolnirs have been provisioned.
# Database configuration for storing which Draupnirs have been provisioned.
db:
engine: "postgres"
connectionString: "postgres://mjolnir-tester:mjolnir-test@localhost:8083/mjolnir-test-db"
Expand Down
2 changes: 1 addition & 1 deletion src/appservice/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface IConfig {
webAPI: {
port: number;
};
/** The admin room for the appservice bot. Not called managementRoom like mjolnir on purpose, so they're not mixed in code somehow. */
/** The admin room for the appservice bot. Not called managementRoom like draupnir on purpose, so they're not mixed in code somehow. */
adminRoom: string;
/** configuration for matrix-appservice-bridge's Logger */
logging?: LoggingOpts;
Expand Down
Loading

0 comments on commit 9cc6407

Please sign in to comment.