Skip to content

Commit

Permalink
Merge pull request #39 from splunk/develop
Browse files Browse the repository at this point in the history
Release 0.2.6
  • Loading branch information
JasonConger authored Jan 30, 2021
2 parents e931744 + 0a5ee15 commit 5a1a0d0
Show file tree
Hide file tree
Showing 10 changed files with 379 additions and 22 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## [0.2.6]
- Fixed an issue where setting names contained `<name>`. Issue [#33](https://github.com/splunk/vscode-extension-splunk/issues/33)
- Fixed an issue reading serverclass.conf.spec. Issue [#35](https://github.com/splunk/vscode-extension-splunk/issues/35)
- 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)
- 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.

![Preview globalConfig.json](https://raw.githubusercontent.com/wiki/splunk/vscode-extension-splunk/images/previewGlobalConfig.png)

## [0.2.5]
- An update to Visual Studio Code changed how Diagnostics are initialized which broke linting. Version 0.2.5 addresses this issue.

Expand Down
4 changes: 2 additions & 2 deletions out/customCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function createCommand(commandName, commandDestination, context) {

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

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

copyDirectoryRecursiveSync(commandSource, commandDest);

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

try {

Expand Down
4 changes: 2 additions & 2 deletions out/customRESTHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function createRESTHandler(handlerName, handlerDestination, context) {

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

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

copyDirectoryRecursiveSync(handlerSource, handlerDest);

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

try {

Expand Down
8 changes: 7 additions & 1 deletion out/extension.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions out/globalConfigPreview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const vscode = require("vscode");
const fs = require("fs")
const path = require("path")

function init(context) {
vscode.commands.registerCommand('splunk.previewGlobalConfig', () => previewHanlder(path.join(context.extensionPath, 'resources', 'templates', 'globalConfig.html')))
}

function render(text, panel) {
try {
const configObject = JSON.parse(text)
panel.webview.postMessage({ action: 'config-data', data: configObject })
} catch (e) {
console.error("Error Rendering preview. ", e.message)
}
}

function previewHanlder(templatePath) {
const panel = vscode.window.createWebviewPanel(
'splunkWebView',
'Global Config Preview',
vscode.ViewColumn.Beside,
{
enableScripts: true,
}
);
const template = fs.readFileSync(templatePath, {
encoding: "utf-8"
});
panel.webview.html = template
const configText = vscode.window.activeTextEditor.document.getText()
render(configText, panel);
vscode.workspace.onDidChangeTextDocument((e) => {
const doc = e.document
if (doc.fileName.endsWith("globalConfig.json")) {
render(doc.getText(), panel)
}
})
}

exports.init = init;
16 changes: 8 additions & 8 deletions out/modViz.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function createModViz(vizName, vizDestination, context) {

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

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

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

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

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

} catch (err) {
Expand Down
15 changes: 9 additions & 6 deletions out/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ exports.getStanzaSettings = getStanzaSettings
exports.isStanzaValid = isStanzaValid
exports.isSettingValid = isSettingValid

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

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

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

const lineTypes = {
Expand Down Expand Up @@ -84,11 +86,12 @@ function parse (str, name) {

let stanza = createStanza(section)

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

if(stanza["stanzaName"] != "default") {
if(!["default", "global"].includes(stanza["stanzaName"])) {
specConfig["stanzas"].push(stanza)
} else if(stanza["settings"].length > 0) {
specConfig["stanzas"].push(stanza)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 31 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "splunk",
"version": "0.2.5",
"version": "0.2.6",
"publisher": "Splunk",
"engines": {
"vscode": "^1.40.0"
Expand Down Expand Up @@ -47,6 +47,12 @@
"path": "./syntaxes/splunk.tmLanguage.json"
}
],
"jsonValidation": [
{
"fileMatch": "globalConfig.json",
"url": "https://raw.githubusercontent.com/splunk/addonfactory-ucc-generator/master/splunk_add_on_ucc_framework/UCC-UI-lib/schema/schema.json"
}
],
"configuration": {
"title": "Splunk",
"properties": {
Expand Down Expand Up @@ -142,6 +148,10 @@
{
"command": "splunk.embeddedReport.show",
"when": "false"
},
{
"command": "splunk.previewGlobalConfig",
"when": "resourceFilename == globalConfig.json"
}
],
"view/title": [
Expand All @@ -167,6 +177,19 @@
"when": "view == embeddedReports",
"group": "inline"
}
],
"editor/context": [
{
"command": "splunk.previewGlobalConfig",
"when": "resourceFilename == globalConfig.json"
}
],
"editor/title": [
{
"command": "splunk.previewGlobalConfig",
"when": "resourceFilename == globalConfig.json",
"group": "navigation"
}
]
},
"commands": [
Expand Down Expand Up @@ -223,6 +246,12 @@
"command": "splunk.new.resthandler",
"title": "New Custom REST Handler",
"category": "Splunk"
},
{
"command": "splunk.previewGlobalConfig",
"title": "Preview globalConfig.json",
"category": "Splunk",
"enablement": "resourceFilename == globalConfig.json"
}
]
},
Expand All @@ -236,6 +265,7 @@
"onCommand:splunk.new.command",
"onCommand:splunk.new.resthandler",
"onCommand:splunk.embeddedReport.show",
"onCommand:splunk.previewGlobalConfig",
"onView:savedSearches",
"onView:embeddedReports"
],
Expand All @@ -245,7 +275,6 @@
},
"icon": "images/icon.png",
"extensionDependencies": [
"ms-python.python"
],
"dependencies": {
"request": "^2.88.0"
Expand Down
Loading

0 comments on commit 5a1a0d0

Please sign in to comment.