Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
7ecb563e
Commit
7ecb563e
authored
Jun 23, 2021
by
Sanad Liaquat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create and use PersonalAccessTokenCache
parent
beb0ca0f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
9 deletions
+33
-9
qa/qa.rb
qa/qa.rb
+1
-0
qa/qa/resource/personal_access_token.rb
qa/qa/resource/personal_access_token.rb
+15
-9
qa/qa/resource/personal_access_token_cache.rb
qa/qa/resource/personal_access_token_cache.rb
+17
-0
No files found.
qa/qa.rb
View file @
7ecb563e
...
...
@@ -87,6 +87,7 @@ module QA
autoload
:CiVariable
,
'qa/resource/ci_variable'
autoload
:Runner
,
'qa/resource/runner'
autoload
:PersonalAccessToken
,
'qa/resource/personal_access_token'
autoload
:PersonalAccessTokenCache
,
'qa/resource/personal_access_token_cache'
autoload
:ProjectAccessToken
,
'qa/resource/project_access_token'
autoload
:User
,
'qa/resource/user'
autoload
:ProjectMilestone
,
'qa/resource/project_milestone'
...
...
qa/qa/resource/personal_access_token.rb
View file @
7ecb563e
...
...
@@ -11,21 +11,25 @@ module QA
# This *could* be different than the api_client.user or the api_user provided by the QA::Resource::ApiFabricator module
attr_writer
:user
attribute
:token
do
Page
::
Profile
::
PersonalAccessTokens
.
perform
(
&
:created_access_token
)
end
attribute
:token
# Only Admins can create PAT via the API.
# If Runtime::Env.admin_personal_access_token is provided, fabricate via the API,
# else, fabricate via the browser.
def
fabricate_via_api!
if
Runtime
::
Env
.
admin_personal_access_token
&&
!
@user
.
nil?
self
.
api_client
=
Runtime
::
API
::
Client
.
as_admi
n
@token
=
QA
::
Resource
::
PersonalAccessTokenCache
.
get_token_for_username
(
user
.
username
)
return
if
@toke
n
super
else
fabricate!
end
resource
=
if
Runtime
::
Env
.
admin_personal_access_token
&&
!
@user
.
nil?
self
.
api_client
=
Runtime
::
API
::
Client
.
as_admin
super
else
fabricate!
end
QA
::
Resource
::
PersonalAccessTokenCache
.
set_token_for_username
(
user
.
username
,
self
.
token
)
resource
end
# When a user is not provided, use default user
...
...
@@ -66,6 +70,8 @@ module QA
# Expire in 2 days just in case the token is created just before midnight
token_page
.
fill_expiry_date
(
Time
.
now
.
utc
.
to_date
+
2
)
token_page
.
click_create_token_button
self
.
token
=
Page
::
Profile
::
PersonalAccessTokens
.
perform
(
&
:created_access_token
)
end
end
end
...
...
qa/qa/resource/personal_access_token_cache.rb
0 → 100644
View file @
7ecb563e
# frozen_string_literal: true
module
QA
module
Resource
class
PersonalAccessTokenCache
@personal_access_tokens
=
{}
def
self
.
get_token_for_username
(
username
)
@personal_access_tokens
[
username
]
end
def
self
.
set_token_for_username
(
username
,
token
)
@personal_access_tokens
[
username
]
=
token
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment