-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Refactor for better maintainability
Signed-off-by: Anurag Rajawat <[email protected]>
- Loading branch information
1 parent
d49b0a0
commit 1095ed3
Showing
23 changed files
with
1,071 additions
and
1,300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
|
||
"github.com/5GSEC/SentryFlow/pkg/core" | ||
"github.com/5GSEC/SentryFlow/pkg/util" | ||
) | ||
|
||
var ( | ||
configFilePath string | ||
kubeConfig string | ||
development bool | ||
logger *zap.SugaredLogger | ||
) | ||
|
||
func init() { | ||
RootCmd.PersistentFlags().StringVar(&configFilePath, "config", "", "config file path") | ||
RootCmd.PersistentFlags().StringVar(&kubeConfig, "kubeconfig", "", "kubeconfig file path") | ||
RootCmd.PersistentFlags().BoolVar(&development, "development", true, "run in development mode") | ||
initLogger(development) | ||
} | ||
|
||
func initLogger(development bool) { | ||
cfg := zap.NewProductionConfig() | ||
cfg.EncoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder | ||
if development { | ||
cfg = zap.NewDevelopmentConfig() | ||
cfg.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder | ||
} | ||
cfg.EncoderConfig.TimeKey = "timestamp" | ||
cfg.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder | ||
coreLogger, _ := cfg.Build() | ||
logger = coreLogger.Sugar() | ||
} | ||
|
||
var RootCmd = &cobra.Command{ | ||
Use: "sentryflow", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
run() | ||
}, | ||
} | ||
|
||
func run() { | ||
logBuildInfo() | ||
ctx := context.WithValue(ctrl.SetupSignalHandler(), util.LoggerCtxKey, logger) | ||
core.Run(ctx, configFilePath, kubeConfig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cmd | ||
|
||
import ( | ||
"runtime" | ||
"runtime/debug" | ||
) | ||
|
||
func logBuildInfo() { | ||
info, _ := debug.ReadBuildInfo() | ||
vcsRev := "" | ||
vcsTime := "" | ||
for _, s := range info.Settings { | ||
if s.Key == "vcs.revision" { | ||
vcsRev = s.Value | ||
} else if s.Key == "vcs.time" { | ||
vcsTime = s.Value | ||
} | ||
} | ||
logger.Infof("Git commit: %s, build time: %s, build version: %s, go os/arch: %s/%s\n", vcsRev, vcsTime, info.Main.Version, runtime.GOOS, runtime.GOARCH) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
sources: | ||
serviceMeshes: | ||
- name: istio-sidecar | ||
enable: true | ||
others: | ||
- name: "optional" | ||
# Either gRPC or HTTP not both | ||
grpc: | ||
url: localhost | ||
port: 1234 | ||
http: | ||
url: localhost | ||
port: 4321 | ||
|
||
exporter: | ||
grpc: | ||
port: 8080 | ||
|
||
debug: | ||
enable: false | ||
pprof: | ||
port: 6060 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/5GSEC/SentryFlow/cmd" | ||
) | ||
|
||
func main() { | ||
_ = cmd.RootCmd.Execute() | ||
} |
Oops, something went wrong.