Added loadSecurityConfigOnce (#5792)

This commit is contained in:
vadimartynov 2024-07-16 19:15:55 +03:00 committed by GitHub
parent 67edf1d014
commit b796c21fa9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
29 changed files with 35 additions and 28 deletions

View File

@ -41,7 +41,7 @@ var (
func main() {
flag.Parse()
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
grpcDialOption = security.LoadClientTLS(util.GetViper(), "grpc.client")
vid := uint32(*volumeId)

View File

@ -26,7 +26,7 @@ var (
func main() {
flag.Parse()
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
genFile(grpcDialOption, 0)

View File

@ -24,7 +24,7 @@ var (
func main() {
flag.Parse()
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
grpcDialOption = security.LoadClientTLS(util.GetViper(), "grpc.client")
vid := uint32(*volumeId)

View File

@ -25,7 +25,7 @@ var (
func main() {
flag.Parse()
util2.LoadConfiguration("security", false)
util2.LoadSecurityConfiguration()
grpcDialOption := security.LoadClientTLS(util2.GetViper(), "grpc.client")
vid := needle.VolumeId(*volumeId)

View File

@ -66,7 +66,7 @@ var cmdBackup = &Command{
func runBackup(cmd *Command, args []string) bool {
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
if *s.volumeId == -1 {

View File

@ -111,7 +111,7 @@ var (
func runBenchmark(cmd *Command, args []string) bool {
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
b.grpcDialOption = security.LoadClientTLS(util.GetViper(), "grpc.client")
fmt.Printf("This is SeaweedFS version %s %s %s\n", util.Version(), runtime.GOOS, runtime.GOARCH)

View File

@ -47,7 +47,7 @@ var cmdDownload = &Command{
}
func runDownload(cmd *Command, args []string) bool {
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
for _, fid := range args {

View File

@ -178,7 +178,7 @@ func runFiler(cmd *Command, args []string) bool {
go http.ListenAndServe(fmt.Sprintf(":%d", *f.debugPort), nil)
}
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
switch {
case *f.metricsHttpIp != "":

View File

@ -59,7 +59,7 @@ var cmdFilerBackup = &Command{
func runFilerBackup(cmd *Command, args []string) bool {
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
util.LoadConfiguration("replication", true)
grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")

View File

@ -59,7 +59,7 @@ var cmdFilerCat = &Command{
func runFilerCat(cmd *Command, args []string) bool {
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
if len(args) == 0 {
return false

View File

@ -83,7 +83,7 @@ var cmdFilerCopy = &Command{
func runCopy(cmd *Command, args []string) bool {
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
if len(args) <= 1 {
return false

View File

@ -56,7 +56,7 @@ The backup writes to another filer store specified in a backup_filer.toml.
func runFilerMetaBackup(cmd *Command, args []string) bool {
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
metaBackup.grpcDialOption = security.LoadClientTLS(util.GetViper(), "grpc.client")
// load backup_filer.toml

View File

@ -45,7 +45,7 @@ var (
func runFilerMetaTail(cmd *Command, args []string) bool {
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
clientId := util.RandomInt32()

View File

@ -78,7 +78,7 @@ var cmdFilerRemoteGateway = &Command{
func runFilerRemoteGateway(cmd *Command, args []string) bool {
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
remoteGatewayOptions.grpcDialOption = grpcDialOption

View File

@ -73,7 +73,7 @@ var cmdFilerRemoteSynchronize = &Command{
func runFilerRemoteSynchronize(cmd *Command, args []string) bool {
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
remoteSyncOptions.grpcDialOption = grpcDialOption

View File

@ -30,7 +30,7 @@ var cmdFilerReplicate = &Command{
func runFilerReplicate(cmd *Command, args []string) bool {
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
util.LoadConfiguration("replication", true)
util.LoadConfiguration("notification", true)
config := util.GetViper()

View File

@ -118,7 +118,7 @@ var cmdFilerSynchronize = &Command{
func runFilerSynchronize(cmd *Command, args []string) bool {
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
grace.SetupProfiling(*syncCpuProfile, *syncMemProfile)

View File

@ -47,7 +47,7 @@ func runIam(cmd *Command, args []string) bool {
func (iamopt *IamOptions) startIamServer() bool {
filerAddress := pb.ServerAddress(*iamopt.filer)
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
for {
err := pb.WithGrpcFilerClient(false, 0, filerAddress, grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {

View File

@ -105,7 +105,7 @@ var (
func runMaster(cmd *Command, args []string) bool {
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
util.LoadConfiguration("master", false)
grace.SetupProfiling(*masterCpuProfile, *masterMemProfile)

View File

@ -68,7 +68,7 @@ var cmdMasterFollower = &Command{
func runMasterFollower(cmd *Command, args []string) bool {
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
util.LoadConfiguration("master", false)
if *mf.portGrpc == 0 {

View File

@ -66,7 +66,7 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
// try to connect to filer
filerAddresses := pb.ServerAddresses(*option.filer).ToAddresses()
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
var cipher bool
var err error

View File

@ -54,7 +54,7 @@ var cmdMqBroker = &Command{
func runMqBroker(cmd *Command, args []string) bool {
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
mqBrokerStandaloneOptions.masters = pb.ServerAddresses(*mqBrokerStandaloneOptions.mastersString).ToAddressMap()

View File

@ -165,7 +165,7 @@ var cmdS3 = &Command{
func runS3(cmd *Command, args []string) bool {
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
switch {
case *s3StandaloneOptions.metricsHttpIp != "":

View File

@ -179,7 +179,7 @@ func runServer(cmd *Command, args []string) bool {
go http.ListenAndServe(fmt.Sprintf(":%d", *serverOptions.debugPort), nil)
}
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
util.LoadConfiguration("master", false)
grace.SetupProfiling(*serverOptions.cpuprofile, *serverOptions.memprofile)

View File

@ -35,7 +35,7 @@ var cmdShell = &Command{
func runShell(command *Command, args []string) bool {
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
shellOptions.GrpcDialOption = security.LoadClientTLS(util.GetViper(), "grpc.client")
shellOptions.Directory = "/"

View File

@ -69,7 +69,7 @@ var cmdUpload = &Command{
func runUpload(cmd *Command, args []string) bool {
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
defaultReplication, err := readMasterConfiguration(grpcDialOption, pb.ServerAddress(*upload.master))

View File

@ -125,7 +125,7 @@ var (
func runVolume(cmd *Command, args []string) bool {
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
// If --pprof is set we assume the caller wants to be able to collect
// cpu and memory profiles via go tool pprof

View File

@ -60,7 +60,7 @@ var cmdWebDav = &Command{
func runWebDav(cmd *Command, args []string) bool {
util.LoadConfiguration("security", false)
util.LoadSecurityConfiguration()
glog.V(0).Infof("Starting Seaweed WebDav Server %s at https port %d", util.Version(), *webDavStandaloneOptions.port)

View File

@ -11,6 +11,7 @@ import (
var (
ConfigurationFileDirectory DirectoryValueType
loadSecurityConfigOnce sync.Once
)
type DirectoryValueType string
@ -31,6 +32,12 @@ type Configuration interface {
SetDefault(key string, value interface{})
}
func LoadSecurityConfiguration(){
loadSecurityConfigOnce.Do(func() {
LoadConfiguration("security", false)
})
}
func LoadConfiguration(configFileName string, required bool) (loaded bool) {
// find a filer store