| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -115,3 +115,22 @@ | |||
| 115 | 115 | # or | |
| 116 | 116 | user.customeattributes.delete(attr_key) | |
| 117 | 117 | # end ca delete | |
| 118 | + | ||
| 119 | + # it list | ||
| 120 | + i_t = user.impersonationtokens.list(state='active') | ||
| 121 | + i_t = user.impersonationtokens.list(state='inactive') | ||
| 122 | + # end it list | ||
| 123 | + | ||
| 124 | + # it get | ||
| 125 | + i_t = user.impersonationtokens.get(i_t_id) | ||
| 126 | + # end it get | ||
| 127 | + | ||
| 128 | + # it create | ||
| 129 | + i_t = user.impersonationtokens.create({'name': 'token1', 'scopes': ['api']}) | ||
| 130 | + # use the token to create a new gitlab connection | ||
| 131 | + user_gl = gitlab.Gitlab(gitlab_url, private_token=i_t.token) | ||
| 132 | + # end it create | ||
| 133 | + | ||
| 134 | + # it delete | ||
| 135 | + i_t.delete() | ||
| 136 | + # end it delete | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -106,6 +106,42 @@ Delete a custom attribute for a user: | |||
| 106 | 106 | :start-after: # ca list | |
| 107 | 107 | :end-before: # end ca list | |
| 108 | 108 | ||
| 109 | + User impersonation tokens | ||
| 110 | + ========================= | ||
| 111 | + | ||
| 112 | + References | ||
| 113 | + ---------- | ||
| 114 | + | ||
| 115 | + * v4 API: | ||
| 116 | + | ||
| 117 | + + :class:`gitlab.v4.objects.UserImpersonationToken` | ||
| 118 | + + :class:`gitlab.v4.objects.UserImpersonationTokenManager` | ||
| 119 | + + :attr:`gitlab.v4.objects.User.impersontaiontokens` | ||
| 120 | + | ||
| 121 | + List impersonation tokens for a user: | ||
| 122 | + | ||
| 123 | + .. literalinclude:: users.py | ||
| 124 | + :start-after: # it list | ||
| 125 | + :end-before: # end it list | ||
| 126 | + | ||
| 127 | + Get an impersonation token for a user: | ||
| 128 | + | ||
| 129 | + .. literalinclude:: users.py | ||
| 130 | + :start-after: # it get | ||
| 131 | + :end-before: # end it get | ||
| 132 | + | ||
| 133 | + Create and use an impersonation token for a user: | ||
| 134 | + | ||
| 135 | + .. literalinclude:: users.py | ||
| 136 | + :start-after: # it create | ||
| 137 | + :end-before: # end it create | ||
| 138 | + | ||
| 139 | + Revoke (delete) an impersonation token for a user: | ||
| 140 | + | ||
| 141 | + .. literalinclude:: users.py | ||
| 142 | + :start-after: # it list | ||
| 143 | + :end-before: # end it list | ||
| 144 | + | ||
| 109 | 145 | Current User | |
| 110 | 146 | ============ | |
| 111 | 147 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -175,6 +175,18 @@ class UserKeyManager(GetFromListMixin, CreateMixin, DeleteMixin, RESTManager): | |||
| 175 | 175 | _create_attrs = (('title', 'key'), tuple()) | |
| 176 | 176 | ||
| 177 | 177 | ||
| 178 | + class UserImpersonationToken(ObjectDeleteMixin, RESTObject): | ||
| 179 | + pass | ||
| 180 | + | ||
| 181 | + | ||
| 182 | + class UserImpersonationTokenManager(NoUpdateMixin, RESTManager): | ||
| 183 | + _path = '/users/%(user_id)s/impersonation_tokens' | ||
| 184 | + _obj_cls = UserImpersonationToken | ||
| 185 | + _from_parent_attrs = {'user_id': 'id'} | ||
| 186 | + _create_attrs = (('name', 'scopes'), ('expires_at',)) | ||
| 187 | + _list_filters = ('state',) | ||
| 188 | + | ||
| 189 | + | ||
| 178 | 190 | class UserProject(RESTObject): | |
| 179 | 191 | pass | |
| 180 | 192 | ||
@@ -198,6 +210,7 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject): | |||
| 198 | 210 | ('customattributes', 'UserCustomAttributeManager'), | |
| 199 | 211 | ('emails', 'UserEmailManager'), | |
| 200 | 212 | ('gpgkeys', 'UserGPGKeyManager'), | |
| 213 | + ('impersonationtokens', 'UserImpersonationTokenManager'), | ||
| 201 | 214 | ('keys', 'UserKeyManager'), | |
| 202 | 215 | ('projects', 'UserProjectManager'), | |
| 203 | 216 | ) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -145,6 +145,17 @@ | |||
| 145 | 145 | attr.delete() | |
| 146 | 146 | assert(len(new_user.customattributes.list()) == 0) | |
| 147 | 147 | ||
| 148 | + # impersonation tokens | ||
| 149 | + user_token = new_user.impersonationtokens.create( | ||
| 150 | + {'name': 'token1', 'scopes': ['api', 'read_user']}) | ||
| 151 | + l = new_user.impersonationtokens.list(state='active') | ||
| 152 | + assert(len(l) == 1) | ||
| 153 | + user_token.delete() | ||
| 154 | + l = new_user.impersonationtokens.list(state='active') | ||
| 155 | + assert(len(l) == 0) | ||
| 156 | + l = new_user.impersonationtokens.list(state='inactive') | ||
| 157 | + assert(len(l) == 1) | ||
| 158 | + | ||
| 148 | 159 | new_user.delete() | |
| 149 | 160 | foobar_user.delete() | |
| 150 | 161 | assert(len(gl.users.list()) == 3) | |
@@ -485,7 +496,7 @@ | |||
| 485 | 496 | p_b = admin_project.protectedbranches.create({'name': '*-stable'}) | |
| 486 | 497 | assert(p_b.name == '*-stable') | |
| 487 | 498 | p_b = admin_project.protectedbranches.get('*-stable') | |
| 488 | - # master is protected by default | ||
| 499 | + # master is protected by default when a branch has been created | ||
| 489 | 500 | assert(len(admin_project.protectedbranches.list()) == 2) | |
| 490 | 501 | admin_project.protectedbranches.delete('master') | |
| 491 | 502 | p_b.delete() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments