Skip to content

Commit 36791b8

Browse files
authored
Merge pull request #10608 from aetertinas9/main
🌱 GitLab can use both Path and RawPath
2 parents 3d22daf + f33bdf4 commit 36791b8

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

cmd/clusterctl/client/repository/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func repositoryFactory(ctx context.Context, providerConfig config.Provider, conf
186186
}
187187

188188
// if the url is a GitLab repository
189-
if strings.HasPrefix(rURL.Host, gitlabHostPrefix) && strings.HasPrefix(rURL.RawPath, gitlabPackagesAPIPrefix) {
189+
if strings.HasPrefix(rURL.Host, gitlabHostPrefix) && strings.HasPrefix(rURL.EscapedPath(), gitlabPackagesAPIPrefix) {
190190
repo, err := NewGitLabRepository(providerConfig, configVariablesClient)
191191
if err != nil {
192192
return nil, errors.Wrap(err, "error creating the GitLab repository client")

cmd/clusterctl/client/repository/repository_gitlab.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ func NewGitLabRepository(providerConfig config.Provider, configVariablesClient c
6666
return nil, errors.Wrap(err, "invalid url")
6767
}
6868

69-
urlSplit := strings.Split(strings.TrimPrefix(rURL.RawPath, "/"), "/")
69+
urlSplit := strings.Split(strings.TrimPrefix(rURL.EscapedPath(), "/"), "/")
7070

7171
// Check if the url is a Gitlab repository
7272
if rURL.Scheme != httpsScheme ||
7373
len(urlSplit) != 9 ||
74-
!strings.HasPrefix(rURL.RawPath, gitlabPackagesAPIPrefix) ||
74+
!strings.HasPrefix(rURL.EscapedPath(), gitlabPackagesAPIPrefix) ||
7575
urlSplit[4] != gitlabPackagesAPIPackages ||
7676
urlSplit[5] != gitlabPackagesAPIGeneric {
7777
return nil, errors.New("invalid url: a GitLab repository url should be in the form https://{host}/api/v4/projects/{projectSlug}/packages/generic/{packageName}/{defaultVersion}/{componentsPath}")

cmd/clusterctl/client/repository/repository_gitlab_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func Test_gitLabRepository_getFile(t *testing.T) {
154154

155155
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
156156
goproxytest.HTTPTestMethod(t, r, "GET")
157-
if r.URL.RawPath == "/api/v4/projects/group%2Fproject/packages/generic/my-package/v0.4.1/file.yaml" {
157+
if r.URL.EscapedPath() == "/api/v4/projects/group%2Fproject/packages/generic/my-package/v0.4.1/file.yaml" {
158158
w.Header().Set("Content-Type", "application/octet-stream")
159159
w.Header().Set("Content-Disposition", "attachment; filename=file.yaml")
160160
fmt.Fprint(w, "content")

0 commit comments

Comments
 (0)