Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
KunLee76 committed Jun 12, 2024
1 parent 05102e0 commit e26359c
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 111 deletions.
33 changes: 0 additions & 33 deletions internal/sbi/api_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,6 @@ func (s *Server) getSearchNFInstances(c *gin.Context) {
return
}

// req := httpwrapper.NewRequest(c.Request, nil)
// req.Query = c.Request.URL.Query()
// httpResponse := s.processor.HandleNFDiscoveryRequest(req)
query := c.Request.URL.Query()
s.Processor().NFDiscoveryProcedure(c, query)

//--------------------第2層
//response, problemDetails := NFDiscoveryProcedure(url.Values(query))
// Send Response
// if response != nil {
// c.JSON(http.StatusOK, response)
// } else if problemDetails != nil {

// } else {
// problemDetails = &models.ProblemDetails{
// Status: http.StatusForbidden,
// Cause: "UNSPECIFIED",
// }
// c.JSON(http.StatusForbidden, problemDetails) // 問一下為什麼這個用不到
// }

//-------------------

// responseBody, err := openapi.Serialize(httpResponse.Body, "application/json")
// if err != nil {
// logger.DiscLog.Warnln(err)
// problemDetails := models.ProblemDetails{
// Status: http.StatusInternalServerError,
// Cause: "SYSTEM_FAILURE",
// Detail: err.Error(),
// }
// c.JSON(http.StatusInternalServerError, problemDetails)
// } else {
// c.Data(httpResponse.Status, "application/json", responseBody)
// }
}
8 changes: 4 additions & 4 deletions internal/sbi/api_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (s *Server) getNFManagementRoutes() []Route {
}

// DeregisterNFInstance - Deregisters a given NF Instance
func (s *Server) DeregisterNFInstance(c *gin.Context) { // OK
func (s *Server) DeregisterNFInstance(c *gin.Context) {
auth_err := authorizationCheck(c, "nnrf-nfm")
if auth_err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()})
Expand All @@ -85,7 +85,7 @@ func (s *Server) DeregisterNFInstance(c *gin.Context) { // OK
}

// GetNFInstance - Read the profile of a given NF Instance
func (s *Server) NFInstance(c *gin.Context) { // OK
func (s *Server) NFInstance(c *gin.Context) {
auth_err := authorizationCheck(c, "nnrf-nfm")
if auth_err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()})
Expand All @@ -98,7 +98,7 @@ func (s *Server) NFInstance(c *gin.Context) { // OK
s.Processor().GetNFInstanceProcedure(c, nfInstanceId)
}

func (s *Server) RegisterNFInstance(c *gin.Context) { // OK
func (s *Server) RegisterNFInstance(c *gin.Context) {
auth_err := authorizationCheck(c, "nnrf-nfm")
if auth_err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()})
Expand Down Expand Up @@ -164,7 +164,7 @@ func (s *Server) RegisterNFInstance(c *gin.Context) { // OK
}

// UpdateNFInstance - Update NF Instance profile
func (s *Server) getUpdateNFInstance(c *gin.Context) { // OK
func (s *Server) getUpdateNFInstance(c *gin.Context) {
auth_err := authorizationCheck(c, "nnrf-nfm")
if auth_err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()})
Expand Down
4 changes: 0 additions & 4 deletions internal/sbi/processor/nfdiscovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func (p *Processor) NFDiscoveryProcedure(c *gin.Context, queryParameters url.Val
Status: http.StatusBadRequest,
Cause: "Loss mandatory parameter",
}
// return nil, problemDetails
c.JSON(int(problemDetails.Status), problemDetails)
}

Expand All @@ -100,7 +99,6 @@ func (p *Processor) NFDiscoveryProcedure(c *gin.Context, queryParameters url.Val
{Param: "complexQuery"},
},
}
// return nil, problemDetails
c.JSON(int(problemDetails.Status), problemDetails)
}
}
Expand All @@ -121,7 +119,6 @@ func (p *Processor) NFDiscoveryProcedure(c *gin.Context, queryParameters url.Val
Detail: err.Error(),
Cause: "SYSTEM_FAILURE",
}
// return nil, problemDetails
c.JSON(int(problemDetails.Status), problemDetails)
}

Expand All @@ -135,7 +132,6 @@ func (p *Processor) NFDiscoveryProcedure(c *gin.Context, queryParameters url.Val
Detail: err.Error(),
Cause: "SYSTEM_FAILURE",
}
// return nil, problemDetails
c.JSON(int(problemDetails.Status), problemDetails)
}

