-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcfCore.ts
175 lines (122 loc) · 5.15 KB
/
cfCore.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
/*
* 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 {
cfDeclaration
} from 'f5-conx-core';
import { logger } from './logger';
/**
* ```
* #########################################################################
*
*
* ██████ ███████
* ██ ██
* ██ █████
* ██ ██
* ██████ ██
*
*
* #########################################################################
* http://patorjk.com/software/taag/#p=display&h=0&f=ANSI%20Regular&t=CF
*
* registers CF commands in vscode
*
* ```
*/
export class CfCore {
constructor(context: ExtensionContext) {
context.subscriptions.push(commands.registerCommand('f5-cf.inspect', async () => {
ext.telemetry.capture({ command: 'f5-cf.inspect' });
await window.withProgress({
location: ProgressLocation.Notification,
title: `Getting CF inspect`
}, async () => {
await ext.f5Client?.cf?.inspect()
.then(resp => utils.displayJsonInEditor(resp.data));
});
}));
context.subscriptions.push(commands.registerCommand('f5-cf.getDec', async () => {
ext.telemetry.capture({ command: 'f5-cf.getDec' });
await window.withProgress({
location: ProgressLocation.Notification,
title: `Getting CF Dec`
}, async () => {
await ext.f5Client?.cf?.getDeclare()
.then(resp => utils.displayJsonInEditor(resp.data));
});
}));
context.subscriptions.push(commands.registerCommand('f5-cf.postDec', async () => {
ext.telemetry.capture({ command: 'f5-cf.postDec' });
await window.withProgress({
location: ProgressLocation.Notification,
title: `Posting CF Dec`
}, async () => {
await utils.getText()
.then(async text => {
// convert text into json
let dec: cfDeclaration = utils.isValidJson(text);
if (!dec) {
// if not valid json, return error message
return window.showErrorMessage('Not valid JSON object');
}
await ext.f5Client?.cf?.postDeclare(dec)
.then(resp => utils.displayJsonInEditor(resp.data) );
});
});
}));
context.subscriptions.push(commands.registerCommand('f5-cf.getTrigger', async () => {
ext.telemetry.capture({ command: 'f5-cf.getTrigger' });
await window.withProgress({
location: ProgressLocation.Notification,
title: `Getting CF Trigger details`
}, async () => {
await ext.f5Client?.cf?.getTrigger()
.then(resp => utils.displayJsonInEditor(resp.data));
});
}));
context.subscriptions.push(commands.registerCommand('f5-cf.triggerDryRun', async () => {
ext.telemetry.capture({ command: 'f5-cf.triggerDryRun' });
await window.withProgress({
location: ProgressLocation.Notification,
title: `Posting CF Trigger as Dry-Run`
}, async () => {
await ext.f5Client?.cf?.trigger('dry-run')
.then(resp => logger.info('f5-cf.triggerDryRun -> COMPLETE', resp.data));
});
}));
context.subscriptions.push(commands.registerCommand('f5-cf.trigger', async () => {
ext.telemetry.capture({ command: 'f5-cf.trigger' });
await window.withProgress({
location: ProgressLocation.Notification,
title: `Posting CF Trigger as Execute`
}, async () => {
await ext.f5Client?.cf?.trigger()
.then(resp => logger.info('f5-cf.trigger -> COMPLETE', resp.data));
});
}));
context.subscriptions.push(commands.registerCommand('f5-cf.reset', async () => {
ext.telemetry.capture({ command: 'f5-cf.reset' });
await window.withProgress({
location: ProgressLocation.Notification,
title: `Posting CF RESET`
}, async () => {
await ext.f5Client?.cf?.reset()
.then(resp => logger.info('f5-cf.reset -> COMPLETE', resp.data));
});
}));
}
}