4
4
"context"
5
5
"fmt"
6
6
"strings"
7
- "time"
8
7
9
8
"github.com/numtide/nix-auth/internal/config"
10
9
"github.com/numtide/nix-auth/internal/provider"
@@ -50,15 +49,13 @@ var (
50
49
loginProvider string
51
50
loginClientID string
52
51
loginForce bool
53
- loginTimeout int
54
52
loginDryRun bool
55
53
)
56
54
57
55
func init () {
58
56
loginCmd .Flags ().StringVar (& loginProvider , "provider" , "auto" , "Provider type when using a host (auto, github, gitlab, gitea, forgejo, codeberg)" )
59
57
loginCmd .Flags ().StringVar (& loginClientID , "client-id" , "" , "OAuth client ID (required for GitHub Enterprise, optional for others)" )
60
58
loginCmd .Flags ().BoolVar (& loginForce , "force" , false , "Skip confirmation prompt when replacing existing tokens" )
61
- loginCmd .Flags ().IntVar (& loginTimeout , "timeout" , 30 , "Timeout in seconds for network operations" )
62
59
loginCmd .Flags ().BoolVar (& loginDryRun , "dry-run" , false , "Preview what would happen without authenticating" )
63
60
}
64
61
@@ -70,7 +67,7 @@ func runLogin(cmd *cobra.Command, args []string) error {
70
67
}
71
68
72
69
// Resolve provider and host
73
- prov , host , err := resolveProviderAndHost (input , loginProvider , loginTimeout )
70
+ prov , host , err := resolveProviderAndHost (input , loginProvider )
74
71
if err != nil {
75
72
return err
76
73
}
@@ -109,17 +106,11 @@ func runLogin(cmd *cobra.Command, args []string) error {
109
106
}
110
107
111
108
// Perform authentication
112
- ctx , cancel := context .WithTimeout (context .Background (), time .Duration (loginTimeout )* time .Second )
113
- defer cancel ()
109
+ ctx := context .Background ()
114
110
token , err := prov .Authenticate (ctx )
115
111
if err != nil {
116
112
errMsg := fmt .Sprintf ("authentication failed: %v" , err )
117
- if strings .Contains (err .Error (), "context deadline exceeded" ) {
118
- errMsg += fmt .Sprintf ("\n \n The operation timed out after %d seconds. Try:\n " +
119
- "- Increasing the timeout: --timeout 60\n " +
120
- "- Checking your internet connection\n " +
121
- "- Verifying the host is accessible: curl https://%s" , loginTimeout , host )
122
- } else if strings .Contains (err .Error (), "client ID" ) {
113
+ if strings .Contains (err .Error (), "client ID" ) {
123
114
errMsg += "\n \n For self-hosted instances, you need to create an OAuth application.\n " +
124
115
"See the instructions above or use --dry-run to preview the configuration."
125
116
}
@@ -151,7 +142,7 @@ func runLogin(cmd *cobra.Command, args []string) error {
151
142
}
152
143
153
144
// resolveProviderAndHost determines the provider and host from the input
154
- func resolveProviderAndHost (input , providerFlag string , timeout int ) (provider.Provider , string , error ) {
145
+ func resolveProviderAndHost (input , providerFlag string ) (provider.Provider , string , error ) {
155
146
// Check if input is a provider alias
156
147
if reg , ok := provider .GetRegistration (input ); ok {
157
148
// It's a provider alias
@@ -176,16 +167,15 @@ func resolveProviderAndHost(input, providerFlag string, timeout int) (provider.P
176
167
}
177
168
178
169
// Input is a host
179
- return resolveProviderForHost (input , providerFlag , timeout )
170
+ return resolveProviderForHost (input , providerFlag )
180
171
}
181
172
182
173
// resolveProviderForHost handles the case where input is a host
183
- func resolveProviderForHost (host , providerFlag string , timeout int ) (provider.Provider , string , error ) {
174
+ func resolveProviderForHost (host , providerFlag string ) (provider.Provider , string , error ) {
184
175
if providerFlag == "auto" {
185
176
// Auto-detect provider type
186
177
fmt .Printf ("Detecting provider type for %s by querying API...\n " , host )
187
- ctx , cancel := context .WithTimeout (context .Background (), time .Duration (timeout )* time .Second )
188
- defer cancel ()
178
+ ctx := context .Background ()
189
179
190
180
prov , err := provider .Detect (ctx , host , loginClientID )
191
181
if err != nil {
0 commit comments