Skip to content

Commit

Permalink
Merge pull request #547 from openinfradev/release
Browse files Browse the repository at this point in the history
241017 main from release
  • Loading branch information
ktkfree authored Oct 17, 2024
2 parents b4925d5 + bfcab0b commit a97281d
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions internal/delivery/http/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,19 @@ func (h *PolicyHandler) CreatePolicy(w http.ResponseWriter, r *http.Request) {
// input.Match.Kinds = normaized
// }

match, matchYaml, err := ValidateAndGetMatch(input.Target)
if err != nil {
ErrorJSON(w, r, httpErrors.NewBadRequestError(err, "P_INVALID_MATCH", ""))
return
var dto model.Policy
if err = serializer.Map(r.Context(), input, &dto); err != nil {
log.Info(r.Context(), err)
}

if input.Target != nil {
match, matchYaml, err := ValidateAndGetMatch(input.Target)
if err != nil {
ErrorJSON(w, r, httpErrors.NewBadRequestError(err, "P_INVALID_MATCH", ""))
return
}
dto.Match = match
dto.MatchYaml = matchYaml
}

if len(input.PolicyResourceName) > 0 {
Expand All @@ -130,14 +139,6 @@ func (h *PolicyHandler) CreatePolicy(w http.ResponseWriter, r *http.Request) {
}
}

var dto model.Policy
if err = serializer.Map(r.Context(), input, &dto); err != nil {
log.Info(r.Context(), err)
}

dto.Match = match
dto.MatchYaml = matchYaml

policyId, err := h.usecase.Create(r.Context(), organizationId, dto)
if err != nil {
ErrorJSON(w, r, err)
Expand Down Expand Up @@ -224,10 +225,15 @@ func (h *PolicyHandler) UpdatePolicy(w http.ResponseWriter, r *http.Request) {
// input.Match.Kinds = normaized
// }

match, matchYaml, err := ValidateAndGetMatch(input.Target)
if err != nil {
ErrorJSON(w, r, httpErrors.NewBadRequestError(err, "P_INVALID_MATCH", ""))
return
var match *domain.Match
var matchYaml *string
if input.Target != nil {
match, matchYaml, err = ValidateAndGetMatch(input.Target)
if err != nil {
ErrorJSON(w, r, httpErrors.NewBadRequestError(err, "P_INVALID_MATCH", ""))
return
}

}

var templateId *uuid.UUID = nil
Expand Down

0 comments on commit a97281d

Please sign in to comment.