From c12c2b634dde9047e41ddcae9758424cc26267af Mon Sep 17 00:00:00 2001 From: ian60509 Date: Wed, 10 Jul 2024 07:31:16 +0000 Subject: [PATCH 01/12] chore: upgrade openapi dependency to feat/r17 --- go.mod | 14 +- go.sum | 34 ++-- internal/context/context.go | 18 +-- internal/sbi/api_sanity_test.go | 2 +- internal/sbi/consumer/consumer.go | 6 +- internal/sbi/consumer/nrf_service.go | 146 +++++++----------- internal/sbi/processor/callback.go | 123 +++++++-------- .../processor/provisioned_data_document.go | 2 +- 8 files changed, 167 insertions(+), 178 deletions(-) diff --git a/go.mod b/go.mod index 735cbfc..6490099 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/google/uuid v1.3.0 github.com/mitchellh/mapstructure v1.4.3 github.com/pkg/errors v0.9.1 - github.com/sirupsen/logrus v1.8.1 + github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.9.0 github.com/urfave/cli v1.22.5 go.mongodb.org/mongo-driver v1.8.4 @@ -20,13 +20,15 @@ require ( ) require ( - github.com/antihax/optional v1.0.0 // indirect github.com/bytedance/sonic v1.9.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/felixge/httpsnoop v1.0.4 // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/stdr v1.2.2 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.14.0 // indirect @@ -35,7 +37,6 @@ require ( github.com/golang-jwt/jwt v3.2.1+incompatible // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/golang/snappy v0.0.1 // indirect - github.com/google/go-cmp v0.5.6 // indirect github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.13.6 // indirect @@ -54,6 +55,11 @@ require ( github.com/xdg-go/scram v1.0.2 // indirect github.com/xdg-go/stringprep v1.0.2 // indirect github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.49.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect + go.opentelemetry.io/otel v1.24.0 // indirect + go.opentelemetry.io/otel/metric v1.24.0 // indirect + go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/arch v0.3.0 // indirect golang.org/x/crypto v0.21.0 // indirect golang.org/x/net v0.23.0 // indirect @@ -66,3 +72,5 @@ require ( gopkg.in/h2non/gock.v1 v1.1.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) + +replace github.com/free5gc/openapi => github.com/free5gc/openapi v1.0.9-0.20240730084256-f724fd925c33 diff --git a/go.sum b/go.sum index c9d0310..4e448fa 100644 --- a/go.sum +++ b/go.sum @@ -33,8 +33,6 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg= -github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ= github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= @@ -61,8 +59,10 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/evanphx/json-patch v0.5.2 h1:xVCHIVMUu1wtM/VkR9jVZ45N3FhZfYMMYGorLCR8P3k= github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ= -github.com/free5gc/openapi v1.0.8 h1:QjfQdB6VVA1GRnzOJ7nILzrI7gMiY0lH64JHVW7vF34= -github.com/free5gc/openapi v1.0.8/go.mod h1:w6y9P/uySczc1d9OJZAEuB2FImR/z60Wg2BekPAVt3M= +github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= +github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/free5gc/openapi v1.0.9-0.20240730084256-f724fd925c33 h1:U/hJW8h7iNLlk5J+jucr/rc5gdwRRkgnEam8Kav42cY= +github.com/free5gc/openapi v1.0.9-0.20240730084256-f724fd925c33/go.mod h1:oy68rqnHakRLUCuEOXcis7/PWGBuil+UaXMeTBeYY8Y= github.com/free5gc/util v1.0.6 h1:dBt9drcXtYKE/cY5XuQcuffgsYclPIpIArhSeS6M+DQ= github.com/free5gc/util v1.0.6/go.mod h1:eSGN7POUM8LNTvg/E591XR6447a6/w1jFWGKNZPHcXw= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= @@ -74,6 +74,11 @@ github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SU github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= @@ -129,8 +134,8 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= -github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= @@ -193,12 +198,11 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= -github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= -github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -238,6 +242,16 @@ go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.49.0 h1:RtcvQ4iw3w9NBB5yRwgA4sSa82rfId7n4atVpvKx3bY= +go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.49.0/go.mod h1:f/PbKbRd4cdUICWell6DmzvVJ7QrmBgFrRHjXmAXbK4= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 h1:jq9TW8u3so/bN+JPT166wjOI6/vQPF6Xe7nMNIltagk= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw= +go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= +go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= +go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI= +go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco= +go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= +go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= @@ -351,6 +365,7 @@ golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= @@ -410,7 +425,6 @@ golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= diff --git a/internal/context/context.go b/internal/context/context.go index adcfe01..0c8d615 100644 --- a/internal/context/context.go +++ b/internal/context/context.go @@ -53,7 +53,7 @@ type UDRContext struct { UriScheme models.UriScheme BindingIPv4 string SBIPort int - NfService map[models.ServiceName]models.NfService + NfService map[models.ServiceName]models.NrfNfManagementNfService RegisterIPv4 string // IP register to NRF HttpIPv6Address string NfId string @@ -160,15 +160,15 @@ func initUdrContext() { } func initNfService(serviceName []models.ServiceName, version string) ( - nfService map[models.ServiceName]models.NfService, + nfService map[models.ServiceName]models.NrfNfManagementNfService, ) { versionUri := "v" + strings.Split(version, ".")[0] - nfService = make(map[models.ServiceName]models.NfService) + nfService = make(map[models.ServiceName]models.NrfNfManagementNfService) for idx, name := range serviceName { - nfService[name] = models.NfService{ + nfService[name] = models.NrfNfManagementNfService{ ServiceInstanceId: strconv.Itoa(idx), ServiceName: name, - Versions: &[]models.NfServiceVersion{ + Versions: []models.NfServiceVersion{ { ApiFullVersion: version, ApiVersionInUri: versionUri, @@ -177,10 +177,10 @@ func initNfService(serviceName []models.ServiceName, version string) ( Scheme: udrContext.UriScheme, NfServiceStatus: models.NfServiceStatus_REGISTERED, ApiPrefix: GetIPv4Uri(), - IpEndPoints: &[]models.IpEndPoint{ + IpEndPoints: []models.IpEndPoint{ { Ipv4Address: udrContext.RegisterIPv4, - Transport: models.TransportProtocol_TCP, + Transport: models.NrfNfManagementTransportProtocol_TCP, Port: int32(udrContext.SBIPort), }, }, @@ -226,13 +226,13 @@ func NewInfluenceDataSubscriptionId() string { return fmt.Sprintf("%08x", GetSelf().InfluenceDataSubscriptionIDGenerator.Uint32()) } -func (c *UDRContext) GetTokenCtx(serviceName models.ServiceName, targetNF models.NfType) ( +func (c *UDRContext) GetTokenCtx(serviceName models.ServiceName, targetNF models.NrfNfManagementNfType) ( context.Context, *models.ProblemDetails, error, ) { if !c.OAuth2Required { return context.TODO(), nil, nil } - return oauth.GetTokenCtx(models.NfType_UDR, targetNF, + return oauth.GetTokenCtx(models.NrfNfManagementNfType_UDR, targetNF, c.NfId, c.NrfUri, string(serviceName)) } diff --git a/internal/sbi/api_sanity_test.go b/internal/sbi/api_sanity_test.go index a670538..6c0556f 100644 --- a/internal/sbi/api_sanity_test.go +++ b/internal/sbi/api_sanity_test.go @@ -89,7 +89,7 @@ func getInfluData(supi string) *models.TrafficInfluData { FlowId: 1, FlowDescriptions: []string{"permit out ip from 60.60.0.1 8080 to any"}, }}, - TrafficRoutes: []models.RouteToLocation{{ + TrafficRoutes: []*models.RouteToLocation{{ Dnai: "edge1", RouteProfId: "1", }, { Dnai: "edge2", RouteProfId: "2", diff --git a/internal/sbi/consumer/consumer.go b/internal/sbi/consumer/consumer.go index f520663..4087ab5 100644 --- a/internal/sbi/consumer/consumer.go +++ b/internal/sbi/consumer/consumer.go @@ -1,7 +1,7 @@ package consumer import ( - "github.com/free5gc/openapi/Nnrf_NFManagement" + "github.com/free5gc/openapi/nrf/NFManagement" "github.com/free5gc/udr/pkg/app" ) @@ -12,10 +12,10 @@ type Consumer struct { } func NewConsumer(udr app.App) *Consumer { - configuration := Nnrf_NFManagement.NewConfiguration() + configuration := NFManagement.NewConfiguration() configuration.SetBasePath(udr.Context().NrfUri) nrfService := &NrfService{ - nfMngmntClients: make(map[string]*Nnrf_NFManagement.APIClient), + nfMngmntClients: make(map[string]*NFManagement.APIClient), } return &Consumer{ diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 29e5d66..273b664 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -3,15 +3,14 @@ package consumer import ( "context" "fmt" - "net/http" "strings" "sync" "time" "github.com/free5gc/openapi" - "github.com/free5gc/openapi/Nnrf_NFDiscovery" - "github.com/free5gc/openapi/Nnrf_NFManagement" "github.com/free5gc/openapi/models" + "github.com/free5gc/openapi/nrf/NFDiscovery" + "github.com/free5gc/openapi/nrf/NFManagement" udr_context "github.com/free5gc/udr/internal/context" "github.com/free5gc/udr/internal/logger" ) @@ -19,10 +18,10 @@ import ( type NrfService struct { nfMngmntMu sync.RWMutex - nfMngmntClients map[string]*Nnrf_NFManagement.APIClient + nfMngmntClients map[string]*NFManagement.APIClient } -func (ns *NrfService) getNFManagementClient(uri string) *Nnrf_NFManagement.APIClient { +func (ns *NrfService) getNFManagementClient(uri string) *NFManagement.APIClient { if uri == "" { return nil } @@ -33,9 +32,9 @@ func (ns *NrfService) getNFManagementClient(uri string) *Nnrf_NFManagement.APICl return client } - configuration := Nnrf_NFManagement.NewConfiguration() + configuration := NFManagement.NewConfiguration() configuration.SetBasePath(uri) - client = Nnrf_NFManagement.NewAPIClient(configuration) + client = NFManagement.NewAPIClient(configuration) ns.nfMngmntMu.RUnlock() ns.nfMngmntMu.Lock() @@ -44,13 +43,13 @@ func (ns *NrfService) getNFManagementClient(uri string) *Nnrf_NFManagement.APICl return client } -func (ns *NrfService) buildNFProfile(context *udr_context.UDRContext) (models.NfProfile, error) { +func (ns *NrfService) buildNFProfile(context *udr_context.UDRContext) (models.NrfNfManagementNfProfile, error) { // config := factory.UdrConfig - profile := models.NfProfile{ + profile := models.NrfNfManagementNfProfile{ NfInstanceId: context.NfId, - NfType: models.NfType_UDR, - NfStatus: models.NfStatus_REGISTERED, + NfType: models.NrfNfManagementNfType_UDR, + NfStatus: models.NrfNfManagementNfStatus_REGISTERED, Ipv4Addresses: []string{context.RegisterIPv4}, UdrInfo: &models.UdrInfo{ SupportedDataSets: []models.DataSetId{ @@ -62,29 +61,29 @@ func (ns *NrfService) buildNFProfile(context *udr_context.UDRContext) (models.Nf }, } - var services []models.NfService + var services []models.NrfNfManagementNfService for _, nfService := range context.NfService { services = append(services, nfService) } if len(services) > 0 { - profile.NfServices = &services + profile.NfServices = services } return profile, nil } -func (ns *NrfService) SendRegisterNFInstance(ctx context.Context, nrfUri string) (string, string, error) { +func (ns *NrfService) SendRegisterNFInstance(ctx context.Context, nrfUri string) ( + resourceNrfUri string, retrieveNfInstanceId string, err error, +) { // Set client and set url profile, err := ns.buildNFProfile(udr_context.GetSelf()) if err != nil { return "", "", fmt.Errorf("failed to build nrf profile %s", err.Error()) } - configuration := Nnrf_NFManagement.NewConfiguration() + configuration := NFManagement.NewConfiguration() configuration.SetBasePath(nrfUri) client := ns.getNFManagementClient(nrfUri) - var resouceNrfUri string - var retrieveNfInstanceId string finish := false @@ -93,110 +92,83 @@ func (ns *NrfService) SendRegisterNFInstance(ctx context.Context, nrfUri string) case <-ctx.Done(): return "", "", fmt.Errorf("context done") default: - nf, res, registerErr := client.NFInstanceIDDocumentApi.RegisterNFInstance(ctx, profile.NfInstanceId, profile) - if registerErr != nil || res == nil { + registerReq := &NFManagement.RegisterNFInstanceRequest{ + NfInstanceID: &profile.NfInstanceId, + NrfNfManagementNfProfile: &profile, + } + rsp, registerErr := client.NFInstanceIDDocumentApi.RegisterNFInstance(ctx, registerReq) + if registerErr != nil || rsp == nil { // TODO : add log logger.ConsumerLog.Errorf("UDR register to NRF Error[%s]", registerErr.Error()) time.Sleep(2 * time.Second) continue } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.ConsumerLog.Errorf("RegisterNFInstance response body cannot close: %+v", rspCloseErr) - } - }() - - status := res.StatusCode - if status == http.StatusOK { - // NFUpdate - finish = true - } else if status == http.StatusCreated { - // NFRegister - resourceUri := res.Header.Get("Location") - resouceNrfUri = resourceUri[:strings.Index(resourceUri, "/nnrf-nfm/")] - retrieveNfInstanceId = resourceUri[strings.LastIndex(resourceUri, "/")+1:] - - oauth2 := false - if nf.CustomInfo != nil { - v, ok := nf.CustomInfo["oauth2"].(bool) - if ok { - oauth2 = v - logger.MainLog.Infoln("OAuth2 setting receive from NRF:", oauth2) - } - } - udr_context.GetSelf().OAuth2Required = oauth2 - if oauth2 && udr_context.GetSelf().NrfCertPem == "" { - logger.CfgLog.Error("OAuth2 enable but no nrfCertPem provided in config.") + + resourceUri := rsp.Location + resourceNrfUri, _, _ = strings.Cut(resourceUri, "/nnrf-nfm/") + retrieveNfInstanceId = resourceUri[strings.LastIndex(resourceUri, "/")+1:] + + oauth2 := false + + if rsp.NrfNfManagementNfProfile.CustomInfo != nil { + v, ok := rsp.NrfNfManagementNfProfile.CustomInfo["oauth2"].(bool) + if ok { + oauth2 = v + logger.MainLog.Infoln("OAuth2 setting receive from NRF:", oauth2) } - finish = true - } else { - logger.ConsumerLog.Errorf("NRF returned wrong status code: %d", status) } + udr_context.GetSelf().OAuth2Required = oauth2 + if oauth2 && udr_context.GetSelf().NrfCertPem == "" { + logger.CfgLog.Error("OAuth2 enable but no nrfCertPem provided in config.") + } + finish = true } } - return resouceNrfUri, retrieveNfInstanceId, nil + return resourceNrfUri, retrieveNfInstanceId, nil } func (ns *NrfService) SendDeregisterNFInstance() (problemDetails *models.ProblemDetails, err error) { logger.ConsumerLog.Infof("Send Deregister NFInstance") - ctx, pd, err := udr_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NfType_NRF) + ctx, pd, err := udr_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NRF) if err != nil { return pd, err } udrSelf := udr_context.GetSelf() // Set client and set url - configuration := Nnrf_NFManagement.NewConfiguration() + configuration := NFManagement.NewConfiguration() configuration.SetBasePath(udrSelf.NrfUri) client := ns.getNFManagementClient(udrSelf.NrfUri) - var res *http.Response - - res, err = client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, udrSelf.NfId) - if err == nil { - return nil, err - } else if res != nil { - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.ConsumerLog.Errorf("DeregisterNFInstance response body cannot close: %+v", rspCloseErr) - } - }() - - if res.Status != err.Error() { - return nil, err + deregisterReq := &NFManagement.DeregisterNFInstanceRequest{ + NfInstanceID: &udrSelf.NfId, + } + _, deregisterErr := client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, deregisterReq) + if deregisterErr != nil { + if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { + pd = apiErr.Model().(*models.ProblemDetails) + return pd, err } - problem := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) - problemDetails = &problem - } else { - err = openapi.ReportError("server no response") + return nil, err } return problemDetails, err } -func (ns *NrfService) SendSearchNFInstances(nrfUri string, targetNfType, requestNfType models.NfType, - param Nnrf_NFDiscovery.SearchNFInstancesParamOpts, -) (*models.SearchResult, error) { +func (ns *NrfService) SendSearchNFInstances(nrfUri string, + param NFDiscovery.SearchNFInstancesRequest, +) (*NFDiscovery.SearchNFInstancesResponse, error) { // Set client and set url - configuration := Nnrf_NFDiscovery.NewConfiguration() + configuration := NFDiscovery.NewConfiguration() configuration.SetBasePath(nrfUri) - client := Nnrf_NFDiscovery.NewAPIClient(configuration) + client := NFDiscovery.NewAPIClient(configuration) - ctx, _, err := udr_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_DISC, models.NfType_NRF) + ctx, _, err := udr_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_DISC, models.NrfNfManagementNfType_NRF) if err != nil { return nil, err } - var res *http.Response - result, res, err := client.NFInstancesStoreApi.SearchNFInstances(ctx, targetNfType, requestNfType, ¶m) - if res != nil && res.StatusCode == http.StatusTemporaryRedirect { - err = fmt.Errorf("temporary redirect for non NRF consumer") - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.ConsumerLog.Errorf("SearchNFInstances response body cannot close: %+v", rspCloseErr) - } - }() + result, err := client.NFInstancesStoreApi.SearchNFInstances(ctx, ¶m) - return &result, err + return result, err } diff --git a/internal/sbi/processor/callback.go b/internal/sbi/processor/callback.go index 5c03629..9971b82 100644 --- a/internal/sbi/processor/callback.go +++ b/internal/sbi/processor/callback.go @@ -5,8 +5,8 @@ import ( "fmt" "runtime/debug" - "github.com/free5gc/openapi/Nudr_DataRepository" "github.com/free5gc/openapi/models" + "github.com/free5gc/openapi/udr/DataRepository" udr_context "github.com/free5gc/udr/internal/context" "github.com/free5gc/udr/internal/logger" "github.com/free5gc/udr/internal/util" @@ -15,7 +15,7 @@ import ( var CurrentResourceUri string func PreHandleOnDataChangeNotify(ueId string, resourceId string, patchItems []models.PatchItem, - origValue interface{}, newValue interface{}, + origValue map[string]interface{}, newValue map[string]interface{}, ) { notifyItems := []models.NotifyItem{} changes := []models.ChangeItem{} @@ -87,32 +87,27 @@ func SendOnDataChangeNotify(ueId string, notifyItems []models.NotifyItem) { }() udrSelf := udr_context.GetSelf() - configuration := Nudr_DataRepository.NewConfiguration() - client := Nudr_DataRepository.NewAPIClient(configuration) + configuration := DataRepository.NewConfiguration() + client := DataRepository.NewAPIClient(configuration) for _, subscriptionDataSubscription := range udrSelf.SubscriptionDataSubscriptions { if ueId == subscriptionDataSubscription.UeId { onDataChangeNotifyUrl := subscriptionDataSubscription.CallbackReference - dataChangeNotify := models.DataChangeNotify{} - dataChangeNotify.UeId = ueId - dataChangeNotify.OriginalCallbackReference = []string{subscriptionDataSubscription.OriginalCallbackReference} - dataChangeNotify.NotifyItems = notifyItems - httpResponse, err := client.DataChangeNotifyCallbackDocumentApi.OnDataChangeNotify( - context.TODO(), onDataChangeNotifyUrl, dataChangeNotify) - if err != nil { - logger.HttpLog.Errorln(err.Error()) - } else if httpResponse == nil { - logger.HttpLog.Errorln("Empty HTTP response") + dataChangeReq := DataRepository.SubscriptionDataSubscriptionsOnDataChangePostRequest{} + dataChangeReq.DataChangeNotify.UeId = ueId + dataChangeReq.DataChangeNotify.OriginalCallbackReference = []string{ + subscriptionDataSubscription.OriginalCallbackReference, } + dataChangeReq.DataChangeNotify.NotifyItems = notifyItems + rsp, err := client.SubsToNotifyCollectionApi.SubscriptionDataSubscriptionsOnDataChangePost( + context.TODO(), onDataChangeNotifyUrl, &dataChangeReq) - defer func() { - if httpResponse.Body != nil { - if err := httpResponse.Body.Close(); err != nil { - logger.HttpLog.Errorln("Failed to close response body:", err) - } - } - }() + if err != nil { + logger.SBILog.Errorln(err.Error()) + } else if rsp == nil { + logger.SBILog.Errorln("Empty SubscriptionDataSubscriptionsOnDataChangePost response") + } } } } @@ -130,31 +125,32 @@ func SendPolicyDataChangeNotification(policyDataChangeNotification models.Policy for _, policyDataSubscription := range udrSelf.PolicyDataSubscriptions { policyDataChangeNotificationUrl := policyDataSubscription.NotificationUri - configuration := Nudr_DataRepository.NewConfiguration() - client := Nudr_DataRepository.NewAPIClient(configuration) - httpResponse, err := client.PolicyDataChangeNotifyCallbackDocumentApi.PolicyDataChangeNotify( - context.TODO(), policyDataChangeNotificationUrl, policyDataChangeNotification) - if err != nil { - logger.HttpLog.Errorln(err.Error()) - } else if httpResponse == nil { - logger.HttpLog.Errorln("Empty HTTP response") + configuration := DataRepository.NewConfiguration() + client := DataRepository.NewAPIClient(configuration) + + req := DataRepository.CreateIndividualPolicyDataSubscriptionPolicyDataChangeNotificationPostRequest{ + PolicyDataChangeNotification: []models.PolicyDataChangeNotification{ + policyDataChangeNotification, + }, } - defer func() { - if httpResponse.Body != nil { - if err := httpResponse.Body.Close(); err != nil { - logger.HttpLog.Errorln("Failed to close response body:", err) - } - } - }() + rsp, err := client.PolicyDataSubscriptionsCollectionApi. + CreateIndividualPolicyDataSubscriptionPolicyDataChangeNotificationPost(context.TODO(), + policyDataChangeNotificationUrl, &req) + + if err != nil { + logger.SBILog.Errorln(err.Error()) + } else if rsp == nil { + logger.SBILog.Errorln("Empty CreateIndividualPolicyDataSubscriptionPolicyDataChangeNotificationPost response") + } } } func SendInfluenceDataUpdateNotification(resUri string, original, modified *models.TrafficInfluData) { udrSelf := udr_context.GetSelf() - configuration := Nudr_DataRepository.NewConfiguration() - client := Nudr_DataRepository.NewAPIClient(configuration) + configuration := DataRepository.NewConfiguration() + client := DataRepository.NewAPIClient(configuration) var trafficInfluDataNotif models.TrafficInfluDataNotif trafficInfluDataNotif.ResUri = resUri @@ -171,40 +167,39 @@ func SendInfluenceDataUpdateNotification(resUri string, original, modified *mode if checkInfluenceDataSubscription(modified, influenceDataSubscription) { logger.HttpLog.Tracef("Send notification about update of influence data") trafficInfluDataNotif.TrafficInfluData = modified - httpResponse, err := client.InfluenceDataUpdateNotifyCallbackDocumentApi.InfluenceDataChangeNotify(context.TODO(), - influenceDataChangeNotificationUrl, []models.TrafficInfluDataNotif{trafficInfluDataNotif}) + + req := DataRepository.CreateIndividualInfluenceDataSubscriptionTrafficInfluenceDataChangeNotificationPostRequest{ + RequestBody: []interface{}{trafficInfluDataNotif}, + } + + rsp, err := client.InfluenceDataSubscriptionsCollectionApi. + CreateIndividualInfluenceDataSubscriptionTrafficInfluenceDataChangeNotificationPost( + context.TODO(), influenceDataChangeNotificationUrl, &req) + if err != nil { - logger.HttpLog.Errorln(err.Error()) - } else if httpResponse == nil { - logger.HttpLog.Errorln("Empty HTTP response") - } else { - defer func() { - if httpResponse.Body != nil { - if err := httpResponse.Body.Close(); err != nil { - logger.HttpLog.Errorln("Failed to close response body:", err) - } - } - }() + logger.SBILog.Errorln(err.Error()) + } else if rsp == nil { + logger.SBILog.Errorln( + "Empty CreateIndividualInfluenceDataSubscriptionTrafficInfluenceDataChangeNotificationPost response") } } else if checkInfluenceDataSubscription(original, influenceDataSubscription) { // If the modified data is not subscribed or nil, check if the original data is subscribed // If positive, send notification about the removal logger.HttpLog.Tracef("Send notification about removal of influence data") trafficInfluDataNotif.TrafficInfluData = nil - httpResponse, err := client.InfluenceDataUpdateNotifyCallbackDocumentApi.InfluenceDataChangeNotify(context.TODO(), - influenceDataChangeNotificationUrl, []models.TrafficInfluDataNotif{trafficInfluDataNotif}) + req := DataRepository.CreateIndividualInfluenceDataSubscriptionTrafficInfluenceDataChangeNotificationPostRequest{ + RequestBody: []interface{}{trafficInfluDataNotif}, + } + + rsp, err := client.InfluenceDataSubscriptionsCollectionApi. + CreateIndividualInfluenceDataSubscriptionTrafficInfluenceDataChangeNotificationPost( + context.TODO(), influenceDataChangeNotificationUrl, &req) + if err != nil { - logger.HttpLog.Errorln(err.Error()) - } else if httpResponse == nil { - logger.HttpLog.Errorln("Empty HTTP response") - } else { - defer func() { - if httpResponse.Body != nil { - if err := httpResponse.Body.Close(); err != nil { - logger.HttpLog.Errorln("Failed to close response body:", err) - } - } - }() + logger.SBILog.Errorln(err.Error()) + } else if rsp == nil { + logger.SBILog.Errorln( + "Empty CreateIndividualInfluenceDataSubscriptionTrafficInfluenceDataChangeNotificationPost response") } } return true diff --git a/internal/sbi/processor/provisioned_data_document.go b/internal/sbi/processor/provisioned_data_document.go index 0b3c2bb..f2cda9d 100644 --- a/internal/sbi/processor/provisioned_data_document.go +++ b/internal/sbi/processor/provisioned_data_document.go @@ -113,7 +113,7 @@ func (p *Processor) QueryProvisionedDataProcedure(c *gin.Context, ueId string, s } smData.DnnConfigurations = tmpDnnConfigurations } - provisionedDataSets.SmData = tmp + provisionedDataSets.SmData.IndividualSmSubsData = tmp } collName = "subscriptionData.provisionedData.traceData" From b3cf85f6200b7fc5654acfe27a4a3ed60867017b Mon Sep 17 00:00:00 2001 From: ian60509 Date: Wed, 7 Aug 2024 05:25:42 +0000 Subject: [PATCH 02/12] fix: return wrong error when deregister --- go.mod | 6 +++--- go.sum | 12 ++++++------ internal/sbi/consumer/nrf_service.go | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 6490099..7f087c9 100644 --- a/go.mod +++ b/go.mod @@ -34,9 +34,10 @@ require ( github.com/go-playground/validator/v10 v10.14.0 // indirect github.com/go-stack/stack v1.8.0 // indirect github.com/goccy/go-json v0.10.2 // indirect - github.com/golang-jwt/jwt v3.2.1+incompatible // indirect + github.com/golang-jwt/jwt/v5 v5.2.1 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/golang/snappy v0.0.1 // indirect + github.com/h2non/gock v1.2.0 // indirect github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.13.6 // indirect @@ -69,8 +70,7 @@ require ( golang.org/x/text v0.14.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.33.0 // indirect - gopkg.in/h2non/gock.v1 v1.1.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace github.com/free5gc/openapi => github.com/free5gc/openapi v1.0.9-0.20240730084256-f724fd925c33 +replace github.com/free5gc/openapi => github.com/yccodr/openapi v1.0.9-0.20240801032959-f8c907cee3a4 diff --git a/go.sum b/go.sum index 4e448fa..0f2c2fb 100644 --- a/go.sum +++ b/go.sum @@ -61,8 +61,6 @@ github.com/evanphx/json-patch v0.5.2 h1:xVCHIVMUu1wtM/VkR9jVZ45N3FhZfYMMYGorLCR8 github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/free5gc/openapi v1.0.9-0.20240730084256-f724fd925c33 h1:U/hJW8h7iNLlk5J+jucr/rc5gdwRRkgnEam8Kav42cY= -github.com/free5gc/openapi v1.0.9-0.20240730084256-f724fd925c33/go.mod h1:oy68rqnHakRLUCuEOXcis7/PWGBuil+UaXMeTBeYY8Y= github.com/free5gc/util v1.0.6 h1:dBt9drcXtYKE/cY5XuQcuffgsYclPIpIArhSeS6M+DQ= github.com/free5gc/util v1.0.6/go.mod h1:eSGN7POUM8LNTvg/E591XR6447a6/w1jFWGKNZPHcXw= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= @@ -91,8 +89,8 @@ github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= -github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfEP4Q1lOd9Z/+c= -github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= +github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= +github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -151,6 +149,8 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/h2non/gock v1.2.0 h1:K6ol8rfrRkUOefooBC8elXoaNGYkpp7y2qcxGG6BzUE= +github.com/h2non/gock v1.2.0/go.mod h1:tNhoxHYW2W42cYkYb1WqzdbYIieALC99kpYr7rH/BQk= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= @@ -230,6 +230,8 @@ github.com/xdg-go/scram v1.0.2 h1:akYIkZ28e6A96dkWNJQu3nmCzH3YfwMPQExUYDaRv7w= github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs= github.com/xdg-go/stringprep v1.0.2 h1:6iq84/ryjjeRmMJwxutI51F2GIPlP5BfTvXHeYjyhBc= github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM= +github.com/yccodr/openapi v1.0.9-0.20240801032959-f8c907cee3a4 h1:s9a4LN+K2bObkYtWdLN0cPuZ6hDugcKIIWhKrW3sJnY= +github.com/yccodr/openapi v1.0.9-0.20240801032959-f8c907cee3a4/go.mod h1:aKw6uGzEibGDrn9++w4/JpWxaaUBo7GaqsvuFKU9fl4= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -509,8 +511,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY= -gopkg.in/h2non/gock.v1 v1.1.2/go.mod h1:n7UGz/ckNChHiK05rDoiC4MYSunEC/lyaUm2WWaDva0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 273b664..2538f9f 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -146,11 +146,11 @@ func (ns *NrfService) SendDeregisterNFInstance() (problemDetails *models.Problem } _, deregisterErr := client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, deregisterReq) if deregisterErr != nil { - if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { + if apiErr, ok := deregisterErr.(openapi.GenericOpenAPIError); ok { pd = apiErr.Model().(*models.ProblemDetails) - return pd, err + return pd, deregisterErr } - return nil, err + return nil, deregisterErr } return problemDetails, err } From bc74a3e054ac9f4460dde815eccfed42ae226ff1 Mon Sep 17 00:00:00 2001 From: ian60509 Date: Fri, 9 Aug 2024 05:31:38 +0000 Subject: [PATCH 03/12] fix: use type assertion to judge deregister error --- internal/sbi/consumer/nrf_service.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 2538f9f..6d666c8 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -146,13 +146,23 @@ func (ns *NrfService) SendDeregisterNFInstance() (problemDetails *models.Problem } _, deregisterErr := client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, deregisterReq) if deregisterErr != nil { - if apiErr, ok := deregisterErr.(openapi.GenericOpenAPIError); ok { - pd = apiErr.Model().(*models.ProblemDetails) - return pd, deregisterErr + switch apiErr := deregisterErr.(type) { + case openapi.GenericOpenAPIError: + switch errModel := apiErr.Model().(type) { + case NFManagement.DeregisterNFInstanceError: + problemDetails = &errModel.ProblemDetails + return problemDetails, nil + case error: + problemDetails = openapi.ProblemDetailsSystemFailure(errModel.Error()) + return problemDetails, nil + } + case error: + problemDetails = openapi.ProblemDetailsSystemFailure(apiErr.Error()) + return problemDetails, nil } return nil, deregisterErr } - return problemDetails, err + return nil, nil } func (ns *NrfService) SendSearchNFInstances(nrfUri string, From 0c024fd2d753e268a203def5182910067cf82e66 Mon Sep 17 00:00:00 2001 From: ian60509 Date: Fri, 9 Aug 2024 05:50:06 +0000 Subject: [PATCH 04/12] refactor: move error parsing --- internal/sbi/consumer/nrf_service.go | 24 +++++------------------- pkg/service/init.go | 24 ++++++++++++++++++------ 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 6d666c8..c9d6e12 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -7,7 +7,6 @@ import ( "sync" "time" - "github.com/free5gc/openapi" "github.com/free5gc/openapi/models" "github.com/free5gc/openapi/nrf/NFDiscovery" "github.com/free5gc/openapi/nrf/NFManagement" @@ -127,12 +126,13 @@ func (ns *NrfService) SendRegisterNFInstance(ctx context.Context, nrfUri string) return resourceNrfUri, retrieveNfInstanceId, nil } -func (ns *NrfService) SendDeregisterNFInstance() (problemDetails *models.ProblemDetails, err error) { +func (ns *NrfService) SendDeregisterNFInstance() (err error) { logger.ConsumerLog.Infof("Send Deregister NFInstance") ctx, pd, err := udr_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NRF) if err != nil { - return pd, err + logger.ConsumerLog.Errorf("Get token context failed: problem details: %+v", pd) + return err } udrSelf := udr_context.GetSelf() @@ -146,23 +146,9 @@ func (ns *NrfService) SendDeregisterNFInstance() (problemDetails *models.Problem } _, deregisterErr := client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, deregisterReq) if deregisterErr != nil { - switch apiErr := deregisterErr.(type) { - case openapi.GenericOpenAPIError: - switch errModel := apiErr.Model().(type) { - case NFManagement.DeregisterNFInstanceError: - problemDetails = &errModel.ProblemDetails - return problemDetails, nil - case error: - problemDetails = openapi.ProblemDetailsSystemFailure(errModel.Error()) - return problemDetails, nil - } - case error: - problemDetails = openapi.ProblemDetailsSystemFailure(apiErr.Error()) - return problemDetails, nil - } - return nil, deregisterErr + return deregisterErr } - return nil, nil + return nil } func (ns *NrfService) SendSearchNFInstances(nrfUri string, diff --git a/pkg/service/init.go b/pkg/service/init.go index f711fb5..a905deb 100644 --- a/pkg/service/init.go +++ b/pkg/service/init.go @@ -10,6 +10,8 @@ import ( "github.com/sirupsen/logrus" + "github.com/free5gc/openapi" + "github.com/free5gc/openapi/nrf/NFManagement" udr_context "github.com/free5gc/udr/internal/context" "github.com/free5gc/udr/internal/logger" "github.com/free5gc/udr/internal/sbi" @@ -128,14 +130,24 @@ func (u *UdrApp) registerToNrf(ctx context.Context) error { } func (a *UdrApp) deregisterFromNrf() { - problemDetails, err := a.consumer.SendDeregisterNFInstance() - if problemDetails != nil { - logger.InitLog.Errorf("Deregister NF instance Failed Problem[%+v]", problemDetails) - } else if err != nil { + err := a.consumer.SendDeregisterNFInstance() + if err != nil { + switch apiErr := err.(type) { + case openapi.GenericOpenAPIError: + switch errModel := apiErr.Model().(type) { + case NFManagement.DeregisterNFInstanceError: + pd := &errModel.ProblemDetails + logger.InitLog.Errorf("Deregister NF instance Failed Problem[%+v]", pd) + case error: + logger.InitLog.Errorf("Deregister NF instance Error[%+v]", err) + } + case error: + logger.InitLog.Errorf("Deregister NF instance Error[%+v]", err) + } logger.InitLog.Errorf("Deregister NF instance Error[%+v]", err) - } else { - logger.InitLog.Infof("Deregister from NRF successfully") } + + logger.InitLog.Infof("Deregister from NRF successfully") } func (a *UdrApp) Start() { From a4dc53ae1435fc67f6c4c71fa59b088da1fdccf1 Mon Sep 17 00:00:00 2001 From: ian60509 Date: Thu, 5 Sep 2024 08:00:45 +0000 Subject: [PATCH 05/12] chore: update go mod --- go.mod | 4 +--- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 7f087c9..1cdcceb 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d github.com/evanphx/json-patch v0.5.2 - github.com/free5gc/openapi v1.0.8 + github.com/free5gc/openapi v1.0.9-0.20240823100026-6a9f667e914f github.com/free5gc/util v1.0.6 github.com/gin-gonic/gin v1.9.1 github.com/golang/mock v1.4.4 @@ -72,5 +72,3 @@ require ( google.golang.org/protobuf v1.33.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) - -replace github.com/free5gc/openapi => github.com/yccodr/openapi v1.0.9-0.20240801032959-f8c907cee3a4 diff --git a/go.sum b/go.sum index 0f2c2fb..db30e41 100644 --- a/go.sum +++ b/go.sum @@ -61,6 +61,8 @@ github.com/evanphx/json-patch v0.5.2 h1:xVCHIVMUu1wtM/VkR9jVZ45N3FhZfYMMYGorLCR8 github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/free5gc/openapi v1.0.9-0.20240823100026-6a9f667e914f h1:b//Fa0CvIDU7fufqMcrEgbVUqpubokK/lFgkTxN3fGM= +github.com/free5gc/openapi v1.0.9-0.20240823100026-6a9f667e914f/go.mod h1:aKw6uGzEibGDrn9++w4/JpWxaaUBo7GaqsvuFKU9fl4= github.com/free5gc/util v1.0.6 h1:dBt9drcXtYKE/cY5XuQcuffgsYclPIpIArhSeS6M+DQ= github.com/free5gc/util v1.0.6/go.mod h1:eSGN7POUM8LNTvg/E591XR6447a6/w1jFWGKNZPHcXw= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= @@ -230,8 +232,6 @@ github.com/xdg-go/scram v1.0.2 h1:akYIkZ28e6A96dkWNJQu3nmCzH3YfwMPQExUYDaRv7w= github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs= github.com/xdg-go/stringprep v1.0.2 h1:6iq84/ryjjeRmMJwxutI51F2GIPlP5BfTvXHeYjyhBc= github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM= -github.com/yccodr/openapi v1.0.9-0.20240801032959-f8c907cee3a4 h1:s9a4LN+K2bObkYtWdLN0cPuZ6hDugcKIIWhKrW3sJnY= -github.com/yccodr/openapi v1.0.9-0.20240801032959-f8c907cee3a4/go.mod h1:aKw6uGzEibGDrn9++w4/JpWxaaUBo7GaqsvuFKU9fl4= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= From 73aada5eb687437b7fb013fe3cf668408d4f1e7f Mon Sep 17 00:00:00 2001 From: ian60509 Date: Wed, 11 Sep 2024 06:37:39 +0000 Subject: [PATCH 06/12] feat: construct GroupIdMap API --- internal/sbi/api_groupIdMap.go | 28 ++++++++++++++++++++++++++++ internal/sbi/server.go | 8 ++++++++ pkg/factory/config.go | 3 ++- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 internal/sbi/api_groupIdMap.go diff --git a/internal/sbi/api_groupIdMap.go b/internal/sbi/api_groupIdMap.go new file mode 100644 index 0000000..fdd93eb --- /dev/null +++ b/internal/sbi/api_groupIdMap.go @@ -0,0 +1,28 @@ +package sbi + +import ( + "net/http" + "github.com/gin-gonic/gin" +) + +func (s *Server) getGroupIdMap() []Route { + return []Route{ + { + Name: "Index", + Method: "GET", + Pattern: "/", + HandlerFunc: Index, + }, + { + Name: "GetNfGroupIDs", + Method: "GET", + Pattern: "/nf-group-ids", + HandlerFunc: s.HTTPGetNfGroupIDs, + }, + } +} + +// GetNfGroupIDs - Retrieves NF-Group IDs for provided Subscriber and NF types +func (s *Server)HTTPGetNfGroupIDs(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} \ No newline at end of file diff --git a/internal/sbi/server.go b/internal/sbi/server.go index d277a9a..ed709d5 100644 --- a/internal/sbi/server.go +++ b/internal/sbi/server.go @@ -100,6 +100,14 @@ func newRouter(s *Server) *gin.Engine { }) dataRepositoryRoutes := s.getDataRepositoryRoutes() AddService(dataRepositoryGroup, dataRepositoryRoutes) + + groupIdGroup := router.Group(factory.UdrGroupIdResUriPrefix) + groupIdGroup.Use(func(c *gin.Context) { + util.NewRouterAuthorizationCheck(models.ServiceName_NUDR_GROUP_ID_MAP).Check(c, s.Context()) + }) + groupIdRoutes := s.getGroupIdMap() + AddService(groupIdGroup, groupIdRoutes) + return router } diff --git a/pkg/factory/config.go b/pkg/factory/config.go index 5abea89..6330624 100644 --- a/pkg/factory/config.go +++ b/pkg/factory/config.go @@ -22,7 +22,8 @@ const ( UdrSbiDefaultPort = 8000 UdrSbiDefaultScheme = "https" UdrDefaultNrfUri = "https://127.0.0.10:8000" - UdrDrResUriPrefix = "/nudr-dr/v1" + UdrDrResUriPrefix = "/nudr-dr/v2" + UdrGroupIdResUriPrefix = "/nudr-group-id-map/v1" ) type DbType string From 31b4a3b9ca52d206cfb3dff6f58375ba57d1c330 Mon Sep 17 00:00:00 2001 From: ian60509 Date: Wed, 11 Sep 2024 06:40:55 +0000 Subject: [PATCH 07/12] fix: linter error --- internal/sbi/api_groupIdMap.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/sbi/api_groupIdMap.go b/internal/sbi/api_groupIdMap.go index fdd93eb..7bfc43e 100644 --- a/internal/sbi/api_groupIdMap.go +++ b/internal/sbi/api_groupIdMap.go @@ -2,15 +2,16 @@ package sbi import ( "net/http" + "github.com/gin-gonic/gin" ) func (s *Server) getGroupIdMap() []Route { return []Route{ { - Name: "Index", - Method: "GET", - Pattern: "/", + Name: "Index", + Method: "GET", + Pattern: "/", HandlerFunc: Index, }, { @@ -23,6 +24,6 @@ func (s *Server) getGroupIdMap() []Route { } // GetNfGroupIDs - Retrieves NF-Group IDs for provided Subscriber and NF types -func (s *Server)HTTPGetNfGroupIDs(c *gin.Context) { +func (s *Server) HTTPGetNfGroupIDs(c *gin.Context) { c.JSON(http.StatusNotImplemented, gin.H{}) -} \ No newline at end of file +} From a1cd82c8e14fccbdb48d4879e2b0404f906f0736 Mon Sep 17 00:00:00 2001 From: ian60509 Date: Mon, 23 Sep 2024 09:26:53 +0000 Subject: [PATCH 08/12] feat: construct imsSDM API --- internal/sbi/api_imsSDM.go | 548 +++++++++++++++++++++++++++++++++++++ internal/sbi/server.go | 7 + pkg/factory/config.go | 1 + 3 files changed, 556 insertions(+) create mode 100644 internal/sbi/api_imsSDM.go diff --git a/internal/sbi/api_imsSDM.go b/internal/sbi/api_imsSDM.go new file mode 100644 index 0000000..e57cca2 --- /dev/null +++ b/internal/sbi/api_imsSDM.go @@ -0,0 +1,548 @@ +package sbi + +import ( + "net/http" + + "github.com/gin-gonic/gin" +) + +func (s *Server) getImsSDMRoutes() []Route { + return []Route{ + { + "Index", + "GET", + "/", + Index, + }, + + { + Name: "DeleteRepositoryDataServInd", + Method: "Delete", + Pattern: "/:imsUeId/repository-data/:serviceIndication", + HandlerFunc: s.HTTPDeleteRepositoryDataServInd, + }, + + { + Name: "DeleteSmsRegistrationInfo", + Method: "Delete", + Pattern: "/:imsUeId/service-data/sms-registration-info", + HandlerFunc: s.HTTPDeleteSmsRegistrationInfo, + }, + + { + Name: "GetChargingInfo", + Method: "Get", + Pattern: "/:imsUeId/ims-data/profile-data/charging-info", + HandlerFunc: s.HTTPGetChargingInfo, + }, + + { + Name: "GetCsUserStateInfo", + Method: "Get", + Pattern: "/:imsUeId/access-data/cs-domain/user-state", + HandlerFunc: s.HTTPGetCsUserStateInfo, + }, + + { + Name: "GetCsrn", + Method: "Get", + Pattern: "/:imsUeId/access-data/cs-domain/csrn", + HandlerFunc: s.HTTPGetCsrn, + }, + + { + Name: "GetDsaiInfo", + Method: "Get", + Pattern: "/:imsUeId/service-data/dsai", + HandlerFunc: s.HTTPGetDsaiInfo, + }, + + { + Name: "GetIMEISVInfo", + Method: "Get", + Pattern: "/:imsUeId/identities/imeisv", + HandlerFunc: s.HTTPGetIMEISVInfo, + }, + + { + Name: "GetIfcs", + Method: "Get", + Pattern: "/:imsUeId/ims-data/profile-data/ifcs", + HandlerFunc: s.HTTPGetIfcs, + }, + + { + Name: "GetImsAssocIds", + Method: "Get", + Pattern: "/:imsUeId/identities/ims-associated-identities", + HandlerFunc: s.HTTPGetImsAssocIds, + }, + + { + Name: "GetImsPrivateIds", + Method: "Get", + Pattern: "/:imsUeId/identities/private-identities", + HandlerFunc: s.HTTPGetImsPrivateIds, + }, + + { + Name: "GetIpAddressInfo", + Method: "Get", + Pattern: "/:imsUeId/access-data/ps-domain/ip-address", + HandlerFunc: s.HTTPGetIpAddressInfo, + }, + + { + Name: "GetLocCsDomain", + Method: "Get", + Pattern: "/:imsUeId/access-data/cs-domain/location-data", + HandlerFunc: s.HTTPGetLocCsDomain, + }, + + { + Name: "GetLocPsDomain", + Method: "Get", + Pattern: "/:imsUeId/access-data/ps-domain/location-data", + HandlerFunc: s.HTTPGetLocPsDomain, + }, + + { + Name: "GetMsisdns", + Method: "Get", + Pattern: "/:imsUeId/identities/msisdns", + HandlerFunc: s.HTTPGetMsisdns, + }, + + { + Name: "GetPriorityInfo", + Method: "Get", + Pattern: "/:imsUeId/ims-data/profile-data/priority-levels", + HandlerFunc: s.HTTPGetPriorityInfo, + }, + + { + Name: "GetProfileData", + Method: "Get", + Pattern: "/:imsUeId/ims-data/profile-data", + HandlerFunc: s.HTTPGetProfileData, + }, + + { + Name: "GetPsUserStateInfo", + Method: "Get", + Pattern: "/:imsUeId/access-data/ps-domain/user-state", + HandlerFunc: s.HTTPGetPsUserStateInfo, + }, + + { + Name: "GetPsiState", + Method: "Get", + Pattern: "/:imsUeId/service-data/psi-status", + HandlerFunc: s.HTTPGetPsiState, + }, + + { + Name: "GetReferenceLocationInfo", + Method: "Get", + Pattern: "/:imsUeId/access-data/wireline-domain/reference-location", + HandlerFunc: s.HTTPGetReferenceLocationInfo, + }, + + { + Name: "GetRegistrationStatus", + Method: "Get", + Pattern: "/:imsUeId/ims-data/registration-status", + HandlerFunc: s.HTTPGetRegistrationStatus, + }, + + { + Name: "GetRepositoryDataServInd", + Method: "Get", + Pattern: "/:imsUeId/repository-data/:serviceIndication", + HandlerFunc: s.HTTPGetRepositoryDataServInd, + }, + + { + Name: "GetRepositoryDataServIndList", + Method: "Get", + Pattern: "/:imsUeId/repository-data", + HandlerFunc: s.HTTPGetRepositoryDataServIndList, + }, + + { + Name: "GetScscfCapabilities", + Method: "Get", + Pattern: "/:imsUeId/ims-data/location-data/scscf-capabilities", + HandlerFunc: s.HTTPGetScscfCapabilities, + }, + + { + Name: "GetScscfSelectionAssistanceInfo", + Method: "Get", + Pattern: "/:imsUeId/ims-data/location-data/scscf-selection-assistance-info", + HandlerFunc: s.HTTPGetScscfSelectionAssistanceInfo, + }, + + { + Name: "GetServerName", + Method: "Get", + Pattern: "/:imsUeId/ims-data/location-data/server-name", + HandlerFunc: s.HTTPGetServerName, + }, + + { + Name: "GetServiceTraceInfo", + Method: "Get", + Pattern: "/:imsUeId/ims-data/profile-data/service-level-trace-information", + HandlerFunc: s.HTTPGetServiceTraceInfo, + }, + + { + Name: "GetSharedData", + Method: "Get", + Pattern: "/shared-data", + HandlerFunc: s.HTTPGetSharedData, + }, + + { + Name: "GetSmsRegistrationInfo", + Method: "Get", + Pattern: "/:imsUeId/service-data/sms-registration-info", + HandlerFunc: s.HTTPGetSmsRegistrationInfo, + }, + + { + Name: "GetSrvccData", + Method: "Get", + Pattern: "/:imsUeId/srvcc-data", + HandlerFunc: s.HTTPGetSrvccData, + }, + + { + Name: "GetTadsInfo", + Method: "Get", + Pattern: "/:imsUeId/access-data/ps-domain/tads-info", + HandlerFunc: s.HTTPGetTadsInfo, + }, + + { + Name: "ImsSdmSubsModify", + Method: "Patch", + Pattern: "/:imsUeId/subscriptions/:subscriptionId", + HandlerFunc: s.HTTPImsSdmSubsModify, + }, + + { + Name: "ImsSdmSubscribe", + Method: "Post", + Pattern: "/:imsUeId/subscriptions", + HandlerFunc: s.HTTPImsSdmSubscribe, + }, + + { + Name: "ImsSdmUnsubscribe", + Method: "Delete", + Pattern: "/:imsUeId/subscriptions/:subscriptionId", + HandlerFunc: s.HTTPImsSdmUnsubscribe, + }, + + { + Name: "ModifySharedDataSubs", + Method: "Patch", + Pattern: "/shared-data-subscriptions/:subscriptionId", + HandlerFunc: s.HTTPModifySharedDataSubs, + }, + + { + Name: "SubscribeToSharedData", + Method: "Post", + Pattern: "/shared-data-subscriptions", + HandlerFunc: s.HTTPSubscribeToSharedData, + }, + + { + Name: "UeReachIpSubscribe", + Method: "Post", + Pattern: "/:imsUeId/access-data/ps-domain/ue-reach-subscriptions", + HandlerFunc: s.HTTPUeReachIpSubscribe, + }, + + { + Name: "UeReachSubsModify", + Method: "Patch", + Pattern: "/:imsUeId/access-data/ps-domain/ue-reach-subscriptions/:subscriptionId", + HandlerFunc: s.HTTPUeReachSubsModify, + }, + + { + Name: "UeReachUnsubscribe", + Method: "Delete", + Pattern: "/:imsUeId/access-data/ps-domain/ue-reach-subscriptions/:subscriptionId", + HandlerFunc: s.HTTPUeReachUnsubscribe, + }, + + { + Name: "UnsubscribeForSharedData", + Method: "Delete", + Pattern: "/shared-data-subscriptions/:subscriptionId", + HandlerFunc: s.HTTPUnsubscribeForSharedData, + }, + + { + Name: "UpdateDsaiState", + Method: "Patch", + Pattern: "/:imsUeId/service-data/dsai", + HandlerFunc: s.HTTPUpdateDsaiState, + }, + + { + Name: "UpdatePsiState", + Method: "Patch", + Pattern: "/:imsUeId/service-data/psi-status", + HandlerFunc: s.HTTPUpdatePsiState, + }, + + { + Name: "UpdateRepositoryDataServInd", + Method: "Put", + Pattern: "/:imsUeId/repository-data/:serviceIndication", + HandlerFunc: s.HTTPUpdateRepositoryDataServInd, + }, + + { + Name: "UpdateSmsRegistrationInfo", + Method: "Put", + Pattern: "/:imsUeId/service-data/sms-registration-info", + HandlerFunc: s.HTTPUpdateSmsRegistrationInfo, + }, + + { + Name: "UpdateSrvccData", + Method: "Patch", + Pattern: "/:imsUeId/srvcc-data", + HandlerFunc: s.HTTPUpdateSrvccData, + }, + } +} + +// DeleteRepositoryDataServInd - delete the Repository Data for a Service Indication +func (s *Server) HTTPDeleteRepositoryDataServInd(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// DeleteSmsRegistrationInfo - delete the SMS registration information +func (s *Server) HTTPDeleteSmsRegistrationInfo(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetChargingInfo - Retrieve the charging information for to the user +func (s *Server) HTTPGetChargingInfo(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetCsUserStateInfo - Retrieve the user state information in CS domain +func (s *Server) HTTPGetCsUserStateInfo(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetCsrn - Retrieve the routeing number in CS domain +func (s *Server) HTTPGetCsrn(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetDsaiInfo - Retrieve the DSAI information associated to an Application Server +func (s *Server) HTTPGetDsaiInfo(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetIMEISVInfo - Retrieve the IMEISV information +func (s *Server) HTTPGetIMEISVInfo(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetIfcs - Retrieve the Initial Filter Criteria for the associated IMS subscription +func (s *Server) HTTPGetIfcs(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetImsAssocIds - Retrieve the associated identities to the IMS public identity included in the service request +func (s *Server) HTTPGetImsAssocIds(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetImsPrivateIds - Retrieve the associated private identities +// to the IMS public identity included in the service request +func (s *Server) HTTPGetImsPrivateIds(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetIpAddressInfo - Retrieve the IP address information +func (s *Server) HTTPGetIpAddressInfo(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetLocCsDomain - Retrieve the location data in CS domain +func (s *Server) HTTPGetLocCsDomain(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetLocPsDomain - Retrieve the location data in PS domain +func (s *Server) HTTPGetLocPsDomain(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetMsisdns - retrieve the Msisdns associated to requested identity +func (s *Server) HTTPGetMsisdns(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetPriorityInfo - Retrieve the service priority levels associated to the user +func (s *Server) HTTPGetPriorityInfo(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetProfileData - Retrieve the complete IMS profile +// for a given IMS public identity (and public identities in the same IRS) +func (s *Server) HTTPGetProfileData(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetPsUserStateInfo - Retrieve the user state information in PS domain +func (s *Server) HTTPGetPsUserStateInfo(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetPsiState - Retrieve the PSI activation state data +func (s *Server) HTTPGetPsiState(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetReferenceLocationInfo - Retrieve the reference location information +func (s *Server) HTTPGetReferenceLocationInfo(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetRegistrationStatus - Retrieve the registration status of a user +func (s *Server) HTTPGetRegistrationStatus(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetRepositoryDataServInd - Retrieve the repository data associated to an IMPU and service indication +func (s *Server) HTTPGetRepositoryDataServInd(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetRepositoryDataServIndList - Retrieve the repository data associated to an IMPU and service indication list +func (s *Server) HTTPGetRepositoryDataServIndList(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetScscfCapabilities - Retrieve the S-CSCF capabilities for the associated IMS subscription +func (s *Server) HTTPGetScscfCapabilities(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetScscfSelectionAssistanceInfo - Retrieve the S-CSCF selection assistance info +func (s *Server) HTTPGetScscfSelectionAssistanceInfo(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetServerName - Retrieve the server name for the associated user +func (s *Server) HTTPGetServerName(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetServiceTraceInfo - Retrieve the IMS service level trace information for the associated user +func (s *Server) HTTPGetServiceTraceInfo(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetSharedData - retrieve shared data +func (s *Server) HTTPGetSharedData(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetSmsRegistrationInfo - Retrieve the SMS registration information associated to a user +func (s *Server) HTTPGetSmsRegistrationInfo(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetSrvccData - Retrieve the srvcc data +func (s *Server) HTTPGetSrvccData(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// GetTadsInfo - Retrieve the T-ADS information +func (s *Server) HTTPGetTadsInfo(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// ImsSdmSubsModify - modify the subscription +func (s *Server) HTTPImsSdmSubsModify(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// ImsSdmSubscribe - subscribe to notifications +func (s *Server) HTTPImsSdmSubscribe(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// ImsSdmUnsubscribe - unsubscribe from notifications +func (s *Server) HTTPImsSdmUnsubscribe(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// ModifySharedDataSubs - modify the subscription +func (s *Server) HTTPModifySharedDataSubs(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// SubscribeToSharedData - subscribe to notifications for shared data +func (s *Server) HTTPSubscribeToSharedData(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// UeReachIpSubscribe - subscribe to notifications of UE reachability +func (s *Server) HTTPUeReachIpSubscribe(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// UeReachSubsModify - modify the subscription +func (s *Server) HTTPUeReachSubsModify(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// UeReachUnsubscribe - unsubscribe from notifications to UE reachability +func (s *Server) HTTPUeReachUnsubscribe(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// UnsubscribeForSharedData - unsubscribe from notifications for shared data +func (s *Server) HTTPUnsubscribeForSharedData(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// UpdateDsaiState - Patch +func (s *Server) HTTPUpdateDsaiState(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// UpdatePsiState - Patch +func (s *Server) HTTPUpdatePsiState(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// UpdateRepositoryDataServInd - Update the repository data associated to an IMPU and service indication +func (s *Server) HTTPUpdateRepositoryDataServInd(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// UpdateSmsRegistrationInfo - Update the SMS registration information associated to a user +func (s *Server) HTTPUpdateSmsRegistrationInfo(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +// UpdateSrvccData - Patch +func (s *Server) HTTPUpdateSrvccData(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} diff --git a/internal/sbi/server.go b/internal/sbi/server.go index ed709d5..6773ea4 100644 --- a/internal/sbi/server.go +++ b/internal/sbi/server.go @@ -108,6 +108,13 @@ func newRouter(s *Server) *gin.Engine { groupIdRoutes := s.getGroupIdMap() AddService(groupIdGroup, groupIdRoutes) + imsSDM := router.Group(factory.HSSIsmSDMUriPrefix) + imsSDM.Use(func(c *gin.Context) { + util.NewRouterAuthorizationCheck(models.ServiceName_NHSS_IMS_SDM).Check(c, s.Context()) + }) + imsSDMRoutes := s.getImsSDMRoutes() + AddService(imsSDM, imsSDMRoutes) + return router } diff --git a/pkg/factory/config.go b/pkg/factory/config.go index 6330624..9491a18 100644 --- a/pkg/factory/config.go +++ b/pkg/factory/config.go @@ -24,6 +24,7 @@ const ( UdrDefaultNrfUri = "https://127.0.0.10:8000" UdrDrResUriPrefix = "/nudr-dr/v2" UdrGroupIdResUriPrefix = "/nudr-group-id-map/v1" + HSSIsmSDMUriPrefix = "/nhss-ims-sdm/v1" ) type DbType string From dc62039f9374ddcf4be8946da824ae46ac22da8e Mon Sep 17 00:00:00 2001 From: "CTFang@WireLab" Date: Fri, 25 Oct 2024 07:11:29 +0000 Subject: [PATCH 09/12] fix: ParseSnssaisFromQueryParam() --- internal/sbi/processor/influence_data.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/sbi/processor/influence_data.go b/internal/sbi/processor/influence_data.go index 4405b5e..a52c425 100644 --- a/internal/sbi/processor/influence_data.go +++ b/internal/sbi/processor/influence_data.go @@ -48,7 +48,7 @@ func (p *Processor) ApplicationDataInfluenceDataGetProcedure(c *gin.Context, col func (p *Processor) ParseSnssaisFromQueryParam(snssaiStr string) []models.Snssai { var snssais []models.Snssai - err := json.Unmarshal([]byte("["+snssaiStr+"]"), &snssais) + err := json.Unmarshal([]byte(snssaiStr), &snssais) if err != nil { logger.DataRepoLog.Warnln("Unmarshal Error in snssaiStruct", err) } From 7c0260db98e0d075478bfaa60e0881a817791f84 Mon Sep 17 00:00:00 2001 From: "CTFang@WireLab" Date: Fri, 25 Oct 2024 07:12:23 +0000 Subject: [PATCH 10/12] fix: QuerySmDataProcedure() --- .../sbi/processor/session_management_subscription_data.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/sbi/processor/session_management_subscription_data.go b/internal/sbi/processor/session_management_subscription_data.go index c999bf5..1e0d5a3 100644 --- a/internal/sbi/processor/session_management_subscription_data.go +++ b/internal/sbi/processor/session_management_subscription_data.go @@ -41,6 +41,7 @@ func (p *Processor) QuerySmDataProcedure(c *gin.Context, collName string, ueId s dnnKey := util.EscapeDnn(dnn) filter["dnnConfigurations."+dnnKey] = bson.M{"$exists": true} } + resp := models.SmSubsData{} sessionManagementSubscriptionDatas, err := mongoapi. RestfulAPIGetMany(collName, filter, mongoapi.COLLATION_STRENGTH_IGNORE_CASE) @@ -57,6 +58,8 @@ func (p *Processor) QuerySmDataProcedure(c *gin.Context, collName string, ueId s logger.DataRepoLog.Debug("SmData Unmarshal error") continue } + resp.IndividualSmSubsData = append(resp.IndividualSmSubsData, tmpSmData) + dnnConfigurations := tmpSmData.DnnConfigurations tmpDnnConfigurations := make(map[string]models.DnnConfiguration) for escapedDnn, dnnConf := range dnnConfigurations { @@ -65,5 +68,5 @@ func (p *Processor) QuerySmDataProcedure(c *gin.Context, collName string, ueId s } smData["DnnConfigurations"] = tmpDnnConfigurations } - c.JSON(http.StatusOK, sessionManagementSubscriptionDatas) + c.JSON(http.StatusOK, resp) } From 4d12dee9902b2a6a21cc47081442b5ca7b5e6018 Mon Sep 17 00:00:00 2001 From: "CTFang@WireLab" Date: Sun, 27 Oct 2024 14:11:18 +0000 Subject: [PATCH 11/12] fix: add log and return in AuthenticationData Procedure --- internal/sbi/processor/authentication_data_document.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/sbi/processor/authentication_data_document.go b/internal/sbi/processor/authentication_data_document.go index 03ac893..29d68c1 100644 --- a/internal/sbi/processor/authentication_data_document.go +++ b/internal/sbi/processor/authentication_data_document.go @@ -23,12 +23,15 @@ import ( func (p *Processor) ModifyAuthenticationProcedure( c *gin.Context, collName string, ueId string, patchItem []models.PatchItem, ) { + logger.ProcLog.Debugf("ModifyAuthenticationProcedure: %s %v", ueId, patchItem) + var err error var origValue, newValue map[string]interface{} filter := bson.M{"ueId": ueId} if origValue, newValue, err = p.PatchDataToDBAndNotify(collName, ueId, patchItem, filter); err != nil { logger.DataRepoLog.Errorf("ModifyAuthenticationProcedure err: %+v", err) c.JSON(http.StatusInternalServerError, util.ProblemDetailsModifyNotAllowed("")) + return } PreHandleOnDataChangeNotify(ueId, CurrentResourceUri, patchItem, origValue, newValue) c.Status(http.StatusNoContent) From 7b452e069b7cdd5e5421075b91bf07de79eaad81 Mon Sep 17 00:00:00 2001 From: ian60509 Date: Wed, 13 Nov 2024 03:16:34 +0000 Subject: [PATCH 12/12] chore: update openapi dependency --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 1cdcceb..d91607b 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d github.com/evanphx/json-patch v0.5.2 - github.com/free5gc/openapi v1.0.9-0.20240823100026-6a9f667e914f + github.com/free5gc/openapi v1.0.9-0.20241112160830-092c679ef6cd github.com/free5gc/util v1.0.6 github.com/gin-gonic/gin v1.9.1 github.com/golang/mock v1.4.4 diff --git a/go.sum b/go.sum index db30e41..f4724cb 100644 --- a/go.sum +++ b/go.sum @@ -61,8 +61,8 @@ github.com/evanphx/json-patch v0.5.2 h1:xVCHIVMUu1wtM/VkR9jVZ45N3FhZfYMMYGorLCR8 github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/free5gc/openapi v1.0.9-0.20240823100026-6a9f667e914f h1:b//Fa0CvIDU7fufqMcrEgbVUqpubokK/lFgkTxN3fGM= -github.com/free5gc/openapi v1.0.9-0.20240823100026-6a9f667e914f/go.mod h1:aKw6uGzEibGDrn9++w4/JpWxaaUBo7GaqsvuFKU9fl4= +github.com/free5gc/openapi v1.0.9-0.20241112160830-092c679ef6cd h1:VRxE3QzfL1uU8ZnR9Y1aXtslHPeMIVoHb3wU0yOz2AI= +github.com/free5gc/openapi v1.0.9-0.20241112160830-092c679ef6cd/go.mod h1:aKw6uGzEibGDrn9++w4/JpWxaaUBo7GaqsvuFKU9fl4= github.com/free5gc/util v1.0.6 h1:dBt9drcXtYKE/cY5XuQcuffgsYclPIpIArhSeS6M+DQ= github.com/free5gc/util v1.0.6/go.mod h1:eSGN7POUM8LNTvg/E591XR6447a6/w1jFWGKNZPHcXw= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=