Skip to content

Commit

Permalink
Merge pull request #26 from HanHongChen/refactor/sbi-logic
Browse files Browse the repository at this point in the history
refactor: App, Server, Processor, Consumer
  • Loading branch information
ianchen0119 authored Jun 27, 2024
2 parents 12b436d + 2a008f6 commit 7df0d40
Show file tree
Hide file tree
Showing 45 changed files with 2,270 additions and 2,835 deletions.
22 changes: 19 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
package main

import (
"context"
"fmt"
"os"
"os/signal"
"path/filepath"
"runtime/debug"
"syscall"

"github.com/urfave/cli"

Expand Down Expand Up @@ -64,19 +67,32 @@ func action(cliCtx *cli.Context) error {
logger.MainLog.Infoln(cliCtx.App.Name)
logger.MainLog.Infoln("PCF version: ", version.GetVersion())

ctx, cancel := context.WithCancel(context.Background())
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)

go func() {
<-sigCh // Wait for interrupt signal to gracefully shutdown UPF
cancel() // Notify each goroutine and wait them stopped
}()

cfg, err := factory.ReadConfig(cliCtx.String("config"))
if err != nil {
sigCh <- nil
return err
}
factory.PcfConfig = cfg

pcf, err := service.NewApp(cfg)
pcf, err := service.NewApp(ctx, cfg, tlsKeyLogPath)
if err != nil {
sigCh <- nil
return err
}
PCF = pcf

pcf.Start(tlsKeyLogPath)
if pcf == nil {
logger.MainLog.Infoln("pcf is nil")
}
pcf.Start()

return nil
}
Expand Down
9 changes: 2 additions & 7 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type NFContext interface {

var _ NFContext = &PCFContext{}

func InitpcfContext(context *PCFContext) {
func InitPcfContext(context *PCFContext) {
config := factory.PcfConfig
logger.UtilLog.Infof("pcfconfig Info: Version[%s] Description[%s]", config.Info.Version, config.Info.Description)
configuration := config.Configuration
Expand Down Expand Up @@ -157,7 +157,7 @@ func Init() {
pcfContext.PcfSuppFeats = make(map[models.ServiceName]openapi.SupportedFeature)
pcfContext.BdtPolicyIDGenerator = idgenerator.NewGenerator(1, math.MaxInt64)
pcfContext.RatingGroupIdGenerator = idgenerator.NewGenerator(1, math.MaxInt64)
InitpcfContext(&pcfContext)
InitPcfContext(&pcfContext)
}

// Create new PCF context
Expand Down Expand Up @@ -458,11 +458,6 @@ func (c *PCFContext) AuthorizationCheck(token string, serviceName models.Service
logger.UtilLog.Debugf("PCFContext::AuthorizationCheck: OAuth2 not required\n")
return nil
}
// TODO: free5gc webconsole uses npcf-oam but it can't get token since it's not an NF.
if serviceName == models.ServiceName_NPCF_OAM {
logger.UtilLog.Warnf("OAuth2 is enable but namf-oam didn't check token now.")
return nil
}

logger.UtilLog.Debugf("PCFContext::AuthorizationCheck: token[%s] serviceName[%s]\n", token, serviceName)
return oauth.VerifyOAuth(token, string(serviceName), c.NrfCertPem)
Expand Down
2 changes: 2 additions & 0 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var (
CfgLog *logrus.Entry
CtxLog *logrus.Entry
GinLog *logrus.Entry
SBILog *logrus.Entry
AmPolicyLog *logrus.Entry
BdtPolicyLog *logrus.Entry
ConsumerLog *logrus.Entry
Expand All @@ -38,6 +39,7 @@ func init() {
CfgLog = NfLog.WithField(logger_util.FieldCategory, "CFG")
CtxLog = NfLog.WithField(logger_util.FieldCategory, "CTX")
GinLog = NfLog.WithField(logger_util.FieldCategory, "GIN")
SBILog = NfLog.WithField(logger_util.FieldCategory, "SBI")
AmPolicyLog = NfLog.WithField(logger_util.FieldCategory, "AmPol")
BdtPolicyLog = NfLog.WithField(logger_util.FieldCategory, "BdtPol")
ConsumerLog = NfLog.WithField(logger_util.FieldCategory, "Consumer")
Expand Down
173 changes: 0 additions & 173 deletions internal/sbi/ampolicy/api_default.go

This file was deleted.

113 changes: 0 additions & 113 deletions internal/sbi/ampolicy/routers.go

This file was deleted.

Loading

0 comments on commit 7df0d40

Please sign in to comment.