Skip to content
Snippets Groups Projects
Verified Commit 59c7f46e authored by Matija Čupić's avatar Matija Čupić
Browse files

Remove actions for async GCP project billing check

parent ab2326f8
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
Loading
Loading
@@ -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 ||=
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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) }
Loading
Loading
@@ -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
 
Loading
Loading
@@ -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
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment