Skip to content

Commit 923ecd9

Browse files
committed
feat: add request timeout opt
Signed-off-by: Josef Andersson <[email protected]>
1 parent 0726af5 commit 923ecd9

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

cmd/synccmd/mirror.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ func createMirrorProviderClient(ctx context.Context, syncCfg gpsconfig.SyncConfi
151151
}
152152

153153
func pushRepository(ctx context.Context, syncCfg gpsconfig.SyncConfig, mirrorCfg gpsconfig.MirrorConfig, client interfaces.GitProvider, repo interfaces.GitRepository) (interfaces.MirrorWriter, error) {
154+
logger := log.Logger(ctx)
155+
logger.Trace().Msg("Entering pushRepository")
156+
154157
writer, err := getMirrorWriter(mirrorCfg)
155158
if err != nil {
156159
return nil, fmt.Errorf("get mirror writer: %w", err)
@@ -160,6 +163,8 @@ func pushRepository(ctx context.Context, syncCfg gpsconfig.SyncConfig, mirrorCfg
160163
return nil, fmt.Errorf("failed to push to mirror target: %w", err)
161164
}
162165

166+
logger.Info().Str("repository", repo.ProjectInfo().CleanName).Msg("Pushed")
167+
163168
incrementSyncCount(ctx)
164169

165170
return writer, nil

internal/model/configuration/appconfiguration.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type SyncConfig struct {
4242
type AuthConfig struct {
4343
CertDirPath string `koanf:"cert_dir_path"`
4444
HTTPScheme string `koanf:"http_scheme"`
45+
RequestTimeout int `koanf:"request_timeout"`
4546
Token string `koanf:"token"`
4647
Protocol string `koanf:"protocol"`
4748
ProxyURL string `koanf:"proxy_url"`
@@ -95,6 +96,10 @@ func (b *BaseConfig) FillDefaults() {
9596
if b.Auth.Protocol == "" {
9697
b.Auth.Protocol = TLS
9798
}
99+
100+
if b.Auth.RequestTimeout == 0 {
101+
b.Auth.RequestTimeout = 30
102+
}
98103
}
99104

100105
func (b BaseConfig) GetDomain() string {

internal/model/configuration/appconfiguration_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ func TestBaseConfig_FillDefaults(t *testing.T) {
8080
Domain: "gitlab.com",
8181
OwnerType: "group",
8282
Auth: AuthConfig{
83-
HTTPScheme: HTTPS,
84-
Protocol: TLS,
83+
HTTPScheme: HTTPS,
84+
Protocol: TLS,
85+
RequestTimeout: 30,
8586
},
8687
},
8788
},
@@ -92,17 +93,19 @@ func TestBaseConfig_FillDefaults(t *testing.T) {
9293
Domain: "custom.github.com",
9394
OwnerType: "user",
9495
Auth: AuthConfig{
95-
HTTPScheme: HTTP,
96-
Protocol: SSH,
96+
HTTPScheme: HTTP,
97+
Protocol: SSH,
98+
RequestTimeout: 31,
9799
},
98100
},
99101
expected: BaseConfig{
100102
ProviderType: "github",
101103
Domain: "custom.github.com",
102104
OwnerType: "user",
103105
Auth: AuthConfig{
104-
HTTPScheme: HTTP,
105-
Protocol: SSH,
106+
HTTPScheme: HTTP,
107+
Protocol: SSH,
108+
RequestTimeout: 31,
106109
},
107110
},
108111
},

internal/provider/clientInit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func newHTTPClient(ctx context.Context, opt model.GitProviderClientOption) (*htt
119119
return &http.Client{
120120
Transport: transport,
121121
// Total timeout for entire request/response cycle
122-
Timeout: 30 * time.Second,
122+
Timeout: time.Duration(opt.AuthCfg.RequestTimeout) * time.Second,
123123
// Limit redirect chains to prevent infinite loops
124124
CheckRedirect: func(_ *http.Request, via []*http.Request) error {
125125
if len(via) >= 10 {

0 commit comments

Comments
 (0)