-
Notifications
You must be signed in to change notification settings - Fork 671
Service account improvements #3109
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
Open
zapp42
wants to merge
6
commits into
python-gitlab:main
Choose a base branch
from
zapp42:service-account-improvements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ec818f3
feat(api): Add instance level service accounts (EE)
fc185a7
feat(api): Add support for group service account access tokens.
8d817a2
feat(unit): Add unit test for group_service_account delete
4405890
feat(unit): Add unit tests for service accounts
454b3ea
feat(api): Add API integration for group service account access tokens
cd9cfa8
feat(unit): Add unit test for group service account access tokens
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
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,76 @@ | ||
""" | ||
GitLab API: https://docs.gitlab.com/ee/api/user_service_accounts.html | ||
""" | ||
|
||
import pytest | ||
import responses | ||
|
||
create_service_account_defaults_content = { | ||
"id": 57, | ||
"username": "service_account_6018816a18e515214e0c34c2b33523fc", | ||
"name": "Service account user", | ||
"email": "service_account_6018816a18e515214e0c34c2b33523fc@noreply.gitlab.example.com", | ||
} | ||
|
||
|
||
create_service_account_content = { | ||
"id": 42, | ||
"username": "my_service_account", | ||
"name": "My Service account user", | ||
"email": "servicebot@example.com", | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def resp_create_service_account_defaults(): | ||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
method=responses.POST, | ||
url="http://localhost/api/v4/service_accounts", | ||
json=create_service_account_defaults_content, | ||
content_type="application/json", | ||
status=200, | ||
) | ||
|
||
yield rsps | ||
|
||
|
||
@pytest.fixture | ||
def resp_create_service_account(): | ||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
method=responses.POST, | ||
url="http://localhost/api/v4/service_accounts", | ||
json=create_service_account_content, | ||
content_type="application/json", | ||
status=200, | ||
) | ||
|
||
yield rsps | ||
|
||
|
||
def test_create_service_account_defaults(gl, resp_create_service_account_defaults): | ||
service_account = gl.service_accounts.create() | ||
assert service_account.id == 57 | ||
assert ( | ||
service_account.username == "service_account_6018816a18e515214e0c34c2b33523fc" | ||
) | ||
assert service_account.name == "Service account user" | ||
assert ( | ||
service_account.email | ||
== "service_account_6018816a18e515214e0c34c2b33523fc@noreply.gitlab.example.com" | ||
) | ||
|
||
|
||
def test_create_service_account(gl, resp_create_service_account): | ||
service_account = gl.service_accounts.create( | ||
{ | ||
"name": "My Service account user", | ||
"username": "my_service_account", | ||
"email": "servicebot@example.com", | ||
} | ||
) | ||
assert service_account.id == 42 | ||
assert service_account.username == "my_service_account" | ||
assert service_account.name == "My Service account user" | ||
assert service_account.email == "servicebot@example.com" |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ServiceAccount currently has no delete support; add ObjectDeleteMixin to the class and DeleteMixin to ServiceAccountManager so that instance-level service accounts can be deleted.
Copilot uses AI. Check for mistakes.