// deleteNetworkPolicyByID deletes the policy specified by the policyID func (l *KubeListener) deleteNetworkPolicyByID(policyID uint64) error { policyURL, err := l.restClient.GetServiceUrl("policy") if err != nil { return err } policyURL = fmt.Sprintf("%s/policies/%d", policyURL, policyID) log.Debugf("deleteNetworkPolicyByID: Deleting policy %d", policyID) deletedPolicy := common.Policy{} err = l.restClient.Delete(policyURL, nil, &deletedPolicy) if err != nil { switch err := err.(type) { default: return err case common.HttpError: if err.StatusCode == http.StatusNotFound { log.Warnf("deleteNetworkPolicyByID: Policy %d not found, ignoring", policyID) return nil } else { return err } } } log.Debugf("deleteNetworkPolicyByID: Deleted policy %s", deletedPolicy) return err }
// deleteNetworkPolicy deletes the policy matching provided policy on whatever // fields are provided. func (l *KubeListener) deleteNetworkPolicy(policy common.Policy) error { policyURL, err := l.restClient.GetServiceUrl("policy") if err != nil { return err } rPolicy := common.Policy{} policyURL = fmt.Sprintf("%s/find/policies/%s", policyURL, policy.Name) err = l.restClient.Get(policyURL, &rPolicy) if err != nil { switch err := err.(type) { default: return err case common.HttpError: if err.StatusCode == http.StatusNotFound { log.Warnf("deleteNetworkPolicy: Policy not found %s, ignoring", policy.Name) return nil } else { return err } } } return l.deleteNetworkPolicyByID(rPolicy.ID) }