Skip to content

Commit

Permalink
Implemented deletion of objects
Browse files Browse the repository at this point in the history
Showing only non-deleted objects (SOMA is showing unsaved changes,
objects have status: saved, modified, deleted - this could be interesting
to use in dpcmder but REST doesn't support this).
  • Loading branch information
vvidovic committed Dec 13, 2019
1 parent fee0506 commit 276cebd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions help/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ F8/8 - create empty file
F9/9 - clone current DataPower configuration under new name
DEL/x - delete selected (or current if none selected) directories and files
- delete DataPower configuration
- delete DataPower object
d - diff current files/directories
(must be "blocking" - see "Custom external commands" below)
/ - find string
Expand Down
44 changes: 42 additions & 2 deletions repo/dp/dp.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,14 +487,15 @@ func (r *dpRepo) CreateDirByPath(dpDomain, parentPath, dirName string) (bool, er

func (r *dpRepo) Delete(currentView *model.ItemConfig, itemType model.ItemType, parentPath, fileName string) (bool, error) {
logging.LogDebugf("repo/dp/Delete(%v, '%s', '%s' (%s))", currentView, parentPath, fileName, itemType)
filePath := r.GetFilePath(parentPath, fileName)

switch itemType {
case model.ItemDpConfiguration:
// deleting DataPower configuration
config.Conf.DeleteDpApplianceConfig(fileName)
return true, nil
case model.ItemDirectory, model.ItemFile:
filePath := r.GetFilePath(parentPath, fileName)

switch r.dataPowerAppliance.DpManagmentInterface() {
case config.DpInterfaceRest:
restPath := makeRestPath(currentView.DpDomain, filePath)
Expand Down Expand Up @@ -551,6 +552,45 @@ func (r *dpRepo) Delete(currentView *model.ItemConfig, itemType model.ItemType,
logging.LogDebug("repo/dp/Delete(), using neither REST neither SOMA.")
return false, errs.Error("DataPower management interface not set.")
}
case model.ItemDpObject:
switch r.dataPowerAppliance.DpManagmentInterface() {
case config.DpInterfaceRest:
restPath := fmt.Sprintf("/mgmt/config/%s/%s/%s", currentView.DpDomain, parentPath, fileName)
logging.LogDebugf("repo/dp/Delete(), restPath: '%s'", restPath)
jsonString, err := r.rest(restPath, "DELETE", "")
if err != nil {
return false, err
}
logging.LogDebugf("jsonString: '%s'", jsonString)
resultMsg, err := parseJSONFindOne(jsonString, fmt.Sprintf("/%s", fileName))
if err != nil {
return false, err
}
if resultMsg == "Configuration was deleted." {
return true, nil
}
case config.DpInterfaceSoma:
somaRequest := fmt.Sprintf(`<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body>`+
`<dp:request xmlns:dp="http://www.datapower.com/schemas/management" domain="%s">`+
`<dp:del-config><%s name="%s"/></dp:del-config></dp:request></soapenv:Body></soapenv:Envelope>`,
currentView.DpDomain, parentPath, fileName)
somaResponse, err := r.soma(somaRequest)
if err != nil {
return false, err
}
result, err := parseSOMAFindOne(somaResponse, "//*[local-name()='response']/*[local-name()='result']")
if err != nil {
logging.LogDebug("Error parsing response SOAP.", err)
return false, err
}
if result == "OK" {
return true, nil
}
return false, errs.Error(result)
default:
logging.LogDebug("repo/dp/Delete(), using neither REST neither SOMA.")
return false, errs.Error("DataPower management interface not set.")
}
default:
logging.LogDebugf("repo/dp/Delete(), don't know how to delete item type %s.", itemType)
return false, errs.Errorf("Don't know how to delete item type %s.", itemType.UserFriendlyString())
Expand Down Expand Up @@ -1285,7 +1325,7 @@ func (r *dpRepo) listObjects(itemConfig *model.ItemConfig) (model.ItemList, erro
return nil, err
}

objectNames, err := parseSOMAFindList(somaResponse, "//*[local-name()='response']/*[local-name()='status']/*[local-name()='ObjectStatus']/Name")
objectNames, err := parseSOMAFindList(somaResponse, "//*[local-name()='response']/*[local-name()='status']/*[local-name()='ObjectStatus']/ConfigState[text()!='deleted']/../Name")
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 276cebd

Please sign in to comment.