summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatija Čupić <matteeyah@gmail.com>2017-12-21 19:02:06 +0100
committerMatija Čupić <matteeyah@gmail.com>2017-12-21 19:02:06 +0100
commit59c7f46e2aa33d633fdc3f78c8a4faa792e40972 (patch)
treee121889226f79c2e4cb04cfbcb1e85a65b928aec
parentab2326f87cab96abc91e10d4a1602a5d2b78f1e8 (diff)
downloadgitlab-ce-59c7f46e2aa33d633fdc3f78c8a4faa792e40972.tar.gz
Remove actions for async GCP project billing check
-rw-r--r--app/controllers/projects/clusters/gcp_controller.rb31
-rw-r--r--config/routes/project.rb2
-rw-r--r--spec/controllers/projects/clusters/gcp_controller_spec.rb200
3 files changed, 11 insertions, 222 deletions
diff --git a/app/controllers/projects/clusters/gcp_controller.rb b/app/controllers/projects/clusters/gcp_controller.rb
index 66a851c52c7..0c8305480ae 100644
--- a/app/controllers/projects/clusters/gcp_controller.rb
+++ b/app/controllers/projects/clusters/gcp_controller.rb
@@ -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 ||=
diff --git a/config/routes/project.rb b/config/routes/project.rb
index b315b53f293..239b5480321 100644
--- a/config/routes/project.rb
+++ b/config/routes/project.rb
@@ -192,8 +192,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
diff --git a/spec/controllers/projects/clusters/gcp_controller_spec.rb b/spec/controllers/projects/clusters/gcp_controller_spec.rb
index 4fa798c5856..485b67de30a 100644
--- a/spec/controllers/projects/clusters/gcp_controller_spec.rb
+++ b/spec/controllers/projects/clusters/gcp_controller_spec.rb
@@ -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