-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2652bfb
commit b16d4a1
Showing
6 changed files
with
161 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import * as vscode from 'vscode'; | ||
import { TenantService } from "../services/TenantService"; | ||
import { SearchAttributesTreeItem } from '../models/IdentityNowTreeItem'; | ||
import { IdentityNowClient } from '../services/IdentityNowClient'; | ||
import { getResourceUri } from '../utils/UriUtils'; | ||
import { SearchAttributeConfigBeta } from 'sailpoint-api-client'; | ||
import { runWizard } from '../wizard/wizard'; | ||
import { InputPromptStep } from '../wizard/inputPromptStep'; | ||
import { Validator } from '../validator/validator'; | ||
import { WizardContext } from '../wizard/wizardContext'; | ||
import { QuickPickTenantStep } from '../wizard/quickPickTenantStep'; | ||
import { openPreview } from '../utils/vsCodeHelpers'; | ||
import { QuickPickSourceStep } from '../wizard/quickPickSourceStep'; | ||
import { QuickPickAccountSchemaStep } from '../wizard/quickPickAccountSchemaStep'; | ||
import * as commands from "../commands/constants"; | ||
|
||
const searchAttributeNameValidator = new Validator({ | ||
required: true, | ||
maxLength: 128, | ||
regexp: '^[A-Za-z0-9 _:;,={}@()#-|^%$!?.*]+$' | ||
}); | ||
|
||
/** | ||
* Command used to create a Search Attribute | ||
*/ | ||
export class NewAttributeSearchConfigCommand { | ||
|
||
constructor(private readonly tenantService: TenantService) { } | ||
|
||
async execute(node?: SearchAttributesTreeItem): Promise<void> { | ||
|
||
console.log("> NewAttributeSearchConfigCommand.newRole", node); | ||
const context: WizardContext = {}; | ||
|
||
// if the command is called from the Tree View | ||
if (node !== undefined && node instanceof SearchAttributesTreeItem) { | ||
context["tenant"] = await this.tenantService.getTenant(node.tenantId); | ||
} | ||
|
||
let client: IdentityNowClient | undefined = undefined; | ||
const values = await runWizard({ | ||
title: "Creation of a search attribute", | ||
hideStepCount: false, | ||
promptSteps: [ | ||
new QuickPickTenantStep( | ||
this.tenantService, | ||
async (wizardContext) => { | ||
client = new IdentityNowClient( | ||
wizardContext["tenant"].id, wizardContext["tenant"].tenantName); | ||
}), | ||
new InputPromptStep({ | ||
name: "searchAttribute", | ||
displayName: "search attribute", | ||
options: { | ||
validateInput: (s: string) => { return searchAttributeNameValidator.validate(s); } | ||
} | ||
}), | ||
new QuickPickSourceStep(() => { return client!; }), | ||
new QuickPickAccountSchemaStep(() => { return client!; }), | ||
] | ||
}, context); | ||
console.log({ values }); | ||
if (values === undefined) { return; } | ||
|
||
const name = values["searchAttribute"].trim() | ||
const searchAttribute: SearchAttributeConfigBeta = { | ||
name: name, | ||
displayName: name, | ||
applicationAttributes: {} | ||
} | ||
searchAttribute.applicationAttributes[values["source"].id] = values["attribute"].name | ||
|
||
await vscode.window.withProgress({ | ||
location: vscode.ProgressLocation.Notification, | ||
title: 'Creating Attribute Search...', | ||
cancellable: false | ||
}, async (task, token) => { | ||
|
||
await client.createSearchAttribute(searchAttribute) | ||
const newUri = getResourceUri( | ||
values["tenant"].tenantName, | ||
"accounts/search-attribute-config", | ||
name, | ||
name, | ||
true | ||
) | ||
|
||
openPreview(newUri); | ||
vscode.commands.executeCommand(commands.REFRESH_FORCED); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
import * as vscode from 'vscode'; | ||
import { QuickPickPromptStep } from "./quickPickPromptStep"; | ||
import { WizardContext } from "./wizardContext"; | ||
import { IdentityNowClient } from "../services/IdentityNowClient"; | ||
|
||
export class QuickPickAccountSchemaStep extends QuickPickPromptStep<WizardContext, vscode.QuickPickItem> { | ||
constructor( | ||
getIdentityNowClient: () => IdentityNowClient, | ||
) { | ||
super({ | ||
name: "attribute", | ||
options: { | ||
matchOnDescription: true, | ||
matchOnDetail: true | ||
}, | ||
skipIfOne: true, | ||
items: async (context: WizardContext): Promise<vscode.QuickPickItem[]> => { | ||
const client = getIdentityNowClient(); | ||
const source = context["source"]; | ||
const results = (await client.getSchemas(source.id)) | ||
.find(x => x.name === "account")?.attributes?.map(x => ({ | ||
...x, | ||
label: x.name, | ||
description: x.description | ||
})); | ||
return results; | ||
} | ||
}) | ||
} | ||
} | ||
|