Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds continue on err #538 #539

Merged
merged 2 commits into from
Sep 13, 2024
Merged
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
53 changes: 32 additions & 21 deletions internal/cmd/kvm/impkvms.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,60 +50,71 @@ var ImpCmd = &cobra.Command{
kvmFile := filepath.Base(orgKVMFile)
kvmMetadata := strings.Split(kvmFile, utils.DefaultFileSplitter)
clilog.Info.Printf("\tCreating KVM %s\n", orgKVMFile)
if _, err = kvm.Create("", kvmMetadata[1], true); err != nil {
if _, err = kvm.Create("", kvmMetadata[1], true); proceedOnError(err) != nil {
return err
}
clilog.Info.Printf("\tImporting entries for %s\n", orgKVMFile)
if err = kvm.ImportEntries("", kvmMetadata[1], conn, orgKVMFile); err != nil {
if err = kvm.ImportEntries("", kvmMetadata[1], conn, orgKVMFile); proceedOnError(err) != nil {
return err
}
}
}

if len(envKVMFileList) > 0 {
clilog.Info.Println("Importing env scoped KVMs...")
for _, envKVMFile := range envKVMFileList {
kvmFile := filepath.Base(envKVMFile)
if len(proxyKVMFileList) > 0 {
clilog.Info.Println("Importing proxy scoped KVMs...")
for _, proxyKVMFile := range proxyKVMFileList {
kvmFile := filepath.Base(proxyKVMFile)
kvmMetadata := strings.Split(kvmFile, utils.DefaultFileSplitter)
apiclient.SetApigeeEnv(kvmMetadata[1])
clilog.Info.Printf("\tCreating KVM %s\n", envKVMFile)
if _, err = kvm.Create("", kvmMetadata[2], true); err != nil {
clilog.Info.Printf("\tCreating KVM %s\n", proxyKVMFile)
if _, err = kvm.Create(kvmMetadata[1], kvmMetadata[2], true); proceedOnError(err) != nil {
return err
}
clilog.Info.Printf("\tImporting entries for %s\n", envKVMFile)
if err = kvm.ImportEntries("", kvmMetadata[2], conn, envKVMFile); err != nil {
clilog.Info.Printf("\tImporting entries for %s\n", proxyKVMFile)
if err = kvm.ImportEntries(kvmMetadata[1], kvmMetadata[2], conn, proxyKVMFile); proceedOnError(err) != nil {
return err
}
}
}

if len(proxyKVMFileList) > 0 {
clilog.Info.Println("Importing proxy scoped KVMs...")
for _, proxyKVMFile := range proxyKVMFileList {
kvmFile := filepath.Base(proxyKVMFile)
if len(envKVMFileList) > 0 {
clilog.Info.Println("Importing env scoped KVMs...")
for _, envKVMFile := range envKVMFileList {
kvmFile := filepath.Base(envKVMFile)
kvmMetadata := strings.Split(kvmFile, utils.DefaultFileSplitter)
clilog.Info.Printf("\tCreating KVM %s\n", proxyKVMFile)
if _, err = kvm.Create(kvmMetadata[1], kvmMetadata[2], true); err != nil {
apiclient.SetApigeeEnv(kvmMetadata[1])
clilog.Info.Printf("\tCreating KVM %s\n", envKVMFile)
if _, err = kvm.Create("", kvmMetadata[2], true); proceedOnError(err) != nil {
return err
}
clilog.Info.Printf("\tImporting entries for %s\n", proxyKVMFile)
if err = kvm.ImportEntries(kvmMetadata[1], kvmMetadata[2], conn, proxyKVMFile); err != nil {
clilog.Info.Printf("\tImporting entries for %s\n", envKVMFile)
if err = kvm.ImportEntries("", kvmMetadata[2], conn, envKVMFile); proceedOnError(err) != nil {
return err
}
}
}

return err
},
}

var folder string
var (
folder string
continueOnErr bool
)

func init() {
ImpCmd.Flags().StringVarP(&folder, "folder", "f",
"", "The absolute path to the folder containing KVM entries")
ImpCmd.Flags().IntVarP(&conn, "conn", "c",
4, "Number of connections")
ImpCmd.Flags().BoolVarP(&continueOnErr, "continue-on-error", "",
false, "Ignore errors and continue importing data")

_ = ImpCmd.MarkFlagRequired("folder")
}

func proceedOnError(e error) error {
if continueOnErr {
return nil
}
return e
}
Loading