mirror of
https://github.com/LukeHagar/sailpoint-cli.git
synced 2025-12-06 04:21:15 +00:00
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
// Copyright (c) 2021, SailPoint Technologies, Inc. All rights reserved.
|
|
package transform
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
|
|
"github.com/sailpoint-oss/sailpoint-cli/client"
|
|
"github.com/sailpoint-oss/sailpoint-cli/util"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func newDeleteCmd(client client.Client) *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "delete [TRANSFORM-ID]",
|
|
Short: "Delete transform",
|
|
Long: "Delete a transform",
|
|
Example: "sp transforms delete 03d5187b-ab96-402c-b5a1-40b74285d77a",
|
|
Aliases: []string{"d"},
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
id := args[0]
|
|
if id == "" {
|
|
return fmt.Errorf("transform ID cannot be empty")
|
|
}
|
|
|
|
endpoint := cmd.Flags().Lookup("transforms-endpoint").Value.String()
|
|
resp, err := client.Delete(cmd.Context(), util.ResourceUrl(endpoint, id))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer func(Body io.ReadCloser) {
|
|
_ = Body.Close()
|
|
}(resp.Body)
|
|
|
|
if resp.StatusCode != http.StatusNoContent {
|
|
body, _ := io.ReadAll(resp.Body)
|
|
return fmt.Errorf("delete transform failed. status: %s\nbody: %s", resp.Status, body)
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
return cmd
|
|
}
|