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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
e911a0f8
Commit
e911a0f8
authored
Mar 16, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose CloudPlatform::Client#projects_list as GcpController#list_projects
parent
45b3bcc3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
1 deletion
+39
-1
app/controllers/projects/clusters/gcp_controller.rb
app/controllers/projects/clusters/gcp_controller.rb
+8
-1
config/routes/project.rb
config/routes/project.rb
+1
-0
spec/controllers/projects/clusters/gcp_controller_spec.rb
spec/controllers/projects/clusters/gcp_controller_spec.rb
+30
-0
No files found.
app/controllers/projects/clusters/gcp_controller.rb
View file @
e911a0f8
class
Projects::Clusters::GcpController
<
Projects
::
ApplicationController
class
Projects::Clusters::GcpController
<
Projects
::
ApplicationController
before_action
:authorize_read_cluster!
before_action
:authorize_read_cluster!
before_action
:authorize_google_api
,
except:
[
:login
]
before_action
:authorize_google_api
,
except:
[
:login
,
:list_projects
]
before_action
:authorize_google_project_billing
,
only:
[
:new
,
:create
]
before_action
:authorize_google_project_billing
,
only:
[
:new
,
:create
]
before_action
:authorize_create_cluster!
,
only:
[
:new
,
:create
]
before_action
:authorize_create_cluster!
,
only:
[
:new
,
:create
]
before_action
:verify_billing
,
only:
[
:create
]
before_action
:verify_billing
,
only:
[
:create
]
...
@@ -35,6 +35,13 @@ class Projects::Clusters::GcpController < Projects::ApplicationController
...
@@ -35,6 +35,13 @@ class Projects::Clusters::GcpController < Projects::ApplicationController
end
end
end
end
def
list_projects
projects
=
GoogleApi
::
CloudPlatform
::
Client
.
new
(
token_in_session
,
nil
).
projects_list
respond_to
do
|
format
|
format
.
json
{
render
status: :ok
,
json:
{
projects:
projects
}
}
end
end
private
private
def
verify_billing
def
verify_billing
...
...
config/routes/project.rb
View file @
e911a0f8
...
@@ -200,6 +200,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
...
@@ -200,6 +200,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
get
'/gcp/new'
,
to:
'clusters/gcp#new'
get
'/gcp/new'
,
to:
'clusters/gcp#new'
get
'/gcp/login'
,
to:
'clusters/gcp#login'
get
'/gcp/login'
,
to:
'clusters/gcp#login'
get
'/gcp/list_projects'
,
to:
'clusters/gcp#list_projects'
post
'/gcp'
,
to:
'clusters/gcp#create'
post
'/gcp'
,
to:
'clusters/gcp#create'
end
end
end
end
...
...
spec/controllers/projects/clusters/gcp_controller_spec.rb
View file @
e911a0f8
...
@@ -199,4 +199,34 @@ describe Projects::Clusters::GcpController do
...
@@ -199,4 +199,34 @@ describe Projects::Clusters::GcpController do
post
:create
,
params
.
merge
(
namespace_id:
project
.
namespace
,
project_id:
project
)
post
:create
,
params
.
merge
(
namespace_id:
project
.
namespace
,
project_id:
project
)
end
end
end
end
describe
'GET list_projects'
do
describe
'functionality'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:api_response
)
{
[
project_id:
'test-project-1234'
]
}
before
do
project
.
add_master
(
user
)
sign_in
(
user
)
allow_any_instance_of
(
GoogleApi
::
CloudPlatform
::
Client
).
to
receive
(
:projects_list
).
and_return
(
api_response
)
end
it
'calls the Google Cloud Platform projects_list'
do
expect_any_instance_of
(
GoogleApi
::
CloudPlatform
::
Client
).
to
receive
(
:projects_list
)
go
end
it
'renders the response as json'
do
go
expect
(
response
.
body
).
to
eq
({
projects:
api_response
}.
to_json
)
end
end
def
go
get
:list_projects
,
namespace_id:
project
.
namespace
,
project_id:
project
,
format: :json
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