Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New OpenAPI codes #19

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,56 +1,58 @@
module github.com/free5gc/ausf

go 1.21
go 1.22.0

require (
github.com/antihax/optional v1.0.0
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/bronze1man/radius v0.0.0-20190516032554-afd8baec892d
github.com/free5gc/openapi v1.0.8
github.com/free5gc/util v1.0.6
github.com/gin-gonic/gin v1.9.1
github.com/gin-gonic/gin v1.10.0
github.com/google/gopacket v1.1.19
github.com/google/uuid v1.3.0
github.com/google/uuid v1.6.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
github.com/urfave/cli v1.22.5
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/bytedance/sonic v1.9.1 // indirect
github.com/ShouheiNishi/openapi5g v0.0.0-20241106074548-e84ac6a60950 // indirect
github.com/bytedance/sonic v1.11.6 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // 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
github.com/go-playground/validator/v10 v10.20.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 v3.2.2+incompatible // indirect
github.com/golang/protobuf v1.5.0 // indirect
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/samber/lo v1.47.0 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/tim-ywliu/nested-logrus-formatter v1.3.2 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // 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
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/oauth2 v0.0.0-20210810183815-faf39c7919d5 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/protobuf v1.33.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/h2non/gock.v1 v1.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
31 changes: 31 additions & 0 deletions go.sum

Large diffs are not rendered by default.

34 changes: 18 additions & 16 deletions internal/context/ausf_context_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"os"
"strconv"

"github.com/ShouheiNishi/openapi5g/models"
"github.com/google/uuid"

"github.com/free5gc/ausf/internal/logger"
"github.com/free5gc/ausf/pkg/factory"
"github.com/free5gc/openapi/models"
)

func InitAusfContext(context *AUSFContext) {
Expand All @@ -19,7 +19,7 @@ func InitAusfContext(context *AUSFContext) {
configuration := config.Configuration
sbi := configuration.Sbi

context.NfId = uuid.New().String()
context.NfId = uuid.New()
context.GroupID = configuration.GroupId
context.NrfUri = configuration.NrfUri
context.NrfCertPem = configuration.NrfCertPem
Expand All @@ -35,9 +35,9 @@ func InitAusfContext(context *AUSFContext) {
}

if sbi.Scheme == "https" {
context.UriScheme = models.UriScheme_HTTPS
context.UriScheme = models.Https
} else {
context.UriScheme = models.UriScheme_HTTP
context.UriScheme = models.Http
}

context.BindingIPv4 = os.Getenv(sbi.BindingIPv4)
Expand All @@ -56,37 +56,39 @@ func InitAusfContext(context *AUSFContext) {
context.PlmnList = append(context.PlmnList, configuration.PlmnSupportList...)

// context.NfService
context.NfService = make(map[models.ServiceName]models.NfService)
context.NfService = make(map[models.ServiceName]models.NrfNFService)
AddNfServices(&context.NfService, config, context)
fmt.Println("ausf context = ", context)

context.EapAkaSupiImsiPrefix = configuration.EapAkaSupiImsiPrefix
}

func AddNfServices(serviceMap *map[models.ServiceName]models.NfService, config *factory.Config, context *AUSFContext) {
var nfService models.NfService
func AddNfServices(serviceMap *map[models.ServiceName]models.NrfNFService, config *factory.Config,
context *AUSFContext,
) {
var nfService models.NrfNFService
var ipEndPoints []models.IpEndPoint
var nfServiceVersions []models.NfServiceVersion
var nfServiceVersions []models.NFServiceVersion
services := *serviceMap

// nausf-auth
nfService.ServiceInstanceId = context.NfId
nfService.ServiceName = models.ServiceName_NAUSF_AUTH
nfService.ServiceInstanceId = context.NfId.String()
nfService.ServiceName = models.ServiceNameNausfAuth

var ipEndPoint models.IpEndPoint
ipEndPoint.Ipv4Address = context.RegisterIPv4
ipEndPoint.Port = int32(context.SBIPort)
ipEndPoint.Port = &context.SBIPort
ipEndPoints = append(ipEndPoints, ipEndPoint)

var nfServiceVersion models.NfServiceVersion
var nfServiceVersion models.NFServiceVersion
nfServiceVersion.ApiFullVersion = config.Info.Version
nfServiceVersion.ApiVersionInUri = "v1"
nfServiceVersions = append(nfServiceVersions, nfServiceVersion)

nfService.Scheme = context.UriScheme
nfService.NfServiceStatus = models.NfServiceStatus_REGISTERED
nfService.NfServiceStatus = models.NFServiceStatusREGISTERED

nfService.IpEndPoints = &ipEndPoints
nfService.Versions = &nfServiceVersions
services[models.ServiceName_NAUSF_AUTH] = nfService
nfService.IpEndPoints = ipEndPoints
nfService.Versions = nfServiceVersions
services[models.ServiceNameNausfAuth] = nfService
}
25 changes: 15 additions & 10 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ package context

import (
"context"
"net/http"
"regexp"
"sync"

"github.com/ShouheiNishi/openapi5g/models"
"github.com/google/uuid"

"github.com/free5gc/ausf/internal/logger"
"github.com/free5gc/openapi/models"
"github.com/free5gc/openapi/oauth"
"github.com/free5gc/util/oauth2"
)

type AUSFContext struct {
suciSupiMap sync.Map
UePool sync.Map
NfId string
NfId uuid.UUID
GroupID string
SBIPort int
RegisterIPv4 string
Expand All @@ -22,7 +26,7 @@ type AUSFContext struct {
UriScheme models.UriScheme
NrfUri string
NrfCertPem string
NfService map[models.ServiceName]models.NfService
NfService map[models.ServiceName]models.NrfNFService
PlmnList []models.PlmnId
UdmUeauUrl string
snRegex *regexp.Regexp
Expand Down Expand Up @@ -162,18 +166,19 @@ func GetSelf() *AUSFContext {
return &ausfContext
}

func (a *AUSFContext) GetSelfID() string {
func (a *AUSFContext) GetSelfID() uuid.UUID {
return a.NfId
}

func (c *AUSFContext) GetTokenCtx(serviceName models.ServiceName, targetNF models.NfType) (
context.Context, *models.ProblemDetails, error,
) {
func (c *AUSFContext) GetTokenRequestEditor(ctx context.Context,
serviceName models.ServiceName, targetNF models.NFType,
) (func(ctx context.Context, req *http.Request) error, error) {
if !c.OAuth2Required {
return context.TODO(), nil, nil
return func(ctx context.Context, req *http.Request) error {
return nil
}, nil
}
return oauth.GetTokenCtx(models.NfType_AUSF, targetNF,
c.NfId, c.NrfUri, string(serviceName))
return oauth2.GetOauth2RequestEditor(ctx, models.NFTypeAUSF, targetNF, c.NfId, c.NrfUri, string(serviceName))
}

func (c *AUSFContext) AuthorizationCheck(token string, serviceName models.ServiceName) error {
Expand Down
26 changes: 0 additions & 26 deletions internal/sbi/api_sorprotection.go

This file was deleted.

Loading