Skip to content

Commit

Permalink
Use prod SDK to fetch OS images
Browse files Browse the repository at this point in the history
Signed-off-by: Vipul Gupta (@vipulgupta2048) <[email protected]>
  • Loading branch information
vipulgupta2048 authored and rcooke-warwick committed Jul 3, 2023
1 parent f90d490 commit d929af3
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions core/lib/components/balena/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ module.exports = class BalenaSDK {
this.balena = getSdk({
apiUrl: `https://api.${apiUrl}`,
});
this.apiUrl = apiUrl
this.pine = this.balena.pine;
this.logger = logger;
this.sshConfig = {
Expand Down Expand Up @@ -130,7 +131,7 @@ module.exports = class BalenaSDK {

/**
* Creates application for a devicetype with the required config
*
*
* @param {string} name Name of the application that needs to be created
* @param {string} deviceType The device type for which application needs to be created
* @param {object} config specify configuration needed for the application
Expand Down Expand Up @@ -161,9 +162,9 @@ module.exports = class BalenaSDK {

/**
* Removes SSH key from balenaCloud account
*
* @param {string} label SSH key label
*
*
* @param {string} label SSH key label
*
* @category helper
*/
async removeSSHKey(label) {
Expand Down Expand Up @@ -340,7 +341,11 @@ module.exports = class BalenaSDK {
*/
async fetchOS(versionOrRange = 'latest', deviceType, osType = 'default') {
// normalize the version string/range, supports 'latest', 'recommended', etc
let version = await this.balena.models.os.getMaxSatisfyingVersion(
const balenaSdkProd = getSdk({
apiUrl: "https://api.balena-cloud.com",
});

let version = await balenaSdkProd.models.os.getMaxSatisfyingVersion(
deviceType,
versionOrRange,
osType,
Expand All @@ -356,15 +361,15 @@ module.exports = class BalenaSDK {
);

// Caching implementation if needed - Check https://github.com/balena-os/leviathan/issues/441

let attempt = 0;
const downloadLatestOS = async () => {
attempt++;
this.logger.log(
`Fetching balenaOS version ${version}, attempt ${attempt}...`,
);

return await new Promise(async (resolve, reject) => {
await this.balena.models.os.download(
await balenaSdkProd.models.os.download(
deviceType,
version,
function (error, stream) {
Expand Down

0 comments on commit d929af3

Please sign in to comment.