-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathas3Core.ts
218 lines (174 loc) · 8.28 KB
/
as3Core.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
* 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,
QuickPickItem,
window
} from 'vscode';
import { ext } from './extensionVariables';
import * as utils from './utils/utils';
import { logger } from './logger';
import { AS3TreeProvider } from './treeViewsProviders/as3TreeProvider';
/**
* ############################################################################
*
* AAA SSSSS 333333
* AAAAA SS 3333
* AA AA SSSSS 3333
* AAAAAAA SS 333
* AA AA SSSSS 333333
*
* ############################################################################
* http://patorjk.com/software/taag/#p=display&h=0&f=Letters&t=AS3
*/
export class As3Core {
constructor(context: ExtensionContext) {
// setting up as3 tree
ext.as3Tree = new AS3TreeProvider();
window.registerTreeDataProvider('as3Tenants', ext.as3Tree);
commands.registerCommand('f5-as3.refreshTenantsTree', () => ext.as3Tree.refresh());
context.subscriptions.push(commands.registerCommand('f5-as3.getDecs', async (item) => {
ext.telemetry.capture({ command: 'f5-as3.getDecs' });
if (item.tenant && item.expanded) {
// const dd = await tenantFromDec(item.command.arguments[0]);
await ext.f5Client?.as3?.getDecs({ tenant: item.tenant, expanded: item.expanded })
.then((resp: any) => ext.panel.render(resp.data))
.catch(err => logger.error('get as3 tenant with param failed:', err));
} else if (item.tenant) {
// just a regular as3 declaration object
ext.panel.render(item.tenant);
} else {
// just a regular as3 declaration object
ext.panel.render(item);
}
}));
context.subscriptions.push(commands.registerCommand('f5-as3.expandedTenant', async (tenant) => {
commands.executeCommand('f5-as3.getDecs', { tenant: tenant.label, expanded: true });
ext.telemetry.capture({ command: 'f5-as3.expandedTenant' });
}));
context.subscriptions.push(commands.registerCommand('f5-as3.deleteTenant', async (tenant) => {
let prompt: boolean = true;
ext.telemetry.capture({ command: 'f5-as3.deleteTenant' });
if (ext.settings.prompts) {
const qpOptions: QuickPickItem[] = [
{
label: "$(thumbsup) Yes",
description: `Delete AS3 Tenant: ${tenant.label}`,
},
{
label: "$(thumbsdown) No",
description: " Cancel Operation"
}
];
// await window.showWarningMessage('Are you sure?', 'Yes', 'Cancel')
await window.showQuickPick(qpOptions, { title: 'Are you sure?' })
.then(resp => {
if (resp === undefined || JSON.stringify(resp).includes('Cancel' || 'No')) {
prompt = false;
} else {
prompt = true;
}
});
logger.info('prompts enabled, f5-as3.deleteTenant called, user chose:', prompt);
}
if (prompt) {
await window.withProgress({
location: ProgressLocation.Notification,
// location: { viewId: 'as3Tenants'},
title: `Deleting ${tenant.label} Tenant`
}, async (progress) => {
await ext.f5Client?.as3?.deleteTenant(tenant.command.arguments[0])
.then((resp: any) => {
const resp2 = resp.data.results[0];
progress.report({ message: `${resp2.code} - ${resp2.message}` });
})
.catch(err => {
progress.report({ message: `${err.message}` });
// might need to adjust logging depending on the error, but this works for now, or at least the main HTTP responses...
logger.error('as3 delete tenant failed with:', {
respStatus: err.response.status,
respText: err.response.statusText,
errMessage: err.message,
errRespData: err.response.data
});
});
// hold the status box for user and let things finish before refresh
await new Promise(resolve => { setTimeout(resolve, 5000); });
});
ext.as3Tree.refresh();
}
}));
context.subscriptions.push(commands.registerCommand('f5-as3.getTask', (id) => {
ext.telemetry.capture({ command: 'f5-as3.getTask' });
window.withProgress({
location: ProgressLocation.Window,
// location: { viewId: 'as3Tenants'},
title: `Getting AS3 Task`
}, async () => {
await ext.f5Client?.as3?.getTasks(id)
.then(resp => ext.panel.render(resp))
.catch(err => logger.error('as3 get task failed:', err));
});
}));
context.subscriptions.push(commands.registerCommand('f5-as3.postDec', async () => {
let prompt: boolean = true;
if (ext.settings.prompts) {
const qpOptions: QuickPickItem[] = [
{
label: "$(thumbsup) Yes",
description: 'Post Declaration',
},
{
label: "$(thumbsdown) No",
description: " Cancel Operation"
}
];
// await window.showWarningMessage('Are you sure?', 'Yes', 'Cancel')
await window.showQuickPick(qpOptions, { title: 'Are you sure?' })
.then(resp => {
if (resp === undefined || JSON.stringify(resp).includes('Cancel' || 'No')) {
prompt = false;
} else {
prompt = true;
}
});
logger.info('prompts enabled, f5-as3.postDec called, user chose:', prompt);
}
if (prompt) {
await utils.getText()
.then(async text => {
if (!utils.isValidJson(text)) {
return window.showErrorMessage('Not valid JSON object');
}
// const dec: As3Declaration | AdcDeclaration = JSON.parse(text);
const dec = JSON.parse(text);
await window.withProgress({
// location: { viewId: 'as3Tenants'},
location: ProgressLocation.Notification,
title: `Posting AS3 Declaration`
}, async () => {
// todo: build as3 stats
// const stats = await as3AppStats(dec);
ext.telemetry.capture({ command: 'f5-as3.expandedTenant' });
await ext.f5Client?.as3?.postDec(dec)
.then(resp => {
ext.panel.render(resp);
ext.as3Tree.refresh();
})
.catch(err => logger.error('as3 post dec failed:', err));
});
});
}
}));
}
}
function as3Stats(dec: any) {
}