- Notifications
You must be signed in to change notification settings - Fork676
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
ec818f3
fc185a7
8d817a2
4405890
454b3ea
cd9cfa8
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,14 +1,55 @@ | ||||||||||||||||||||||
fromgitlab.baseimportRESTObject | ||||||||||||||||||||||
fromgitlab.mixinsimport ( | ||||||||||||||||||||||
CreateMixin, | ||||||||||||||||||||||
DeleteMixin, | ||||||||||||||||||||||
ListMixin, | ||||||||||||||||||||||
ObjectDeleteMixin, | ||||||||||||||||||||||
ObjectRotateMixin, | ||||||||||||||||||||||
RotateMixin, | ||||||||||||||||||||||
) | ||||||||||||||||||||||
fromgitlab.typesimportArrayAttribute,RequiredOptional | ||||||||||||||||||||||
__all__= [ | ||||||||||||||||||||||
"ServiceAccount", | ||||||||||||||||||||||
"ServiceAccountManager", | ||||||||||||||||||||||
"GroupServiceAccount", | ||||||||||||||||||||||
"GroupServiceAccountManager", | ||||||||||||||||||||||
"GroupServiceAccountAccessToken", | ||||||||||||||||||||||
"GroupServiceAccountAccessTokenManager", | ||||||||||||||||||||||
] | ||||||||||||||||||||||
classGroupServiceAccountAccessToken(ObjectRotateMixin,RESTObject): | ||||||||||||||||||||||
pass | ||||||||||||||||||||||
classGroupServiceAccountAccessTokenManager( | ||||||||||||||||||||||
CreateMixin[GroupServiceAccountAccessToken], | ||||||||||||||||||||||
RotateMixin[GroupServiceAccountAccessToken], | ||||||||||||||||||||||
): | ||||||||||||||||||||||
_path="/groups/{group_id}/service_accounts/{user_id}/personal_access_tokens" | ||||||||||||||||||||||
_obj_cls=GroupServiceAccountAccessToken | ||||||||||||||||||||||
_from_parent_attrs= {"group_id":"group_id","user_id":"id"} | ||||||||||||||||||||||
_create_attrs=RequiredOptional( | ||||||||||||||||||||||
required=("name","scopes"),optional=("expires_at",) | ||||||||||||||||||||||
) | ||||||||||||||||||||||
_types= {"scopes":ArrayAttribute} | ||||||||||||||||||||||
classServiceAccount(RESTObject): | ||||||||||||||||||||||
pass | ||||||||||||||||||||||
classServiceAccountManager(CreateMixin[ServiceAccount],ListMixin[ServiceAccount]): | ||||||||||||||||||||||
Comment on lines +39 to +43 CopilotAI |
classServiceAccount(RESTObject): | |
pass | |
classServiceAccountManager(CreateMixin[ServiceAccount],ListMixin[ServiceAccount]): | |
classServiceAccount(ObjectDeleteMixin,RESTObject): | |
pass | |
classServiceAccountManager(CreateMixin[ServiceAccount],DeleteMixin[ServiceAccount],ListMixin[ServiceAccount]): |
Copilot uses AI. Check for mistakes.
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" |