Debian Codegraph @

lfshttp/endpoint.go

raw symbols SCIP
1 package lfshttpscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/
2
3 import (
4 "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/"
5 "net/urlscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/"
6 "regexpscip-go gomod github.com/golang/go/src go1.25.0 regexp/"
7 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
8
9 "github.com/git-lfs/git-lfs/v3/gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/"
10 "github.com/git-lfs/git-lfs/v3/sshscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/"
11 )
12
13 const UrlUnknownscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/UrlUnknown. = "<unknown>"
14
15 // An Endpoint describes how to access a Git LFS server.
16 type Endpointscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint# struct {
17 Urlscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#Url. string
18 SSHMetadatascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#SSHMetadata. sshscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/.SSHMetadatascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata#
19 Operationscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#Operation. string
20 OriginalUrlscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#OriginalUrl. string
21 }
22
23 func endpointOperationscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/endpointOperation().(e Endpointscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#, method string) string {
24 if len(e.Operationscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#Operation.) > 0 {
25 return e.Operationscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#Operation.
26 }
27
28 switch method {
29 case "GET", "HEAD":
30 return "download"
31 default:
32 return "upload"
33 }
34 }
35
36 // EndpointFromSshUrl constructs a new endpoint from an ssh:// URL
37 func EndpointFromSshUrlscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/EndpointFromSshUrl().(u *urlscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#) Endpointscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint# {
38 var endpoint Endpointscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#
39 // Pull out port now, we need it separately for SSH
40 regex := regexpscip-go gomod github.com/golang/go/src go1.25.0 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.25.0 regexp/MustCompile().(`^([^\:]+)(?:\:(\d+))?$`)
41 match := regex.FindStringSubmatchscip-go gomod github.com/golang/go/src go1.25.0 regexp/Regexp#FindStringSubmatch().(u.Hostscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#Host.)
42 if match == nil || len(match) < 2 {
43 endpoint.Urlscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#Url. = UrlUnknownscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/UrlUnknown.
44 return endpoint
45 }
46
47 endpoint.OriginalUrlscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#OriginalUrl. = u.Stringscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#String().()
48
49 host := match[1]
50 if u.Userscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#User. != nil && u.Userscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#User..Usernamescip-go gomod github.com/golang/go/src go1.25.0 `net/url`/Userinfo#Username().() != "" {
51 endpoint.SSHMetadatascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#SSHMetadata..UserAndHostscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata#UserAndHost. = fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("%s@%s", u.Userscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#User..Usernamescip-go gomod github.com/golang/go/src go1.25.0 `net/url`/Userinfo#Username().(), host)
52 } else {
53 endpoint.SSHMetadatascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#SSHMetadata..UserAndHostscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata#UserAndHost. = host
54 }
55
56 if len(match) > 2 {
57 endpoint.SSHMetadatascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#SSHMetadata..Portscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata#Port. = match[2]
58 }
59
60 endpoint.SSHMetadatascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#SSHMetadata..Pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata#Path. = u.Pathscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#Path.
61
62 // Fallback URL for using HTTPS while still using SSH for git
63 // u.Host includes host & port so can't use SSH port
64 endpoint.Urlscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#Url. = fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("https://%s%s", host, u.Pathscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#Path.)
65
66 return endpoint
67 }
68
69 // EndpointFromBareSshUrl constructs a new endpoint from a bare SSH URL:
70 //
71 // [email protected]:path/to/repo.git or
72 // [[email protected]:port]:path/to/repo.git
73 func EndpointFromBareSshUrlscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/EndpointFromBareSshUrl().(rawurl string) Endpointscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint# {
74 parts := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Splitscip-go gomod github.com/golang/go/src go1.25.0 strings/Split().(rawurl, ":")
75 partsLen := len(parts)
76 if partsLen < 2 {
77 return Endpointscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#{Urlscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#Url.: rawurl}
78 }
79
80 // Treat presence of ':' as a bare URL
81 var newPath string
82 if len(parts) > 2 { // port included; really should only ever be 3 parts
83 // Correctly handle [host:port]:path URLs
84 parts[0] = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/TrimPrefix().(parts[0], "[")
85 parts[1] = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.TrimSuffixscip-go gomod github.com/golang/go/src go1.25.0 strings/TrimSuffix().(parts[1], "]")
86 newPath = fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("%v:%v", parts[0], stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.25.0 strings/Join().(parts[1:], "/"))
87 } else {
88 newPath = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.25.0 strings/Join().(parts, "/")
89 }
90 newrawurl := fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("ssh://%v", newPath)
91 newu, err := urlscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/.Parsescip-go gomod github.com/golang/go/src go1.25.0 `net/url`/Parse().(newrawurl)
92 if err != nil {
93 return Endpointscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#{Urlscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#Url.: UrlUnknownscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/UrlUnknown.}
94 }
95
96 endpoint := EndpointFromSshUrlscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/EndpointFromSshUrl().(newu)
97 if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasPrefix().(endpoint.SSHMetadatascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#SSHMetadata..Pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata#Path., "/") {
98 endpoint.SSHMetadatascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#SSHMetadata..Pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata#Path. = endpoint.SSHMetadatascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#SSHMetadata..Pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/ssh`/SSHMetadata#Path.[1:]
99 }
100 return endpoint
101 }
102
103 // Construct a new endpoint from a HTTP URL
104 func EndpointFromHttpUrlscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/EndpointFromHttpUrl().(u *urlscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#) Endpointscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint# {
105 // just pass this straight through
106 return Endpointscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#{Urlscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#Url.: u.Stringscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#String().(), OriginalUrlscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#OriginalUrl.: u.Stringscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#String().()}
107 }
108
109 func EndpointFromLocalPathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/EndpointFromLocalPath().(path string) Endpointscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint# {
110 url := gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.RewriteLocalPathAsURLscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/RewriteLocalPathAsURL().(path)
111 return Endpointscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#{Urlscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#Url.: url, OriginalUrlscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#OriginalUrl.: url}
112 }
113
114 // Construct a new endpoint from a file URL
115 func EndpointFromFileUrlscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/EndpointFromFileUrl().(u *urlscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#) Endpointscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint# {
116 // just pass this straight through
117 return Endpointscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#{Urlscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#Url.: u.Stringscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#String().(), OriginalUrlscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Endpoint#OriginalUrl.: u.Stringscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#String().()}
118 }