@@ -55,20 +55,34 @@ type GitopiaHandler struct {
5555func (h * GitopiaHandler ) Initialize (remote * core.Remote ) error {
5656 var err error
5757
58+ // Check existing configuration
5859 grpcHost , _ := config .GitConfigGet (config .GitopiaConfigGRPCHostOption )
5960 tmAddr , _ := config .GitConfigGet (config .GitopiaConfigTmAddrOption )
61+
62+ // Validate and configure gRPC and RPC hosts
63+ needsReconfiguration := false
6064 if grpcHost == "" || tmAddr == "" || ! api .CheckGRPCHostLiveness (grpcHost ) || ! api .CheckRPCHostLiveness (tmAddr ) {
65+ needsReconfiguration = true
66+ }
67+
68+ if needsReconfiguration {
69+ remote .Logger .Printf ("Configuring Gitopia hosts..." )
6170 provider := api .GetBestApiProvider ()
6271 grpcHost = provider .GRPCHost
72+ tmAddr = provider .TMAddr
73+
6374 if err := api .SetConfiguredGRPCHost (provider .GRPCHost ); err != nil {
6475 return err
6576 }
77+
6678 if err := api .SetConfiguredTmAddr (provider .TMAddr ); err != nil {
6779 return err
6880 }
6981 }
7082
83+ // Check and configure Git server host
7184 gitServerHost , _ := config .GitConfigGet (config .GitopiaConfigGitServerHostOption )
85+
7286 if gitServerHost == "" || ! api .CheckGitServerHostLiveness (gitServerHost ) {
7387 gitServerHost = api .GetBestGitServerHost (grpcHost )
7488 if gitServerHost != "" {
@@ -78,10 +92,6 @@ func (h *GitopiaHandler) Initialize(remote *core.Remote) error {
7892 }
7993 }
8094
81- remote .Logger .Printf ("grpc host: %s" , grpcHost )
82- remote .Logger .Printf ("rpc host: %s" , tmAddr )
83- remote .Logger .Printf ("git server host: %s" , gitServerHost )
84-
8595 h .grpcConn , err = grpc .Dial (grpcHost , grpc .WithTransportCredentials (insecure .NewCredentials ()))
8696 if err != nil {
8797 return err
0 commit comments