aboutsummaryrefslogtreecommitdiff
path: root/internal/unsorted/ssh_utils.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-04-06 09:26:46 +0800
committerRunxi Yu <me@runxiyu.org>2025-04-06 09:27:53 +0800
commitda1d8f4e7c332c7109427915e6459b10209cedce (patch)
tree280b921be3b51f93d82d916b4eaa89387b7102cc /internal/unsorted/ssh_utils.go
parentgit2c, git2d: Rename cmd1 and cmd2 descriptively (diff)
downloadforge-0.1.32.tar.gz
forge-0.1.32.tar.zst
forge-0.1.32.zip
Move the Go stuff to ./forged/v0.1.32
Diffstat (limited to 'internal/unsorted/ssh_utils.go')
-rw-r--r--internal/unsorted/ssh_utils.go79
1 files changed, 0 insertions, 79 deletions
diff --git a/internal/unsorted/ssh_utils.go b/internal/unsorted/ssh_utils.go
deleted file mode 100644
index d9850d2..0000000
--- a/internal/unsorted/ssh_utils.go
+++ /dev/null
@@ -1,79 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-only
-// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org>
-
-package unsorted
-
-import (
- "context"
- "errors"
- "fmt"
- "io"
- "net/url"
-
- "go.lindenii.runxiyu.org/forge/internal/ansiec"
- "go.lindenii.runxiyu.org/forge/internal/misc"
-)
-
-var errIllegalSSHRepoPath = errors.New("illegal SSH repo path")
-
-// getRepoInfo2 also fetches repo information... it should be deprecated and
-// implemented in individual handlers.
-func (s *Server) getRepoInfo2(ctx context.Context, sshPath, sshPubkey string) (groupPath []string, repoName string, repoID int, repoPath string, directAccess bool, contribReq, userType string, userID int, err error) {
- var segments []string
- var sepIndex int
- var moduleType, moduleName string
-
- segments, err = misc.PathToSegments(sshPath)
- if err != nil {
- return
- }
-
- for i, segment := range segments {
- var err error
- segments[i], err = url.PathUnescape(segment)
- if err != nil {
- return []string{}, "", 0, "", false, "", "", 0, err
- }
- }
-
- if segments[0] == "-" {
- return []string{}, "", 0, "", false, "", "", 0, errIllegalSSHRepoPath
- }
-
- sepIndex = -1
- for i, part := range segments {
- if part == "-" {
- sepIndex = i
- break
- }
- }
- if segments[len(segments)-1] == "" {
- segments = segments[:len(segments)-1]
- }
-
- switch {
- case sepIndex == -1:
- return []string{}, "", 0, "", false, "", "", 0, errIllegalSSHRepoPath
- case len(segments) <= sepIndex+2:
- return []string{}, "", 0, "", false, "", "", 0, errIllegalSSHRepoPath
- }
-
- groupPath = segments[:sepIndex]
- moduleType = segments[sepIndex+1]
- moduleName = segments[sepIndex+2]
- repoName = moduleName
- switch moduleType {
- case "repos":
- _1, _2, _3, _4, _5, _6, _7 := s.getRepoInfo(ctx, groupPath, moduleName, sshPubkey)
- return groupPath, repoName, _1, _2, _3, _4, _5, _6, _7
- default:
- return []string{}, "", 0, "", false, "", "", 0, errIllegalSSHRepoPath
- }
-}
-
-// writeRedError is a helper function that basically does a Fprintf but makes
-// the entire thing red, in terms of ANSI escape sequences. It's useful when
-// producing error messages on SSH connections.
-func writeRedError(w io.Writer, format string, args ...any) {
- fmt.Fprintln(w, ansiec.Red+fmt.Sprintf(format, args...)+ansiec.Reset)
-}