Skip to content

Commit

Permalink
Merge pull request #26 from mountaindude/main
Browse files Browse the repository at this point in the history
0.0.5
  • Loading branch information
mountaindude authored Sep 3, 2023
2 parents 9668421 + deddfa7 commit 51446ca
Show file tree
Hide file tree
Showing 19 changed files with 216 additions and 155 deletions.
6 changes: 2 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

## [0.0.4](https://github.com/ptarmiganlabs/ctrl-q-nr/compare/v0.0.3...v0.0.4) (2023-09-03)


### Bug Fixes

* Add CA cert support for QSEoW ([ff4a715](https://github.com/ptarmiganlabs/ctrl-q-nr/commit/ff4a7150118dbb06b770a6b990a01d6da9056656)), closes [#20](https://github.com/ptarmiganlabs/ctrl-q-nr/issues/20)

- Add CA cert support for QSEoW ([ff4a715](https://github.com/ptarmiganlabs/ctrl-q-nr/commit/ff4a7150118dbb06b770a6b990a01d6da9056656)), closes [#20](https://github.com/ptarmiganlabs/ctrl-q-nr/issues/20)

### Refactoring

* Put cloud and QSEoW files in separate directories ([dece4b3](https://github.com/ptarmiganlabs/ctrl-q-nr/commit/dece4b31157121023ff4430fac198271371e9881)), closes [#21](https://github.com/ptarmiganlabs/ctrl-q-nr/issues/21)
- Put cloud and QSEoW files in separate directories ([dece4b3](https://github.com/ptarmiganlabs/ctrl-q-nr/commit/dece4b31157121023ff4430fac198271371e9881)), closes [#21](https://github.com/ptarmiganlabs/ctrl-q-nr/issues/21)

## [0.0.3](https://github.com/ptarmiganlabs/ctrl-q-nr/compare/v0.0.2...v0.0.3) (2023-09-02)

Expand Down
32 changes: 30 additions & 2 deletions src/lib/cloud/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@ async function authenticate(node, done) {
// Which authentication type to use?
let auth;
if (node.tenant.authType === 'oauth2-m2m') {
// Make sure that the client ID and client secret are specified
if (node.tenant.clientId === '') {
node.status({ fill: 'red', shape: 'ring', text: 'client ID not specified' });
node.log('Client ID not specified');
if (done) {
done('Client ID not specified');
}
return false;
}

if (node.tenant.clientSecret === '') {
node.status({ fill: 'red', shape: 'ring', text: 'client secret not specified' });
node.log('Client secret not specified');
if (done) {
done('Client secret not specified');
}
return false;
}

// Authenticate with OAuth2 m2m
auth = new Auth({
authType: AuthType.OAuth2,
Expand All @@ -25,6 +44,16 @@ async function authenticate(node, done) {

await auth.authorize();
} else if (node.tenant.authType === 'apikey') {
// Make sure that the API key is specified
if (node.tenant.apiKey === '') {
node.status({ fill: 'red', shape: 'ring', text: 'API key not specified' });
node.log('API key not specified');
if (done) {
done('API key not specified');
}
return false;
}

// Authenticate with API key
auth = new Auth({
authType: AuthType.APIKey,
Expand All @@ -38,10 +67,9 @@ async function authenticate(node, done) {
if (done) {
done(`Invalid auth type: ${node.tenant.authType}`);
}
return;
return false;
}

// eslint-disable-next-line consistent-return
return auth;
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/cloud/reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ async function getAllReloads(auth) {
const allItems = [];
let path = '/reloads';

// eslint-disable-next-line no-constant-condition
while (true) {
const response = await auth.rest(path);
const reloads = await response.json();
Expand Down
11 changes: 9 additions & 2 deletions src/lib/cloud/reloadstatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,17 @@ class ReloadStateMachine {
// Check via the get /reloads endpoint if
// a) there are any new reloads that are not in the state machine and add them
// b) there are any reloads in the state machine that are not in the response and delete them
async updateReloadStates() {
async updateReloadStates(node) {
// Debug
this.node.log('updating reload states');

// Get reloads from Qlik Sense Cloud
const auth = await authenticate(this.node);
const auth = await authenticate(node);
if (!auth) {
// Error when authenticating
node.status({ fill: 'red', shape: 'ring', text: 'error authenticating' });
return false;
}

const allItemsInCloud = [];
try {
Expand Down Expand Up @@ -258,6 +263,8 @@ class ReloadStateMachine {

// Reset number of remaining seconds
this.remainingSeconds = this.updateIntervalSeconds;

return true;
}
}

Expand Down
50 changes: 33 additions & 17 deletions src/lib/qseow/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ function getAuth(node) {
let httpsAgent;

if (authType === 'cert') {

// Ensure that the cert and key files exist
if (!fs.existsSync(node.senseServer.certFile)) {
node.error(`Cert file does not exist: ${node.senseServer.certFile}`);
Expand All @@ -35,29 +34,46 @@ function getAuth(node) {
node.error(`Cert CA file does not exist: ${node.senseServer.certCaFile}`);
throw new Error(`Cert CA file does not exist: ${node.senseServer.certCaFile}`);
}
process.env.NODE_EXTRA_CA_CERTS = 'node.senseServer.certCaFile';
}

const cert = fs.readFileSync(node.senseServer.certFile);
const key = fs.readFileSync(node.senseServer.keyFile);

httpsAgent = new https.Agent({
cert,
key,
rejectUnauthorized: false,
});

// Only use the cert CA file if it is specified
if (node.senseServer.certCaFile !== '') {
const ca = fs.readFileSync(node.senseServer.certCaFile);

httpsAgent = new https.Agent({
cert,
key,
ca,
rejectUnauthorized: false,
});
} else {
httpsAgent = new https.Agent({
cert,
key,
rejectUnauthorized: false,
});
}
// if (node.senseServer.certCaFile !== '') {
// node.log('Using root CA file');
// // Debug which files are being used
// node.log(`Using cert file: "${node.senseServer.certFile}"`);
// node.log(`Using key file: "${node.senseServer.keyFile}"`);
// node.log(`Using cert CA file: "${node.senseServer.certCaFile}"`);

// const ca = fs.readFileSync(node.senseServer.certCaFile);

// httpsAgent = new https.Agent({
// cert,
// key,
// ca,
// rejectUnauthorized: false,
// });
// } else {
// node.log('Not using root CA file');
// node.log(`Using cert file: "${node.senseServer.certFile}"`);
// node.log(`Using key file: "${node.senseServer.keyFile}"`);
// node.log(`Using cert CA file: "${node.senseServer.certCaFile}"`);

// httpsAgent = new https.Agent({
// cert,
// key,
// rejectUnauthorized: false,
// });
// };
} else if (authType === 'jwt') {
const token = node.senseServer.jwt;
headers.Authorization = `Bearer ${token}`;
Expand Down
5 changes: 2 additions & 3 deletions src/qscloud/qscloud-app-nr.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@
<script type="text/html" data-template-name="qscloud-app">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
<input type="text" id="node-input-name" placeholder="Name" />
</div>
<div class="form-row">
<label for="node-input-tenant"><i class="fa fa-server"></i> Qlik Sense Cloud tenant</label>
<input type="text" id="node-input-tenant" placeholder="Select tenant" readonly>
<input type="text" id="node-input-tenant" placeholder="Select tenant" readonly />
</div>
<div class="form-row">
<label for="node-input-op"><i class="fa fa-cog"></i> Operation</label>
Expand Down Expand Up @@ -162,4 +162,3 @@
<script type="text/html" data-help-name="qscloud-app">
<p>A node that gets license information from Qlik Sense Cloud</p>
</script>

10 changes: 9 additions & 1 deletion src/qscloud/qscloud-app-nr.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ module.exports = function (RED) {

// Get auth object
const auth = await authenticate(node, done);
if (!auth) {
// Error when authenticating
node.status({ fill: 'red', shape: 'ring', text: 'error authenticating' });
done('Error authenticating');
return false;
}

// Which operation to perform?
if (node.op === 'c') {
Expand Down Expand Up @@ -179,7 +185,7 @@ module.exports = function (RED) {
node.status({ fill: 'red', shape: 'ring', text: 'invalid operation' });
node.log(`Invalid operation: ${node.op}`);
done(`Invalid operation: ${node.op}`);
return;
return false;
}

// Send message to output 1
Expand All @@ -190,6 +196,8 @@ module.exports = function (RED) {
node.error(err);
done(err);
}

return true;
});
}

Expand Down
5 changes: 2 additions & 3 deletions src/qscloud/qscloud-license-nr.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
<script type="text/html" data-template-name="qscloud-license">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
<input type="text" id="node-input-name" placeholder="Name" />
</div>
<div class="form-row">
<label for="node-input-tenant"><i class="fa fa-server"></i> Qlik Sense Cloud tenant</label>
<input type="text" id="node-input-tenant" placeholder="Select tenant" readonly>
<input type="text" id="node-input-tenant" placeholder="Select tenant" readonly />
</div>
</script>

<script type="text/html" data-help-name="qscloud-license">
<p>A node that gets license information from Qlik Sense Cloud</p>
</script>

38 changes: 0 additions & 38 deletions src/qscloud/qscloud-license-nr.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,44 +33,6 @@ module.exports = function (RED) {

await auth.authorize();

// let resp = await auth.rest('/users/me').then((output) => output.json());
// console.log(resp);

// // get a list of applications
// resp = await auth.rest('/apps').then((output) => output.json());

// // iterate through the resulting array and retrieve the app id and name
// resp.data.forEach((item) => {
// // console output to show the app information from the rest endpoint
// console.log(`${item.attributes.id} - ${item.attributes.name}`);
// });
// const apps = new Apps(auth);

// // get the reference to the first app returned in the list
// let app = await apps.get(resp.data[0].attributes.id);

// // open the app
// await app.open();

// // get the app layout
// let appLayout = await app.getAppLayout();
// // console output from the Qlik Analytics Engine containing app metadata
// console.log(appLayout);

// const licenses = new Licenses(auth);

// let response = await auth.rest('/licenses/status').then((output) => output.json());
// let response = await auth.rest('/licenses/status').then((output) => {
// const a = await output.json();
// console.log(a);

// return {
// data: output.json(),
// status: output.status,

// }
// } );

// Get endpoint /licenses/overview
let response = await auth.rest('/licenses/overview');
const licenseOverview = await response.json();
Expand Down
5 changes: 2 additions & 3 deletions src/qscloud/qscloud-reload-nr.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
<script type="text/html" data-template-name="qscloud-reload">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
<input type="text" id="node-input-name" placeholder="Name" />
</div>
<div class="form-row">
<label for="node-input-tenant"><i class="fa fa-server"></i> Qlik Sense Cloud tenant</label>
<input type="text" id="node-input-tenant" placeholder="Select tenant" readonly>
<input type="text" id="node-input-tenant" placeholder="Select tenant" readonly />
</div>
<div class="form-row">
<label for="node-input-op"><i class="fa fa-cog"></i> Operation</label>
Expand All @@ -43,4 +43,3 @@
<script type="text/html" data-help-name="qscloud-reload">
<p>A node that manage app reloads in Qlik Sense Cloud</p>
</script>

13 changes: 11 additions & 2 deletions src/qscloud/qscloud-reload-nr.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ module.exports = function (RED) {

// Get auth object
const auth = await authenticate(node, done);
if (!auth) {
// Error when authenticating
node.status({ fill: 'red', shape: 'ring', text: 'error authenticating' });
done('Error authenticating');
return false;
}

// Which operation to perform?
if (node.op === 'c') {
Expand Down Expand Up @@ -60,7 +66,8 @@ module.exports = function (RED) {

// 1. Get reload history from Qlik Sense Cloud
// 2. Init a state machine to keep track of each reload's state
// 3. Possible states: There are seven states. QUEUED, RELOADING, CANCELING are the active states. SUCCEEDED, FAILED,CANCELED,EXCEEDED_LIMIT are the end states.
// 3. Possible states: There are seven states. QUEUED, RELOADING, CANCELING are the active states.
// SUCCEEDED, FAILED,CANCELED,EXCEEDED_LIMIT are the end states.
// 4. For each reload that is a) new or b) in a non.end state, check the state and update the state machine
// 5. Update the state machine every 15 seconds

Expand All @@ -72,7 +79,7 @@ module.exports = function (RED) {
node.status({ fill: 'red', shape: 'ring', text: 'invalid operation' });
node.log(`Invalid operation: ${node.op}`);
done(`Invalid operation: ${node.op}`);
return;
return false;
}

// Send message to output 1
Expand All @@ -83,6 +90,8 @@ module.exports = function (RED) {
node.error(err);
done(err);
}

return true;
});
}

Expand Down
5 changes: 2 additions & 3 deletions src/qscloud/qscloud-reload-status-nr.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@
<script type="text/html" data-template-name="qscloud-reload-status">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
<input type="text" id="node-input-name" placeholder="Name" />
</div>
<div class="form-row">
<label for="node-input-tenant"><i class="fa fa-server"></i> Qlik Sense Cloud tenant</label>
<input type="text" id="node-input-tenant" placeholder="Select tenant" readonly>
<input type="text" id="node-input-tenant" placeholder="Select tenant" readonly />
</div>
</script>

<script type="text/html" data-help-name="qscloud-reload-status">
<p>A node that keeps track of app reload statuses in Qlik Sense Cloud</p>
</script>

Loading

0 comments on commit 51446ca

Please sign in to comment.