Skip to content

Commit

Permalink
feat(nssaiavailability): validate nfid on put S-NSSAIs
Browse files Browse the repository at this point in the history
  • Loading branch information
yccodr committed Jul 7, 2024
1 parent e093e2a commit 06945f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 12 additions & 6 deletions internal/sbi/api_nssaiavailability.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,23 @@ func (s *Server) NSSAIAvailabilityPatch(c *gin.Context) {
s.Processor().NssaiAvailabilityNfInstancePatch(c, patchDocument, nfId)
}

type NssaiAvailabilityPutParams struct {
NfId string `uri:"nfId" binding:"required,uuid"`
}

// NSSAIAvailabilityPut - Updates/replaces the NSSF
// with the S-NSSAIs the NF service consumer (e.g AMF) supports per TA
func (s *Server) NSSAIAvailabilityPut(c *gin.Context) {
logger.NssaiavailLog.Infof("Handle NSSAIAvailabilityPut")

nfId := c.Params.ByName("nfId")

if nfId == "" {
// nfId := c.Params.ByName("nfId")
var params NssaiAvailabilityPutParams
if err := c.ShouldBindUri(&params); err != nil {
problemDetails := &models.ProblemDetails{
Status: http.StatusBadRequest,
Cause: "UNSPECIFIED", // TODO: Check if this is the correct cause
Title: "Malformed Request",
Status: http.StatusBadRequest,
Cause: "MALFORMED_REQUEST",
InvalidParams: util.BindErrorInvalidParamsMessages(err),
}

util.GinProblemJson(c, problemDetails)
Expand Down Expand Up @@ -188,7 +194,7 @@ func (s *Server) NSSAIAvailabilityPut(c *gin.Context) {
return
}

s.Processor().NssaiAvailabilityNfInstanceUpdate(c, nssaiAvailabilityInfo, nfId)
s.Processor().NssaiAvailabilityNfInstanceUpdate(c, nssaiAvailabilityInfo, params.NfId)
}

func (s *Server) NSSAIAvailabilitySubscriptionPatch(c *gin.Context) {
Expand Down
2 changes: 2 additions & 0 deletions internal/util/error_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func BindErrorInvalidParamsMessages(err error) []models.InvalidParam {
ip.Reason = fmt.Sprintf("The `%s` field is required when `%s` is present.", e.Field(), e.Param())
case "required_without":
ip.Reason = fmt.Sprintf("The `%s` field is required when `%s` is not present.", e.Field(), e.Param())
case "uuid":
ip.Reason = fmt.Sprintf("The `%s` field must be a valid UUID.", e.Field())
default:
ip.Reason = fmt.Sprintf("Failed on the `%s` tag.", e.Tag())
}
Expand Down

0 comments on commit 06945f1

Please sign in to comment.