Skip to content

Commit

Permalink
make configurable, and maintain backwards comp
Browse files Browse the repository at this point in the history
Change-type: patch
Signed-off-by: Ryan Cooke <[email protected]>
  • Loading branch information
rcooke-warwick committed Jun 29, 2023
1 parent 06e0fef commit 9a24d7b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
22 changes: 6 additions & 16 deletions core/lib/common/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ module.exports = class Worker {
url,
username,
sshKey,
sshConfig = {}
) {
this.deviceType = deviceType;
this.url = url;
Expand All @@ -96,26 +97,15 @@ module.exports = class Worker {
this.url.includes(`worker`)
|| this.url.includes('unix:')
);
if (this.url.includes(`balena-devices.com`)) {
// worker is a testbot connected to balena cloud - we ssh into it via the vpn
this.uuid = this.url.match(
/(?<=https:\/\/)(.*)(?=.balena-devices.com)/,
)[1];
this.workerHost = `ssh.balena-devices.com`;
this.workerUser = this.username;
this.workerPort = '22';
this.sshPrefix = `host ${this.uuid} `;
}
if (this.url.includes(`bm.balena-dev.com`)) {
// worker is a testbot connected to balena cloud - we ssh into it via the vpn
if(!this.directConnect){
this.uuid = this.url.match(
/https:\/\/([^\.]+)\./,
)[1];
this.workerHost = `ssh.devices.bm.balena-dev.com`;
this.workerUser = this.username;
this.workerPort = '222';
this.sshPrefix = `host ${this.uuid} `;
}
this.workerUser = this.username;
this.workerPort = sshConfig.port || 22;
this.workerHost = sshConfig.host || 'ssh.balena-devices.com'
}
}

/**
Expand Down
10 changes: 7 additions & 3 deletions core/lib/components/balena/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,17 @@ module.exports = class BalenaSDK {
constructor(
apiUrl,
logger = { log: console.log, status: console.log, info: console.log },
sshConfig = {}
) {
this.balena = getSdk({
apiUrl: `https://api.${apiUrl}`,
});
this.pine = this.balena.pine;
this.logger = logger;
this.sshConfig = {
host: sshConfig.host || 'ssh.balena-devices.com',
port: sshConfig.port || 22
}
}

/**
Expand All @@ -91,7 +96,6 @@ module.exports = class BalenaSDK {
tries: 600,
},
) {
const sshPort = 22;

return retry(
async () => {
Expand All @@ -102,9 +106,9 @@ module.exports = class BalenaSDK {
const result = await utils.executeCommandOverSSH(
`host -s ${device} source /etc/profile ; ${command}`,
{
host: `ssh.${await this.balena.settings.get('proxyUrl')}`,
host: this.sshConfig.host,
username: await this.balena.auth.whoami(),
port: sshPort,
port: this.sshConfig.sshPort,
},
);

Expand Down

0 comments on commit 9a24d7b

Please sign in to comment.