Skip to content

Commit f1ce17d

Browse files
allow registering by REG_TOKEN environment variable (RocketChat#23737)
1 parent e0fa701 commit f1ce17d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

app/cloud/server/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import { getWorkspaceAccessToken } from './functions/getWorkspaceAccessToken';
66
import { getWorkspaceAccessTokenWithScope } from './functions/getWorkspaceAccessTokenWithScope';
77
import { getWorkspaceLicense } from './functions/getWorkspaceLicense';
88
import { getUserCloudAccessToken } from './functions/getUserCloudAccessToken';
9+
import { retrieveRegistrationStatus } from './functions/retrieveRegistrationStatus';
910
import { getWorkspaceKey } from './functions/getWorkspaceKey';
1011
import { syncWorkspace } from './functions/syncWorkspace';
12+
import { connectWorkspace } from './functions/connectWorkspace';
1113
import { settings } from '../../settings/server';
14+
import { SystemLogger } from '../../../server/lib/logger/system';
1215

1316
const licenseCronName = 'Cloud Workspace Sync';
1417

@@ -34,6 +37,22 @@ Meteor.startup(function() {
3437
job: syncWorkspace,
3538
});
3639
});
40+
41+
const { workspaceRegistered } = retrieveRegistrationStatus();
42+
43+
if (process.env.REG_TOKEN && process.env.REG_TOKEN !== '' && !workspaceRegistered) {
44+
try {
45+
SystemLogger.info('REG_TOKEN Provided. Attempting to register');
46+
47+
if (!connectWorkspace(process.env.REG_TOKEN)) {
48+
throw new Error('Couldn\'t register with token. Please make sure token is valid or hasn\'t already been used');
49+
}
50+
51+
console.log('Successfully registered with token provided by REG_TOKEN!');
52+
} catch (e) {
53+
SystemLogger.error('An error occured registering with token.', e.message);
54+
}
55+
}
3756
});
3857

3958
export { getWorkspaceAccessToken, getWorkspaceAccessTokenWithScope, getWorkspaceLicense, getWorkspaceKey, getUserCloudAccessToken };

0 commit comments

Comments
 (0)