-
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.
Merge pull request #98 from sailpoint-oss/fning/PLTCONN-3577
PLTCONN-3577: Customizer init command
- Loading branch information
Showing
20 changed files
with
321 additions
and
27 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
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
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,101 @@ | ||
// Copyright (c) 2023, SailPoint Technologies, Inc. All rights reserved. | ||
package connector | ||
|
||
import ( | ||
"embed" | ||
"errors" | ||
"fmt" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
//go:embed static/customizer/* | ||
var customizerStaticDir embed.FS | ||
|
||
const ( | ||
customizerDirName = "customizer" | ||
customizerTemplatePath = "static/" + customizerDirName | ||
) | ||
|
||
func newCustomizerInitCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "init <customizer-name>", | ||
Short: "Initialize new connector customizer project", | ||
Long: `init sets up a new TypeScript project with sample connector customizer included for reference.`, | ||
Example: "sail conn customizers init \"My Customizer\"", | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
projName := args[0] | ||
if projName == "" { | ||
printError(cmd.ErrOrStderr(), errors.New("connector customizer name cannot be empty")) | ||
return | ||
} | ||
|
||
if f, err := os.Stat(projName); err == nil && f.IsDir() && f.Name() == projName { | ||
printError(cmd.ErrOrStderr(), fmt.Errorf("Error: project '%s' already exists.\n", projName)) | ||
return | ||
} | ||
|
||
if err := createDir(projName); err != nil { | ||
_ = os.RemoveAll(projName) | ||
printError(cmd.ErrOrStderr(), err) | ||
return | ||
} | ||
|
||
err := fs.WalkDir(customizerStaticDir, customizerTemplatePath, func(path string, d fs.DirEntry, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if d.Name() == customizerDirName { | ||
return nil | ||
} | ||
|
||
if d.IsDir() { | ||
if err := createDir(filepath.Join(projName, d.Name())); err != nil { | ||
return err | ||
} | ||
} else { | ||
fileName := filepath.Join(projName, strings.TrimPrefix(path, customizerTemplatePath)) | ||
|
||
data, err := customizerStaticDir.ReadFile(path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := createFile(fileName, data); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if d.Name() == packageJsonName { | ||
fileAbsPath, err := filepath.Abs(filepath.Join(projName, strings.TrimPrefix(path, customizerTemplatePath))) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := createFileFromTemplate(projName, d.Name(), fileAbsPath); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
return nil | ||
}) | ||
if err != nil { | ||
_ = os.RemoveAll(projName) | ||
printError(cmd.ErrOrStderr(), err) | ||
return | ||
} | ||
|
||
printDir(cmd.OutOrStdout(), projName, 0) | ||
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Successfully created project '%s'.\nRun `npm install` to install dependencies.\n", projName) | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,19 @@ | ||
# macOS General | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Visual Studio Code | ||
.vscode/ | ||
.history/ | ||
|
||
# Intellij | ||
.idea/ | ||
*.iml | ||
|
||
# Dependency directories | ||
node_modules/ | ||
|
||
# Compiled source | ||
dist/ | ||
coverage/ |
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,51 @@ | ||
{ | ||
"name": "{{$.ProjectName}}", | ||
"version": "0.1.0", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"clean": "shx rm -rf ./dist", | ||
"prebuild": "npm run clean", | ||
"build": "npx ncc build ./src/index.ts -o ./dist -m -C", | ||
"dev": "cross-env NODE_OPTIONS=--enable-source-maps spcx run dist/index.js", | ||
"debug": "spcx run dist/index.js", | ||
"prettier": "npx prettier --write .", | ||
"test": "jest --coverage", | ||
"prepack-zip": "npm ci && npm run build", | ||
"pack-zip": "spcx package" | ||
}, | ||
"private": true, | ||
"dependencies": { | ||
"@sailpoint/connector-sdk": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^27.0.1", | ||
"@vercel/ncc": "^0.34.0", | ||
"jest": "^27.0.6", | ||
"prettier": "^2.3.2", | ||
"shx": "^0.3.3", | ||
"ts-jest": "^27.0.5", | ||
"typescript": "4.3.5", | ||
"cross-env": "7.0.3" | ||
}, | ||
"jest": { | ||
"preset": "ts-jest", | ||
"testEnvironment": "node", | ||
"clearMocks": true, | ||
"collectCoverage": true, | ||
"coverageThreshold": { | ||
"global": { | ||
"statements": 60, | ||
"branches": 50, | ||
"functions": 40, | ||
"lines": 60 | ||
} | ||
} | ||
}, | ||
"prettier": { | ||
"printWidth": 120, | ||
"trailingComma": "es5", | ||
"tabWidth": 4, | ||
"semi": false, | ||
"singleQuote": true | ||
} | ||
} |
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,43 @@ | ||
import { connectorCustomizer } from './index' | ||
import { CustomizerType, StandardCommand } from '@sailpoint/connector-sdk' | ||
|
||
const mockConfig: any = { | ||
token: 'xxx123' | ||
} | ||
process.env.CONNECTOR_CONFIG = Buffer.from(JSON.stringify(mockConfig)).toString('base64') | ||
|
||
describe('connector customizer unit tests', () => { | ||
|
||
it('should not change input from beforeStdAccountReadHandler', async () => { | ||
let customizer = await connectorCustomizer() | ||
let input = { | ||
identity: 'john.doe', | ||
} | ||
let updatedInput = await customizer._exec( | ||
customizer.handlerKey(CustomizerType.Before, StandardCommand.StdAccountRead), | ||
{}, | ||
input | ||
) | ||
|
||
expect(input).toStrictEqual(updatedInput) | ||
}) | ||
|
||
it('should add location attribute from afterStdAccountReadHandler', async () => { | ||
let customizer = await connectorCustomizer() | ||
let output = await customizer._exec( | ||
customizer.handlerKey(CustomizerType.After, StandardCommand.StdAccountRead), | ||
{}, | ||
{ | ||
identity: '', | ||
attributes: { | ||
username: 'john.doe', | ||
firstName: 'john', | ||
lastName: 'doe', | ||
email: 'john.doe@example.com', | ||
} | ||
} | ||
) | ||
|
||
expect(output.attributes.location).toStrictEqual('Austin') | ||
}) | ||
}) |
Oops, something went wrong.