diff options
Diffstat (limited to 'pkg/kafkacomm/handler/pdp_update_deploy_policy.go')
-rw-r--r-- | pkg/kafkacomm/handler/pdp_update_deploy_policy.go | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/pkg/kafkacomm/handler/pdp_update_deploy_policy.go b/pkg/kafkacomm/handler/pdp_update_deploy_policy.go index bf56951..5d6cd93 100644 --- a/pkg/kafkacomm/handler/pdp_update_deploy_policy.go +++ b/pkg/kafkacomm/handler/pdp_update_deploy_policy.go @@ -36,6 +36,7 @@ import ( "policy-opa-pdp/pkg/opasdk" "policy-opa-pdp/pkg/policymap" "policy-opa-pdp/pkg/utils" + "sort" "strings" ) @@ -168,7 +169,7 @@ func extractAndDecodePolicies(policy model.ToscaPolicy) (map[string]string, []st return nil, nil, err } - log.Debugf("Decoded policy content for key '%s': %s", key, decodedPolicy) + log.Tracef("Decoded policy content for key '%s': %s", key, decodedPolicy) } return decodedPolicies, keys, nil @@ -228,7 +229,7 @@ func getDirName(policy model.ToscaPolicy) []string { for key, _ := range policy.Properties.Data { - dirNames = append(dirNames, strings.ReplaceAll(consts.Data+"/"+key, ".", "/")) + dirNames = append(dirNames, strings.ReplaceAll(consts.DataNode+key, ".", "/")) } for key, _ := range policy.Properties.Policy { @@ -258,13 +259,14 @@ func upsertPolicy(policy model.ToscaPolicy) error { // handles writing data to sdk. func upsertData(policy model.ToscaPolicy) error { decodedDataContent, dataKeys, _ := extractAndDecodeDataVar(policy) + sort.Sort(utils.ByDotCount{Keys: dataKeys, Ascend: true}) for _, dataKey := range dataKeys { dataContent := decodedDataContent[dataKey] reader := bytes.NewReader([]byte(dataContent)) decoder := json.NewDecoder(reader) decoder.UseNumber() - var wdata map[string]interface{} + var wdata interface{} err := decoder.Decode(&wdata) if err != nil { log.Errorf("Failed to Insert Data: %s: %v", policy.Name, err) @@ -365,11 +367,7 @@ func checkIfPolicyAlreadyDeployed(pdpUpdate model.PdpUpdate) []model.ToscaPolicy // verfies policy by creating bundle. func verifyPolicyByBundleCreation(policy model.ToscaPolicy) error { // get directory name - dirNames := getDirName(policy) - if len(dirNames) == 0 { - log.Warnf("Unable to extract folder name from policy %s", policy.Name) - return fmt.Errorf("failed to extract folder name") - } + dirNames := []string{strings.ReplaceAll(consts.DataNode+"/"+policy.Name, ".", "/"), strings.ReplaceAll(consts.Policies+"/"+policy.Name, ".", "/")} // create bundle output, err := createBundleFuncVar(exec.Command, policy) if err != nil { |