Expand Down
19 changes: 2 additions & 17 deletions internal/sbi/processor/nfmanagement.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,28 @@ import (

func (p *Processor) HandleRemoveSubscriptionRequest(c *gin.Context, subscriptionID string) {
logger.NfmLog.Infoln("Handle RemoveSubscription")
// subscriptionID := request.Params["subscriptionID"]

RemoveSubscriptionProcedure(subscriptionID)

c.JSON(http.StatusNoContent, nil)
// return httpwrapper.NewResponse(http.StatusNoContent, nil, nil)
}

func (p *Processor) HandleCreateSubscriptionRequest(c *gin.Context, subscription models.NrfSubscriptionData) {
logger.NfmLog.Infoln("Handle CreateSubscriptionRequest")
// subscription := request.Body.(models.NrfSubscriptionData)

response, problemDetails := CreateSubscriptionProcedure(subscription)
if response != nil {
logger.NfmLog.Traceln("CreateSubscription success")
// return httpwrapper.NewResponse(http.StatusCreated, nil, response)
c.JSON(http.StatusCreated, response)
} else if problemDetails != nil {
logger.NfmLog.Traceln("CreateSubscription failed")
// return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)
c.JSON(int(problemDetails.Status), problemDetails)
}
problemDetails = &models.ProblemDetails{
Status: http.StatusForbidden,
Cause: "UNSPECIFIED",
}
logger.NfmLog.Traceln("CreateSubscription failed")
// return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails)
c.JSON(http.StatusForbidden, problemDetails)
}

Expand Down Expand Up @@ -101,7 +95,6 @@ func CreateSubscriptionProcedure(subscription models.NrfSubscriptionData) (bson.
}

func (p *Processor) UpdateSubscriptionProcedure(c *gin.Context, subscriptionID string, patchJSON []byte) {
// map[string]interface{} { //OK
collName := "Subscriptions"
filter := bson.M{"subscriptionId": subscriptionID}

Expand All @@ -113,13 +106,10 @@ func (p *Processor) UpdateSubscriptionProcedure(c *gin.Context, subscriptionID s
Detail: err.Error(),
}
c.JSON(http.StatusInternalServerError, problemDetails)
// return nil
} else {
if response, err := mongoapi.RestfulAPIGetOne(collName, filter); err == nil {
c.JSON(http.StatusOK, response)
// return response
}
// return nil
}
}

Expand All @@ -132,9 +122,9 @@ func RemoveSubscriptionProcedure(subscriptionID string) {
}
}

func (p *Processor) GetNFInstancesProcedure( // OK
func (p *Processor) GetNFInstancesProcedure(
c *gin.Context, nfType string, limit int,
) { // (*nrf_context.UriList, *models.ProblemDetails) {
) {
collName := "urilist"
filter := bson.M{"nfType": nfType}
if nfType == "" {
Expand All @@ -151,7 +141,6 @@ func (p *Processor) GetNFInstancesProcedure( // OK
Detail: err.Error(),
Cause: "SYSTEM_FAILURE",
}
// return nil, problemDetail
c.JSON(int(problemDetail.Status), problemDetail)
}
logger.NfmLog.Infoln("ULs: ", ULs)
Expand All @@ -167,9 +156,6 @@ func (p *Processor) GetNFInstancesProcedure( // OK
Cause: "SYSTEM_FAILURE",
}
c.JSON(http.StatusInternalServerError, problemDetail)
// return nil, problemDetail
// c.JSON(int(problemDetail.Status), problemDetail)
// c.Data(http.StatusInternalServerError, "application/json", []byte("error in GetNFInstancesProcedure"))
}
rspUriList.Link.Item = append(rspUriList.Link.Item, originalUL.Link.Item...)
if nfType != "" && rspUriList.NfType == "" {
Expand All @@ -178,7 +164,6 @@ func (p *Processor) GetNFInstancesProcedure( // OK
}

nrf_context.NnrfUriListLimit(rspUriList, limit)
// return rspUriList, nil
c.JSON(http.StatusOK, rspUriList)

logger.NfmLog.Traceln("GetNFInstances failed")
Expand Down
53 changes: 0 additions & 53 deletions internal/sbi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package sbi

import (
"context"
//"fmt"
"log"
"net/http"
"runtime/debug"
"sync"
"time"

//"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"

Expand Down Expand Up @@ -96,18 +94,6 @@ func NewServer(nrf nrf, tlsKeyLogPath string) (*Server, error) {
nrf: nrf,
}

// s.router.Use(cors.New(cors.Config{
// AllowMethods: []string{"GET", "POST", "OPTIONS", "PUT", "PATCH", "DELETE"},
// AllowHeaders: []string{
// "Origin", "Content-Length", "Content-Type", "User-Agent",
// "Referrer", "Host", "Token", "X-Requested-With",
// },
// ExposeHeaders: []string{"Content-Length"},
// AllowCredentials: true,
// AllowAllOrigins: true,
// MaxAge: CorsConfigMaxAge,
// }))

cfg := s.Config()
bindAddr := cfg.GetSbiBindingAddr()
logger.SBILog.Infof("Binding addr: [%s]", bindAddr)
Expand Down Expand Up @@ -175,45 +161,6 @@ func (s *Server) startServer(wg *sync.WaitGroup) {
logger.SBILog.Warnf("SBI server (listen on %s) stopped", s.httpServer.Addr)
}

// nolint
// func checkContentTypeIsJSON(gc *gin.Context) (string, error) {
// var err error
// contentType := gc.GetHeader("Content-Type")
// if openapi.KindOfMediaType(contentType) != openapi.MediaKindJSON {
// err = fmt.Errorf("Wrong content type %q", contentType)
// }

// if err != nil {
// logger.SBILog.Error(err)
// gc.JSON(http.StatusInternalServerError,
// openapi.ProblemDetailsMalformedReqSyntax(err.Error()))
// return "", err
// }

// return contentType, nil
// }

// nolint
// func (s *Server) deserializeData(gc *gin.Context, data interface{}, contentType string) error {
// reqBody, err := gc.GetRawData()
// if err != nil {
// logger.SBILog.Errorf("Get Request Body error: %v", err)
// gc.JSON(http.StatusInternalServerError,
// openapi.ProblemDetailsSystemFailure(err.Error()))
// return err
// }

// err = openapi.Deserialize(data, reqBody, contentType)
// if err != nil {
// logger.SBILog.Errorf("Deserialize Request Body error: %v", err)
// gc.JSON(http.StatusBadRequest,
// openapi.ProblemDetailsMalformedReqSyntax(err.Error()))
// return err
// }

// return nil
// }

func (s *Server) bindData(gc *gin.Context, data interface{}) error {
err := gc.Bind(data)
if err != nil {
Expand Down

0 comments on commit e26359c

Please sign in to comment.