Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"icon": "media/soarcloud.png",
"publisher": "Splunk",
"license": "Apache-2.0",
"version": "0.0.32",
"version": "0.0.33",
"engines": {
"vscode": "^1.72.0"
},
Expand Down
65 changes: 60 additions & 5 deletions src/commands/environments/addEnvironmentWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {MultiStepInput} from '../../wizard/MultiStepInput'
import { ConnectEnvironment } from './environments';

const wizardTitle = "Add Environment"
const totalSteps = 4
const totalSteps = 5

function shouldResume() {
// Could show a notification with the option to resume.
Expand Down Expand Up @@ -44,14 +44,38 @@ async function connectSslVerifyInput(input: MultiStepInput, state: Partial<Conne
canSelectMany: false
});
state.sslVerify = sslPick[0].label === "Yes"
return (input: MultiStepInput) => conectUsernameInput(input, state);
return (input: MultiStepInput) => authTypeInput(input, state);
}

async function conectUsernameInput(input: MultiStepInput, state: Partial<ConnectEnvironment>){
state.username = await input.showInputBox({
async function authTypeInput(input: MultiStepInput, state: Partial<ConnectEnvironment>){
let authPick = await input.showQuickPick({
title: wizardTitle,
step: 3,
totalSteps: totalSteps,
placeholder: 'Auth type',
value: state.authType || '',
items: [{"label": "local"}, {"label": "token"}],
shouldResume: shouldResume,
ignoreFocusOut: true,
canSelectMany: false
});

if (authPick[0].label === "local") {
state.authType = "local";
return (input: MultiStepInput) => connectUsernameInput(input, state);
}
else {
state.authType = "token";
return (input: MultiStepInput) => connectTokenNameInput(input, state);
}

}

async function connectUsernameInput(input: MultiStepInput, state: Partial<ConnectEnvironment>){
state.username = await input.showInputBox({
title: wizardTitle,
step: 4,
totalSteps: totalSteps,
value: state.username || '',
prompt: `Username`,
shouldResume: shouldResume,
Expand All @@ -62,10 +86,41 @@ async function conectUsernameInput(input: MultiStepInput, state: Partial<Connect
return (input: MultiStepInput) => connectPasswordInput(input, state);
}

async function connectTokenNameInput(input: MultiStepInput, state: Partial<ConnectEnvironment>){
state.username = await input.showInputBox({
title: wizardTitle,
step: 4,
totalSteps: totalSteps,
value: state.username || '',
prompt: `Token name`,
shouldResume: shouldResume,
validate: validateNameIsUnique,
ignoreFocusOut: true
});

return (input: MultiStepInput) => connectTokenInput(input, state);
}

async function connectTokenInput(input: MultiStepInput, state: Partial<ConnectEnvironment>){
state.password = await input.showInputBox({
title: wizardTitle,
step: 5,
totalSteps: totalSteps,
value: '',
prompt: `Token`,
shouldResume: shouldResume,
validate: validateNameIsUnique,
isPassword: true,
ignoreFocusOut: true
});

return;
}

async function connectPasswordInput(input: MultiStepInput, state: Partial<ConnectEnvironment>){
state.password = await input.showInputBox({
title: wizardTitle,
step: 4,
step: 5,
totalSteps: totalSteps,
value: '',
prompt: `Password`,
Expand Down
14 changes: 10 additions & 4 deletions src/commands/environments/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ export const ACTIVE_ENV_KEY = "splunkSOAR.activeEnvironment"
export interface BaseConnectEnvironment {
url: string,
sslVerify: boolean,
username: string
username: string,
authType: string
}


export interface ConnectEnvironment extends BaseConnectEnvironment {
password: string
}
Expand All @@ -37,7 +39,7 @@ export async function addEnvironment(context: vscode.ExtensionContext) {
}

let envKey = deriveEnvKey(state.url, state.username)
let newEnv: ConfiguredConnectEnvironment = {"key": envKey , "url": state.url, "username": state.username, "sslVerify": state.sslVerify}
let newEnv: ConfiguredConnectEnvironment = {"key": envKey , "url": state.url, "username": state.username, "sslVerify": state.sslVerify, "authType": state.authType}

let currentEnvironments = listEnvironments(context)

Expand Down Expand Up @@ -132,6 +134,10 @@ export async function getEnvironment(context: vscode.ExtensionContext, envKey: s

let env = currentEnvironments.find(env => env.key == envKey)!

// If this environment was created in an older version of the extension, authType
// will be undefined.
env.authType ??= "local";

return {...env, "password": password}
}

Expand Down Expand Up @@ -172,7 +178,7 @@ export async function environmentVersion(context: vscode.ExtensionContext, envir
}

let environment = await getEnvironment(context, envKey)
let client = new SoarClient(environment.url, environment.username, environment.password, environment.sslVerify)
let client = new SoarClient(environment.url, environment.authType, environment.username, environment.password, environment.sslVerify)

let response = await client.version().catch((err) => {
return Promise.reject(err)
Expand All @@ -186,7 +192,7 @@ export async function copyPasswordToClipboard(context: vscode.ExtensionContext,
let env: ConfiguredConnectEnvironment = environmentContext.data

let environment = await getEnvironment(context, env.key)
let client = new SoarClient(environment.url, environment.username, environment.password, environment.sslVerify)
let client = new SoarClient(environment.url, environment.authType, environment.username, environment.password, environment.sslVerify)

vscode.env.clipboard.writeText(client.password)
vscode.window.setStatusBarMessage("Copied password to clipboard", 2000)
Expand Down
13 changes: 7 additions & 6 deletions src/soar/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ export class SoarClient {
httpClient: AxiosInstance
fileClient: AxiosInstance

constructor(server: string, username: string, password: string, sslVerify: boolean) {
constructor(server: string, authType: string, username: string, password: string, sslVerify: boolean) {
this.server = server
this.username = username
this.password = password
this.sslVerify = sslVerify

const axiosConfig = {
baseURL: `${server}/rest/`,
auth: {username: username, password: password},
...(authType === "local" && {auth: {username: username, password: password}}),
...(authType === "token" && {headers: {"ph-auth-token": password} })
}

this.httpClient = axios.create(axiosConfig)
Expand Down Expand Up @@ -277,14 +278,14 @@ export class SoarClient {

export async function getClientForActiveEnvironment(context: vscode.ExtensionContext): Promise<SoarClient> {

let {url, username, sslVerify, password} = await getActiveEnvironment(context)
let {url, username, sslVerify, password, authType} = await getActiveEnvironment(context)

return new SoarClient(url, username, password, sslVerify)
return new SoarClient(url, authType, username, password, sslVerify)
}

export async function getClientForEnvironment(context: vscode.ExtensionContext, envKey: string): Promise<SoarClient> {

let {url, username, sslVerify, password} = await getEnvironment(context, envKey)
let {url, username, sslVerify, password, authType} = await getEnvironment(context, envKey)

return new SoarClient(url, username, password, sslVerify)
return new SoarClient(url, authType, username, password, sslVerify)
}