简体   繁体   中英

How to delete a GitLab repository using curl?

I am able to achieve this with GitHub. But I am unable to do the same with GitLab. Currently, what I have is:

curl -u "$user:$token" -H "Content-Type:application/json" -H "PRIVATE-TOKEN:$token" \
-X DELETE https://git.lab.com/api/v4/projects/$repo_name

And then I get this error:

curl: (35) error:14077438:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error

I already have a working script using curl to create a GitLab repository on the command line so my curl is working fine. I just needed the delete part.

Removing a project by project path

curl -H 'Content-Type: application/json' -H 'Private-Token: $privatetoken' \
-X DELETE https://gitlab.com/api/v4/projects/$namespace%2F$projectname

Possible causes for the SSL error

Namespaced path encoding

The URI is split by the forward slashes on the server side and then the resulting path elements are categorized.

Since the forward slash is treated as a special character, we need to URL encode it if we want to include it as a URI path element, so the server does not try to split it.

How this could cause a problem is more evident if you are executing a request with additional parameters behind the ID.

In the following examples $namespace is foo and $projectname is bar .

Good

Request: GET /projects/foo%2Fbar/users

URI path elements:

  • projects - the resources the call will be executed on
  • foo%2Fbar - the specific resource (project) name is foo/bar (after URL decoding it)
  • users - the resources to return

Bad

Request: GET /projects/foo/bar/users

URI path elements:

  • projects - the resources the call will be executed on
  • foo - the specific resource (project) name is foo (no such project, namespace is missing)
  • bar - the resource to query or action to execute (no such resource or action)
  • users - additional query parameter (parent resource or action does not exist in the first place)

API endpoint

If you are using the public GitLab hosted at https://gitlab.com/ , you should use the gitlab.com domain name instead of git.lab.com , the latter is not owned by GitLab Inc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM