Skip to content
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

Improve [Matrix] badge generation #2527

Merged
merged 30 commits into from
Dec 20, 2018
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a20f367
Resolve homeservers' names through DNS if possible
babolivier Dec 13, 2018
d3f4110
Add a connectivity check before trying to register
babolivier Dec 13, 2018
d02e309
Comply with the overall coding style
babolivier Dec 13, 2018
ffc3282
Bonus: Use room aliases (with correct syntax) instead of room IDs
babolivier Dec 13, 2018
8453c2f
Bonus: Store access tokens in memory to avoid countless registrations
babolivier Dec 13, 2018
a72bb2d
Update doc
babolivier Dec 13, 2018
55b33b0
Fix error message
babolivier Dec 13, 2018
a7468fd
Add new test for alias + improve existing tests
babolivier Dec 13, 2018
48cff03
Use optional URL parameter to determine where to reach homeservers ra…
babolivier Dec 17, 2018
0b6a19b
Get branch up to date with the latest master revision
babolivier Dec 17, 2018
e17fd8e
Remove in-memory cache for access tokens
babolivier Dec 18, 2018
3d9a5bb
Add test case for homeserver fqdn
babolivier Dec 18, 2018
3ae25b6
Rename room readibility test with a more explicit name
babolivier Dec 18, 2018
1c1fccd
Fix unknown request test
babolivier Dec 18, 2018
ea1433e
Get branch up to date with the latest master revision
babolivier Dec 18, 2018
3ac4a25
Use namedParams instead of exampleUrl
babolivier Dec 20, 2018
b6c9938
Get branch up to date with the latest master revision
babolivier Dec 20, 2018
d655fa1
Add serverFqdnOptional to example (as we run into errors otherwise)
babolivier Dec 20, 2018
75b799d
Make error thrown when parsing the alias more explicit
babolivier Dec 20, 2018
f929910
Remove mention of 'room host'
babolivier Dec 20, 2018
fad3add
Incorporate upstream's test suite improvements
babolivier Dec 20, 2018
2800387
Fix handling of port in alias
babolivier Dec 20, 2018
8bb5ebe
Add tests for invalid alias and port in alias
babolivier Dec 20, 2018
3ec0c77
Update comment
babolivier Dec 20, 2018
2a94b15
URL-encode room IDs and aliases
babolivier Dec 20, 2018
410015e
Move server FQDN to query parameters
babolivier Dec 20, 2018
2d4ec57
Update doc and examples with recent changes
babolivier Dec 20, 2018
56db2a9
Fix typo in doc
babolivier Dec 20, 2018
fcdbd8e
Validate query params + use snake case
paulmelnikow Dec 20, 2018
61f7194
Merge branch 'master' into babolivier/fix-matrix
paulmelnikow Dec 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Resolve homeservers' names through DNS if possible
  • Loading branch information
babolivier committed Dec 13, 2018
commit a20f367d8bc2ed47fb75efd24be5dff7d3a903c4
19 changes: 19 additions & 0 deletions services/matrix/matrix.service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const dns = require('dns')
const util = require('util')
const Joi = require('joi')
const BaseJsonService = require('../base-json')

Expand Down Expand Up @@ -39,7 +41,14 @@ const documentation = `
</p>
`

const srvPrefix = '_matrix._tcp.'
const resolve = util.promisify(dns.resolveSrv)

module.exports = class Matrix extends BaseJsonService {
async lookupMatrixHomeserver(host) {
return resolve(srvPrefix + host)
}

async registerAccount({ host, guest }) {
return this._requestJson({
url: `https://${host}/_matrix/client/r0/register`,
Expand All @@ -65,6 +74,16 @@ module.exports = class Matrix extends BaseJsonService {
}

async fetch({ host, roomId }) {
try {
const addrs = await this.lookupMatrixHomeserver(host)
if (addrs.length) {
host = addrs[0].name
}
} catch (e) {
if (e.code !== 'ENOTFOUND') {
throw e
}
}
let auth
try {
auth = await this.registerAccount({ host, guest: true })
Expand Down