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: Send cloud token to Federation Hub #13651

Merged
merged 2 commits into from
Mar 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 7 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -414,21 +414,21 @@ 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
filters:
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
Expand All @@ -449,15 +449,15 @@ 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
filters:
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:
Expand All @@ -466,13 +466,13 @@ 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
filters:
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]+)?$/

1 change: 1 addition & 0 deletions packages/rocketchat-federation/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Package.onUse(function(api) {
api.use([
'ecmascript',
'rocketchat:api',
'rocketchat:cloud',
'rocketchat:lib',
'rocketchat:reactions',
'rocketchat:models',
Expand Down
4 changes: 4 additions & 0 deletions packages/rocketchat-federation/server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-federation/server/peerClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand Down
9 changes: 7 additions & 2 deletions packages/rocketchat-federation/server/peerDNS.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!');

Expand Down
16 changes: 8 additions & 8 deletions packages/rocketchat-federation/server/peerHTTP.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
}

Expand Down