Skip to content

Commit

Permalink
Enhancement.icall tmsh (#200)
Browse files Browse the repository at this point in the history
* Added iCall script to IRULES/IAPPS Tree treeViewsProviders

* Fixed an issue with big-ip obj wrapper

* Added iCall and TMSH scripts to the editor tree.
- modified: package.json
- modified: src/tclCore.ts
- modified: src/treeViewsProviders/tclTreeProvider.ts
  • Loading branch information
f5-rahm authored Dec 9, 2022
1 parent 187622c commit 8aeb0b4
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
},
{
"id": "as3Tasks",
"name": "iRules/iApps",
"name": "Tcl Objects",
"when": "f5.tcl"
},
{
Expand Down
16 changes: 16 additions & 0 deletions src/tclCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,24 @@ export default function tclCore(context: ExtensionContext) {
return tclTreeProvider.deleteRule(rule);
}));

// --- ICALL Script COMMANDS ---
context.subscriptions.push(commands.registerCommand('f5-tcl.getIcallscript', async (icallscript) => {
return tclTreeProvider.displayIcallscript(icallscript);
}));

context.subscriptions.push(commands.registerCommand('f5-tcl.deleteIcallscript', async (icallscript) => {
return tclTreeProvider.deleteIcallscript(icallscript);
}));


// --- TMSH Script COMMANDS ---
context.subscriptions.push(commands.registerCommand('f5-tcl.getTMSHscript', async (tmshscript) => {
return tclTreeProvider.displayTMSHscript(tmshscript);
}));

context.subscriptions.push(commands.registerCommand('f5-tcl.deleteTMSHscript', async (tmshscript) => {
return tclTreeProvider.deleteTMSHscript(tmshscript);
}));


// --- IAPP COMMANDS ---
Expand Down
130 changes: 124 additions & 6 deletions src/treeViewsProviders/tclTreeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export class TclTreeProvider implements TreeDataProvider<TCLitem> {
readonly onDidChangeTreeData: Event<TCLitem | undefined> = this._onDidChangeTreeData.event;

private _iRules: string[] = [];
private _iCallScripts: string[] = [];
private _TMSHScripts: string[] = [];
private _apps: string[] = [];
private _iAppTemplates: string[] = [];

Expand Down Expand Up @@ -69,28 +71,48 @@ export class TclTreeProvider implements TreeDataProvider<TCLitem> {
{ command: 'f5-tcl.getRule', title: '', arguments: [el] });
});

} else if (element.label === 'Deployed-Apps'){
} else if (element.label === 'iCall Scripts'){
treeItems = this._iCallScripts.map( (el: any) => {
const content = `sys icall script ${el.fullPath} {\r\n` + `definition {\r\n` + el.definition + '\r\n}\r\n}';
const toolTip = new MarkdownString()
.appendCodeblock(content, 'irule-lang');
return new TCLitem(el.fullPath, '', toolTip, 'iCallScript', TreeItemCollapsibleState.None,
{ command: 'f5-tcl.getIcallscript', title: '', arguments: [el] });
});
} else if (element.label === 'TMSH Scripts'){
treeItems = this._TMSHScripts.map( (el: any) => {
const content = `cli script ${el.fullPath} {\r\n` + el.apiAnonymous + '\r\n}';
const toolTip = new MarkdownString()
.appendCodeblock(content, 'irule-lang');
return new TCLitem(el.fullPath, '', toolTip, 'tmshScript', TreeItemCollapsibleState.None,
{ command: 'f5-tcl.getTMSHscript', title: '', arguments: [el] });
});
} else if (element.label === 'iApps (Deployed)'){
// todo: get iapps stuff
treeItems = this._apps.map( (el: any) => {
return new TCLitem(el.fullPath, '', '', 'iApp', TreeItemCollapsibleState.None,
{ command: 'f5-tcl.getApp', title: '', arguments: [el] });
});

} else if (element.label === 'iApp-Templates'){
} else if (element.label === 'iApps (Templates)'){
// todo: get iapp templates stuff
treeItems = this._iAppTemplates.map( (el: any) => {
return new TCLitem(el.fullPath, '', '', 'iAppTemplate', TreeItemCollapsibleState.None,
{ command: 'f5-tcl.getTMPL', title: '', arguments: [el] });
});
}
}

} else {

await this.getIrules(); // refresh tenant information
await this.getIcallscripts(); // refresh tenant information
await this.getTMSHscripts(); // refresh tenant information
await this.getApps(); // refresh tasks information
await this.getTemplates(); // refresh tasks information

const ruleCount = this._iRules.length !== 0 ? this._iRules.length.toString() : '';
const icallscriptsCount = this._iCallScripts.length !== 0 ? this._iCallScripts.length.toString() : '';
const TMSHscriptsCount = this._TMSHScripts.length !== 0 ? this._TMSHScripts.length.toString() : '';
const appCount = this._apps.length !== 0 ? this._apps.length.toString() : '';
const tempCount = this._iAppTemplates.length !== 0 ? this._iAppTemplates.length.toString() : '';

Expand All @@ -99,11 +121,19 @@ export class TclTreeProvider implements TreeDataProvider<TCLitem> {
{ command: '', title: '', arguments: [''] })
);
treeItems.push(
new TCLitem('Deployed-Apps', appCount, '', '', TreeItemCollapsibleState.Collapsed,
new TCLitem('iCall Scripts', icallscriptsCount, '', '', TreeItemCollapsibleState.Collapsed,
{ command: '', title: '', arguments: [''] })
);
treeItems.push(
new TCLitem('TMSH Scripts', TMSHscriptsCount, '', '', TreeItemCollapsibleState.Collapsed,
{ command: '', title: '', arguments: [''] })
);
treeItems.push(
new TCLitem('iApps (Deployed)', appCount, '', '', TreeItemCollapsibleState.Collapsed,
{ command: '', title: '', arguments: [''] })
);
treeItems.push(
new TCLitem('iApp-Templates', tempCount, '', '', TreeItemCollapsibleState.Collapsed,
new TCLitem('iApps (Templates)', tempCount, '', '', TreeItemCollapsibleState.Collapsed,
{ command: '', title: '', arguments: [''] })
);
}
Expand All @@ -123,6 +153,24 @@ export class TclTreeProvider implements TreeDataProvider<TCLitem> {
.then( resp => this._iRules = resp.data.items );
}

/**
* Get all iCall scripts to hold in "this" view class
*/
private async getIcallscripts() {
this._iCallScripts = []
await ext.f5Client?.https(`/mgmt/tm/sys/icall/script`)
.then( resp => this._iCallScripts = resp.data.items );
}

/**
* Get all TMSH scripts to hold in "this" view class
*/
private async getTMSHscripts() {
this._TMSHScripts = []
await ext.f5Client?.https(`/mgmt/tm/cli/script`)
.then( resp => this._TMSHScripts = resp.data.items );
}

/**
* Get all deployed iApp-Apps to hold in "this" view class
*/
Expand Down Expand Up @@ -193,6 +241,76 @@ export class TclTreeProvider implements TreeDataProvider<TCLitem> {
});
}


/**
* crafts iCall tcl object and displays in editor with icall language
* @param item iCule item passed from view click
*/
async displayIcallscript(item: any) {

// make it look like a tcl irule object so it can be merged back with changes
const content = `sys icall script ${item.fullPath} {\r\n` + `definition {\r\n` + item.definition + '\r\n}\r\n}';

// open editor and feed it the content
const doc = await workspace.openTextDocument({ content: content, language: 'irule-lang' });
// make the editor appear
await window.showTextDocument( doc, { preview: false });
return doc; // return something for automated testing
}

async deleteIcallscript(item: any) {
logger.debug('deleteIcallscript: ', item);

const name = this.name2uri(item.label);

// const resp: any = await ext.mgmtClient?.makeRequest(`/mgmt/tm/sys/icall/script/${name}`, {
// method: 'DELETE'
// });

const resp = await ext.f5Client?.https(`/mgmt/tm/sys/icall/script/${name}`, {
method: 'DELETE'
})
.then (resp => {
setTimeout( () => { this.refresh();}, 500); // refresh after update
return `${resp.status}-${resp.statusText}`;
});
}

/**
* crafts tmsh script tcl object and displays in editor with tmsh language
* @param item tmsh script item passed from view click
*/
async displayTMSHscript(item: any) {

// make it look like a tcl tmsh script object so it can be merged back with changes
const content = `cli script ${item.fullPath} {\r\n` + item.apiAnonymous + '\r\n}';

// open editor and feed it the content
const doc = await workspace.openTextDocument({ content: content, language: 'irule-lang' });
// make the editor appear
await window.showTextDocument( doc, { preview: false });
return doc; // return something for automated testing
}

async deleteTMSHscript(item: any) {
logger.debug('deleteTMSHscript: ', item);

const name = this.name2uri(item.label);

// const resp: any = await ext.mgmtClient?.makeRequest(`/mgmt/tm/cli/script/${name}`, {
// method: 'DELETE'
// });

const resp = await ext.f5Client?.https(`/mgmt/tm/cli/script/${name}`, {
method: 'DELETE'
})
.then (resp => {
setTimeout( () => { this.refresh();}, 500); // refresh after update
return `${resp.status}-${resp.statusText}`;
});
}


/**
* display .tmpl from f5 in editor
* @param item from tree view click
Expand Down Expand Up @@ -520,4 +638,4 @@ class TCLitem extends TreeItem {
super(label, collapsibleState);
}
contextValue = this.context;
}
}

0 comments on commit 8aeb0b4

Please sign in to comment.