-
Notifications
You must be signed in to change notification settings - Fork 670
feat(api): add support for Gitlab Deploy Token API #1052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
max-wittig
merged 1 commit into
python-gitlab:master
from
machine424:deploy-tokens-support
Apr 7, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
####### | ||
Deploy tokens | ||
####### | ||
|
||
Deploy tokens allow read-only access to your repository and registry images | ||
without having a user and a password. | ||
|
||
Deploy tokens | ||
============= | ||
|
||
This endpoint requires admin access. | ||
|
||
Reference | ||
--------- | ||
|
||
* v4 API: | ||
|
||
+ :class:`gitlab.v4.objects.DeployToken` | ||
+ :class:`gitlab.v4.objects.DeployTokenManager` | ||
+ :attr:`gitlab.Gitlab.deploytokens` | ||
|
||
* GitLab API: https://docs.gitlab.com/ce/api/deploy_tokens.html | ||
|
||
Examples | ||
-------- | ||
|
||
Use the ``list()`` method to list all deploy tokens across the GitLab instance. | ||
|
||
:: | ||
|
||
# List deploy tokens | ||
deploy_tokens = gl.deploytokens.list() | ||
|
||
Project deploy tokens | ||
===================== | ||
|
||
machine424 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This endpoint requires project maintainer access or higher. | ||
|
||
Reference | ||
--------- | ||
|
||
* v4 API: | ||
|
||
+ :class:`gitlab.v4.objects.ProjectDeployToken` | ||
+ :class:`gitlab.v4.objects.ProjectDeployTokenManager` | ||
+ :attr:`gitlab.v4.objects.Project.deploytokens` | ||
|
||
* GitLab API: https://docs.gitlab.com/ce/api/deploy_tokens.html#project-deploy-tokens | ||
|
||
Examples | ||
-------- | ||
|
||
List the deploy tokens for a project:: | ||
|
||
deploy_tokens = project.deploytokens.list() | ||
|
||
Create a new deploy token to access registry images of a project: | ||
|
||
In addition to required parameters ``name`` and ``scopes``, this method accepts | ||
the following parameters: | ||
|
||
* ``expires_at`` Expiration date of the deploy token. Does not expire if no value is provided. | ||
* ``username`` Username for deploy token. Default is ``gitlab+deploy-token-{n}`` | ||
|
||
|
||
:: | ||
|
||
deploy_token = project.deploytokens.create({'name': 'token1', 'scopes': ['read_registry'], 'username':'', 'expires_at':''}) | ||
# show its id | ||
print(deploy_token.id) | ||
# show the token value. Make sure you save it, you won't be able to access it again. | ||
print(deploy_token.token) | ||
|
||
.. warning:: | ||
|
||
With GitLab 12.9, even though ``username`` and ``expires_at`` are not required, they always have to be passed to the API. | ||
You can set them to empty strings, see: https://gitlab.com/gitlab-org/gitlab/-/issues/211878. | ||
Also, the ``username``'s value is ignored by the API and will be overriden with ``gitlab+deploy-token-{n}``, | ||
see: https://gitlab.com/gitlab-org/gitlab/-/issues/211963 | ||
These issues were fixed in GitLab 12.10. | ||
|
||
Remove a deploy token from the project:: | ||
|
||
deploy_token.delete() | ||
# or | ||
project.deploytokens.delete(deploy_token.id) | ||
|
||
|
||
Group deploy tokens | ||
=================== | ||
|
||
Reference | ||
--------- | ||
|
||
* v4 API: | ||
|
||
+ :class:`gitlab.v4.objects.GroupDeployToken` | ||
+ :class:`gitlab.v4.objects.GroupDeployTokenManager` | ||
+ :attr:`gitlab.v4.objects.Group.deploytokens` | ||
|
||
* GitLab API: https://docs.gitlab.com/ce/api/deploy_tokens.html#group-deploy-tokens | ||
|
||
Examples | ||
-------- | ||
|
||
List the deploy tokens for a group:: | ||
|
||
deploy_tokens = group.deploytokens.list() | ||
|
||
Create a new deploy token to access all repositories of all projects in a group: | ||
|
||
In addition to required parameters ``name`` and ``scopes``, this method accepts | ||
the following parameters: | ||
|
||
* ``expires_at`` Expiration date of the deploy token. Does not expire if no value is provided. | ||
* ``username`` Username for deploy token. Default is ``gitlab+deploy-token-{n}`` | ||
|
||
:: | ||
|
||
deploy_token = group.deploytokens.create({'name': 'token1', 'scopes': ['read_repository'], 'username':'', 'expires_at':''}) | ||
# show its id | ||
print(deploy_token.id) | ||
|
||
.. warning:: | ||
|
||
With GitLab 12.9, even though ``username`` and ``expires_at`` are not required, they always have to be passed to the API. | ||
You can set them to empty strings, see: https://gitlab.com/gitlab-org/gitlab/-/issues/211878. | ||
Also, the ``username``'s value is ignored by the API and will be overriden with ``gitlab+deploy-token-{n}``, | ||
see: https://gitlab.com/gitlab-org/gitlab/-/issues/211963 | ||
These issues were fixed in GitLab 12.10. | ||
|
||
Remove a deploy token from the group:: | ||
|
||
deploy_token.delete() | ||
# or | ||
group.deploytokens.delete(deploy_token.id) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.