Skip to content

Commit

Permalink
not relying on jq library to fetch .json contents
Browse files Browse the repository at this point in the history
  • Loading branch information
dev2-nomo committed Dec 20, 2023
1 parent 553abe7 commit 7db9e8d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/services/ssh-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,15 @@ export class SSHOperations {
public executeCommand({ command }: { command: string }): string {
return command;
}

public getWebonVersionIfExists({ sshBaseDir }: { sshBaseDir: string }) {
const checkManifestCommand = `${this.sshConnect} "[ -e ${path.join(
sshBaseDir,
"manifest"
)} ] && cat ${path.join(
sshBaseDir,
"manifest"
)} | jq -r .webon_version || echo 'not_found'"`;

)} | grep -oP '(?<=\\"webon_version\\":\\s\\")[^\\"]*' || node -pe \\"try { const manifest = JSON.parse(fs.readFileSync(0, 'utf8')); console.log(manifest.webon_version); } catch (error) { console.log('not_found'); }\\" || jq -r '.webon_version // \\"not_found\\"'"`;
// it tries 3 different ways to retrieve the contents of a .json on a server
return this.executeCommand({ command: checkManifestCommand });
}

Expand All @@ -100,10 +99,11 @@ export class SSHOperations {
)} ] && cat ${path.join(
sshBaseDir,
"manifest"
)} | jq -r .webon_id || echo 'not_found'"`;
)} | grep -oP '(?<=\\"webon_id\\":\\s\\")[^\\"]*' || node -pe \\"try { const manifest = JSON.parse(fs.readFileSync(0, 'utf8')); console.log(manifest.webon_id); } catch (error) { console.log('not_found'); }\\" || jq -r '.webon_id // \\"not_found\\"'"`;

return this.executeCommand({ command: checkManifestCommand });
}

public checkSshBaseDirExists({ sshBaseDir }: { sshBaseDir: string }) {
const checkDirCommand = `${this.sshConnect} "[ -d ${sshBaseDir} ] && echo 'sshDir exists' || echo 'not_found'"`;
return this.executeCommand({ command: checkDirCommand });
Expand Down

0 comments on commit 7db9e8d

Please sign in to comment.