From 1fe3a69c2a1c55dc34674b99198b533c6d636d48 Mon Sep 17 00:00:00 2001 From: kun Date: Wed, 12 Jun 2024 06:39:51 +0000 Subject: [PATCH] remove unused code --- internal/sbi/api_accesstoken.go | 4 +- internal/sbi/api_discovery.go | 33 ---------------- internal/sbi/api_management.go | 8 ++-- internal/sbi/processor/nfdiscovery.go | 4 -- internal/sbi/processor/nfmanagement.go | 19 +-------- internal/sbi/server.go | 53 -------------------------- 6 files changed, 8 insertions(+), 113 deletions(-) diff --git a/internal/sbi/api_accesstoken.go b/internal/sbi/api_accesstoken.go index c69ced1..e8861a9 100644 --- a/internal/sbi/api_accesstoken.go +++ b/internal/sbi/api_accesstoken.go @@ -23,7 +23,7 @@ import ( // Index is the index handler. func Index(c *gin.Context) { - c.String(http.StatusOK, "msg") + c.String(http.StatusOK, "StatusOK") } func (s *Server) getAccessTokenRoutes() []Route { @@ -32,7 +32,7 @@ func (s *Server) getAccessTokenRoutes() []Route { Method: http.MethodGet, Pattern: "/", APIFunc: func(ctx *gin.Context) { - ctx.JSON(http.StatusOK, gin.H{"status": "msg"}) + ctx.JSON(http.StatusOK, gin.H{"status": "StatusOK"}) }, }, { diff --git a/internal/sbi/api_discovery.go b/internal/sbi/api_discovery.go index 4630ed7..5f0d326 100644 --- a/internal/sbi/api_discovery.go +++ b/internal/sbi/api_discovery.go @@ -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) - // } } diff --git a/internal/sbi/api_management.go b/internal/sbi/api_management.go index 69f2a99..bf876b9 100644 --- a/internal/sbi/api_management.go +++ b/internal/sbi/api_management.go @@ -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()}) @@ -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()}) @@ -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()}) @@ -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()}) diff --git a/internal/sbi/processor/nfdiscovery.go b/internal/sbi/processor/nfdiscovery.go index 7aab814..dbf0a43 100644 --- a/internal/sbi/processor/nfdiscovery.go +++ b/internal/sbi/processor/nfdiscovery.go @@ -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) } @@ -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) } } @@ -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) } @@ -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) } diff --git a/internal/sbi/processor/nfmanagement.go b/internal/sbi/processor/nfmanagement.go index 66a69e1..6a4f72f 100644 --- a/internal/sbi/processor/nfmanagement.go +++ b/internal/sbi/processor/nfmanagement.go @@ -24,26 +24,21 @@ 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{ @@ -51,7 +46,6 @@ func (p *Processor) HandleCreateSubscriptionRequest(c *gin.Context, subscription Cause: "UNSPECIFIED", } logger.NfmLog.Traceln("CreateSubscription failed") - // return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails) c.JSON(http.StatusForbidden, problemDetails) } @@ -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} @@ -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 } } @@ -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 == "" { @@ -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) @@ -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 == "" { @@ -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") diff --git a/internal/sbi/server.go b/internal/sbi/server.go index 5a284b2..f82be68 100644 --- a/internal/sbi/server.go +++ b/internal/sbi/server.go @@ -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" @@ -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) @@ -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 {