Skip to content

Commit 60d55bf

Browse files
authored
feat: mc assets --mode tree (#325)
* chore: export-asset-model * chore:wip * feat: asset-model export * feat: release * feat: release 3.20.0 🎉 * chore: fixed lgtm
1 parent 6f70d4e commit 60d55bf

File tree

11 files changed

+353
-12
lines changed

11 files changed

+353
-12
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,8 @@ mindconnect-nodejs-win.exe
108108
.idea
109109

110110
# markdown-help
111-
markdown-help/**
111+
markdown-help/**
112+
113+
## downloaded assets models
114+
115+
*.mdsp.assetmodel/**

.npmignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,8 @@ mindconnect-nodejs-win.exe
6565
.spelling
6666

6767
# markdown-help
68-
markdown-help/**
68+
markdown-help/**
69+
70+
## downloaded assets models
71+
72+
*.mdsp.assetmodel/**

CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Changelog
22

3-
## 3.20.0 - (Spring Green Vienna) - June 2022
3+
## 3.20.0 - (Spring Green Vienna) - July 2022
44

5-
- added default value (`aggregates.mdsp.json`) for `mdsp aggregates --download` parameter
6-
- improved `mdsp aggregates` command. all parameters, including intervalunit and intervalvalue can be specified.
7-
- Created a new `mdsp timeseries` command to match the `mdsp aggregates` command. [#318](https://github.com/mindsphere/mindconnect-nodejs/issues/318)
5+
- SDK: added GetUserTenant() method to SDK Level read out the user tenant from the current configuration (if token manager authentication is used)
6+
- CLI: new mode `--mode tree` for `mdsp assets` command provides tree visualization of mindsphere assets in the tenant
7+
- CLI: added default value (`aggregates.mdsp.json`) for `mdsp aggregates --download` parameter
8+
- CLI: improved `mdsp aggregates` command. all parameters, including intervalunit and intervalvalue can be specified.
9+
- CLI: Created a new `mdsp timeseries` command to match the `mdsp aggregates` command. [#318](https://github.com/mindsphere/mindconnect-nodejs/issues/318)
810
- Bumped most depedencies
911

1012
## 3.19.0 - (Dove Vienna) - April 2022

package-lock.json

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mindconnect/mindconnect-nodejs",
3-
"version": "3.20.0-0",
3+
"version": "3.20.0",
44
"description": "NodeJS Library for MindSphere Connectivity - TypeScript SDK for MindSphere - MindSphere Command Line Interface - MindSphere Development Proxy",
55
"main": "./dist/src/index.js",
66
"browser": "./dist/src/index.bundle.js",
@@ -59,6 +59,7 @@
5959
"lodash": "^4.17.21",
6060
"mime-types": "^2.1.35",
6161
"ora": "^5.4.1",
62+
"performant-array-to-tree": "^1.11.0",
6263
"rsa-pem-to-jwk": "^1.1.3",
6364
"update-notifier": "^5.1.0",
6465
"url-search-params-polyfill": "^8.1.1",

src/api/sdk/common/sdk-client.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ export abstract class SdkClient {
2727
return this._authenticator.GetTenant();
2828
}
2929

30+
public GetUserTenant(): string | undefined {
31+
if (this._authenticator instanceof TokenManagerAuth) {
32+
return this._authenticator.GetUserTenant();
33+
}
34+
return undefined;
35+
}
36+
3037
protected _authenticator: TokenRotation;
3138

3239
public async HttpAction({

src/api/tokenmanager-auth.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,27 @@ export class TokenManagerAuth extends AuthBase implements TokenRotation {
7070
return this._accessToken.access_token;
7171
}
7272

73+
/**
74+
* User Tenant
75+
*
76+
* @returns {string}
77+
*
78+
* @memberOf TokenManagerAuth
79+
*/
80+
public GetUserTenant(): string {
81+
return this._userTenant;
82+
}
83+
84+
/**
85+
* HostTenant
86+
*
87+
* @returns {string}
88+
*
89+
* @memberOf TokenManagerAuth
90+
*/
91+
public GetHostTenant(): string {
92+
return this._hostTenant;
93+
}
7394
/**
7495
* Creates an instance of TokenManagerAuth.
7596
* @param {string} _gateway

src/api/utils.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import * as crypto from "crypto";
33
import * as fs from "fs";
44
import * as os from "os";
5+
import { TreeItem } from "performant-array-to-tree";
56
import { URL } from "url";
67
import { TimeStampedDataPoint } from "..";
78
import { IMindConnectConfiguration } from "./mindconnect-models";
@@ -326,7 +327,7 @@ export function addAndStoreConfiguration(configuration: any) {
326327
(!configuration || !configuration.credentials) && throwError("invalid configuration!");
327328
configuration.credentials.forEach((element: credentialEntry) => {
328329
element.gateway = isUrl(element.gateway) ? element.gateway : `https://gateway.${element.gateway}.mindsphere.io`;
329-
newConfiguration.credentials.push(element.passkey ? encrypt(element) : ((element as unknown) as authJson));
330+
newConfiguration.credentials.push(element.passkey ? encrypt(element) : (element as unknown as authJson));
330331
});
331332
checkList(newConfiguration.credentials);
332333
storeAuth(newConfiguration);
@@ -406,3 +407,13 @@ export function isGuid(x: string): boolean {
406407
const guidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
407408
return guidRegex.test(x);
408409
}
410+
411+
export function printTree(treeItem: TreeItem, level: number, color: (x: string) => string) {
412+
const prefix = level == 0 ? "" : "│ ".repeat(level) + "├─";
413+
414+
console.log(`${prefix}[${color(treeItem.data.assetId)}] ${treeItem.data.name} [${treeItem.data.typeId}]`);
415+
416+
treeItem.children.forEach((child: TreeItem) => {
417+
printTree(child, level + 1, color);
418+
});
419+
}

0 commit comments

Comments
 (0)