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
e6234503
Commit
e6234503
authored
Dec 21, 2017
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove actions for async GCP project billing check
parent
eda14fa3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
222 deletions
+11
-222
app/controllers/projects/clusters/gcp_controller.rb
app/controllers/projects/clusters/gcp_controller.rb
+0
-31
config/routes/project.rb
config/routes/project.rb
+0
-2
spec/controllers/projects/clusters/gcp_controller_spec.rb
spec/controllers/projects/clusters/gcp_controller_spec.rb
+11
-189
No files found.
app/controllers/projects/clusters/gcp_controller.rb
View file @
e6234503
...
...
@@ -18,29 +18,6 @@ class Projects::Clusters::GcpController < Projects::ApplicationController
end
end
def
check
respond_to
do
|
format
|
format
.
json
do
Gitlab
::
PollingInterval
.
set_header
(
response
,
interval:
STATUS_POLLING_INTERVAL
)
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
render
json:
{
billing:
redis
.
get
(
CheckGcpProjectBillingWorker
.
redis_shared_state_key_for
(
token_in_session
))
}
end
end
format
.
html
{
render
:check
}
end
end
def
run_check
respond_to
do
|
format
|
format
.
json
do
CheckGcpProjectBillingWorker
.
perform_async
(
token_in_session
)
head
:no_content
end
end
end
def
new
@cluster
=
::
Clusters
::
Cluster
.
new
.
tap
do
|
cluster
|
cluster
.
build_provider_gcp
...
...
@@ -84,14 +61,6 @@ class Projects::Clusters::GcpController < Projects::ApplicationController
end
end
def
authorize_google_project_billing
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
unless
redis
.
get
(
CheckGcpProjectBillingWorker
.
redis_shared_state_key_for
(
token_in_session
))
==
'true'
CheckGcpProjectBillingWorker
.
perform_async
(
token_in_session
)
redirect_to
action:
'check'
end
end
end
def
token_in_session
@token_in_session
||=
...
...
config/routes/project.rb
View file @
e6234503
...
...
@@ -227,8 +227,6 @@ constraints(ProjectUrlConstrainer.new) do
get
'/gcp/new'
,
to:
'clusters/gcp#new'
get
'/gcp/login'
,
to:
'clusters/gcp#login'
get
'/gcp/check'
,
to:
'clusters/gcp#check'
post
'/gcp/check'
,
to:
'clusters/gcp#run_check'
post
'/gcp'
,
to:
'clusters/gcp#create'
end
end
...
...
spec/controllers/projects/clusters/gcp_controller_spec.rb
View file @
e6234503
...
...
@@ -62,132 +62,6 @@ describe Projects::Clusters::GcpController do
end
end
describe
'GET check'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
project
.
add_master
(
user
)
sign_in
(
user
)
end
describe
'functionality'
do
context
'when access token is valid'
do
before
do
stub_google_api_validate_token
end
context
'when redis has wanted billing status'
do
let
(
:token
)
{
'bogustoken'
}
before
do
redis_double
=
double
allow
(
Gitlab
::
Redis
::
SharedState
).
to
receive
(
:with
).
and_yield
(
redis_double
)
allow
(
redis_double
).
to
receive
(
:get
).
and_return
(
'true'
)
end
it
'should render json with billing status'
do
go
expect
(
response
).
to
have_http_status
(
:ok
)
expect
(
JSON
.
parse
(
response
.
body
)).
to
include
(
'billing'
=>
'true'
)
end
end
context
'when redis does not have billing status'
do
before
do
redis_double
=
double
allow
(
Gitlab
::
Redis
::
SharedState
).
to
receive
(
:with
).
and_yield
(
redis_double
)
allow
(
redis_double
).
to
receive
(
:get
).
and_return
(
nil
)
end
it
'should render json with null billing status'
do
go
expect
(
response
).
to
have_http_status
(
:ok
)
expect
(
JSON
.
parse
(
response
.
body
)).
to
include
(
'billing'
=>
nil
)
end
end
end
context
'when access token is expired'
do
before
do
stub_google_api_expired_token
end
it
{
expect
(
go
).
to
redirect_to
(
gcp_login_project_clusters_path
(
project
))
}
end
context
'when access token is not stored in session'
do
it
{
expect
(
go
).
to
redirect_to
(
gcp_login_project_clusters_path
(
project
))
}
end
end
describe
'security'
do
it
{
expect
{
go
}.
to
be_allowed_for
(
:admin
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:owner
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:master
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:developer
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:reporter
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:guest
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:user
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:external
)
}
end
def
go
get
:check
,
namespace_id:
project
.
namespace
,
project_id:
project
,
format: :json
end
end
describe
'POST check'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
project
.
add_master
(
user
)
sign_in
(
user
)
end
describe
'functionality'
do
context
'when access token is valid'
do
before
do
stub_google_api_validate_token
end
it
'calls check worker asynchronously'
do
expect
(
CheckGcpProjectBillingWorker
).
to
receive
(
:perform_async
)
expect
(
go
).
to
have_http_status
(
:no_content
)
end
end
context
'when access token is expired'
do
before
do
stub_google_api_expired_token
end
it
{
expect
(
go
).
to
redirect_to
(
gcp_login_project_clusters_path
(
project
))
}
end
context
'when access token is not stored in session'
do
it
{
expect
(
go
).
to
redirect_to
(
gcp_login_project_clusters_path
(
project
))
}
end
end
describe
'security'
do
it
{
expect
{
go
}.
to
be_allowed_for
(
:admin
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:owner
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:master
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:developer
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:reporter
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:guest
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:user
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:external
)
}
end
def
go
post
:run_check
,
namespace_id:
project
.
namespace
,
project_id:
project
,
format: :json
end
end
describe
'GET new'
do
describe
'functionality'
do
let
(
:user
)
{
create
(
:user
)
}
...
...
@@ -202,36 +76,10 @@ describe Projects::Clusters::GcpController do
stub_google_api_validate_token
end
context
'when google project billing status is true'
do
before
do
stub_google_project_billing_status
end
it
'has new object'
do
go
expect
(
assigns
(
:cluster
)).
to
be_an_instance_of
(
Clusters
::
Cluster
)
end
end
context
'when google project billing status is not true'
do
before
do
redis_double
=
double
allow
(
Gitlab
::
Redis
::
SharedState
).
to
receive
(
:with
).
and_yield
(
redis_double
)
allow
(
redis_double
).
to
receive
(
:get
).
and_return
(
nil
)
end
it
'redirects to check page'
do
allow
(
CheckGcpProjectBillingWorker
).
to
receive
(
:perform_async
)
expect
(
go
).
to
redirect_to
(
gcp_check_project_clusters_path
(
project
))
end
it
'calls gcp project billing check worker'
do
expect
(
CheckGcpProjectBillingWorker
).
to
receive
(
:perform_async
)
it
'has new object'
do
go
go
end
expect
(
assigns
(
:cluster
)).
to
be_an_instance_of
(
Clusters
::
Cluster
)
end
end
...
...
@@ -289,40 +137,14 @@ describe Projects::Clusters::GcpController do
stub_google_api_validate_token
end
context
'when google project billing status is true'
do
before
do
stub_google_project_billing_status
end
context
'when creates a cluster on gke'
do
it
'creates a new cluster'
do
expect
(
ClusterProvisionWorker
).
to
receive
(
:perform_async
)
expect
{
go
}.
to
change
{
Clusters
::
Cluster
.
count
}
.
and
change
{
Clusters
::
Providers
::
Gcp
.
count
}
expect
(
response
).
to
redirect_to
(
project_cluster_path
(
project
,
project
.
clusters
.
first
))
expect
(
project
.
clusters
.
first
).
to
be_gcp
expect
(
project
.
clusters
.
first
).
to
be_kubernetes
end
end
end
context
'when google project billing status is not true'
do
before
do
redis_double
=
double
allow
(
Gitlab
::
Redis
::
SharedState
).
to
receive
(
:with
).
and_yield
(
redis_double
)
allow
(
redis_double
).
to
receive
(
:get
).
and_return
(
nil
)
end
it
'redirects to check page'
do
allow
(
CheckGcpProjectBillingWorker
).
to
receive
(
:perform_async
)
expect
(
go
).
to
redirect_to
(
gcp_check_project_clusters_path
(
project
))
end
it
'calls gcp project billing check worker'
do
expect
(
CheckGcpProjectBillingWorker
).
to
receive
(
:perform_async
)
go
context
'when creates a cluster on gke'
do
it
'creates a new cluster'
do
expect
(
ClusterProvisionWorker
).
to
receive
(
:perform_async
)
expect
{
go
}.
to
change
{
Clusters
::
Cluster
.
count
}
.
and
change
{
Clusters
::
Providers
::
Gcp
.
count
}
expect
(
response
).
to
redirect_to
(
project_cluster_path
(
project
,
project
.
clusters
.
first
))
expect
(
project
.
clusters
.
first
).
to
be_gcp
expect
(
project
.
clusters
.
first
).
to
be_kubernetes
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