Skip to content
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
8 changes: 4 additions & 4 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Use Node.js 14.x
uses: actions/setup-node@v3
- uses: actions/checkout@v6
- name: Use Node.js 24.x
uses: actions/setup-node@v6
with:
node-version: 14.x
node-version: 24.x
cache: 'npm'
- run: npm install
- run: npm test
25 changes: 24 additions & 1 deletion im.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
// trick to make it work both in browser and nodejs code
var fetch = fetch;
try {
fetch = require("node-fetch");
const nodeFetch = require("node-fetch");
fetch = nodeFetch.default || nodeFetch;
} catch (e) {
console.log("node-fetch not found. Running in browser mode.");
}
Expand Down Expand Up @@ -704,6 +705,28 @@ class IMClient {
return new IMResponse(false, null, output['message']);
}
}

/**
* Get the quotas or images of a cloud provider
*
* @param {string} cloud_id: String with the ID of the cloud provider.
* @param {string} type: String with the type of info to retrieve (quotas or images).
*
* @return {IMResponse}: Returns an IMResponse object with data = Object with the quotas or images in case of success.
*/
async getCloudInfo(cloud_id, type) {
const headers = {'Accept': 'application/json',
'Authorization': this.authData.formatAuthData()};
const url = this.imUrl + '/clouds/' + cloud_id + '/' + type;
const response = await fetch(url, {headers: headers});
const output = await response.json();
if (response.ok) {
return new IMResponse(true, output[type], null);
} else {
return new IMResponse(false, null, output['message']);
}
}

}

try {
Expand Down
Loading