Improve: Send cloud token to Federation Hub (#13651)

pull/13559/head^2
Diego Sampaio 6 years ago committed by GitHub
parent 40a2c9f20c
commit 969ba3d41b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      .circleci/config.yml
  2. 1
      packages/rocketchat-federation/package.js
  3. 4
      packages/rocketchat-federation/server/main.js
  4. 1
      packages/rocketchat-federation/server/peerClient.js
  5. 9
      packages/rocketchat-federation/server/peerDNS.js
  6. 16
      packages/rocketchat-federation/server/peerHTTP.js

@ -414,13 +414,13 @@ workflows:
- build:
filters:
tags:
only: /^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$/
only: /^[0-9]+\.[0-9]+\.[0-9]+(?:-(?:rc|beta)\.[0-9]+)?$/
- test-with-oplog-mongo-3-2: &test-mongo
requires:
- build
filters:
tags:
only: /^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$/
only: /^[0-9]+\.[0-9]+\.[0-9]+(?:-(?:rc|beta)\.[0-9]+)?$/
- test-with-oplog-mongo-3-4: &test-mongo-no-pr
requires:
- build
@ -428,7 +428,7 @@ workflows:
branches:
only: develop
tags:
only: /^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$/
only: /^[0-9]+\.[0-9]+\.[0-9]+(?:-(?:rc|beta)\.[0-9]+)?$/
- test-with-oplog-mongo-3-6: *test-mongo-no-pr
- test-with-oplog-mongo-4-0: *test-mongo
- test-without-oplog-mongo-3-2: *test-mongo-no-pr
@ -449,7 +449,7 @@ workflows:
branches:
only: develop
tags:
only: /^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$/
only: /^[0-9]+\.[0-9]+\.[0-9]+(?:-(?:rc|beta)\.[0-9]+)?$/
- image-build:
requires:
- deploy
@ -457,7 +457,7 @@ workflows:
branches:
only: develop
tags:
only: /^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$/
only: /^[0-9]+\.[0-9]+\.[0-9]+(?:-(?:rc|beta)\.[0-9]+)?$/
- hold:
type: approval
requires:
@ -466,7 +466,7 @@ workflows:
branches:
ignore: develop
tags:
only: /^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$/
only: /^[0-9]+\.[0-9]+\.[0-9]+(?:-(?:rc|beta)\.[0-9]+)?$/
- pr-image-build:
requires:
- hold
@ -474,5 +474,5 @@ workflows:
branches:
ignore: develop
tags:
only: /^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$/
only: /^[0-9]+\.[0-9]+\.[0-9]+(?:-(?:rc|beta)\.[0-9]+)?$/

@ -9,6 +9,7 @@ Package.onUse(function(api) {
api.use([
'ecmascript',
'rocketchat:api',
'rocketchat:cloud',
'rocketchat:lib',
'rocketchat:reactions',
'rocketchat:models',

@ -2,6 +2,7 @@ import { Meteor } from 'meteor/meteor';
import { _ } from 'meteor/underscore';
import { settings } from 'meteor/rocketchat:settings';
import { FederationKeys } from 'meteor/rocketchat:models';
import { getWorkspaceAccessToken } from 'meteor/rocketchat:cloud';
import './federation-settings';
import './methods';
@ -76,6 +77,9 @@ const updateSettings = _.debounce(Meteor.bindEnvironment(function() {
url: _peerUrl.replace(/\/+$/, ''),
public_key: FederationKeys.getPublicKeyString(),
},
cloud: {
token: getWorkspaceAccessToken(),
},
};
// If the settings are correctly set, let's update the configuration

@ -36,6 +36,7 @@ class PeerClient {
domain: this.config.peer.domain,
url: this.config.peer.url,
public_key: this.config.peer.public_key,
cloud_token: this.config.cloud.token,
};
}

@ -33,13 +33,18 @@ class PeerDNS {
//
// ########
register(peerConfig) {
const { uniqueId, domain, url, public_key } = peerConfig;
const { uniqueId, domain, url, public_key, cloud_token } = peerConfig;
this.log(`Registering peer with domain ${ domain }...`);
let headers;
if (cloud_token && cloud_token !== '') {
headers = { Authorization: `Bearer ${ cloud_token }` };
}
// Attempt to register peer
try {
peerHTTP.request(this.HubPeer, 'POST', '/api/v1/peers', { uniqueId, domain, url, public_key }, { total: 5, stepSize: 1000, tryToUpdateDNS: false });
peerHTTP.request(this.HubPeer, 'POST', '/api/v1/peers', { uniqueId, domain, url, public_key }, { total: 5, stepSize: 1000, tryToUpdateDNS: false }, headers);
this.log('Peer registered!');

@ -20,7 +20,7 @@ const delay = Meteor.wrapAsync(function(ms, callback) {
}, ms);
});
function doSimpleRequest(peer, method, uri, body) {
function doSimpleRequest(peer, method, uri, body, headers = {}) {
this.log(`Request: ${ method } ${ uri }`);
const { url: serverBaseURL } = peer;
@ -35,12 +35,12 @@ function doSimpleRequest(peer, method, uri, body) {
this.log(`Sending request: ${ method } - ${ uri }`);
return HTTP.call(method, url, { data, timeout: 2000, headers: { 'x-federation-domain': this.config.peer.domain } });
return HTTP.call(method, url, { data, timeout: 2000, headers: { ...headers, 'x-federation-domain': this.config.peer.domain } });
}
//
// Actually does the request, handling retries and everything
function doRequest(peer, method, uri, body, retryInfo = {}) {
function doRequest(peer, method, uri, body, retryInfo = {}, headers = {}) {
// Normalize retry info
retryInfo = {
total: retryInfo.total || 1,
@ -52,7 +52,7 @@ function doRequest(peer, method, uri, body, retryInfo = {}) {
for (let i = 0; i <= retryInfo.total; i++) {
try {
return doSimpleRequest.call(this, peer, method, uri, body);
return doSimpleRequest.call(this, peer, method, uri, body, headers);
} catch (err) {
try {
if (retryInfo.tryToUpdateDNS && !retryInfo.DNSUpdated) {
@ -112,14 +112,14 @@ class PeerHTTP {
//
// Direct request
simpleRequest(peer, method, uri, body) {
return doSimpleRequest.call(this, peer, method, uri, body);
simpleRequest(peer, method, uri, body, headers) {
return doSimpleRequest.call(this, peer, method, uri, body, headers);
}
//
// Request trying to find DNS entries
request(peer, method, uri, body, retryInfo = {}) {
return doRequest.call(this, peer, method, uri, body, retryInfo);
request(peer, method, uri, body, retryInfo = {}, headers = {}) {
return doRequest.call(this, peer, method, uri, body, retryInfo, headers);
}
}

Loading…
Cancel
Save