-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdoCore.ts
144 lines (103 loc) · 4.56 KB
/
doCore.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* Copyright 2020. F5 Networks, Inc. See End User License Agreement ("EULA") for
* license terms. Notwithstanding anything to the contrary in the EULA, Licensee
* may copy and modify this software product for its internal business purposes.
* Further, Licensee may upload, publish and distribute the modified version of
* the software product on devcentral.f5.com or github.com/f5devcentral.
*/
'use strict';
import {
commands,
ExtensionContext,
ProgressLocation,
window
} from 'vscode';
import { ext } from './extensionVariables';
import * as utils from './utils/utils';
// import {
// DoDeclartion,
// DeviceDeclartion
// } from 'f5-conx-core';
import { logger } from './logger';
/**
* ```
* #########################################################################
*
* █████ ██████
* ██ ██ ██ ██
* ██ ██ ██ ██
* ██ ██ ██ ██
* █████ ██████
*
* #########################################################################
* http://patorjk.com/software/taag/#p=display&h=0&f=ANSI%20Regular&t=DO
*
* registers DO commands in vscode
*
* ```
*/
export class DoCore {
constructor(context: ExtensionContext) {
context.subscriptions.push(commands.registerCommand('f5-do.getDec', async () => {
ext.telemetry.capture({ command: 'f5-do.getDec' });
await window.withProgress({
location: ProgressLocation.Notification,
title: `Getting DO Dec`
}, async () => {
await ext.f5Client?.do?.get()
.then(resp => ext.panel.render(resp));
});
}));
context.subscriptions.push(commands.registerCommand('f5-do.postDec', async () => {
ext.telemetry.capture({ command: 'f5-do.postDec' });
await window.withProgress({
location: ProgressLocation.Notification,
title: `Posting DO Dec`
}, async () => {
await utils.getText()
.then(async text => {
// convert text into json
let dec = utils.isValidJson(text);
if (!dec) {
// if not valid json, return error message
return window.showErrorMessage('Not valid JSON object');
}
// testing this new function provided by f5-conx-core
logger.info('is DO declaration async? =>', ext.f5Client?.do?.isAsync(dec));
// inspect json dec for async param
if (!ext.f5Client?.do?.isAsync(dec)) {
window.showWarningMessage('async DO post highly recommended!!!');
}
// old way I was checking DO declaration for async post (now using above)
// if (dec.class === 'DO' && (dec.declaration.async === false || dec.declaration.async === undefined)) {
// window.showWarningMessage('async DO post highly recommended!!!');
// } else if (dec.class === 'Device' && (dec.async === false || dec.async === undefined)) {
// window.showWarningMessage('async DO post highly recommended!!!');
// }
await ext.f5Client?.do?.post(dec)
.then(resp => ext.panel.render(resp) );
});
});
}));
context.subscriptions.push(commands.registerCommand('f5-do.inspect', async () => {
ext.telemetry.capture({ command: 'f5-do.inspect' });
await window.withProgress({
location: ProgressLocation.Notification,
title: `Getting DO Inspect`
}, async () => {
await ext.f5Client?.do?.inpsect()
.then(resp => ext.panel.render(resp));
});
}));
context.subscriptions.push(commands.registerCommand('f5-do.getTasks', async () => {
ext.telemetry.capture({ command: 'f5-do.getTasks' });
await window.withProgress({
location: ProgressLocation.Notification,
title: `Getting DO Tasks`
}, async () => {
await ext.f5Client?.do?.task()
.then(resp => ext.panel.render(resp));
});
}));
}
}