Commit e911a0f8 authored by Matija Čupić's avatar Matija Čupić

Expose CloudPlatform::Client#projects_list as GcpController#list_projects

parent 45b3bcc3
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
......
...@@ -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
......
...@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment