The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/app/api/server/v1/dns.ts

130 lines
3.3 KiB

import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
import { API } from '../api';
import { resolveSRV, resolveTXT } from '../../../federation/server/functions/resolveDNS';
/**
* @openapi
* /api/v1/dns.resolve.srv:
* get:
* description: Resolves DNS service records (SRV records) for a hostname
* security:
* $ref: '#/security/authenticated'
* parameters:
* - name: url
* in: query
* description: The hostname
* required: true
* schema:
* type: string
* example: open.rocket.chat
* responses:
* 200:
* description: The resolved records
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiSuccessV1'
* - type: object
* properties:
* resolved:
* type: object
* properties:
* target:
* type: string
* priority:
* type: number
* weight:
* type: number
* port:
* type: number
* default:
* description: Unexpected error
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ApiFailureV1'
*/
API.v1.addRoute(
'dns.resolve.srv',
{ authRequired: true },
{
async get() {
check(
this.queryParams,
Match.ObjectIncluding({
url: String,
}),
);
const { url } = this.queryParams;
if (!url) {
throw new Meteor.Error('error-missing-param', 'The required "url" param is missing.');
}
const resolved = await resolveSRV(url);
return API.v1.success({ resolved });
},
},
);
/**
* @openapi
* /api/v1/dns.resolve.txt:
* get:
* description: Resolves DNS text records (TXT records) for a hostname
* security:
* $ref: '#/security/authenticated'
* parameters:
* - name: url
* in: query
* description: The hostname
* required: true
* schema:
* type: string
* example: open.rocket.chat
* responses:
* 200:
* description: The resolved records
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiSuccessV1'
* - type: object
* properties:
* resolved:
* type: string
* default:
* description: Unexpected error
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ApiFailureV1'
*/
API.v1.addRoute(
'dns.resolve.txt',
{ authRequired: true },
{
async post() {
check(
this.queryParams,
Match.ObjectIncluding({
url: String,
}),
);
const { url } = this.queryParams;
if (!url) {
throw new Meteor.Error('error-missing-param', 'The required "url" param is missing.');
}
const resolved = await resolveTXT(url);
return API.v1.success({ resolved });
},
},
);