Skip to content

Commit

Permalink
feat: remove the ability to export revisions #340
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed Dec 5, 2023
1 parent 8dfe950 commit b86340c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 39 deletions.
3 changes: 1 addition & 2 deletions cmd/org/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ var ExportCmd = &cobra.Command{

if orgs.GetAddOn("apiSecurityConfig") {
clilog.Info.Println("Exporting API Security Configuration...")
if err = securityprofiles.Export(conn, securityProfilesFolderName,
false); proceedOnError(err) != nil {
if err = securityprofiles.Export(conn, securityProfilesFolderName); proceedOnError(err) != nil {
return err
}
}
Expand Down
5 changes: 1 addition & 4 deletions cmd/securityprofiles/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,18 @@ var ExpCmd = &cobra.Command{
if err = apiclient.FolderExists(folder); err != nil {
return err
}
return securityprofiles.Export(conn, folder, false)
return securityprofiles.Export(conn, folder)
},
}

var (
conn int
folder string
// allRevisions bool
)

func init() {
ExpCmd.Flags().IntVarP(&conn, "conn", "c",
4, "Number of connections")
ExpCmd.Flags().StringVarP(&folder, "folder", "f",
"", "folder to export Security Profiles")
/*ExpCmd.Flags().BoolVarP(&allRevisions, "all", "",
false, "Export all proxy revisions")*/
}
42 changes: 9 additions & 33 deletions internal/client/securityprofiles/securityprofiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func Compute(name string, startTime string, endTime string, filters []string,
}

// Export
func Export(conn int, folder string, allRevisions bool) (err error) {
func Export(conn int, folder string) (err error) {
apiclient.ClientPrintHttpResponse.Set(false)
defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting())

Expand Down Expand Up @@ -323,7 +323,7 @@ func Export(conn int, folder string, allRevisions bool) (err error) {

for i := 0; i < conn; i++ {
fanOutWg.Add(1)
go exportWorker(&fanOutWg, workChan, folder, allRevisions, errChan)
go exportWorker(&fanOutWg, workChan, folder, errChan)
}

for _, i := range listsecprofiles.SecurityProfiles {
Expand All @@ -342,14 +342,11 @@ func Export(conn int, folder string, allRevisions bool) (err error) {
return nil
}

func exportWorker(wg *sync.WaitGroup, workCh <-chan secprofile, folder string, allRevisions bool, errs chan<- error) {
func exportWorker(wg *sync.WaitGroup, workCh <-chan secprofile, folder string, errs chan<- error) {
defer wg.Done()
for {
var respBody []byte
var err error

listsecprofiles := secprofiles{}

work, ok := <-workCh
if !ok {
return
Expand All @@ -360,34 +357,13 @@ func exportWorker(wg *sync.WaitGroup, workCh <-chan secprofile, folder string, a
return
}

if allRevisions {
securityProfileName := work.Name[strings.LastIndex(work.Name, "/")+1:]
clilog.Info.Printf("Exporting all the revisions for Security Profile %s\n", securityProfileName)

if respBody, err = ListRevisions(securityProfileName); err != nil {
errs <- err
}
err = json.Unmarshal(respBody, &listsecprofiles)
if err != nil {
errs <- err
}
for _, s := range listsecprofiles.SecurityProfiles {
payload, err := json.Marshal(s)
if err != nil {
errs <- err
}
payload, _ = apiclient.PrettifyJSON(payload)
apiclient.WriteByteArrayToFile(path.Join(folder, s.Name+".json"), false, payload)
}
} else {
clilog.Info.Printf("Exporting Security Profile %s\n", work.Name)
payload, err := json.Marshal(work)
if err != nil {
errs <- err
}
payload, _ = apiclient.PrettifyJSON(payload)
apiclient.WriteByteArrayToFile(path.Join(folder, work.Name+".json"), false, payload)
clilog.Info.Printf("Exporting Security Profile %s\n", work.Name)
payload, err := json.Marshal(work)
if err != nil {
errs <- err
}
payload, _ = apiclient.PrettifyJSON(payload)
apiclient.WriteByteArrayToFile(path.Join(folder, work.Name+".json"), false, payload)
}
}

Expand Down

0 comments on commit b86340c

Please sign in to comment.