Skip to content

Commit 3f9ea71

Browse files
authored
Add timeout (#61)
1 parent 37948f7 commit 3f9ea71

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ The available flags are:
103103
-s, --silent silent mode
104104
--subject-token string third party token
105105
--subject-token-type string third party token type
106+
--timeout duration http client timeout (default 1m0s)
106107
--tls-cert string path to tls cert pem file
107108
--tls-key string path to tls key pem file
108109
--tls-root-ca string path to tls root ca pem file

cmd/oauth2.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func NewOAuth2Cmd() (cmd *OAuth2Cmd) {
7070
cmd.PersistentFlags().StringVar(&cconfig.TLSCert, "tls-cert", "", "path to tls cert pem file")
7171
cmd.PersistentFlags().StringVar(&cconfig.TLSKey, "tls-key", "", "path to tls key pem file")
7272
cmd.PersistentFlags().StringVar(&cconfig.TLSRootCA, "tls-root-ca", "", "path to tls root ca pem file")
73+
cmd.PersistentFlags().DurationVar(&cconfig.Timeout, "timeout", time.Minute, "http client timeout")
7374
cmd.PersistentFlags().BoolVar(&cconfig.Insecure, "insecure", false, "allow insecure connections")
7475
cmd.PersistentFlags().BoolVarP(&silent, "silent", "s", false, "silent mode")
7576
cmd.PersistentFlags().BoolVar(&cconfig.DPoP, "dpop", false, "use DPoP")
@@ -112,7 +113,7 @@ func (c *OAuth2Cmd) Run(cconfig *oauth2.ClientConfig) func(cmd *cobra.Command, a
112113
},
113114
}
114115

115-
hc := &http.Client{Timeout: 10 * time.Second, Transport: tr}
116+
hc := &http.Client{Timeout: cconfig.Timeout, Transport: tr}
116117

117118
if cconfig.TLSCert != "" && cconfig.TLSKey != "" {
118119
if cert, err = oauth2.ReadKeyPair(cconfig.TLSCert, cconfig.TLSKey, hc); err != nil {

internal/oauth2/oauth2.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ type ClientConfig struct {
8585
TLSCert string
8686
TLSKey string
8787
TLSRootCA string
88+
Timeout time.Duration
8889
DPoP bool
8990
Claims string
9091
}

0 commit comments

Comments
 (0)