mirror of
https://github.com/LukeHagar/sailpoint-cli.git
synced 2025-12-10 04:21:26 +00:00
PLTCONN-3577: Init command and fixing tests
This commit is contained in:
@@ -21,7 +21,8 @@ import (
|
|||||||
var staticDir embed.FS
|
var staticDir embed.FS
|
||||||
|
|
||||||
const (
|
const (
|
||||||
staticDirName = "static"
|
connectorDirName = "connector"
|
||||||
|
connectorTemplatePath = "static/" + connectorDirName
|
||||||
packageJsonName = "package.json"
|
packageJsonName = "package.json"
|
||||||
connectorSpecName = "connector-spec.json"
|
connectorSpecName = "connector-spec.json"
|
||||||
)
|
)
|
||||||
@@ -54,12 +55,12 @@ func newConnInitCmd() *cobra.Command {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := fs.WalkDir(staticDir, staticDirName, func(path string, d fs.DirEntry, err error) error {
|
err := fs.WalkDir(staticDir, connectorTemplatePath, func(path string, d fs.DirEntry, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.Name() == staticDirName {
|
if d.Name() == connectorDirName {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +69,7 @@ func newConnInitCmd() *cobra.Command {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fileName := filepath.Join(projName, strings.TrimPrefix(path, staticDirName))
|
fileName := filepath.Join(projName, strings.TrimPrefix(path, connectorTemplatePath))
|
||||||
|
|
||||||
data, err := staticDir.ReadFile(path)
|
data, err := staticDir.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -81,7 +82,7 @@ func newConnInitCmd() *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if d.Name() == packageJsonName || d.Name() == connectorSpecName {
|
if d.Name() == packageJsonName || d.Name() == connectorSpecName {
|
||||||
fileAbsPath, err := filepath.Abs(filepath.Join(projName, strings.TrimPrefix(path, staticDirName)))
|
fileAbsPath, err := filepath.Abs(filepath.Join(projName, strings.TrimPrefix(path, connectorTemplatePath)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ func newConnCustomizersCmd(client client.Client) *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd.AddCommand(
|
cmd.AddCommand(
|
||||||
|
newCustomizerInitCmd(),
|
||||||
newCustomizerListCmd(client),
|
newCustomizerListCmd(client),
|
||||||
newCustomizerCreateCmd(client),
|
newCustomizerCreateCmd(client),
|
||||||
newCustomizerGetCmd(client),
|
newCustomizerGetCmd(client),
|
||||||
|
|||||||
94
cmd/connector/customizer_init.go
Normal file
94
cmd/connector/customizer_init.go
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
// Copyright (c) 2023, SailPoint Technologies, Inc. All rights reserved.
|
||||||
|
package connector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
const customizerDirName = "static/customizer"
|
||||||
|
|
||||||
|
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 Connector\"",
|
||||||
|
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(staticDir, customizerDirName, 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, customizerDirName))
|
||||||
|
|
||||||
|
data, err := staticDir.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, customizerDirName)))
|
||||||
|
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
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { connector } from './index'
|
import { connector } from './index'
|
||||||
import { StandardCommand } from '@sailpoint/connector-sdk'
|
import { Connector, RawResponse, ResponseType, StandardCommand } from '@sailpoint/connector-sdk'
|
||||||
import { PassThrough } from 'stream'
|
import { PassThrough } from 'stream'
|
||||||
|
|
||||||
const mockConfig: any = {
|
const mockConfig: any = {
|
||||||
@@ -10,7 +10,7 @@ process.env.CONNECTOR_CONFIG = Buffer.from(JSON.stringify(mockConfig)).toString(
|
|||||||
describe('connector unit tests', () => {
|
describe('connector unit tests', () => {
|
||||||
|
|
||||||
it('connector SDK major version should be 0', async () => {
|
it('connector SDK major version should be 0', async () => {
|
||||||
expect((await connector()).sdkVersion).toStrictEqual(0)
|
expect((await connector()).sdkVersion).toStrictEqual(Connector.SDK_VERSION)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should execute stdTestConnectionHandler', async () => {
|
it('should execute stdTestConnectionHandler', async () => {
|
||||||
@@ -18,7 +18,7 @@ describe('connector unit tests', () => {
|
|||||||
StandardCommand.StdTestConnection,
|
StandardCommand.StdTestConnection,
|
||||||
{},
|
{},
|
||||||
undefined,
|
undefined,
|
||||||
new PassThrough({ objectMode: true }).on('data', (chunk) => expect(chunk).toStrictEqual({}))
|
new PassThrough({ objectMode: true }).on('data', (chunk) => expect(chunk).toStrictEqual(new RawResponse ({}, ResponseType.Output)))
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user