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
489a961e
Commit
489a961e
authored
Jan 06, 2022
by
Sri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move Google OAuth2 related private methods to BaseController
parent
b4c272ca
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
37 deletions
+35
-37
app/controllers/projects/google_cloud/base_controller.rb
app/controllers/projects/google_cloud/base_controller.rb
+35
-0
app/controllers/projects/google_cloud/service_accounts_controller.rb
...lers/projects/google_cloud/service_accounts_controller.rb
+0
-37
No files found.
app/controllers/projects/google_cloud/base_controller.rb
View file @
489a961e
...
...
@@ -23,4 +23,39 @@ class Projects::GoogleCloud::BaseController < Projects::ApplicationController
def
feature_flag_enabled!
access_denied!
unless
Feature
.
enabled?
(
:incubation_5mp_google_cloud
,
project
)
end
def
validate_gcp_token!
is_token_valid
=
GoogleApi
::
CloudPlatform
::
Client
.
new
(
token_in_session
,
nil
)
.
validate_token
(
expires_at_in_session
)
return
if
is_token_valid
return_url
=
project_google_cloud_index_path
(
project
)
state
=
generate_session_key_redirect
(
request
.
url
,
return_url
)
@authorize_url
=
GoogleApi
::
CloudPlatform
::
Client
.
new
(
nil
,
callback_google_api_auth_url
,
state:
state
).
authorize_url
redirect_to
@authorize_url
end
def
generate_session_key_redirect
(
uri
,
error_uri
)
GoogleApi
::
CloudPlatform
::
Client
.
new_session_key_for_redirect_uri
do
|
key
|
session
[
key
]
=
uri
session
[
:error_uri
]
=
error_uri
end
end
def
token_in_session
session
[
GoogleApi
::
CloudPlatform
::
Client
.
session_key_for_token
]
end
def
expires_at_in_session
session
[
GoogleApi
::
CloudPlatform
::
Client
.
session_key_for_expires_at
]
end
def
handle_gcp_error
(
error
,
project
)
Gitlab
::
ErrorTracking
.
track_exception
(
error
,
project_id:
project
.
id
)
@js_data
=
{
screen:
'gcp_error'
,
error:
error
.
to_s
}.
to_json
render
status: :unauthorized
,
template:
'projects/google_cloud/errors/gcp_error'
end
end
app/controllers/projects/google_cloud/service_accounts_controller.rb
View file @
489a961e
...
...
@@ -45,41 +45,4 @@ class Projects::GoogleCloud::ServiceAccountsController < Projects::GoogleCloud::
rescue
Google
::
Apis
::
ClientError
,
Google
::
Apis
::
ServerError
,
Google
::
Apis
::
AuthorizationError
=>
error
handle_gcp_error
(
error
,
project
)
end
private
def
validate_gcp_token!
is_token_valid
=
GoogleApi
::
CloudPlatform
::
Client
.
new
(
token_in_session
,
nil
)
.
validate_token
(
expires_at_in_session
)
return
if
is_token_valid
return_url
=
project_google_cloud_index_path
(
project
)
state
=
generate_session_key_redirect
(
request
.
url
,
return_url
)
@authorize_url
=
GoogleApi
::
CloudPlatform
::
Client
.
new
(
nil
,
callback_google_api_auth_url
,
state:
state
).
authorize_url
redirect_to
@authorize_url
end
def
generate_session_key_redirect
(
uri
,
error_uri
)
GoogleApi
::
CloudPlatform
::
Client
.
new_session_key_for_redirect_uri
do
|
key
|
session
[
key
]
=
uri
session
[
:error_uri
]
=
error_uri
end
end
def
token_in_session
session
[
GoogleApi
::
CloudPlatform
::
Client
.
session_key_for_token
]
end
def
expires_at_in_session
session
[
GoogleApi
::
CloudPlatform
::
Client
.
session_key_for_expires_at
]
end
def
handle_gcp_error
(
error
,
project
)
Gitlab
::
ErrorTracking
.
track_exception
(
error
,
project_id:
project
.
id
)
@js_data
=
{
screen:
'gcp_error'
,
error:
error
.
to_s
}.
to_json
render
status: :unauthorized
,
template:
'projects/google_cloud/errors/gcp_error'
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