Skip to content

Commit 5a1a0d0

Browse files
authored
Merge pull request #39 from splunk/develop
Release 0.2.6
2 parents e931744 + 0a5ee15 commit 5a1a0d0

File tree

10 files changed

+379
-22
lines changed

10 files changed

+379
-22
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Change Log
22

3+
## [0.2.6]
4+
- Fixed an issue where setting names contained `<name>`. Issue [#33](https://github.com/splunk/vscode-extension-splunk/issues/33)
5+
- Fixed an issue reading serverclass.conf.spec. Issue [#35](https://github.com/splunk/vscode-extension-splunk/issues/35)
6+
- Fixed a Windows path issue when creating custom search commands, custom REST handlers, and modular visualizations. Issue [#36](https://github.com/splunk/vscode-extension-splunk/issues/36)
7+
- Added functionality to preview the UI that [ucc-gen](https://github.com/splunk/addonfactory-ucc-generator) creates from `globalConfig.json`. To use this functionality, create a `globalConfig.json` file ([reference](https://github.com/splunk/addonfactory-ucc-generator/blob/main/tests/data/globalConfig.json)), then right-click and choose Preview globalConfig.json.
8+
9+
![Preview globalConfig.json](https://raw.githubusercontent.com/wiki/splunk/vscode-extension-splunk/images/previewGlobalConfig.png)
10+
311
## [0.2.5]
412
- An update to Visual Studio Code changed how Diagnostics are initialized which broke linting. Version 0.2.5 addresses this issue.
513

out/customCommand.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function createCommand(commandName, commandDestination, context) {
88

99
// copy from source to dest folder
1010
let commandSource = path.join(context.extensionPath, "resources", "projects", "searchcommands_template");
11-
let commandDest = path.join(commandDestination[0].path, commandName);
11+
let commandDest = path.join(commandDestination[0].fsPath, commandName);
1212

1313
if(fs.existsSync(commandDest)) {
1414
vscode.window.showWarningMessage(`Path for command already exists and will not be created. ${commandDest}`)
@@ -17,7 +17,7 @@ function createCommand(commandName, commandDestination, context) {
1717

1818
copyDirectoryRecursiveSync(commandSource, commandDest);
1919

20-
let app_conf = path.join(commandDestination[0].path, commandName, "default", "app.conf");
20+
let app_conf = path.join(commandDestination[0].fsPath, commandName, "default", "app.conf");
2121

2222
try {
2323

out/customRESTHandler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function createRESTHandler(handlerName, handlerDestination, context) {
88

99
// copy from source to dest folder
1010
let handlerSource = path.join(context.extensionPath, "resources", "projects", "resthandler_template");
11-
let handlerDest = path.join(handlerDestination[0].path, handlerName);
11+
let handlerDest = path.join(handlerDestination[0].fsPath, handlerName);
1212

1313
if(fs.existsSync(handlerDest)) {
1414
vscode.window.showWarningMessage(`Path for REST handler already exists and will not be created. ${handlerDest}`)
@@ -17,7 +17,7 @@ function createRESTHandler(handlerName, handlerDestination, context) {
1717

1818
copyDirectoryRecursiveSync(handlerSource, handlerDest);
1919

20-
let app_conf = path.join(handlerDestination[0].path, handlerName, "default", "app.conf");
20+
let app_conf = path.join(handlerDestination[0].fsPath, handlerName, "default", "app.conf");
2121

2222
try {
2323

out/extension.js

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/globalConfigPreview.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const vscode = require("vscode");
2+
const fs = require("fs")
3+
const path = require("path")
4+
5+
function init(context) {
6+
vscode.commands.registerCommand('splunk.previewGlobalConfig', () => previewHanlder(path.join(context.extensionPath, 'resources', 'templates', 'globalConfig.html')))
7+
}
8+
9+
function render(text, panel) {
10+
try {
11+
const configObject = JSON.parse(text)
12+
panel.webview.postMessage({ action: 'config-data', data: configObject })
13+
} catch (e) {
14+
console.error("Error Rendering preview. ", e.message)
15+
}
16+
}
17+
18+
function previewHanlder(templatePath) {
19+
const panel = vscode.window.createWebviewPanel(
20+
'splunkWebView',
21+
'Global Config Preview',
22+
vscode.ViewColumn.Beside,
23+
{
24+
enableScripts: true,
25+
}
26+
);
27+
const template = fs.readFileSync(templatePath, {
28+
encoding: "utf-8"
29+
});
30+
panel.webview.html = template
31+
const configText = vscode.window.activeTextEditor.document.getText()
32+
render(configText, panel);
33+
vscode.workspace.onDidChangeTextDocument((e) => {
34+
const doc = e.document
35+
if (doc.fileName.endsWith("globalConfig.json")) {
36+
render(doc.getText(), panel)
37+
}
38+
})
39+
}
40+
41+
exports.init = init;

out/modViz.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function createModViz(vizName, vizDestination, context) {
88

99
// copy from source to dest folder
1010
let modVizSource = path.join(context.extensionPath, "resources", "projects", "modViz");
11-
let modVizDest = path.join(vizDestination[0].path, vizName);
11+
let modVizDest = path.join(vizDestination[0].fsPath, vizName);
1212

1313
if(fs.existsSync(modVizDest)) {
1414
vscode.window.showWarningMessage(`Path for visualization already exists and will not be created. ${modVizDest}`)
@@ -20,18 +20,18 @@ function createModViz(vizName, vizDestination, context) {
2020
// rename appserver/static/visualizations/(standin) directory to the new viz name
2121
try {
2222
fs.renameSync(
23-
path.join(vizDestination[0].path, vizName, "appserver", "static", "visualizations", "standin"),
24-
path.join(vizDestination[0].path, vizName, "appserver", "static", "visualizations", vizName)
23+
path.join(vizDestination[0].fsPath, vizName, "appserver", "static", "visualizations", "standin"),
24+
path.join(vizDestination[0].fsPath, vizName, "appserver", "static", "visualizations", vizName)
2525
);
2626
} catch (err) {
2727
vscode.window.showErrorMessage(err.message);
2828
return
2929
}
3030

31-
let package_json = path.join(vizDestination[0].path, vizName, "appserver", "static", "visualizations", vizName, "package.json");
32-
let visualizations_conf = path.join(vizDestination[0].path, vizName, "default", "visualizations.conf");
33-
let default_meta = path.join(vizDestination[0].path, vizName, "metadata", "default.meta");
34-
let app_conf = path.join(vizDestination[0].path, vizName, "default", "app.conf");
31+
let package_json = path.join(vizDestination[0].fsPath, vizName, "appserver", "static", "visualizations", vizName, "package.json");
32+
let visualizations_conf = path.join(vizDestination[0].fsPath, vizName, "default", "visualizations.conf");
33+
let default_meta = path.join(vizDestination[0].fsPath, vizName, "metadata", "default.meta");
34+
let app_conf = path.join(vizDestination[0].fsPath, vizName, "default", "app.conf");
3535

3636
try {
3737
// modify package.json "name": "standin"
@@ -53,7 +53,7 @@ export = system`
5353

5454
// run npm install
5555
cp.exec('npm install', {
56-
cwd: path.join(vizDestination[0].path, vizName, "appserver", "static", "visualizations", vizName)
56+
cwd: path.join(vizDestination[0].fsPath, vizName, "appserver", "static", "visualizations", vizName)
5757
});
5858

5959
} catch (err) {

out/spec.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ exports.getStanzaSettings = getStanzaSettings
44
exports.isStanzaValid = isStanzaValid
55
exports.isSettingValid = isSettingValid
66

7-
const PREAMBLE_REGEX = /^.*?GLOBAL\sSETTINGS/s
7+
const PREAMBLE_REGEX = /^.*?((GLOBAL\sSETTINGS)|(Global\sstanza[^\[]*))/s
88
// Start the match at the beginning of the string ^
99
// Lazily match anything .*?
10-
// Match GLOBAL SETTINGS literally
10+
// Match GLOBAL SETTINGS literally
11+
// OR match Global stanza until a [ is encountered (refer to serverclass.conf.spec for an example of this case)
1112
// Enable multiline /s
1213

1314
const SECTION_REGEX = /^.*?(?=\n\[|$)/s
@@ -26,7 +27,8 @@ const STANZA_PREFIX_REGEX = /^\[(?<prefix>[^\]].*?(=|:|::|::...|_))[\<|\w|\/]/
2627
const STANZA_FREEFORM_REGEX = /^\[\<(?<stanza>.*?)\>\]/ // matches things like [<spec>] or [<custom_alert_action>]
2728
const STANZA_ABSOLUTE_REGEX = /^\[(?<stanza>[^\<\>\:\/]+)\]/ // matches things like [tcp] or [SSL] (does not allow <, >, :, or /)
2829

29-
const SETTING_REGEX = /^(?<setting>\w.*?)\s*=\s*(?<value>[^\r\n]+)/
30+
//const SETTING_REGEX = /^(?<setting>\w.*?)\s*=\s*(?<value>[^\r\n]+)/
31+
const SETTING_REGEX = /^(?<setting>((\w)|\<name\>).*?)\s*=\s*(?<value>[^\r\n]+)/
3032
const SETTING_PREFIX_REGEX = /^(?<prefix>[^-\.].*?)\<.*?\>/
3133

3234
const lineTypes = {
@@ -84,11 +86,12 @@ function parse (str, name) {
8486

8587
let stanza = createStanza(section)
8688

87-
// Some spec files can create empty default stanzas if the spec file explicitlly defines [default].
88-
// limits.conf.spec does this for example.
89+
// Some spec files can create empty default stanzas if the spec file explicitlly defines [default] or [global]
90+
// limits.conf.spec does this with [default]for example.
91+
// serverclass.conf does this with [global] for example.
8992
// In these cases, a default stanza can be produced with no settings.
9093

91-
if(stanza["stanzaName"] != "default") {
94+
if(!["default", "global"].includes(stanza["stanzaName"])) {
9295
specConfig["stanzas"].push(stanza)
9396
} else if(stanza["settings"].length > 0) {
9497
specConfig["stanzas"].push(stanza)

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "splunk",
3-
"version": "0.2.5",
3+
"version": "0.2.6",
44
"publisher": "Splunk",
55
"engines": {
66
"vscode": "^1.40.0"
@@ -47,6 +47,12 @@
4747
"path": "./syntaxes/splunk.tmLanguage.json"
4848
}
4949
],
50+
"jsonValidation": [
51+
{
52+
"fileMatch": "globalConfig.json",
53+
"url": "https://raw.githubusercontent.com/splunk/addonfactory-ucc-generator/master/splunk_add_on_ucc_framework/UCC-UI-lib/schema/schema.json"
54+
}
55+
],
5056
"configuration": {
5157
"title": "Splunk",
5258
"properties": {
@@ -142,6 +148,10 @@
142148
{
143149
"command": "splunk.embeddedReport.show",
144150
"when": "false"
151+
},
152+
{
153+
"command": "splunk.previewGlobalConfig",
154+
"when": "resourceFilename == globalConfig.json"
145155
}
146156
],
147157
"view/title": [
@@ -167,6 +177,19 @@
167177
"when": "view == embeddedReports",
168178
"group": "inline"
169179
}
180+
],
181+
"editor/context": [
182+
{
183+
"command": "splunk.previewGlobalConfig",
184+
"when": "resourceFilename == globalConfig.json"
185+
}
186+
],
187+
"editor/title": [
188+
{
189+
"command": "splunk.previewGlobalConfig",
190+
"when": "resourceFilename == globalConfig.json",
191+
"group": "navigation"
192+
}
170193
]
171194
},
172195
"commands": [
@@ -223,6 +246,12 @@
223246
"command": "splunk.new.resthandler",
224247
"title": "New Custom REST Handler",
225248
"category": "Splunk"
249+
},
250+
{
251+
"command": "splunk.previewGlobalConfig",
252+
"title": "Preview globalConfig.json",
253+
"category": "Splunk",
254+
"enablement": "resourceFilename == globalConfig.json"
226255
}
227256
]
228257
},
@@ -236,6 +265,7 @@
236265
"onCommand:splunk.new.command",
237266
"onCommand:splunk.new.resthandler",
238267
"onCommand:splunk.embeddedReport.show",
268+
"onCommand:splunk.previewGlobalConfig",
239269
"onView:savedSearches",
240270
"onView:embeddedReports"
241271
],
@@ -245,7 +275,6 @@
245275
},
246276
"icon": "images/icon.png",
247277
"extensionDependencies": [
248-
"ms-python.python"
249278
],
250279
"dependencies": {
251280
"request": "^2.88.0"

0 commit comments

Comments
 (0)