detached c58e6af

fix: resolve lint issues from remote resolution refactor

Extract token and TLS helpers from Resolve() to reduce cyclomatic
complexity. Fix gofmt formatting in auth.go and resolve_test.go.
commit
c58e6af6d436efdf777185a6c87193619718a968
author
brice · · 2026-04-04 11:34 UTC
parent
5b718b1
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
3 files · +45 -43
M internal/adapters/in/cli/auth.go +0 -2
@@ -387,8 +387,6 @@ func runAuthLogout(out io.Writer) error {
387387 return nil
388388 }
389389
390-
391-
392390 // runShowInternalAuth displays the internal registry credentials.
393391 func runShowInternalAuth() error {
394392 creds, err := app.GetInternalCredentials()
@@ -387,8 +387,6 @@ func runAuthLogout(out io.Writer) error {
387 return nil387 return nil
388 }388 }
389 389
390-
391-
392 // runShowInternalAuth displays the internal registry credentials.390 // runShowInternalAuth displays the internal registry credentials.
393 func runShowInternalAuth() error {391 func runShowInternalAuth() error {
394 creds, err := app.GetInternalCredentials()392 creds, err := app.GetInternalCredentials()
M internal/adapters/in/cli/remote/config.go +45 -40
@@ -209,6 +209,42 @@ type ResolvedRemote struct {
209209 InsecureTLS bool
210210 }
211211
212+// resolveTokenForTarget resolves the authentication token.
213+// Precedence: flag > GORDON_TOKEN env > stored token for named remote.
214+func resolveTokenForTarget(flagToken, name string, remotes *ClientConfig) string {
215+ if flagToken != "" {
216+ return flagToken
217+ }
218+ if envToken := os.Getenv("GORDON_TOKEN"); envToken != "" {
219+ return envToken
220+ }
221+ if name != "" && remotes != nil {
222+ if entry, ok := remotes.Remotes[name]; ok {
223+ return ResolveTokenForRemote(name, entry)
224+ }
225+ }
226+ return ""
227+}
228+
229+// resolveInsecureForTarget resolves InsecureTLS setting.
230+// Precedence: flag > GORDON_INSECURE env > remote entry field.
231+func resolveInsecureForTarget(flagInsecure bool, name string, remotes *ClientConfig) bool {
232+ if flagInsecure {
233+ return true
234+ }
235+ if env := os.Getenv("GORDON_INSECURE"); env != "" {
236+ if v, err := strconv.ParseBool(env); err == nil && v {
237+ return true
238+ }
239+ }
240+ if name != "" && remotes != nil {
241+ if entry, ok := remotes.Remotes[name]; ok {
242+ return entry.InsecureTLS
243+ }
244+ }
245+ return false
246+}
247+
212248 // Resolve resolves the remote target from flags, environment, and config.
213249 // Returns nil, false when no remote is configured (local mode).
214250 //
@@ -227,54 +263,23 @@ func Resolve(flagRemote, flagToken string, flagInsecure bool) (*ResolvedRemote,
227263 name, url, found = resolveTarget(envRemote, remotes)
228264 }
229265 }
230- if !found {
231- if remotes != nil && remotes.Active != "" {
232- if entry, ok := remotes.Remotes[remotes.Active]; ok {
233- name = remotes.Active
234- url = entry.URL
235- found = true
236- }
266+ if !found && remotes != nil && remotes.Active != "" {
267+ if entry, ok := remotes.Remotes[remotes.Active]; ok {
268+ name = remotes.Active
269+ url = entry.URL
270+ found = true
237271 }
238272 }
239273 if !found {
240274 return nil, false
241275 }
242276
243- r := &ResolvedRemote{
277+ return &ResolvedRemote{
244278 Name: name,
245279 URL: url,
246- InsecureTLS: flagInsecure,
247- }
248-
249- // Token: flag > env > stored
250- switch {
251- case flagToken != "":
252- r.Token = flagToken
253- case os.Getenv("GORDON_TOKEN") != "":
254- r.Token = os.Getenv("GORDON_TOKEN")
255- case name != "":
256- if remotes != nil {
257- if entry, ok := remotes.Remotes[name]; ok {
258- r.Token = ResolveTokenForRemote(name, entry)
259- }
260- }
261- }
262-
263- // InsecureTLS: flag already set; check env then entry
264- if !r.InsecureTLS {
265- if env := os.Getenv("GORDON_INSECURE"); env != "" {
266- if v, err := strconv.ParseBool(env); err == nil {
267- r.InsecureTLS = v
268- }
269- }
270- }
271- if !r.InsecureTLS && name != "" && remotes != nil {
272- if entry, ok := remotes.Remotes[name]; ok {
273- r.InsecureTLS = entry.InsecureTLS
274- }
275- }
276-
277- return r, true
280+ Token: resolveTokenForTarget(flagToken, name, remotes),
281+ InsecureTLS: resolveInsecureForTarget(flagInsecure, name, remotes),
282+ }, true
278283 }
279284
280285 // resolveTarget checks if value is a saved remote name or an ad-hoc URL.
@@ -209,6 +209,42 @@ type ResolvedRemote struct {
209 InsecureTLS bool209 InsecureTLS bool
210 }210 }
211 211
212+// resolveTokenForTarget resolves the authentication token.
213+// Precedence: flag > GORDON_TOKEN env > stored token for named remote.
214+func resolveTokenForTarget(flagToken, name string, remotes *ClientConfig) string {
215+ if flagToken != "" {
216+ return flagToken
217+ }
218+ if envToken := os.Getenv("GORDON_TOKEN"); envToken != "" {
219+ return envToken
220+ }
221+ if name != "" && remotes != nil {
222+ if entry, ok := remotes.Remotes[name]; ok {
223+ return ResolveTokenForRemote(name, entry)
224+ }
225+ }
226+ return ""
227+}
228+
229+// resolveInsecureForTarget resolves InsecureTLS setting.
230+// Precedence: flag > GORDON_INSECURE env > remote entry field.
231+func resolveInsecureForTarget(flagInsecure bool, name string, remotes *ClientConfig) bool {
232+ if flagInsecure {
233+ return true
234+ }
235+ if env := os.Getenv("GORDON_INSECURE"); env != "" {
236+ if v, err := strconv.ParseBool(env); err == nil && v {
237+ return true
238+ }
239+ }
240+ if name != "" && remotes != nil {
241+ if entry, ok := remotes.Remotes[name]; ok {
242+ return entry.InsecureTLS
243+ }
244+ }
245+ return false
246+}
247+
212 // Resolve resolves the remote target from flags, environment, and config.248 // Resolve resolves the remote target from flags, environment, and config.
213 // Returns nil, false when no remote is configured (local mode).249 // Returns nil, false when no remote is configured (local mode).
214 //250 //
@@ -227,54 +263,23 @@ func Resolve(flagRemote, flagToken string, flagInsecure bool) (*ResolvedRemote,
227 name, url, found = resolveTarget(envRemote, remotes)263 name, url, found = resolveTarget(envRemote, remotes)
228 }264 }
229 }265 }
230- if !found {266+ if !found && remotes != nil && remotes.Active != "" {
231- if remotes != nil && remotes.Active != "" {267+ if entry, ok := remotes.Remotes[remotes.Active]; ok {
232- if entry, ok := remotes.Remotes[remotes.Active]; ok {268+ name = remotes.Active
233- name = remotes.Active269+ url = entry.URL
234- url = entry.URL270+ found = true
235- found = true
236- }
237 }271 }
238 }272 }
239 if !found {273 if !found {
240 return nil, false274 return nil, false
241 }275 }
242 276
243- r := &ResolvedRemote{277+ return &ResolvedRemote{
244 Name: name,278 Name: name,
245 URL: url,279 URL: url,
246- InsecureTLS: flagInsecure,280+ Token: resolveTokenForTarget(flagToken, name, remotes),
247- }281+ InsecureTLS: resolveInsecureForTarget(flagInsecure, name, remotes),
248-282+ }, true
249- // Token: flag > env > stored
250- switch {
251- case flagToken != "":
252- r.Token = flagToken
253- case os.Getenv("GORDON_TOKEN") != "":
254- r.Token = os.Getenv("GORDON_TOKEN")
255- case name != "":
256- if remotes != nil {
257- if entry, ok := remotes.Remotes[name]; ok {
258- r.Token = ResolveTokenForRemote(name, entry)
259- }
260- }
261- }
262-
263- // InsecureTLS: flag already set; check env then entry
264- if !r.InsecureTLS {
265- if env := os.Getenv("GORDON_INSECURE"); env != "" {
266- if v, err := strconv.ParseBool(env); err == nil {
267- r.InsecureTLS = v
268- }
269- }
270- }
271- if !r.InsecureTLS && name != "" && remotes != nil {
272- if entry, ok := remotes.Remotes[name]; ok {
273- r.InsecureTLS = entry.InsecureTLS
274- }
275- }
276-
277- return r, true
278 }283 }
279 284
280 // resolveTarget checks if value is a saved remote name or an ad-hoc URL.285 // resolveTarget checks if value is a saved remote name or an ad-hoc URL.
M internal/adapters/in/cli/remote/resolve_test.go +0 -1
@@ -202,4 +202,3 @@ func TestResolve_UnknownNameReturnsNotFound(t *testing.T) {
202202 assert.False(t, ok)
203203 assert.Nil(t, resolved)
204204 }
205-
@@ -202,4 +202,3 @@ func TestResolve_UnknownNameReturnsNotFound(t *testing.T) {
202 assert.False(t, ok)202 assert.False(t, ok)
203 assert.Nil(t, resolved)203 assert.Nil(t, resolved)
204 }204 }
205-

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close